40 hours of SEO Analysis Within Minutes!

Fast. Secure. Free.

 

<!– customHTML on sale page AND event=gtm.dom ready –>

<script>

// Cannot execute loops within an array declaration.

// Thus – first create the products array before pushing it into dataLayer.

window.digitalData = window.digitalData || [];

var eCommProducts = [],

currProduct, i, ii;

for (i = 0, ii = window.digitalData.transaction.item.productInfo.length; i < ii; i += 1) {

currProduct = window.digitalData.transaction.item.productInfo[i];

eCommProducts.push({

“id”       : window.digitalData.transaction.transactionID, // OrderID

“sku”     : currProduct.productID, // ProductSKU

“name”     : currProduct.productName,

“category” : currProduct.category,

“brand”   : currProduct.manufacturer,

“variant” : currProduct.size,

“coupon”   : currProduct.voucher,

“price”   : currProduct.price,

“quantity” : currProduct.quantity

});

}

// Now declare Ecommerce payment dataLayer variables

window.dataLayer = window.dataLayer || [];

window.dataLayer.push({

“transactionCurrency”   : window.digitalData.transaction.total.currency,

“transactionId”         : window.digitalData.transaction.transactionID,

“transactionAffiliation”: window.transaction.attributes.paymentMethod,

“transactionPaymentType”: window.digitalData.transaction.attributes.paymentMethod,

“transactionTotal”     : window.digitalData.transaction.total.transactionTotal,

“transactionTax”       : window.digitalData.transaction.total.tax,

“transactionShipping”   : window.digitalData.transaction.total.shipping,

“transactionDate”     : window.dataLayer.attributes.transactionDate,

“transactionVoucher”   : window.digitalData.transaction.total.voucherCode,

“transactionVoucherDiscount”: window.digitalData.transaction.total.voucherDiscount,

“transactionProducts”   : eCommProducts // Trigger Loop array above

});

// Set the pagetype

window.dataLayer.push({

“google_tag_params”: {

“ecomm_pagetype”: “purchase”

},

“page”: {

“category”: {

“primaryCategory”: “confirmation”,

“pageType”: “purchase”

},

}

};

// Now Send Transaction

window.dataLayer.push({“event”: “customhtml_wc3_ecommerce_mapping_loaded”});

</script>

 

0117 3361103