Download the PHP package norsys/google-tag-manager-bundle without Composer
On this page you can find all versions of the php package norsys/google-tag-manager-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download norsys/google-tag-manager-bundle
More information about norsys/google-tag-manager-bundle
Files in norsys/google-tag-manager-bundle
Package google-tag-manager-bundle
Short Description Bundle handling Google Tag Manager
License MIT
Informations about the package google-tag-manager-bundle
Google Tag Manager Bundle
This project is a bundle which eases the configuration and handling of Google Tag Manager.
It provides a bunch of base classes to extend from.
Installation
Step 1: Add the repository & download the Bundle
Open a command console, enter your project directory and execute the following commands:
This command requires you to have composer
installed globally, as explained
in the installation chapter
of the Composer documentation.
Step 2: Register the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:
Step 3: Configuration & Implementation
The GTM bundle allows you to define google tag manager parameters, providing a default values management.
Basic integration
Template integration
To ease quick integration, the bundle provides a twig
partial and a javascript file to include in your template:
Example:
Controlling GTM loading
By default, GoogleTagManager is initialized at the point the javascript file is included.
You can also tied it to a specific DOM event:
DataLayer configuration
The GoogleTagManager Bundle handles 2 distinct types of parameters:
- Static parameters
-
Dynamic parameters
:warning: As a rule of thumb,
static
anddynamic
parameters must have different names.
Static parameters
Here is a very basic config example:
The bundle will merge defaults and per-route static parameters, and issue the resulting data layer.
The dataLayer sent for the page responding to the faq
route will be:
Dynamic parameters
On some situations, it can be useful to have some parameters value changing dynamically upon the context.
For this purpose, the bundle provides support for dynamic parameters.
Each dynamic parameter consists of a service implementing NorsysGoogleTagManagerBundle\Dynamic\ParameterInterface.
The custom dynamic parameter class will have to implement the 2 following methods:
getValue()
The method responsible for calculating the parameters value. It receives the whole merged and resolved config as unique argumentgetName()
This method must return the unique parameter name, the one that represents it in the config
Each dynamic parameter class refered to in the bundle config must be registered, hence declared using the appropriate tag:
Now we can use the parameter in the bundle config, referencing to it via the alias defined by its getName()
method.
Even if rarely ever needed for most cases, it is possible to pass the parameter an initialization string, and then fetch it in the associated service.
As an example, let's say we want to pass a C-like template string:
We can then easily fetch this init value for further processing inside the getValue()
method:
Dynamic parameters can also be overriden, on a per-route basis:
Dynamic parameters aliases
Additionnally this bundle also supports aliases for dynamic parameters.
Let's consider using an alias of the previously created acmeDynamicParam
:
Now we can use the aliased name to refer directly to its target:
Conclusion
Now, taking for granted the 2 above static
and dynamic
configured parameters, the resulting generated dataLayer for the faq
route would be something like:
Credits
Developped by :heart: with Norsys
License
This project is licensed under the MIT license.
All versions of google-tag-manager-bundle with dependencies
symfony/dependency-injection Version ^3.1.0
symfony/config Version ^3.1.0
symfony/http-kernel Version ^3.1.0
twig/extensions Version ^1.5