定制 ozankurt/google-analytics 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ozankurt/google-analytics

最新稳定版本:v2.0.1

Composer 安装命令:

composer require ozankurt/google-analytics

包简介

Laravel Google Analytics

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License

Connecting to your analytics account and getting whatever data you need was never this easy. 😎

Installation

Step 1

Add ozankurt/google-analytics to your composer requirements.

composer require ozankurt/google-analytics

Step 2

Configure ozankurt/google-core package by following its README.

Step 3

Select the Analytics API

Select the Analytics API

Enable it

Enable It

Step 4

Add analytics scope to your scopes array to the configurations in ozankurt/google-core package.

'scopes' => [
	'https://www.googleapis.com/auth/analytics.readonly',
],

Usage (Laravel)

Step 1

Add analytics.viewId to your config/google.php.

    /**
     * View ID can be found in `http://google.com/analytics` under the `Admin` tab on navigation.
     *
     * Select `Account`, `Property` and `View`. You will see a `View Settings` link.
     */
    'analytics' => [
        'viewId' => 'ga:12345678',
    ],

Controller Example

use Kurt\Google\Analytics\Analytics as GoogleAnalytics;

class GoogleController extends Controller
{
    private $ga;

    function __construct(GoogleAnalytics $ga) {
        $this->ga = $ga;
    }

    public function index()
    {
        $results = $this->ga->getUsersAndPageviewsOverTime();

        var_dump($results);
    }
}

Usage (Pure PHP)

Example

<?php

require 'vendor/autoload.php';

use Kurt\Google\Core\Core;
use Kurt\Google\Analytics\Analytics;

$googleCore = new Core([
    'applicationName'       => 'Google API Wrapper Demo',
    'jsonFilePath'          => 'Google API Wrapper Demo-174e172143a9.json',
    'scopes' => [
        Google_Service_Analytics::ANALYTICS_READONLY,
    ],
    'analytics' => [
        'viewId' => 'ga:97783314'
    ],
]);

$analytics = new Analytics($googleCore);

$results = $analytics->getUsersAndPageviewsOverTime();

var_dump($results);

Results

Both of these examples will give a result like this.

The result of GoogleController@index should look like this:

array (size=2)
    'cols' => 
        array (size=2)
            0 => string 'ga:sessions' (length=11)
            1 => string 'ga:pageviews' (length=12)
    'rows' => 
        array (size=1)
            0 => array (size=2)
                'ga:sessions' => string '100' (length=3)
                'ga:pageviews' => string '250' (length=3)

License

This open-sourced is software licensed under the MIT license.

统计信息

  • 总下载量: 16.86k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 76
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 75
  • Watchers: 5
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-07