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
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
Note: types are case-sensitive
event
pageview
Methods | Required | Value Type |
---|---|---|
setDocumentHostname |
false |
string |
setPage |
false |
string |
setTitle |
false |
string |
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']>
)