cybercog/yii2-google-analytics
最新稳定版本:v0.3.2
Composer 安装命令:
composer require cybercog/yii2-google-analytics
包简介
Google Analytics Widget for the Yii2 framework
关键字:
README 文档
README
This extension provides easy way to add Universal Analytics tracking in your Yii2 application.
Installation
The preferred way to install this extension is through composer.
Run in console
php composer.phar require cybercog/yii2-google-analytics
Usage
In your /views/layouts/main.php add
use cybercog\yii\googleanalytics\widgets\GATracking;
Then before </head> add following code
<?= GATracking::widget([ 'trackingId' => 'UA-XXXXXXXX-X', ]) ?>
Advanced usage
Omit script tag
By default this script generated output:
<script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXXXXXX-X', "auto"); ga('send', 'pageview'); ga('set', 'anonymizeIp', true); </script>
But sometimes we need the output without script tag to combined with registerJs or registerJsFile as renderPartial to add dependency or positioning configuration, you can use omitScriptTag true to disable script tag, example:
<?= $this->registerJs( GATracking::widget([ 'trackingId' => 'UA-XXXXXXXX-X', 'omitScriptTag' => true, ]), \yii\web\View::POS_END ); ?>
Example of advanced usage
You can configure tracking script for your needs:
<?= GATracking::widget([ 'trackingId' => 'UA-XXXXXXXX-X', 'trackingConfig' => [ 'name' => 'myTracker', 'allowAnchor' => false, ], 'omitScriptTag' => false, 'debug' => true, 'debugTrace' => true, 'anonymizeIp' => true, 'plugins' => [ 'linkid' => [ 'cookieName' => '_ccli', 'duration' => 45, 'levels' => 5, ], ], ]) ?>
Available fields (parameters)
| Field Name | Value Type | Default Value |
|---|---|---|
| anonymizeIp | boolean | true |
| debug | boolean | false |
| debugTrace | boolean | false |
Official field reference
Available plugins
linkid (Enhanced Link Attribution)
| Option Name | Default Value | Description |
|---|---|---|
| cookieName | _gali | Cookie name |
| duration | 30 | Cookie duration (seconds) |
| levels | 3 | Max DOM levels from link to look for element ID |
Creating your own plugins
cybercog/yii2-google-analytics 适用场景与选型建议
cybercog/yii2-google-analytics 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 75.52k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「analytics」 「google」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cybercog/yii2-google-analytics 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cybercog/yii2-google-analytics 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cybercog/yii2-google-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.
Magento 2 Social Login extension is designed for quick login to your Magento 2 store without procesing complex register steps
SCEditor, a lightweight WYSIWYG BBCode & HTML editor extension for Yii 2.0 Framework
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
统计信息
- 总下载量: 75.52k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 16
- 点击次数: 32
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2026-01-04