atlasmobile / yii2-ga
yii2 google analytics 组件
1.0.4
2016-03-10 14:12 UTC
Requires
- google/apiclient: 1.*
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2024-09-26 01:00:47 UTC
README
Yii2 的 Google Analytics 组件
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一:
php composer.phar require --prefer-dist atlasmobile/yii2-ga "*"
或将以下内容添加到您的 composer.json 文件的 require 部分:
"atlasmobile/yii2-ga": "*"
应用参数
要使用此扩展,请在您的应用参数中添加以下代码
return [ ... 'googleAnalytics' => [ 'developerKey' => '', // Public key 'clientId' => 'xxx.apps.googleusercontent.com', // Client ID 'analyticsId' => 'ga:xxxxxxxxx', //(It is the number at the end of the URL starting with p: https://www.google.com/analytics/web/#home/a33443w112345pXXXXXXXX/) 'serviceAccountName' => 'xxx@xxx.gserviceaccount.com', // Email address 'privateKeyPath' => '', //path to private key in p12 format ], ];
将 serviceAccountName (xxx@dxxx.gserviceaccount.com) 添加为您的 Analyics 属性的新用户。
使用方法
use atlasmobile\analytics\Analytics; class Test { public function example() { $analytics = new Analytics(); $analytics->startDate = ''; $analytics->endDate = ''; $sessionsData = $analytics->getSessions(); $visitorsData = $analytics->getUsers(); $pageViewsData = $analytics->getPageViews(); $avgSessionsDurationData = $analytics->getAvgSessionDuration(); $countriesData = $analytics->getCountries(); } }
默认情况下,'startDate' 和 'endDate' 参数设置为昨天