Download the PHP package 8ctopus/php-ga-measurement-protocol without Composer
On this page you can find all versions of the php package 8ctopus/php-ga-measurement-protocol. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download 8ctopus/php-ga-measurement-protocol
More information about 8ctopus/php-ga-measurement-protocol
Files in 8ctopus/php-ga-measurement-protocol
Package php-ga-measurement-protocol
Short Description Send data to Google Analytics from the server using PHP. This library fully implements GA measurement protocol.
License MIT
Informations about the package php-ga-measurement-protocol
Google Analytics Measurement Protocol library for PHP
This is a fork of the original no longer maintained project https://github.com/theiconic/php-ga-measurement-protocol.git. There are no plans to add support for Google Analytics 4, this package is maintenance only for php 8.x support.
Description
Send data to Google Analytics from the server using PHP. This library fully implements GA measurement protocol so its possible to send any data that you would usually do from analytics.js on the client side. You can send data regarding the following parameters categories (Full List):
- General
- User
- Session
- Traffic Sources
- System Info
- Hit
- Content Information
- App Tracking
- Event Tracking
- E-Commerce
- Enhanced E-Commerce
- Social Interactions
- Timing
- Exceptions
- Custom Dimensions / Metrics
- Content Experiments
- Content Grouping
Installation
Use Composer to install this package.
composer require 8ctopus/php-ga-measurement-protocol
Integrations
You can use this package on its own, or use a convenient framework integration:
- Laravel 5+ - https://github.com/irazasyed/laravel-gamp
- Yii 2 - https://github.com/baibaratsky/yii2-ga-measurement-protocol
- Symfony2 - https://github.com/fourlabsldn/GampBundle
Feel free to create an integration with your favourite framework, let us know so we list it here.
Usage
The required parameters for all hits are Protocol Version, Tracking ID and at least one of these: Client ID or User ID. Some optional ones like IP Override are recommended if you don't want all hits to seem like coming from your servers.
The hit should have arrived to the GA property UA-26293728-11. You can verify this in your Real Time dashboard. Take notice, if you need GA reports to tie this event with previous user actions you must get and set the ClientId to be same as the GA Cookie. Read (here).
The library is 100% done, full documentation is a work in progress, but basically all parameters can be set the same way.
All methods for setting parameters should Autocomplete if you use an IDE such as PHPStorm, which makes building the Analytics object very easy.
Use Cases
Order Tracking with simple E-commerce
Order Tracking with Enhanced E-commerce
Batch Hits
GA has an endpoint that you can hit to register multiple hits at once, with a limit of 20 hits. Hits to be send can be placed in a queue as you build up the Analytics object.
Here's an example that sends two hits, and then empties the queue.
The queue is emptied when the hits are sent, but it can also be empty manually with emptyQueue
method.
If more than 20 hits are attempted to be enqueue, the library will throw a EnqueueUrlsOverflowException
.
Validating Hits
From Google Developer Guide:
The Google Analytics Measurement Protocol does not return HTTP error codes, even if a Measurement Protocol hit is malformed or missing required parameters. To ensure that your hits are correctly formatted and contain all required parameters, you can test them against the validation server before deploying them to production.
To send a validation hit, turn on debug mode like this
GA actually returns a JSON that is parsed into an associative array. Read (here) to understand how to interpret response.
Disable library hits for Staging/Dev environments
In your app configuration, you can have a flag for enabling or disabling the library, this in order to not actually send hits to GA, in this case the lib returns a AnalyticsResponseInterface object that returns empty values.
This is specially useful in dev or staging environments.
Contributors
- Jorge A. Borges - Lead Developer (http://jorgeborges.me)
- Juan Falcón - arcticfalcon
- Syed Irfaq R. - irazasyed
- Andrei Baibaratsky - baibaratsky
- Martín Palombo - lombo
- Amit Rana - amit0rana
- Stefan Zweifel - stefanzweifel
- Titouan Benoit - nightbr
- Hayashi Ryo - ryo88c
- Radek Hřebeček - http://www.hrebecek.cz/
- edim24 - ryo88c
- venyii - venyii
- Peter Jaap Blaakmeer - peterjaap
- Alberto Bottarini - alberto-bottarini
License
THE ICONIC Google Analytics Measurement Protocol library for PHP is released under the MIT License.