Merge branch 'ticket-GAnalytics'

This commit is contained in:
Marion Muszynski 2016-10-07 13:57:15 +02:00
commit 797b0e499f

View File

@ -193,7 +193,102 @@
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-68580471-1', 'auto');
ga('send', 'pageview');
{/literal}{if isset($page_name) && $page_name == 'category'}{literal}
ga('require', 'ec');
{/literal}{else if isset($page_name) && $page_name == 'product'}{literal}
ga('require', 'ec');
ga('ec:addProduct', {
'id': {/literal}{$product->id}{literal},
'name': "{/literal}{$product->name|escape:'htmlall':'UTF-8'}{literal}",
'category': "{/literal}{$sale->title[$cookie->id_lang]}{literal}"
});
ga('ec:setAction', 'detail');
{/literal}{else if isset($page_name) && $page_name == 'order'}{literal}
ga('require', 'ec');
{/literal}
{if $step == 0 || $step == 1}
{if $cart}
{assign var='cartProducts' value=$cart->getProducts()}
{foreach from=$cartProducts item=cartProduct}
{literal}
ga('ec:addProduct', {
'id': {/literal}{$cartProduct['id_product']}{literal},
'name': "{/literal}{$cartProduct['name']}{literal}",
'category': "{/literal}{$cartProduct['category']}{literal}",
'price': {/literal}{Tools::ps_round(Product::getPriceStatic((int)$cartProduct['id_product'], true, ((isset($cartProduct['id_product_attribute']) AND !empty($cartProduct['id_product_attribute'])) ? (int)($cartProduct['id_product_attribute']) : NULL), 2), 2)}{literal},
'quantity': {/literal}{$cartProduct['cart_quantity']}{literal}
});
{/literal}
{/foreach}
{/if}
{/if}
{literal}
{/literal}{if $step == 0}{literal}
//cart
ga('ec:setAction','checkout', {
'step': 1,
});
{/literal}{else if $step == 1}{literal}
// address
ga('ec:setAction','checkout', {
'step': 2,
});
{/literal}{else if $step == 2}{literal}
// carrier
ga('ec:setAction','checkout', {
'step': 3,
});
{/literal}{else if $step == 3}{literal}
// payment
ga('ec:setAction','checkout', {
'step': 4,
});
{/literal}{/if}
{/if}{literal}
{/literal}{if isset($page_name) && (($page_name == 'order-confirmation' && $isEC==0) || $page_name != 'order-confirmation')}{literal}
// send pageview via header.tpl du module GA si isEC=1 and $page_name == 'order-confirmation'
ga('send', 'pageview');
{/literal}{/if}{literal}
function onStepComplete(stepNumber, option, redirect, form) {
ga('ec:setAction', 'checkout_option', {
'step': stepNumber,
'option': option
});
if (redirect != null) {
ga('send', 'event', 'Checkout', 'Option', {
hitCallback: function() {
document.location = redirect;
}
});
} else if (form != null) {
ga('send', 'event', 'Checkout', 'Option', {
hitCallback: function() {
form.submit();
}
});
} else {
ga('send', 'event', 'Checkout', 'Option', {});
}
}
function addToCartToGA(product) {
ga('ec:addProduct', {
'id': product.id,
'name': product.name,
'variant' : product.variant,
'price': product.price,
'quantity': product.qty
});
ga('ec:setAction', 'add');
ga('send', 'event', 'UX', 'click', 'add to cart');
}
</script>
{/literal}
{/if}