Created
January 23, 2018 14:22
-
-
Save branneman/f69b7f5b2279ee9a3c1f70eaae38756d to your computer and use it in GitHub Desktop.
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 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