Google e-Commerce tracking doesn't track - google-analytics

I tried to test google e-commerce tracking locally and I have put this code in my order finalize.aspx page
But when I go to google analytics profile - I see that one user is checking the site but none of my products are added to the reporrting of e-commerce
What may be the problem?
<title>Receipt for your clothing purchase from Acme Clothing</title>
<script type="text/javascript">
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-68062306-1', 'none');
ga('send', 'pageview');
ga('require', 'ecommerce');
ga('ecommerce:addTransaction', {
'id': '1234', // Transaction ID. Required.
'revenue': '11.99', // Grand Total.
'shipping': '5', // Shipping.
'tax': '1.29' // Tax.
});
ga('ecommerce:addItem', {
'id': '1234', // Transaction ID. Required.
'name': 'Fluffy Pink Bunnies', // Product name. Required.
'sku': 'DD23444', // SKU/code.
'category': 'Party Toys', // Category or variation.
'price': '11.99', // Unit price.
'quantity': '1' // Quantity.
});
ga('ecommerce:send');
</script>

Related

Google Analytics GA - purchase event

I can't sent purchase event to google analytics. I can send others events if i use "ga('enet', 'event' ... " but code below do not working.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Success Page</title>
<script>
(function (i, s, o, g, r, a, m) {
i.GoogleAnalyticsObject = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga("create", "UA-XXXX-Y");
ga('require', 'ec');
ga('set', 'currencyCode', 'USD');
ga('set', 'anonymizeIp', true);
ga('ec:addProduct', {
'id': "8500830",
'name': "TEST",
'price': "2.9100",
'quantity': "1.0000"
});
ga('ec:setAction', 'purchase', {
'action': 'purchase',
'affiliation': "TEST",
'id': "000000111",
'revenue': "15.9100",
'shipping': "13.0000",
'tax': "0.0000"
});
ga('send', 'pageview');
</script>
</head>
<body></body>
</html>
I do not see any errors in chrome dev tools, but this event dosen't appear in "Real-time -> Conversion".
Any suggestion why?
E-commerce transactions are not reported as 'event' in google analytics so it's OK if you don't see it in Real-time report.
In this case, transaction data are sent alongside pageview hit so only corresponding pageview will appear in Real-Time.
Check the Conversions>Ecommecre reports to check if your transactions data are processed properly.

Creating a product array for Google Analytics ecommerce via GTM

I have the following function to pass items from a shopping cart into the data layer and then on to Google Analytics through GTM.
No problem with the variables, those are all populating fine. It's how I've tried to create the products array, it's not done correctly. If I have more than one product in the cart, only the first product gets passed into the data layer.
You'll notice two events: sendTransaction and sendUpsell. That's because there's an option in the shopping cart to also make a personal donation on top of the products you're purchasing which gets added to the total transaction amount.
function eCommerceTracker(){
var storeId = "store_id";
var personalGift = $('p#additional_donation').text().replace("$","").replace(/[,]/g, "").trim();
var trackingCode = $('span#tracking_code').text().trim();
var numItems = $("div.ShoppingCart [class*='ShoppingCartRow']").length;
eQuantity = [];
transTotal = [];
itemName = [];
$("div.ShoppingCart [class*='ShoppingCartRow']").each(function(){
eQuantity.push($(this).find("div.quantity-column").text().trim());
itemName.push($(this).find("span.CartItemName").text().replace("'",""));
transTotal.push($(this).find("div.price-column").text().replace("$","").replace(/[,]/g, "").trim());
});
eTotal = $("div.ShoppingCart div.total-price-column:last").text().replace("$","").replace(/[,]/g, "").trim();
for (var i = 0; i < numItems; i++) {
if(eQuantity[i] > 0){
dataLayer.push({
'event': 'sendTransaction',
'ecommerce': {
'purchase': {
'actionField': {
'id': trackingCode,
'affiliation': storeId,
'revenue': eTotal
},
'products': [{
'id': trackingCode,
'name': itemName,
'category': 'eCommerce',
'price': transTotal,
'brand': 'myBrand',
'quantity': eQuantity
}]
}
}
});
}
}
//Adding personal gift
if(personalGift){
dataLayer.push({
'event': 'sendUpsell',
'ecommerce': {
'purchase': {
'actionField': {
'id': trackingCode,
'affiliation': storeId,
'revenue': personalGift
},
'products': [{
'id': trackingCode,
'name': 'Personal Gift',
'category': 'Upsell',
'price': personalGift,
'brand': 'myBrand',
'quantity': '1'
}]
}
}
});
}
}
Does anything look immediately wrong with what I've created here?

Shopping Behavior Analysis is not showing data in google analytics

I have connected my big-commerce site with google analytics E-commerce , but i am unable to view any data in "Shopping Behavior Analysis" section
Here is my site e-commerce tracking code
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-25352625-2', 'duringdays.com.au');
ga('send', 'pageview');
ga('require', 'ecommerce', 'ecommerce.js');
function trackEcommerce() {
this._addTrans = addTrans;
this._addItem = addItems;
this._trackTrans = trackTrans;
}
function addTrans(orderID,store,total,tax,shipping,city,state,country) {
ga('ecommerce:addTransaction', {
'id': orderID,
'affiliation': store,
'revenue': total,
'tax': tax,
'shipping': shipping,
'city': city,
'state': state,
'country': country
});
}
function addItems(orderID,sku,product,variation,price,qty) {
ga('ecommerce:addItem', {
'id': orderID,
'sku': sku,
'name': product,
'category': variation,
'price': price,
'quantity': qty
});
}
function trackTrans() {
ga('ecommerce:send');
}
var pageTracker = new trackEcommerce();
</script>
please any body let me know where i am wrong , i need to add any other code to track those information ?
thanks

how to include google analytics in each page but eccomerce tracking only in my 'thank you page'

I've included the Google Analytics tracking in the layout of my site so each page can be tracked.
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-XXXXX-YY', 'none');
ga('send', 'pageview');
</script>
And I want to include the script for ecommerce tracking only in my last thank you page after a purchase has been made.
<script>
ga('ecommerce:addTransaction', {
'id': '<%:order.DocumentNo%>', // Transaction ID. Required.
'revenue': '<%:order.TotalOrderPriceWithVat%>', // Grand Total.
'shipping': '<%:order.TotalTransportPrice %>', // Shipping.
'tax': '0' // Tax.
});
<
ga('ecommerce:addItem', {
'id': '<%:order.DocumentNo %>', // Transaction ID. Required.
'name': '<%:item.ProductDescription %>' +' '+ '<%:item.BrandName%>', // Product name. Required.
'sku': '<%:item.Item_Id %>', //Item ID
'category': '<%:item.CustomData %>', // Category or variation.
'price': '<%:item.OrderPriceWithVat %>', // Unit price.
'quantity': '<%:item.Quantity %>' // Quantity.
});
</script>
The problem is in the last page I get the error ga is undefined
Basic tracking
load analytics.js library
init tracker (create)
track pageview
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-XXXXXXX-YYY', 'none');
ga('send', 'pageview');
Ecommerce tracking
load analytics.js library
init tracker (create)
load ecommerce plugin
track pageview
add transaction description
track transaction
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-XXXXXXX-YYY', 'none');
ga('require', 'ecommerce'); // load ecommerce plugin
ga('send', 'pageview');
ga('ecommerce:addTransaction', {
'id': '<%:order.DocumentNo%>', // Transaction ID. Required.
'revenue': '<%:order.TotalOrderPriceWithVat%>', // Grand Total.
'shipping': '<%:order.TotalTransportPrice %>', // Shipping.
'tax': '0' // Tax.
});
ga('ecommerce:addItem', {
'id': '<%:order.DocumentNo %>', // Transaction ID. Required.
'name': '<%:item.ProductDescription %>' +' '+ '<%:item.BrandName%>', // Product name. Required.
'sku': '<%:item.Item_Id %>', //Item ID
'category': '<%:item.CustomData %>', // Category or variation.
'price': '<%:item.OrderPriceWithVat %>', // Unit price.
'quantity': <%:item.Quantity %> // Quantity.
});
ga('ecommerce:send'); // track transaction
Documentation
https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce

Google Analytic Enhanced eCommerce issue

No problems with my code(checked with tag assistant as well as analytics debugger). The problem is that I am not seeing product impression data from within analytics. IP filter is disabled, and cookiedomain is set to none.
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-XXXXXX-1', 'none');
ga('require', 'ec');
ga('require', 'displayfeatures');
ga('ec:addImpression', {
'id': 'lg1111',
'name': 'LG Example Product ',
'category': 'Cell Phones',
'brand': 'LG',
});
ga('set','dimension1', 'exampleSKU'); // REQUIRED Product ID value, e.g., 12345, 67890
ga('set','dimension2', 'product'); // Optional Page type value, e.g., home, cart, purchase
ga('send', 'pageview');
</script>
A product impression is not the same as a "product view".
Use the add product detail view to register a hit for a product.

Resources