Analytics
4.6K members online now
4.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

Some enhanced ecommerce purchases not recorded but events are

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I have a purchase form. Upon success, the following javascript is executed:

ga('send', 'event', productInfo.name, 'purchased');
ga('set', '&cu', productInfo.currency);
ga('ec:addProduct', {'id':productInfo.id, 'name':productInfo.name, 'price':productInfo.price, 'quantity':1});
ga('ec:setAction', 'purchase', {id: data.txn_id, revenue: productInfo.price});

As you can see, at the same time I'm sending a 'purchase' event and an enhanced eCommerce event.

 

Here's where it get weird: the 'purchase' event is recorded correctly, but only about 50% of the eCommerce events are recorded. It just doesn't make any sense. The values should match within a very narrow threshold.

 

The GA code I'm using in page's head is:

(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-x', 'xxxxxxxxxxxx.com');
ga('require', 'ec');
ga('send', 'pageview');

Any ideas? 

1 Expert replyverified_user

Some enhanced ecommerce purchases not recorded but events are

Follower ✭ ✭ ✭
# 2
Follower ✭ ✭ ✭

The problem might be the execution of the javascript. The DOM might not finish rendering the page elements in time for the next commands to send the following ec events. 

 

ga('ec:setAction', 'purchase', {id: data.txn_id, revenue: productInfo.price});

You need to add ' ' to the value pairs for this line? id and revenue

 

Maybe throw in some console.logs and send the same data to the console so you can see if it is sending the rest I think the above will fix your problem.

Some enhanced ecommerce purchases not recorded but events are

Top Contributor
# 3
Top Contributor

Hi @Armand N just make sure the event line is below the ecommerce setup and not on top as EE requires an existing hit for the payload to be sent with.

 

e.g. 


ga('set', '&cu', productInfo.currency);
ga('ec:addProduct', {'id':productInfo.id, 'name':productInfo.name, 'price':productInfo.price, 'quantity':1});
ga('ec:setAction', 'purchase', {'id': data.txn_id, 'revenue': productInfo.price});
ga('send', 'event', productInfo.name, 'purchased');

Hope it helps!

 

Kind regards,

Zorin

Web analyst @ escapestudio.net

Some enhanced ecommerce purchases not recorded but events are

Visitor ✭ ✭ ✭
# 4
Visitor ✭ ✭ ✭

I found the issue. The txn_id needed to be quoted.... Silly me. Some IDs were numeric and working, some were alpha-numeric and were failing, hence the inconsistent results.