Updated: Tracking Exit Links in Google Analytics
I’ve just updated my code on tracking exit links in Google Analytics to skip applying the code if the href of an anchor tag is ‘#’. This is usually the case when the anchor tag is there to execute javascript or to scroll to the top of the page, thus does not contain any exit liks.
This can be found on line 29 with the addition of a condition in the condition statement, anchors[i].href != (document.location + ‘#’).
I’ve seen a few other scripts that tracks exit links but some of them I don’t think are very good as they lack error checking and also some of them overwrite the existing onclick attribute which I guess could break the site’s functionality.
Also to prove to you that my script is working, I’ve included a screenshot of the report found in google analytics.
Of course you can click through to the individual links and analyse the dimensions for further analysis. I will be working on more google analytics custom scripts to help bring and enhance more meaningful reports.
Tracking Exit Links in Google Analytics
I’ve been spending my time writing a script that will help track exit links (external links) in Google Analytics. This script will traverse through all anchor tags within the body and apply tracking codes on tags with the href attribute.
If the anchor tag has an onclick attribute already, it appends the tracking code to it and it shouldn’t affect the functionality.
I will try to post screenshots of how it looks in Google Analytics once I gather some data. To use it, simply paste the following code after the google analytics code and before the </body> tag.
<script type="text/javascript" src="<PATH-TO-SCRIPT>"></script> <script type="text/javascript"> dtalk_ga.applyVirtualExits(); </script>
You can view the source code here,
Continue reading »
Google Analytics API
For some reason I found it pretty hard to find Google Analytic’s (GA) API on Google itself.
Most GA users usually use the default installation by just copying and pasting the code into their templates to track website statistics.
If you’re interesting it configuring GA to track e-commerce transactions and customising how GA records your traffic and visitors, visit the Google Analytic’s API.
The documentation is quite good and easy to understand (somewhat similar to Java’s API documentation).



