/    Sign up×
Community /Pin to ProfileBookmark

Sharing an onClick with Google Analytics

Let me say at the onset, I know my code is wrong. I need some help. I have tried searching the internet for answers and figured it was time to get on a forum and ask for help.

I participate with Google Analytics. It’s great. I am able to add code like

[code]onClick=”javascript:urchinTracker (‘/download/audiofile1’);”[/code]

to a link and it will track that action so that I know how often a file on my HTML site has been downloaded.

The problem is, what if you are using buttons that have rollovers and there is already an onClick in place? How do you add Google’s code to what you already have to get both to work? I am not a novice with javascript, but I am also not a pro, so I need some help on this one. Here’s my code (and I have the standard rollover javascript that Fireworks 8 outputs – it’s linked in as a separate .js file rather than right in the HTML document):

[code]<a href=”../assets/mp3_clips/audioclip1.mp3″ onmouseout=”MM_swapImgRestore()” onmouseover=”MM_swapImage(‘sr_nav_r3_c4′,”,’../assets/nav1_f2.gif’,1)” onclick=”javascript:Popup(‘My Audio’,this.href,’1′); return false” “javascript:urchinTracker(‘/download/audio_clip1’)”><img src=”../assets/nav1.gif” alt=”Clip Length: 1 Min. 1 Sec.” name=”nav1″ width=”70″ height=”19″ border=”0″ id=”nav1″ /></a>[/code]

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@JCF1976authorJun 20.2006 — One note: I have already been communicating with Google Analytics and the code I offered here is one of the options they suggested. The other option didn't seem to work either.
Copy linkTweet thisAlerts:
@JulianJJun 20.2006 — I don't know this google thing but you can put any old javascript code into an event, like so:

onclick="Popup('My Audio',this.href,'1'); urchinTracker('/download/audio_clip1'); return false;"

Julian
Copy linkTweet thisAlerts:
@CharlesJun 20.2006 — onclick="urchinTracker('/download/audio_clip1'); Popup('My Audio',this.href,'1'); return false"
Copy linkTweet thisAlerts:
@JCF1976authorJun 20.2006 — onclick="urchinTracker('/download/audio_clip1'); Popup('My Audio',this.href,'1'); return false"[/QUOTE]

Your example makes sense. I'll try it. Can you explain the return false and how it may or may not affect the urchinTracker('/download/audio_clip1') ?
Copy linkTweet thisAlerts:
@CharlesJun 20.2006 — It has no effect on what goes before. It stops the handler and returns a value of "false"; and that supresses the links natural behavior. Try it with and without and you'll get the idea.
Copy linkTweet thisAlerts:
@JCF1976authorJun 20.2006 — It has no effect on what goes before. It stops the handler and returns a value of "false"; and that supresses the links natural behavior. Try it with and without and you'll get the idea.[/QUOTE]

Thanks! I'll post here again to let you know how it all goes!
Copy linkTweet thisAlerts:
@JCF1976authorJun 21.2006 — onclick="urchinTracker('/download/audio_clip1'); Popup('My Audio',this.href,'1'); return false"[/QUOTE]

Charles, I wanted to let you know that it worked!!! Success!!! I changed the code, tested it on my site, and Google Analytics tracked the MP3 downloads!!!

NOTE: I don't know if it matters (probably not), but I put ";" at the end of "return false"
Copy linkTweet thisAlerts:
@JCF1976authorJun 21.2006 — It has no effect on what goes before. It stops the handler and returns a value of "false"; and that supresses the links natural behavior. Try it with and without and you'll get the idea.[/QUOTE]

By the way, I passed your code along to Google and told them that it worked and that they need to put a page in their Analytics help section with this code! So, if they do put it there then y'all get the credit! You saw it here first, folks!!
×

Success!

Help @JCF1976 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...