Skip to content

neomrc/google-analytics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:
use Neomrc\GoogleAnalytics;
...
try {
    $tracker = new GoogleAnalytics()->track('event');
    $tracker->setCategory('categoryFoo');
        ->setAction('actionBar');
        ->send();
} catch (\Exception $e) {
    // tracker sending failed
}

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.