Google Analytics Solutions (Part 2)
Following on from my earlier post: Google Analytics Woes And Solutions; with how my favourite champagne site seems to deal with the unresposiveness of the tracking part of analytics...
In the first post I covered how they deal with loading the urchin.js file when the server was unresposive. Here I cover how they manage keeping the page rendering fast when the tracking is unresponsive. Rather than the regular:
<script type="text/javascript">
_uacct = "UA-xxxxxx-x";
urchinTracker();
</script>
Which contacts Google with the tracking information, they take the execution of the tracking outside of the page rendering, so the page will display and any onload functions will run uninfluenced by any delays in the tracking, as show below.
<script type="text/javascript">
_uacct = "UA-xxxxxx-x";
setTimeout("try{urchinTracker();}catch (e){}",10);
</script>
What they do is fire it off in a timeout or background thread, so the page finishes loading fast, the body's onload fires and all that kind of good stuff happens. (Obviously the UA-xxxxxx-x in the line _uacct = "UA-xxxxxx-x"; would have to be set to your unique code or you won't record anything)
What are the possible downsides with doing this?
I'll have to think on this more but this seems to work nicely...
Update
I took the plunge and have been trying this since Saturday. I am getting tracking for Internet Explorer, Firefox, Safari, Netscape and Opera; so it seems to work with most major browsers.
Reminder
If you do do this remember to keep your urchin.js file fresh with the one from Google as I doubt they'll say when its changed. You should have some leway as they will have to cope with a little lag from proxies caching the file. (see: First post:Google Analytics Woes And Solutions)
In the first post I covered how they deal with loading the urchin.js file when the server was unresposive. Here I cover how they manage keeping the page rendering fast when the tracking is unresponsive. Rather than the regular:
<script type="text/javascript">
_uacct = "UA-xxxxxx-x";
urchinTracker();
</script>
Which contacts Google with the tracking information, they take the execution of the tracking outside of the page rendering, so the page will display and any onload functions will run uninfluenced by any delays in the tracking, as show below.
<script type="text/javascript">
_uacct = "UA-xxxxxx-x";
setTimeout("try{urchinTracker();}catch (e){}",10);
</script>
What they do is fire it off in a timeout or background thread, so the page finishes loading fast, the body's onload fires and all that kind of good stuff happens. (Obviously the UA-xxxxxx-x in the line _uacct = "UA-xxxxxx-x"; would have to be set to your unique code or you won't record anything)
What are the possible downsides with doing this?
- You aren't using it the way Google suggests you should be using it
- It might not work in every browser, works on IE and Firefox, but I don't have a Mac to test Safari and be sure about that.
- If people leave the page too quickly the timeout might not have fired so they won't be tracked; on the other hand if they wait 2 mins for the page to load they are probablly going to leave anyway, not be tracked and possibly not come back...
I'll have to think on this more but this seems to work nicely...
Update
I took the plunge and have been trying this since Saturday. I am getting tracking for Internet Explorer, Firefox, Safari, Netscape and Opera; so it seems to work with most major browsers.
Reminder
If you do do this remember to keep your urchin.js file fresh with the one from Google as I doubt they'll say when its changed. You should have some leway as they will have to cope with a little lag from proxies caching the file. (see: First post:Google Analytics Woes And Solutions)