Last active
August 29, 2015 14:07
-
-
Save SearchStar/0daf857ba5ed0cc20d49 to your computer and use it in GitHub Desktop.
Push ecommerce data into a data layer array using JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
var cartProducts = []; | |
var dataLayer = []; | |
for(var i=0; i<x; i++){ | |
cartProducts.push({ | |
'id': transactionId, | |
'sku': sku[i], // string; product ID | |
'name': name[i], // string; product name | |
'category': category[i], // string; category name | |
'price': price[i], // string; product price without tax and shipping | |
'quantity': quantity[i] // string: item count | |
});} | |
dataLayer.push({ | |
'transactionId': transactionId, | |
'transactionAffiliation' : transactionAffiliation, | |
'transactionTotal': transactionTotal, // total price, | |
'transactionTax': transactionTax, // float; tax; number rounded to 2 decimal places | |
'transactionShipping': transactionShipping, // float; shipping price; number rounded to 2 decimal places | |
'transactionProducts': cartProducts, | |
'event': 'trackTrans'}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment