Product Purchase Button:
<button id="btnBuy" onclick="SendData();"
JavaScript function to track product details:
<script>
var dataLayer = [];
dataLayer.push( {
'ecommerce': {
'detail': {
'actionField': {'list': 'Apparel Gallery'},
'products': [{
'name': '@GetString("Ecom:Product.Name")',
'id': '@GetValue("Ecom:Product.Number")',
'price': '@GetValue("Ecom:Product.ActualPriceWithVAT")',
'brand': '@GetString("Ecom:Manufacturer.Name")',
'category': 'PRODUCT_CATEGORY'
}]
}
}
});
function SendData()
{
var purchaseData =
dataLayer.push( {
'event': 'addToCart',
'ecommerce': {
'currencyCode': 'SEK',
'add': {
'products': [{
'name': '@GetString("Ecom:Product.Name")',
'id': '@GetValue("Ecom:Product.Number")',
'price': '@GetValue("Ecom:Product.ActualPriceWithVAT")',
'brand': '@GetString("Ecom:Manufacturer.Name")',
'category': 'Apparel',
'variant': $j('input[name=radioDim1]:checked').val(),
'quantity': $j( '#QuantitySelector option:selected' ).val(),
'size': $j( 'input[name=radioDim2]:checked' ).closest( 'label' ).text()
}]
}
}
} );
return purchaseData;
}
</script>
Tag info: Tracking: Event Category: Add to cart Action: {{Event}} Label: {{Page Path}}
Trigger: Event equals addToCart
The Preview mode in Chrome registers the click event but does not show the trigger being fired.