Wednesday, October 09, 2013

Massively Throwing Off Your Google Analytics eCommerce Stats in One Easy Step

One of my clients was looking through their Google Analytics eCommerce stats when they were surprised to see this completely whacky amount. Under transactions, it stated that one of the orders had a revenue value of: ($9,223,372,022,317.22).

That's special, no?

Google Analytics for eCommerce is fairly easy to setup. You just need to invoke some JavaScript, specifically the _addTrans() function.

My first thought when I saw that whacky number was that it was due to a type conversion issue. Suppose I have:

 var x = "30";
 var y = "50";
 alert(x + y);

You might think that the above value is 80, but of course, the answer is 3050. That is, I was thinking the above massive (well, super tiny massive) number was constructed out of string concatenation.

Turns out, my guess was wrong and the answer was even easier. Apparently, the total for the order was being set to NaN. And I was sending the following to Google:

http://www.google-analytics.com/__utm.gif?
  utmwv=5.4.5&
  utmtid=TXID&
  utmtto=NaN&  **** Notice the NaN
  utmttx=&
  utmtsp=0&
  ...

Apparently, when Google interprets the text NaN it's coming up with that super tiny value.

I fixed the bug that was causing the total to be NaN in JavaScript, and now I'm good to go.

Still, it's surprising how easy it was to get that ridiculous value in Analytics.

No comments:

Post a Comment