From 5d1585f060eff8a547eefc6324350f741fb80eb3 Mon Sep 17 00:00:00 2001 From: Sharoon Thomas Date: Wed, 3 Jun 2015 22:38:09 +0530 Subject: [PATCH 1/2] Add optional google tag manager code The block with be enabled if there is a GOOGLE_TAG_MANAGER variable in the template context that has a value. The value should be the code in the tag manager for the container --- templates/webshop/base.jinja | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/templates/webshop/base.jinja b/templates/webshop/base.jinja index f268e5e..447fca0 100644 --- a/templates/webshop/base.jinja +++ b/templates/webshop/base.jinja @@ -61,6 +61,18 @@ + {% if GOOGLE_TAG_MANAGER %} + + + + + {% endif %} + {% block header %}
{% block header_row_1 %} From 6530e1615696f6d5a5983b1a8c2eb855568a20eb Mon Sep 17 00:00:00 2001 From: Sharoon Thomas Date: Wed, 3 Jun 2015 23:24:36 +0530 Subject: [PATCH 2/2] Avoid stopping propogation of product clicks Stopping the propogation results in customers getting a surprise when using cmd+click or equivalent to open the link in new window. The beacon transport is supported only in some browsers, but it is not worth it to let customers suffer for the sake of analytics. About beacon: https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#transport --- templates/webshop/base.jinja | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/templates/webshop/base.jinja b/templates/webshop/base.jinja index 447fca0..7227225 100644 --- a/templates/webshop/base.jinja +++ b/templates/webshop/base.jinja @@ -647,28 +647,13 @@ if(typeof ga == 'undefined'){ return true; } - e.preventDefault(); - e.stopPropagation(); - var url = $(this).attr('href'); - - // register safety net timeout: - var t = setTimeout(function() { - document.location.href = url - }, 500); - ga('ec:addProduct', { 'id': $(this).data('ga-product-id'), 'name': $(this).data('ga-product-name'), 'category': $(this).data('ga-product-category') }); ga('ec:setAction', 'click', {list: $(this).data('ga-product-list')}); - ga('send', 'event', 'Product', 'click', $(this).data('ga-event-label') || '', { - 'hitCallback': function() { - clearTimeout(t); - // redirect anyway: - document.location.href = url; - }}); - }); + ga('send', 'event', 'Product', 'click', $(this).data('ga-event-label') || '', {transport: 'beacon'}); }); //Tracking product add-to-cart.