bebeboutik/modules/ganalytics/header.tpl
Michael RICOIS 85f4874ac8 Validation
2018-01-23 17:10:17 +01:00

70 lines
2.7 KiB
Smarty
Executable File

<script type="text/javascript">
{if $isOrder eq true}
{if $isEC == 0}
ga('require', 'ecommerce', 'ecommerce.js');
ga('ecommerce:addTransaction', {
'id': '{$trans.id}', // Transaction ID. Required
'affiliation': '{$trans.store}', // Affiliation or store name.
'revenue': '{$trans.total}', // Grand Total.
'shipping': '{$trans.shipping}', // Shipping.
'tax': '{$trans.tax}' // Tax.
});
{foreach from=$items item=item}
ga('ecommerce:addItem', {
'id': '{$item.OrderId}', // Transaction ID. Required.
'name': '{$item.Product}', // Product name. Required.
'sku': 'DD23444', // SKU/code.
'category': '{$item.Category}', // Category or variation.
'price': '{$item.Price}', // Unit price.
'quantity': '{$item.Quantity}' // Quantity.
});
{/foreach}
ga('ecommerce:send');
ga('ecommerce:clear');
{else}
ga('require', 'ec');
{foreach from=$items item=item}
ga('ec:addProduct', { // Provide product details in an productFieldObject.
'id': '{$item.SKU}', // Product ID (string).
'name': '{$item.Product}', // Product name (string).
'category': '{$item.Category}', // Product category (string).
'brand': '{$item.Category}', // Product brand (string).
'price': '{$item.Price}', // Product price (currency).
'quantity': {$item.Quantity} // Product quantity (number).
});
{/foreach}
{if $cookie->transCpt < 2}
ga('ec:setAction', 'purchase', { // Transaction details are provided in an actionFieldObject.
'id': '{$trans.id}', // (Required) Transaction id (string).
'affiliation': '{$trans.store}', // Affiliation (string).
'revenue': '{$trans.total}', // Revenue (currency).
'tax': '{$trans.tax}', // Tax (currency).
'shipping': '{$trans.shipping}', // Shipping (currency).
});
{/if}
{literal}
var re = new RegExp("([?&])(email=)[^&#]*", "g");
var re2 = new RegExp("([?&])(customer_lastname=)[^&#]*", "g");
var re3 = new RegExp("([?&])(customer_firstname=)[^&#]*", "g");
if (document.location.href.match(re) || document.location.href.match(re2) || document.location.href.match(re3)) {
// remove personal data from url before sending to GA
url = window.location.search.replace(re, '$1$2');
url = url.replace(re2, '$1$2');
url = url.replace(re3, '$1$2');
var page = window.location.pathname+url;
ga('send', 'pageview', page);
} else {
ga('send', 'pageview');
}
{/literal}
{/if}
{/if}
</script>