Skip to content

Instantly share code, notes, and snippets.

@reatlat
Last active October 31, 2022 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reatlat/eb84e4ccd5c63dd88c84c3d3b63c9f3c to your computer and use it in GitHub Desktop.
Save reatlat/eb84e4ccd5c63dd88c84c3d3b63c9f3c to your computer and use it in GitHub Desktop.
GTM dataLayer example
module.exports = (...args) => {
if (location.hostname.match("local"))
console.log("🦄:", ...args);
};
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' });
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