]> _ Git - cubist_gtag.git/commitdiff
wip #2951
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 3 Sep 2019 14:54:39 +0000 (16:54 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 3 Sep 2019 14:54:39 +0000 (16:54 +0200)
resources/public/js/gtag.js

index 43420e01d34d779106fca901d094e90e1d114020..31119e273e68e0dc8c28a18298fddb01ee9bd7da 100644 (file)
@@ -20,11 +20,30 @@ cubistga.prototype.initEvents = function () {
     }, false);
 };
 
-cubistga.prototype.event = function (action, category, label, value, noninteraction) {
+cubistga.prototype.addToCart = function (id, name, quantity) {
+    this.event('add_to_cart', 'ecommerce', null, null, false, {
+        items: [
+            {id: id, name: name, quantity: quantity}
+        ]
+    });
+};
+
+cubistga.prototype.removeFromCart = function (id, name, quantity) {
+    this.event('remove_from_cart', 'ecommerce', null, null, false, {
+        items: [
+            {id: id, name: name, quantity: quantity}
+        ]
+    });
+};
+
+cubistga.prototype.event = function (action, category, label, value, noninteraction, options) {
     if (noninteraction === undefined) {
         noninteraction = false;
     }
-    let options = {non_interaction: noninteraction};
+    if (options === undefined) {
+        options = {};
+    }
+    options.non_interaction = noninteraction;
     if (undefined !== category && null !== category) {
         options.event_category = category;
     }
@@ -34,6 +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);
     return gtag('event', action, options)
 };