Est. Reading Time: 4 minutes
Sometimes when a website is not working correctly it causes you do document someone else’s code. In this case, I discovered something about Google Analytics (“GA”).
One of my newly inherited clients recently installed a “popover” advertisement on their front page, as a promo for a new product line, and wanted to track the clicks in Google Analytics. It wasn’t tracking, however. The original code installed had a couple of problems:
- The page didn’t originally have the GA code installed to send events anywhere. That was fixed.
- The page then wasn’t firing the event. The event was there, but there wasn’t an onClick or onLoad being used to reference or “fire” the event back to GA. That too was fixed, but still no events were tracking.
We are using the new asynchronous (“async”) style GA code in the popover’s HTML. The popover was being loaded by the homepage in an iFrame. The homepage was still using the older Urchin GA code. I was pretty sure this was the problem. It wasn’t.
The originally coded event was:
_gaq.push(['_trackEvent', 'the-event-name', 'Click', 1]);
_gaq.push(['_trackEvent', 'category', 'action', 'label']);
After changing the attributes to what I thought would be informative categories, actions and labels, all as strings, it worked. Now tracks the events with Ads being the Category, Popovers being the Action and The-Ad-Name is the Label.
Alittle More on Urchin vs Traditional JS vs Async Google Analytics Calls
Why Wasn’t It a Problem?
Since the popover is loaded in an IFRAME, with its own URI and HTML, it is treated as a distinct event by GA. Sometimes you find good answers out of simple curiosity when something isn’t working.
I JUST WANTED IT TO WORK