Download the PHP package label84/laravel-tagmanager without Composer
On this page you can find all versions of the php package label84/laravel-tagmanager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download label84/laravel-tagmanager
More information about label84/laravel-tagmanager
Files in label84/laravel-tagmanager
Package laravel-tagmanager
Short Description Easier way to add Google Tag Manager to your Laravel application.
License MIT
Informations about the package laravel-tagmanager
Laravel TagManager
Easier way to add Google Tag Manager to your Laravel application. Including support for User-ID, E-commerce and Server Side Events (Measurement Protocol).
- Laravel support
- Installation
- Usage
- Events
- User-ID
- Ecommerce (GA4)
- Ecommerce Item
- Ecommerce Events
- Server Side Events
- Measurement Protocol
- Measurement Protocol Debug Mode
- Tests
- License
Laravel support
Version | Release |
---|---|
11.x | ^1.4 |
10.x | ^1.4 |
Installation
Read the article on Medium.com for a more detailed instruction: Medium: Add Google Analytics to your Laravel application with Google Tag Manager.
1. Install package
Install the package
2. Add the head and body tag to your (layout) view
Add the head tag directly above the closing </head>
tag and the body tag directly after the opening <body>
tag.
3. Add the TagManagerMiddleware to your Kernel
Add the TagManagerMiddleware directly after the StartSession middleware in your 'web' middleware group.
4. Publish the config file
Publish the config file. This will generate a tagmanager.php
file in your config directory.
5. Add your GTM ID to your .env
Go to https://tagmanager.google.com
and copy the 'Container ID' of the account (it looks like GTM-XXXXXXX).
Usage
Events
You can also use the following methods. These will automatically set the correct event key and value.
You can find a list of recommended events on: https://support.google.com/analytics/answer/9267735?hl=en
User-ID
This package also supports the User-ID feature.
To start using the User-ID feature you've to add the TagManagerUserIdMiddleware
in your 'web' middleware group directly after the TagManagerMiddleware
.
By default the 'id' of the User model will be used. You change the key in config/tagmanager.php
.
More information: https://developers.google.com/analytics/devguides/collection/ga4/user-id?technology=tagmanager
Ecommerce (GA4)
You can use the following snippets to trigger an Ecommerce event with Google Analytics 4 (GA4).
Ecommerce item
The TagManagerItem
class allows you to easily create an Ecommerce item. You can set extra parameters with dynamic calls. Method names are used as keys and automatically converted to underscore case.
Example: create item
Ecommerce events
The items parameter can be a single TagManagerItem
item or an array of TagManagerItem
items. You can also use plain arrays if you don't want to use the TagManagerItem class.
Example: call event with item
More information: https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtm
Server Side Events
The Google Analytics Measurement Protocol allows developers to make HTTP requests to send raw user interaction data directly to Google Analytics servers. This allows developers to measure how users interact with their business from almost any environment. Developers can then use the Measurement Protocol to:
- Measure user activity in new environments.
- Tie online to offline behavior.
- Send data from both the client and server.
Measurement Protocol
You need complete the general installation steps first, such as adding the .env
variables, adding the head and body tags to your layout file and adding the TagManagerMiddleware
.
Add the following extra variables to your .env file.
Add the following snippet to the head of your blade layout file (below the existing x-tagmanager-head
tag).
You can view the events directly in the Google Analytics UI under Realtime > Events.
Measurement Protocol Debug Mode
You can enable the debug mode by calling the debug()
method. This will return a JSON validation response instead of sending the request to Google Analytics.
If there are any errors, they will be returned in the validation messages response. If there are no errors, the validation response array will be empty.