定制 jmpatricio/easy-google-analytics 二次开发

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

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

jmpatricio/easy-google-analytics

Composer 安装命令:

composer require jmpatricio/easy-google-analytics

包简介

README 文档

README

Laravel Package to connect Google Analytics

Latest Stable Version Codacy Badge Code Climate License

Changelog

  • 1.0.4 | 2015-08-21
  • Added new users metric
  • Duplicate code removed
  • PHP Docs improved
  • Code Style fixed

Instalation

  1. Run composer require jmpatricio/easy-google-analytics

  2. Add Jmpatricio\EasyGoogleAnalytics\EasyGoogleAnalyticsServiceProvider to your service providers

  3. Instalation Done.

Configuration

This step is the most important. Let's make it simple:

  • Open a terminal and run: php artisan config:publish "jmpatricio/easy-google-analytics".
  • Now you have {$projectRoot}/app/config/packages/jmpatricio/easy-google-analytics/config.php file with:
return [
    'client_id'            => 'xxx.apps.googleusercontent.com',
    'service_account_name' => 'xxx@developer.gserviceaccount.com',
    'keyfile'              => storage_path('xxx.p12'),
    'analytics_id'         => 'ga:xxx',
];
  • Now you have to go to your googe developer account and configure a new project. (If you already have a project, ignore this step) Create a new project

  • You need to enable the Analytics API to your project. Inside project, go to APIs & auth and then inside APIs. Enable the analytics

  • Inside the project, on developers console, go to Credentials inside APIs & auth, create a new Service Account

  • Choose a p12 key

  • Save your p12 key inside {$projectRoot}/app/storage.

  • Edit the config file and define the keyfile entry: 'keyfile' => storage_path('Easy-Google-Analytics-da31194a03c6.p12'),

  • Now you have the information about the credentials Click on the email, and the following screen shows up:

  • Add the client id and the email address to the config:

return [
	'client_id'            => '459875649264-vs034lhn7ocddcch0nq1vdurst1mr8bu.apps.googleusercontent.com',
	'service_account_name' => '459875649264-vs034lhn7ocddcch0nq1vdurst1mr8bu@developer.gserviceaccount.com',
	'keyfile'              => storage_path('Easy-Google-Analytics-da31194a03c6.p12'),
	'analytics_id'         => 'ga:xxx',
];
  • Now the only thing missing is the analytics id
  • Go to your analytics dashboard, and inside the admin area select the view settings:
  • Copy the view id and add to the config:

The config will be the following:

return [
    'client_id'            => '459875649264-vs034lhn7ocddcch0nq1vdurst1mr8bu.apps.googleusercontent.com',
    'service_account_name' => '459875649264-vs034lhn7ocddcch0nq1vdurst1mr8bu@developer.gserviceaccount.com',
    'keyfile'              => storage_path('Easy-Google-Analytics-da31194a03c6.p12'),
    'analytics_id'         => 'ga:106917230',
];
  • Now we have to add permissions to the service account inside analytics console:

  • Go to the analytics admin console, and add the user with the respective permissions:

  • The configuration is complete!

Basic usage

$connector = new Jmpatricio\EasyGoogleAnalytics\Connector();

// Total visits for today
$totalVisitors = $connector->getTotalVisits();

// Total visits with from-to dates
$totalVisitors = $connector->getTotalVisits(new Carbon\Carbon('2015-08-01'), new Carbon\Carbon('2015-08-05'));

// Active users
$activeUsers = $connector->getActiveUsers();

// Generic API Access

// GA API
$fromDate = new Carbon\Carbon('2015-08-01');
$toDate = new Carbon\Carbon('2015-08-05');
$serviceResponse = $connector->getGA($fromDate,$toDate,'ga:visitors')

// Realtime API
$serviceResponse = $connector->getRT('rt:activeUsers',['dimensions'=>'rt:country']);

jmpatricio/easy-google-analytics 适用场景与选型建议

jmpatricio/easy-google-analytics 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 77 次下载、GitHub Stars 达 6, 最近一次更新时间为 2015 年 08 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「analytics」 「google」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jmpatricio/easy-google-analytics 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jmpatricio/easy-google-analytics 我们能提供哪些服务?
定制开发 / 二次开发

基于 jmpatricio/easy-google-analytics 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 77
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

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