项目作者: neomrc

项目描述 :
Google Measurement Protocol
高级语言: PHP
项目地址: git://github.com/neomrc/google-analytics.git
创建时间: 2019-03-07T14:13:38Z
项目社区:https://github.com/neomrc/google-analytics

开源协议:MIT License

下载


Google Measurement Protocol

This package helps developers to make google analytics dispatches easy. Based on google’s documentation: https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide


To start do:

composer require neomrc/google-analytics



This is a pretty straightforward service. Here is a sample of an event hit:

  1. use Neomrc\GoogleAnalytics;
  2. ...
  3. try {
  4. $tracker = new GoogleAnalytics()->track('event');
  5. $tracker->setCategory('categoryFoo');
  6. ->setAction('actionBar');
  7. ->send();
  8. } catch (\Exception $e) {
  9. // tracker sending failed
  10. }


To instantiate:

new GoogleAnalytics()->track(<enter hit type here>);


Set Tracking ID:

->setTrackingId(<trackingId>)


Set Client ID:

->setClientId(<clientId>)


Set User ID:

->setUserId(<userId>)


This will initialize the hit type class in which you can set the values by using the methods below


Possible hit types

Note: types are case-sensitive

  • event
  • pageview


Pageview

Methods Required Value Type
setDocumentHostname false string
setPage false string
setTitle false string


Event

Methods Required Value Type
setCategory true string
setAction true string
setLabel false string
setValue false string



To send/dispatch the analytics object

->send(<optional array of data here ['key' => 'value']>)


This is my first package. I hope someone will find this useful.