Adding onclick event to links

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
jgold723
Super Advanced
Super Advanced
Posts: 40
Joined: Wed Nov 19, 2003 10:14 pm

Adding onclick event to links

Post by jgold723 »

I want to use Google Analytics to track clicks on an outbound link in my Milonic Menu. I need to add the following code to the url:

<a onclick="_gaq.push(['_trackEvent', 'Outbound Links', 'Click', 'Google']);"

How do I do this without breaking the menu?
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Re: Adding onclick event to links

Post by Ruth »

Hi,

I am not a js person, nor analytics so I will post to Milonic, however, I did find a couple of post about onlclicks in a link and using it in a menu. Here is the response, but I have no idea if it will work, you would have to try it and see if the google analytics actually does the tracking or whatever. The original link code given as an example was

Code: Select all

<a href="http://websites.milonic.com/example.com" onClick="javascript: pageTracker._trackPageview('/outgoing/example.com');">
the original aI menu code was

Code: Select all

aI("text=New Helmet Rule;url=/forms/helmet_rule.doc;status=New Helmet Rule;separatorsize=1;");
and then the onclick event was put in like this

Code: Select all

aI("text=New Helmet Rule;url=/forms/helmet_rule.doc;clickfunction=javascript: pageTracker._trackPageview('/forms/helmet_rule.doc') status=New Helmet Rule;separatorsize=1;");
Andy said to remove the javascript: part and make the aI the following:

Code: Select all

aI("text=New Helmet Rule;url=/forms/helmet_rule.doc;clickfunction=pageTracker._trackPageview('/forms/helmet_rule.doc');separatorsize=1;");
So, using yours, and not knowing anything about the text or url, I made this up :)

Code: Select all

aI("text=Whatever Text;url=someplace/on/the/web;clickfunction=_gaq.push(['_trackEvent', 'Outbound Links', 'Click', 'Google']);" );
However, please note, the one Andy put in did not have those square brackets, and it also had a repeat of the url, i.e. that /forms/helmet_rule.doc stuff so I'm not really sure if this will do anything, but figured you could play and see if it worked while I post to Milonic :). I have no way to test for google analytics on my computer to try anything out for you. :(

Ruth
jgold723
Super Advanced
Super Advanced
Posts: 40
Joined: Wed Nov 19, 2003 10:14 pm

Re: Adding onclick event to links

Post by jgold723 »

Thank you! I"ll give that a try.
Post Reply