Google Analytics vs Spry Framework
While working on My Fan Flash, I was asked to integrate Google Analytics to the site. After all, what site these days doesn’t want to track it’s users?
So I did the usual. I created a new analytics account, grabbed the tracking script and installed it with the proper tracking code in the footer of the site. After pushing it to production, I was done. Sat back and waited for the first hit. And waited. Hmm… visited the site a few times with different browsers, but still no hits were being recorded.
Alright, time to get dirty. I opened the site in Firefox and enabled Firebug (I can’t work without it,it’s just too useful!). I set a breakpoint on the _trackPageView function and to my suprise it wasn’t hit. I put another breakpoint on the script load, refreshed the page and to my relief that breakpoint was hit. I started stepping through the code and ended up inside the Spry framework code. Apparently, Spry is wiring up an event handler that breaks the new Google Analytics script.
Surprisingly, there wasn’t much to be found on the internet about this but over on the Google Analytics, I did find the brand new asynchronous tracking script that can go in the document head instead of the footer. Google claims that this will speed page loads and improve compatibily with scripts that use onLoad handlers.
After replacing the old ga.js snippet with the shiny new async snippet and pushing to production, tracking for this site was functional again. So if you are having issues with Google Analytics not working on your site and you’re using third-party scripts that hook into the page load event, switch to the new the async snippet.
Filed under: Development
