From 79dbf34a1e56b074135d4069d6acc43383219ee0 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 4 Sep 2019 15:01:58 +0200 Subject: [PATCH] wip #2951 --- resources/public/js/gtag.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/resources/public/js/gtag.js b/resources/public/js/gtag.js index 31119e2..c029730 100644 --- a/resources/public/js/gtag.js +++ b/resources/public/js/gtag.js @@ -11,11 +11,11 @@ cubistga.prototype.initEvents = function () { }); document.addEventListener('click', function (e) { - if (e.target.matches('[data-ga]')) { + if (e.target.matches('a[data-ga]')) { $this.handleGtag(e.target); } - if (e.target.closest('[data-ga]')) { - $this.handleGtag(e.target.closest('[data-ga]')); + if (e.target.closest('a[data-ga]')) { + $this.handleGtag(e.target.closest('a[data-ga]')); } }, false); }; @@ -53,7 +53,7 @@ cubistga.prototype.event = function (action, category, label, value, noninteract if (undefined !== value && null !== value) { options.value = value; } - console.log('gtag event',action,options); + console.log('gtag event', action, options); return gtag('event', action, options) }; @@ -63,8 +63,12 @@ cubistga.prototype.handleGtag = function (el) { let category = el.getAttribute('data-ga-category'); let label = el.getAttribute('data-ga-label'); let value = el.getAttribute('data-ga-value'); + let options = el.getAttribute('data-ga-options'); + if (options !== null) { + options = JSON.parse(options); + } - return this.event(action, category, label, value, el.getAttribute('data-ga-noninteraction') === 1); + return this.event(action, category, label, value, el.getAttribute('data-ga-noninteraction') === 1, options); } }; -- 2.39.5