reactmore-tech / google-analytics
Codeigniter 4 的 Google Analytics 库
1.0.0
2023-02-26 16:51 UTC
Requires
- php: ^7.4 || ^8.0
- ext-json: *
- google/apiclient: ^2.12.6
- psr/http-message: ~1.0
Requires (Dev)
- codeigniter/coding-standard: ^1.5
- codeigniter4/framework: ^4.2.9
- friendsofphp/php-cs-fixer: ^3.11
- phpmd/phpmd: @stable
- phpunit/phpunit: *
README
安装
composer require reactmore-tech/google-analytics
配置 .env
VIEW_ID=215165900
SERVICE_CREDENTIALS_JSON= 'google_analytic_services.json'
使用
service('GoogleAnalytics'); $GA = service('GoogleAnalytics'); $Analytics = new Analytics(); echo '<pre>'; $GA->Fetching()->fetchTopBrowsers(PeriodTime::days(10)) //Result Array echo '</pre>'; // Method $Analytics = new Analytics(); // Fetch Users and New Users $GA->Fetching()->fetchUserTypes(Period::days(7)); // Get Data Top Browser used visitor $GA->Fetching()->fetchTopBrowsers(Period::days(7)); // Get Data Refferer Page $GA->Fetching()->fetchTopReferrers(Period::days(7)); // Populer Pages $GA->Fetching()->fetchMostVisitedPages(Period::days(7)); // Get Visitor and Pageviews $GA->Fetching()->fetchTotalVisitorsAndPageViews(Period::days(7));
示例输出数组
array(2) {
[0]=>
array(2) {
["type"]=>
string(11) "New Visitor"
["sessions"]=>
int(2581)
}
[1]=>
array(2) {
["type"]=>
string(17) "Returning Visitor"
["sessions"]=>
int(1215)
}
}
// Custom Query $Analytics->Fetching()->performQuery($period, $metrix, $other = array()); // Example $Analytics->Fetching()->performQuery(Period::days(7), 'ga:sessions', ['dimensions' => 'ga:country', 'sort' => '-ga:sessions'])->getRows();
示例输出原始数组
array(30) {
[0]=>
array(2) {
[0]=>
string(9) "Indonesia"
[1]=>
string(4) "3534"
}
[1]=>
array(2) {
[0]=>
string(11) "Afghanistan"
[1]=>
string(2) "96"
}
[2]=>
array(2) {
[0]=>
string(13) "United States"
[1]=>
string(2) "88"
}
}
在此应用上探索查询 ga-dev-tools