Skip to content

Instantly share code, notes, and snippets.

@noximus
Created October 28, 2022 15:19
Show Gist options
  • Save noximus/39f2bbca50cd336d96cd9cf4a3445bf2 to your computer and use it in GitHub Desktop.
Save noximus/39f2bbca50cd336d96cd9cf4a3445bf2 to your computer and use it in GitHub Desktop.
React Google Tag Manager react-gtm-module snippets
// react-gtm-module setup
import TagManager from 'react-gtm-module';
const tagManagerArgs = {
gtmId: 'GTM-XXXXXXX',
};
TagManager.initialize(tagManagerArgs);
// react-gtm-module event
const dataLayer = window.dataLayer || [];
dataLayer.push({
event: 'event-name',
eventCategory: 'event-category',
eventAction: 'event-action',
eventLabel: 'event-label',
eventValue: 'event-value',
});
// react-gtm-module page load
import TagManager from 'react-gtm-module';
const tagManagerArgs = {
dataLayer: {
page: 'page-name',
pageCategory: 'page-category',
pageAction: 'page-action',
pageLabel: 'page-label',
pageValue: 'page-value',
},
};
TagManager.dataLayer(tagManagerArgs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment