Created
October 28, 2022 15:19
-
-
Save noximus/39f2bbca50cd336d96cd9cf4a3445bf2 to your computer and use it in GitHub Desktop.
React Google Tag Manager react-gtm-module snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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