BUG: Flash Google Analytics trackEvent

Today I was integrating with Google Analytic’s Flash codebase and ran into a bug that had me running up against a wall for about 45 minutes. It was a simple bug, but no details bubbled up from the code base to let me know what was occurring. I’m noting it here for everyone else’s sanity. If you want to skip all the details and just know the cause jump down to the end of the post.

I had set up my analytics package all via code and made a simple track call.

For the sake of this example, it looked equivalent this

 import com.google.analytics.GATracker;
// setup tracker
 var tracker:GATracker = new GATracker(this, "UA-111-222", "AS3", true);
// make simple track event with a numeric value
 tracker.trackEvent("MyCategory", "MyEvent", "Title1", 10.5);

Very simple right? I had followed examples online and on the surface it all appeared to work correctly. I could see the calls in the visual debugger working exactly how I wanted. However, when looked to see if the calls were going to the server with a packet sniffer, no dice! Nothing was going through. I checked my code about 500 times, looked to see if trackEvents were just beta, and tried to find out if I wasn’t setting something for production.

I couldn’t find anything. It wasn’t until I switched the call to trackPageview that it started to go through. That worked. I decided to take the numeric value out of the call for the trackEvent call, since that was a variant between trackEvent and trackPageview. Ching, ching, little winner. Everytime I added it back in it failed silently and didn’t call the server. I then noticed that the number was a fraction and not a Integer (even though the call’s signature has it as Number). Therefore I decided to round the fraction everytime, and triple ching, we had the final winner.

The bug turned out to be that trackEvent can only take Integers as the numeric value in it’s call. If you make calls using trackEvent you must round all numbers going in or the calls will not be sent out to the server.

Hope this helps with some folks headaches. Also if you ever have a bug with no details, follow the example above and work backwards. Looking at variants and testing multiple inputs you can find the root.

Post a comment

You may use the following HTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">