yiimaker/yii2-google-analytics

Google Analytics (测量协议)

安装次数1,502

依赖: 0

建议者: 0

安全: 0

星标: 2

关注者: 4

分支: 0

开放问题: 0

类型:yii2-extension

1.0.0 2016-12-04 14:45 UTC

This package is auto-updated.

Last update: 2024-09-14 03:32:55 UTC


README

Google Analytics (测量协议)

安装

安装此扩展的首选方式是通过 Composer

运行以下命令之一:

php composer.phar require --prefer-dist yiimaker/yii2-google-analytics "*"

或者在您的 composer.json 文件的 require 部分添加以下内容:

"yiimaker/yii2-google-analytics": "*"

示例

初始化

$analytics = \Yii::createObject([
    'class' => \ymaker\google\analytics\mp\Analytics::className(),
    
    'v' => 1,                                       // Protocol version. Default value: 1
    'tid' => 'UA-XXXX-Y'                            // Tracking ID / Web Property ID
    'cid' => '35009a79-1a05-49d7-b876-2b884d0f825b' // Client ID. Random UUID (http://www.ietf.org/rfc/rfc4122.txt)
]);

用法

/** @var yii\httpclient\Response $responce */
$responce = $analytics->send([
    't' => 'event',     // Hit Type.
    'ec' => 'video',    // Event Category.
    'ea' => 'play',     // Event Action.
    'el' => 'holiday',  // Event label.
    'ev' => 300,        // Event value.
]);

更多详细信息,请参考 API 官方文档