Last active
October 31, 2022 18:07
-
-
Save reatlat/eb84e4ccd5c63dd88c84c3d3b63c9f3c to your computer and use it in GitHub Desktop.
GTM dataLayer example
This file contains hidden or 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
module.exports = (...args) => { | |
if (location.hostname.match("local")) | |
console.log("🦄:", ...args); | |
}; |
This file contains hidden or 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
import gtmEvent from "./gtmEvent"; | |
gtmEvent({ | |
event: 'product_application', // event property is required | |
customer: { // any properties are allowed and optional | |
name: 'John Doe', | |
_id: '1234567890', | |
} | |
}); | |
gtmEvent({ | |
event: 'self_service_signup', | |
customer: { | |
name: 'John Doe', | |
_id: '1234567890', | |
} | |
}); | |
// minimal version to trigger some tags on GTM layer | |
gtmEvent({ event: 'my_awesome_event_name' }); |
This file contains hidden or 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
import debugLog from "./debugLog"; | |
module.exports = (obj) => { | |
try { | |
debugLog("GTM: [try]", obj); | |
window.dataLayer.push(obj); | |
} catch (err) { | |
debugLog("GTM: [catch]", err); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment