fr30n/ganalytics
Composer 安装命令:
composer require fr30n/ganalytics
包简介
A Laravel 5 package to retrieve Google Analytics data.
README 文档
README
Using this package you can easily retrieve data from Google Analytics.
Here are a few examples of the provided methods:
use GAnalytics; use Fr3on\GAnalytics\Period; //fetch the most visited pages for today and the past week GAnalytics::fetchMostVisitedPages(Period::days(7)); //fetch visitors and page views for the past week GAnalytics::fetchVisitorsAndPageViews(Period::days(7));
Most methods will return an \Illuminate\Support\Collection object containing the results.
Fr3on is a software agency in Cairo, Egypt. You'll find an overview of all our open source projects on our website.
Installation
This package can be installed through Composer.
composer require fr30n/ganalytics
Optionally, you can publish the config file of this package with this command:
php artisan vendor:publish --provider="Fr30n\GAnalytics\GAnalyticsServiceProvider"
The following config file will be published in config/ganalytics.php
return [ /* * The view id of which you want to display data. */ 'view_id' => env('ANALYTICS_VIEW_ID'), /* * Path to the client secret json file. Take a look at the README of this package * to learn how to get this file. You can also pass the credentials as an array * instead of a file path. */ 'service_account_credentials_json' => storage_path('app/ganalytics/service-account-credentials.json'), /* * The amount of minutes the Google API responses will be cached. * If you set this to zero, the responses won't be cached at all. */ 'cache_lifetime_in_minutes' => 60 * 24, /* * Here you may configure the "store" that the underlying Google_Client will * use to store it's data. You may also add extra parameters that will * be passed on setCacheConfig (see docs for google-api-php-client). * * Optional parameters: "lifetime", "prefix" */ 'cache' => [ 'store' => 'file', ], ];
Usage
When the installation is done you can easily retrieve Analytics data. Nearly all methods will return an Illuminate\Support\Collection-instance.
Here are a few examples using periods
//retrieve visitors and pageview data for the current day and the last seven days $analyticsData = GAnalytics::fetchVisitorsAndPageViews(Period::days(7)); //retrieve visitors and pageviews since the 6 months ago $analyticsData = GAnalytics::fetchVisitorsAndPageViews(Period::months(6)); //retrieve sessions and pageviews with yearMonth dimension since 1 year ago $analyticsData = GAnalytics::performQuery( Period::years(1), 'ga:sessions', [ 'metrics' => 'ga:sessions, ga:pageviews', 'dimensions' => 'ga:yearMonth' ] );
$analyticsData is a Collection in which each item is an array that holds keys date, visitors and pageViews
If you want to have more control over the period you want to fetch data for, you can pass a startDate and an endDate to the period object.
$startDate = Carbon::now()->subYear(); $endDate = Carbon::now(); Period::create($startDate, $endDate);
Provided methods
Visitors and pageviews
public function fetchVisitorsAndPageViews(Period $period): Collection
The function returns a Collection in which each item is an array that holds keys date, visitors, pageTitle and pageViews.
Total visitors and pageviews
public function fetchTotalVisitorsAndPageViews(Period $period): Collection
The function returns a Collection in which each item is an array that holds keys date, visitors, and pageViews.
Most visited pages
public function fetchMostVisitedPages(Period $period, int $maxResults = 20): Collection
The function returns a Collection in which each item is an array that holds keys url, pageTitle and pageViews.
Top referrers
public function fetchTopReferrers(Period $period, int $maxResults = 20): Collection
The function returns a Collection in which each item is an array that holds keys url and pageViews.
User Types
public function fetchUserTypes(Period $period): Collection
The function returns a Collection in which each item is an array that holds keys type and sessions.
Top browsers
public function fetchTopBrowsers(Period $period, int $maxResults = 10): Collection
The function returns a Collection in which each item is an array that holds keys browser and sessions.
All other Google Analytics queries
To perform all other queries on the Google Analytics resource use performQuery. Google's Core Reporting API provides more information on which metrics and dimensions might be used.
public function performQuery(Period $period, string $metrics, array $others = [])
You can get access to the underlying Google_Service_Analytics object:
GAnalytics::getAnalyticsService();
Testing
Run the tests with:
vendor/bin/phpunit
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email hello@fr30n.com instead of using the issue tracker.
Credits
Support us
Fr3on is a software agency based in Cairo, Egypt. You'll find an overview of all our open source projects on our website.
Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.
License
The MIT License (MIT). Please see License File for more information.
fr30n/ganalytics 适用场景与选型建议
fr30n/ganalytics 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 03 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「analytics」 「google」 「laravel」 「reports」 「retrieve」 「fr30n」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fr30n/ganalytics 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fr30n/ganalytics 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fr30n/ganalytics 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Analytics chooser extensions for site settings.
A Laravel Nova Card to show Fathom Analytics stats.
Magento 2 Social Login extension is designed for quick login to your Magento 2 store without procesing complex register steps
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
Alfabank REST API integration
Google Recaptcha Package For PHP front and backend.
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-03-28