From c458a06e61ccdfc217d3ac4d5a12ac0aa3b4f5ea Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 3 Sep 2019 16:54:39 +0200 Subject: [PATCH] wip #2951 --- resources/public/js/gtag.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/resources/public/js/gtag.js b/resources/public/js/gtag.js index 43420e0..31119e2 100644 --- a/resources/public/js/gtag.js +++ b/resources/public/js/gtag.js @@ -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) }; -- 2.39.5