Helick GTM WP Registry grade A-. Low-severity findings · 1 findingWP RegistryLow-severity findings · 1 findingOpen the reportA-
Plugin for Google Tag Manager integration
Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/helick/gtm/archive/refs/heads/master.zipOn Packagist as helick/gtm:
composer require helick/gtmHelick Google Tag Manager
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-variablestring Optionally override the default data layer variable name for this event.data-gtm-onenum [click|submit|keyup|focus|blur] The JS event to listen for, defaults to 'click'.data-gtm-eventstring The event name.data-gtm-categorystring Optional group the event belongs to.data-gtm-labelstring Optional human readable label for the event.data-gtm-valuenumber Optional numeric value associated with the event.data-gtm-fieldsstring 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.
Releases
4 releases.
These releases are tags only. The author does not attach a packaged zip, so there are no download counts to report.