Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* @module GTMEventTracking
* @example
* <a
* data-module="event-tracking/GTMEventTracking"
* data-payload='{"event":"EventOpenGoogle"}'
* href="https://google.com/" target="_blank">
* Click me
* </a>
*/
class GTMEventTracking {
/**
* @param {HTMLElement} element
* @param {Object} options
*/
constructor(element, options) {
this._element = element;
this._options = options;
this.load();
}
load() {
const payload = JSON.parse(this._options.payload);
this._element.addEventListener('click', () => {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push(payload);
});
}
}
export default GTMEventTracking;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment