Download the PHP package devpro/laravel-ga4-event-tracking without Composer

On this page you can find all versions of the php package devpro/laravel-ga4-event-tracking. 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 laravel-ga4-event-tracking

Laravel Google Analytics 4 Measurement Protocol Event Tracking

Version Tests License

Simplifies using the Measurement Protocol for Google Analytics 4 to track events in Laravel applications.

Installation

1) Install package via Composer

2) Set GA4_MEASUREMENT_ID and GA4_MEASUREMENT_PROTOCOL_API_SECRET in your .env file.

Copy from Google Analytics > Admin > Data Streams > [Select Site] > Measurement ID & Google Analytics > Admin > Data Streams > [Select Site] > Measurement Protocol API secrets respectively.

3) Optional: Publish the config / view files by running this command in your terminal:

4) Include the sendGA4ClientID directive in your layout file after the Google Analytics Code tracking code.

The client_id is required to send an event to Google Analytics. This package provides a Blade directive which you can put in your layout file after the Google Analytics Code tracking code. It grabs the current user's GA client_id from either the ga() or gtag() helper functions injected by Google Analytics and makes a POST request to your application to store the client_id in the session, which is later used by the DispatchAnalyticsJob when sending events to GA4.

If you do not use this blade directive, you will have to handle retrieving, storing, and sending the client_id yourself. You can use GA$::setClientId($clientId) to set the client_id manually.

Usage

This package provides two ways to send events to Google Analytics 4:

Directly via the GA4 facade:

Sending event directly is as simple as calling the sendEvent($eventData) method on the GA4 facade from anywhere in your backend to post event to Google Analytics 4. $eventData contains the name and params of the event as per this reference page. For example:

The sendEvent() method will return an array with the status of the request.

Broadcast events to GA4 via the Laravel Event System

Just add the ShouldBroadcastToAnalytics interface to your event, and you're ready! You don't have to manually bind any listeners.

There are two additional methods that lets you customize the call sent to GA4.

With the broadcastGA4EventAs method you can customize the name of the Event Action. By default, we use the class name with the class's namespace removed. This method gives you access to the underlying GA4 class instance as well.

With the withGA4Parameters method you can set the parameters of the event being sent.

Handle framework and 3rd-party events

If you want to handle events where you can't add the ShouldBroadcastToAnalytics interface, you can manually register them in your EventServiceProvider using the DispatchAnalyticsJob listener.

Debugging Mode

You can also enable debugging mode by calling enableDebugging() method before calling the sendEvent() method. Like so - GA4::enableDebugging()->sendEvent($eventData). The sendEvent() method will return the response (array) from Google Analytics request in that case.

Testing

or

Security

If you discover any security related issues, please use the Report a vulnerability button instead of using the issue tracker.

Credits:

This package is a fork of the following projects:

License

This package is open-sourced software licensed under the MIT License.


All versions of laravel-ga4-event-tracking with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1 || ^8.2
illuminate/bus Version ^8.0 || ^9.0 || ^10.0
illuminate/queue Version ^8.0 || ^9.0 || ^10.0
illuminate/http Version ^8.74 || ^9.0 || ^10.0
illuminate/validation Version ^8.0 || ^9.0 || ^10.0
guzzlehttp/guzzle Version ^7.5
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 devpro/laravel-ga4-event-tracking contains the following files

Loading the files please wait ....