]> _ Git - cubist_gtag.git/commitdiff
wip #2951
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 4 Sep 2019 13:01:58 +0000 (15:01 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 4 Sep 2019 13:01:58 +0000 (15:01 +0200)
resources/public/js/gtag.js

index 31119e273e68e0dc8c28a18298fddb01ee9bd7da..c0297300312bd4ed26302b11f358293123206ee1 100644 (file)
@@ -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);
     }
 };