infoweb-internet-solutions/yii2-cms-analytics
Composer 安装命令:
composer require infoweb-internet-solutions/yii2-cms-analytics
包简介
Analytics module for Yii2
README 文档
README
Google analytics
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist infoweb-internet-solutions/yii2-cms-analytics "*"
or add
"infoweb-internet-solutions/yii2-cms-analytics": "*"
to the require section of your composer.json file.
Go to the Google developers console
Create a new project (or use an existing project)
Open the project
Go to 'API & Auth -> API's' and enable the 'Analytics API'
Go to 'API & Auth -> Credentials' and under 'OAuth' click 'Create new Client ID'
Choose 'Service account' and click 'Create client id'
Save the certificate to 'backend\assets\certificate\certificate.p12' (don't forget to rename the file)
Write down the 'private key's password' somewhere
Add the credentials to your backend params
return [ ... 'analytics' => [ 'developerKey' => '', // Public key fingerprints 'serviceAccountName' => 'xxx@developer.gserviceaccount.com', // Email address 'clientId' => 'xxx.apps.googleusercontent.com', // Client ID ], ];
Go to Google analytics, open your property and get your 'Profile ID'
(It is the number at the end of the URL starting with p: https://www.google.com/analytics/web/#home/a11345062w43527078pXXXXXXXX/)
Add the 'Profile ID' to your params
return [ ... 'analytics' => [ ... 'analyticsId' => 'ga:XXXXXXXX', ], ];
Add the serviceAccountName (xxx@developer.gserviceaccount.com) as a new user to your Analyics property
Create the alias '@google/api' in the bootstrap file in common/config like so:
Yii::setAlias('google/api', dirname(dirname(__DIR__)) . '/vendor/google/apiclient/src');
Import the translations and use category 'infoweb/analytics':
yii i18n/import @infoweb/analytics/messages
If you can't access the /tmp folder on your server (shared hosting), change line 94 in vendor\google\apiclient\src\Google\
'directory' => dirname(Yii::getAlias('@webroot')) . '/runtime/Google_Client'
Usage
Once the extension is installed, replace the contents of backend/views/site/index.php with the following:
<?php use infoweb\analytics\Analytics; $this->title = Yii::$app->name; ?>
<div class="site-index">
<div class="body-content">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">
<?= Yii::t('app', 'Dashboard'); ?>
<span class="pull-right report-period">
<strong><?= Yii::$app->formatter->asDate(date('d-m-Y', strtotime('-1 month')), 'medium'); ?> - <?= Yii::$app->formatter->asDate(date('d-m-Y'), 'medium'); ?></strong>
</span>
</h1>
</div>
</div>
<div class="row">
<?= Analytics::widget(['dataType' => Analytics::TOTAl_SESSIONS]); ?>
<?= Analytics::widget(['dataType' => Analytics::TOTAL_USERS]); ?>
<?= Analytics::widget(['dataType' => Analytics::TOTAL_PAGE_VIEWS]); ?>
<?= Analytics::widget(['dataType' => Analytics::AVERAGE_SESSION_LENGTH]); ?>
</div>
<div class="row">
<?= Analytics::widget(['dataType' => Analytics::SESSIONS]); ?>
</div>
<div class="row">
<?= Analytics::widget(['dataType' => Analytics::VISITORS]); ?>
<?= Analytics::widget(['dataType' => Analytics::COUNTRIES]); ?>
</div>
</div>
</div>
Useful links
Google Analytics Query Explorer 2
Google API Php Client
Developer Documentation
Google Charts
infoweb-internet-solutions/yii2-cms-analytics 适用场景与选型建议
infoweb-internet-solutions/yii2-cms-analytics 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.4k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2014 年 10 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「analytics」 「yii2」 「infoweb」 「yii2-cms-analytics」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 infoweb-internet-solutions/yii2-cms-analytics 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 infoweb-internet-solutions/yii2-cms-analytics 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 infoweb-internet-solutions/yii2-cms-analytics 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
Analytics chooser extensions for site settings.
A Laravel Nova Card to show Fathom Analytics stats.
CMS module for Yii2
Yii2 pages
Menu module for Yii2
统计信息
- 总下载量: 2.4k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 27
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-10-03