Download the PHP package alexwestergaard/php-ga4 without Composer

On this page you can find all versions of the php package alexwestergaard/php-ga4. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-ga4

Package

Version License PHPVersion Size Code Coverage Badge

Development

Version Issues Pulls Contributors LastCommit

GDPR Notice

European Union have noticed that default setup of Google Analytics does not comply with GDPR as data is sent unrestricted to an american service possibly outside of Europe. This includes the use of gtag.js as JavaScript pushes the request from visitors device including their IP-Address.

Server Side Tracking, however, does only send information specified inside the body and about your server.

Relying solely on Google Analytics 4 Events - that is not pushed through the gtag.js script - can be scraped of GDPR-related information.

Getting started

To setup Analytics you need a Measurement ID and API Secret.

Go to Administrator (bottom left) and then select your Account -> Data Streams -> your stream.
Here you will find Measurement-ID at top from and further down Api Secrets for Measurement Protocol, in there you can create yourself an API Secret.

PLEASE note that Google Analytics will look out from traffic gathered by the gtag.js library, as Server Side Events are supposed to supplement the frontend through its _ga/_gid cookie sessions.

Data flow

session_id > Google Analytics does not specify a required type of session or user id. You are free to use any kind of unique identifier you want; the catch, however, is that Google Analytics populates some internal data with gtag.js, that is then referenced to their _ga cookie session id. Just be aware that gtag.js is using client-side Javascript and can therefore have some GDPR complications as requests back to Google Analytics contains client information; such as their IP Address.

  1. Acquire proper GDPR Consent
  2. Client/GTAG.js sends session_start and first_visit to GA4
  3. GA4 sends _ga and _gid cookies back to Client/GTAG.js
  4. Server uses _ga (or _gid; or your unique session_id) to populate events

Note: It is entirely possible to push events to backend without acquiring the session cookies from Google Analytics; you will however lose information bundled inside the GTAG.js request if you do not figure out how to push that via backend too.

Layers

The code is following 3 layers that should be considered; 5 layers at max.

Events

This is a list of prebuilt events as shown in the documentation. All events have the following parameters to locate trigger location of each event.

Default

badge badge badge badge badge badge badge badge badge badge badge badge

E-commerce

badge badge badge badge badge badge badge badge badge badge

Engagement / Gaming

badge badge badge badge badge badge badge badge

Frontend & Backend Communication

This library is built for backend server side tracking, but you will probably trigger most events through frontend with Javascript or Websockets. There will be 2 examples, one as pure backend for logged/queued events and one for frontend to backend communication.

Logging / Queue

Frontend => Backend

Frontend

Backend

Custom Events

You can build your own custom events. All you need is to implement and fullfill the AlexWestergaard\PhpGa4\Facade\Type\EventType facade/interface. If you want ease of life features, then you can extend your event from AlexWestergaard\PhpGa4\Helper\EventHelper and overwrite as you see fit.

Debug

Measurement protocol for GA4 has debug functionality that can be enabled with the debug parameter in the Analytics constructor.

When Debug is enabled then events are sent to https://www.google-analytics.com/debug/mp/collect where issues will be caught with GA4Exception (Be aware of $exception->getPrevious() stacks); such response will look as follows:

Notice: This library already validates that events are properly formatted when added to analytics ($analytics->addEvent(...)).

Two important points:

Additional information

Documentation


All versions of php-ga4 with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0,<8.4
guzzlehttp/guzzle Version ^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package alexwestergaard/php-ga4 contains the following files

Loading the files please wait ....