Reputation: 89
I added the code below via GTM, when I make a test purchase I see the data layer but the ecommerce data is not being sent to analytics. I have the tag firing on a page view of the success page.
<script>
window.dataLayer = window.dataLayer || [];
var productArray = [];
var x = document.getElementsByClassName("ved");
var quantity = document.getElementsByClassName("qty-class");
var sku = document.getElementsByClassName("productid");
var price = document.getElementsByClassName("price-class");
var y = x[0].innerHTML;
var len=x.length;
for(i=0; i < len; i++){
var pO = {};
pO.name = x[i].innerHTML;
pO.quantity = parseInt(quantity[i].innerHTML);
pO.price = parseInt(price[i].innerText);
pO.sku = sku[i].innerHTML;
pO.category = 'MyCategory';
productArray.push(pO);
};
var revenue = document.getElementById("order-total").innerText;
var ship = document.getElementById("shipping").innerText;
var tid = document.getElementById("t_id").innerText;
dataLayer.push({
'transactionId': tid,
'transactionAffiliation': 'MyWebsite',
'referrer':{{ref}},
'transactionTotal': parseInt(revenue),
'transactionTax': 0,
'transactionShipping':parseInt(ship),
'transactionProducts': productArray,
'event':'transactioncomplete'
});
</script>
Upvotes: 1
Views: 1587
Reputation: 8907
It looks like you are implementing standard ecommerce tracking (as opposed to enhanced ecommerce). To track the transaction into GA, you need to use a "Transaction" type tag, and not a pageview tag. It should be pretty clear here (https://support.google.com/tagmanager/answer/6107169?hl=en) on how to set that up in GTM. Your event transactioncomplete
would then trigger this tag.
Upvotes: 2
Reputation: 564
First, make sure that you have enabled enhanced ecommerce in the admin section of GA. Second, it looks like you are missing the ecommerce portion in the dataLayer. See the GTM docs
Upvotes: 0