Download the PHP package kitbrennan90/php-ga-measurement-protocol without Composer
On this page you can find all versions of the php package kitbrennan90/php-ga-measurement-protocol. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kitbrennan90/php-ga-measurement-protocol
More information about kitbrennan90/php-ga-measurement-protocol
Files in kitbrennan90/php-ga-measurement-protocol
Package php-ga-measurement-protocol
Short Description PHP package for interacting with Google Analytics measurement protocol (eg. send page views and events to Google Analytics using your server side).
License MIT
Informations about the package php-ga-measurement-protocol
GA Measurement Protocol PHP Library
This simple library lets you send server side track events to Google Analytics.
Installation
This library is best installed via composer. Via the command line: composer require kitbrennan90/php-ga-measurement-protocol
If you are using PSR-4 (or a modern framework), simply import the client at the top of your script:
If you are not using PSR-4, you should require the composer autoloader: require_once('vendor/autoload.php');
Using the library
Initialise the Client
Sending a pageview
The library defaults to firing pageviews.
Not working? The Measurement Protocol will not raise any errors by default, please explore the debug section below if your results are not showing in Google Analytics the issue.
Sending other hit types (eg. event, screenview)
The library supports every tracking type (available as constants):
- GaMeasurementProtocol\Enums\HitType::PAGEVIEW
- GaMeasurementProtocol\Enums\HitType::SCREENVIEW
- GaMeasurementProtocol\Enums\HitType::EVENT
- GaMeasurementProtocol\Enums\HitType::TRANSACTION
- GaMeasurementProtocol\Enums\HitType::ITEM
- GaMeasurementProtocol\Enums\HitType::SOCIAL
- GaMeasurementProtocol\Enums\HitType::EXCEPTION
- GaMeasurementProtocol\Enums\HitType::TIMING
Just call setHitType($type)
on the request:
Sending additional parameters
The full supported parameter list can be found here: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
Add all your optional parameters to an array, and call setParameters($params)
on the request object:
Debugging
The Measurement Protocol always returns 200, even if parameters are invalid. You instead need to enable debug mode, which will var_dump the debug results to your view.
Note If debug mode is turned on, the results will NOT appear in your Google Analytics.
Once debug mode says your hit is valid, you should turn debug mode off and send your request again.