Automatically add an "onclick" to links?
-
I need to add an "onclick" event across ~20 websites to improve my Google Analytics implementation. I know I could do this manually but I"m wondering if there is a script or something that will do this automatically?
I need to modify all the links to look like this:
onclick="_gaq.push(['_link', 'http://www.website.com']); return false;">Website
-
I'm guessing you want to add the onclick events on offsite links or the downloading of files since moving between internal pages in GA is already tracked.
We recently wrote a blog post about this here: http://www.blastam.com/blog/index.php/2011/04/how-to-track-downloads-in-google-analytics/
The automated tagging tool we use is Analytics Engine
It works great and is easy to use.
-
We want to track movement between company websites. Not internal pages but different websites.
We want to add the onclick even to push the user data across domains so we don't lose their history.
-
Ok, to track movement between websites and see them all in one profile you will need to set up some cross domain tracking.
We have another blog post that describes how to do this here: Google Analytics Cross Domain Tracking
I think this is more what you are looking for.
-
That looks great but leads me back to my original question. Is there an automated way to update all of our links between domaina.com and domainb.com to include the onclick gaq push?
We have approximately 20 websites that are all interlinked in some way so it would take quite a bit of time to update every link on every site to include the onclicl.
I'm wondering if there is some kind of tool/product out there that would update these links automatically to include the onclick or do we have to go into each site and manually update each link?
-
The script below can help you automate the cross-domain tagging using jQuery. A few notes:
- Make sure that '_gaq.push(['_setAllowLinker', true])' is defined before the code below
- Edit the 'domainList' array to define your set of domains
- jQuery is required

Let me know if you have any questions.
-
There are some automated scripts that you can try:
http://www.lunametrics.com/blog/2010/02/04/automatic-cross-domain-tracking/
http://www.analyticsmarket.com/freetools/link-tagger
You should always remember to test these 3rd party scripts out thoroughly after installing them to make sure they are tracking correctly.
-
Thank you both for your help. We'll look into these!