Analytics
3.6K members online now
3.6K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Ecommerce Tracking code

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Dear Team,

 

Please help me understand the implementation of the ecommerce tracking code on a website.

 

1. Updating my universal GA code for ecommerce tracking

How to add ecommerce part to my existing Universal GA code?

Below is the update that i have done to my GA code. But my code is not working as no tracking has been recorded yet.

 

Is it correct or need some changes like Trackecommerce or TrackTrans sections? Is it the right way for writing this 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','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-68xxxxxx', 'auto');
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>

 

2. Do i have to add the updated GA code to all pages or just the 'Thank you' Page?

 

3. Does it track both COD and online transaction or just online?

 

 

 

Guys please help with the above queries on priority.

1 Expert replyverified_user

Ecommerce Tracking code

Rising Star
# 2
Rising Star

HI Vivek,

 

So it's hard to say what you've done is good or not.  That is, Ecom requires specific values to be passed into GA. 

 

E.G.  You have these values

 

id': orderID,
'affiliation': store,
'revenue': total,
'tax': tax,
'shipping': shipping,
'city': city,
'state': state,
'country': country

 

is orderId a proper variable for your site?    Most ecom platforms have some sort of integration to turn this on.

 

The GA code only needs to be updated on the receipt page; that said, you're code looks legacy as city, state etc has not been part of the ecom package for a LONG time.

 

Your transaction should carry your order id, revenue shipping and tax and affiliation (if you want).  Some organizations choose not to count shipping and tax and instead pass 0.

 

Your second component of ecommerce is the product array.  Which passes data on all products selected.   At the end of the day, if you don't have a check box integration on your plaftorm, you'll need a developer to do this for you.

 

More on classic ecom here:

 

https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce

 

 

Cheers,

 

Theo Bennett

Analytics Evangelist at MoreVisibility | Contact Me
Connect on LinkedIn

Ecommerce Tracking code

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Dear Theo Bennett

 

Thanks for your reply.

 

I think you are right, i need to customize my code according to my website.

 

Also, can you let me know whether it will track all type of orders like COD and online ?

 

 

 

 

Thanks in advance!

Ecommerce Tracking code

Rising Star
# 4
Rising Star

Hi Vivek,

 

GA is GIGO (Garbage In / Garbabe Out)  so whatever you send, it will track. 

 

Best,

 

Theo

Analytics Evangelist at MoreVisibility | Contact Me
Connect on LinkedIn