2016-09-22 16:49:39 +02:00

53 lines
2.3 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).
'price': '{$item.Price}', // Product price (currency).
'quantity': {$item.Quantity} // Product quantity (number).
});
{/foreach}
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).
});
ga('send', 'pageview');
{/if}
{/if}
</script>