helick / gtm
The Helick Google Tag Manager plugin
Installs: 169
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 1
Type:wordpress-plugin
Requires
- php: >=7.1
- composer/installers: ^1.6
- helick/contracts: ^1.1
Requires (Dev)
This package is auto-updated.
Last update: 2024-10-23 23:19:52 UTC
README
Google Tag Manager integration.
Requirements
Make sure all dependencies have been installed before moving on:
Install
Install via Composer:
$ composer require helick/gtm
Update your application config by declaring the following:
Config::define('GTM_CONTAINER_ID', env('GTM_CONTAINER_ID'));
Update your env variables by declaring the following:
GTM_CONTAINER_ID=GTM-XXXX
Usage
To support the fallback iframe for devices without javascript add the following code just after the opening <body>
tag in your theme:
<?php wp_body_open(); ?>
Data layer
Google Tag Manager offers a data layer which allows you pass arbitrary data that can be used to modify which tags are added to your site.
This plugin adds some default information such as post, tags and categories and provides a simple filter for adding in your own custom data.
add_filter('helick_gtm_data_layer', function (array $dataLayer) { $dataLayer['foo'] = 'bar'; return $dataLayer; });
Event tracking
To deactivate the event tracking you may declare the following:
add_filter('helick_gtm_enable_event_tracking', '__return_false');
By default the event listener script will look for the elements on the page with special data attributes in your markup and listen for the specified event to push to the data layer.
The data attributes are:
data-gtm-variable
string Optionally override the default data layer variable name for this event.data-gtm-on
enum [click|submit|keyup|focus|blur] The JS event to listen for, defaults to 'click'.data-gtm-event
string The event name.data-gtm-category
string Optional group the event belongs to.data-gtm-label
string Optional human readable label for the event.data-gtm-value
number Optional numeric value associated with the event.data-gtm-fields
string Optional extra data provided as encoded JSON.
Example:
<button data-gtm-on="click" data-gtm-event="play" data-gtm-category="videos" data-gtm-label="Featured Promotional Video" > Play video </button>
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email evgenii@helick.io instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.