kebir / universal-analytics
谷歌通用分析跟踪器
2.1.1
2016-08-30 14:25 UTC
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-09-14 16:00:19 UTC
README
#通用分析
一个允许在服务器端跟踪谷歌分析事件的包。
安装
将包添加到你的 composer.json 文件中
{ require: { "kebir/universal-analytics": "~2.*" } }
使用
<?php use Kebir\UniversalAnalytics\UniversalAnalyticsTracker as Tracker; use Kebir\UniversalAnalytics\PixelRequest; //Create a tracker instance $tracker = new Tracker(new PixelRequest()); //Set the google analytics account. $tracker->setAccount($account); //Set the client id of the visitor. $tracker->setClientId($client_id); //Set custom dimensions or metrics $tracker->setCustomDimension(1, "Member"); $tracker->setCustomMetric(2, 1); //You can also set other informations $tracker->setCampaignSource("CampaignSource"); $tracker->setCampaignName("CampaignName"); $tracker->setCampaignMedium("CampaignMedium"); $tracker->setCampaignKeyword("CampaignKeyword"); $tracker->setCampaignContent("CampaignContent"); $tracker->setGoogleAdwordsId("GoogleAdwordsId"); $tracker->setGoogleDisplayAdsId("GoogleDisplayAdsId"); $tracker->setIp("Ip"); $tracker->setUserAgent("UserAgent"); $tracker->setUserLanguage("UserLanguage"); $tracker->setNonInteraction("NonInteraction"); $tracker->setExperimentId("ExperimentId"); $tracker->setExperimentVariation("ExperimentVariation"); //To track a pageview $tracker->trackPageview('/page'); //To track an event $tracker->trackEvent('General Events', 'Click', 'Facebook Link'); //To track a transaction //First we have to create the items $items = array( Tracker::createItem('Product Name', 10.99, 2) ); $tracker->trackTransaction($items, 'transaction_id', 10.99, 'My website');