Skip to content

Instantly share code, notes, and snippets.

@alex-y-su
Created December 14, 2022 06:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alex-y-su/0b24f8ded0a0adea5f6397c47864d58b to your computer and use it in GitHub Desktop.
Save alex-y-su/0b24f8ded0a0adea5f6397c47864d58b to your computer and use it in GitHub Desktop.
var trackClickEvent = function () {
var eventCategory = this.getAttribute("data-event-category") || "unknown";
var eventLabel = this.getAttribute("data-event-label") || "";
gtag('event', eventCategory, { 'label' : eventLabel, 'debug_mode': true });
};
var elementsToTrack = document.getElementsByClassName("ga-event");
for (var i = 0; i < elementsToTrack.length; i++) {
elementsToTrack[i].addEventListener('click', trackClickEvent, false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment