2016-01-04 12:49:26 +01:00
|
|
|
<script type="text/javascript">
|
2016-09-22 16:49:39 +02:00
|
|
|
{if $isOrder eq true}
|
|
|
|
{if $isEC == 0}
|
|
|
|
ga('require', 'ecommerce', 'ecommerce.js');
|
2016-01-04 12:49:26 +01:00
|
|
|
|
2016-09-22 16:49:39 +02:00
|
|
|
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.
|
|
|
|
});
|
2016-01-04 12:49:26 +01:00
|
|
|
|
2016-09-22 16:49:39 +02:00
|
|
|
{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}
|
2016-01-04 12:49:26 +01:00
|
|
|
|
2016-09-22 16:49:39 +02:00
|
|
|
ga('ecommerce:send');
|
|
|
|
ga('ecommerce:clear');
|
|
|
|
{else}
|
|
|
|
ga('require', 'ec');
|
2016-01-04 12:49:26 +01:00
|
|
|
|
2016-09-22 16:49:39 +02:00
|
|
|
{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).
|
2017-03-07 13:25:46 +01:00
|
|
|
'brand': '{$item.Category}', // Product brand (string).
|
2016-09-22 16:49:39 +02:00
|
|
|
'price': '{$item.Price}', // Product price (currency).
|
|
|
|
'quantity': {$item.Quantity} // Product quantity (number).
|
|
|
|
});
|
|
|
|
{/foreach}
|
2016-01-04 12:49:26 +01:00
|
|
|
|
2016-09-22 16:49:39 +02:00
|
|
|
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).
|
|
|
|
});
|
|
|
|
|
2016-12-06 11:53:34 +01:00
|
|
|
{literal}
|
|
|
|
var re = new RegExp("([?&])(email=)[^&#]*", "g");
|
2016-12-06 12:07:23 +01:00
|
|
|
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)) {
|
2016-12-06 11:53:34 +01:00
|
|
|
// remove personal data from url before sending to GA
|
2016-12-06 12:07:23 +01:00
|
|
|
url = window.location.search.replace(re, '$1$2');
|
|
|
|
url = url.replace(re2, '$1$2');
|
|
|
|
url = url.replace(re3, '$1$2');
|
2016-12-06 11:53:34 +01:00
|
|
|
var page = window.location.pathname+url;
|
|
|
|
ga('send', 'pageview', page);
|
|
|
|
} else {
|
|
|
|
ga('send', 'pageview');
|
|
|
|
}
|
|
|
|
{/literal}
|
2016-09-22 15:52:17 +02:00
|
|
|
{/if}
|
2016-01-04 12:49:26 +01:00
|
|
|
{/if}
|
|
|
|
|
|
|
|
</script>
|