For my website I already have GA & GTM. Enhanced E-commerce is already enabled. As can see from below image.
I have tried below code as well.
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<!-- Google Tag Manager -->
<script>(function (w, d, s, l, i) {
w[l] = w[l] || [];
w[l].push(
{'gtm.start': new Date().getTime(), event: 'gtm.js'}
);
var f = d.getElementsByTagName(s)[0],
j = d.createElement(s), dl = l != 'dataLayer' ? '&l=' + l : '';
j.async = true;
j.src =
'https://www.googletagmanager.com/gtm.js?id=' + i + dl;
f.parentNode.insertBefore(j, f);
})(window, document, 'script', 'dataLayer', 'GTM-XXXXX');</script>
<!-- End Google Tag Manager -->
<!-- Google Tag Manager (noscript) -->
<noscript>
<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe>
</noscript>
<!-- End Google Tag Manager (noscript) -->
</head>
<body>
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
"event": "addToCart",
"ecommerce": {
"currencyCode": "USD",
"add": {
"products": [{
"id": "57b9d",
"name": "Kiosk T-Shirt",
"price": "55.00",
"brand": "Kiosk",
"category": "T-Shirts",
"variant": "red",
"dimension1": "M",
"quantity": 1
}]
}
}
});
dataLayer.push({
'event' : 'purchase',
'transactionId': '1234',
'transactionAffiliation': 'Acme Clothing',
'transactionTotal': 38.26,
'transactionTax': 1.29,
'transactionShipping': 5,
'transactionProducts': [{
'sku': 'DD44',
'name': 'T-Shirt',
'category': 'Apparel',
'price': 11.99,
'quantity': 1
},{
'sku': 'AA1243544',
'name': 'Hat',
'category': 'Apparel',
'price': 9.99,
'quantity': 2
}]
});
ga('create', 'UA-XXXXXXX-4');
ga('require', 'ec');
ga('set', 'currencyCode', 'SGD');
ga('ec:addProduct', {
'id': 'P12345',
'name': 'Android Warhol T-Shirt - with UA 4',
'category': 'Apparel',
'brand': 'Google',
'variant': 'black',
'price': '29.20',
'quantity': 1
});
// Transaction level information is provided via an actionFieldObject.
ga('ec:setAction', 'purchase', {
'id': 'T12345',
'affiliation': 'Google Store - Online - with UA 4',
'revenue': '37.39',
'tax': '2.85',
'shipping': '5.34',
'coupon': 'SUMMER2013' // User added a coupon at checkout.
});
ga('send', 'pageview'); // Send transaction data with initial pageview.
</script>
</body>
</html>
I have followed https://ga-dev-tools.appspot.com/enhanced-ecommerce/
Although doing above things it is still not showing any result.
I want to track two things initially.
- Product added to cart
- Order purchase
Any help on above one greatly appreciated.
Thanks
[UPDATE]
I have followed below tutorial as well.
- https://www.youtube.com/watch?v=xgLGWvhOyHU
- https://www.youtube.com/watch?v=3G5wvjC1rHo
- https://www.youtube.com/watch?v=OpUtb_Grl2A [I have done GTM settings like this]
https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce#measure_purchases -> I tried this already
So my latest test code is now
<script>
var dataLayer = window.dataLayer || [];
dataLayer.push({
'event' : 'transaction',
'ecommerce': {
'purchase': {
'actionField': {
'id': 'T12345', // Transaction ID. Required for purchases and refunds.
'affiliation': 'Online Store',
'revenue': '35.43', // Total transaction value (incl. tax and shipping)
'tax':'4.90',
'shipping': '5.99',
'coupon': 'SUMMER_SALE'
},
'products': [{ // List of productFieldObjects.
'name': 'Triblend Android T-Shirt', // Name or ID is required.
'id': '12345',
'price': '15.25',
'brand': 'Google',
'category': 'Apparel',
'variant': 'Gray',
'quantity': 1,
'coupon': '' // Optional fields may be omitted or set to empty string.
},
{
'name': 'Donut Friday Scented T-Shirt',
'id': '67890',
'price': '33.75',
'brand': 'Google',
'category': 'Apparel',
'variant': 'Black',
'quantity': 1
}]
}
}
});
</script>
1st issue it is not showing any event over here.
[LATEST UPDATE]
I am able to get events now, but in E-commerce overview still it's blank