Download the PHP package bluepsyduck/ga4-measurement-protocol without Composer
On this page you can find all versions of the php package bluepsyduck/ga4-measurement-protocol. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bluepsyduck/ga4-measurement-protocol
More information about bluepsyduck/ga4-measurement-protocol
Files in bluepsyduck/ga4-measurement-protocol
Package ga4-measurement-protocol
Short Description A small client implementing the Measurement Protocol for Google Analytics 4.
License GPL-3.0-or-later
Homepage https://github.com/BluePsyduck/ga4-measurement-protocol
Informations about the package ga4-measurement-protocol
Google Analytics 4 Measurement Protocol Client
This library contains a small client able to send events through the Measurement Protocol to Google Analytics 4.
Please always keep Google's warning about the current state of the API in mind when using this library:
Warning: This is an alpha API and subject to change. You may encounter breaking changes while it is in alpha. Code using this API should not be pushed to production. See limitations for issues that will be address before a general availability launch.
Installation
Install this library through composer as any sane PHP developer would do:
Usage
This library uses PSR-17 and PSR-18 to decouple its own logic from the actual client implementation. A compatible implementation must be provided to be able to use this library.
The following example shows how to use the guzzlehttp/guzzle
package with the client class:
Pre-defined events
The library ships with classes representing the events as specified in the Google docs. These classes use public properties and type-hints to ensure basic data compatibility. The library does not contain any additional data validation to keep it as small as possible.
Here is an example of building an actual payload with pre-defined events:
All attributes of the events are considered optional by the library, and initialised with null
. Please refer to the
reference docs to get additional information about which attributes may actually be required to be set.
Custom events
To create your own events, simply implement the EventInterface
and add the Event
attribute to the class specifying
the name of the event, as well as the Parameter
attribute to each property which should get send to Google Analytics.
All parameters which should appear in the payload must be marked with the Parameter
or ParameterArray
attributes.
It is recommended to make the default value of all parameters null
, as those will get filtered out and do not appear
in the payload.
Further reading
All versions of ga4-measurement-protocol with dependencies
ext-json Version *
psr/http-client Version ^1.0
psr/http-factory Version ^1.0