the google analytics help section tells me it's possible to track javascript events using the _trackPageview() function. (you can see more here: http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55521.

i've tried this, but it's not working. i think it has something to do with the _trackPageview function being defined at the bottom of the page, and not the top.

any ideas?

thanks!
debra

Comments

hass’s picture

any ideas?

No. For links you do not need to do anything.

debonator’s picture

hmm... it's not showing up anywhere in google under events, and i've checked everywhere. in fact, it's never shown up, not even before google changed the API.

debonator’s picture

oh, i should probably also explain that it's not a link to a page, per se. it's a link to the rock the vote registration widget that let's you register to vote. the widget itself is hosted at rock the vote (and not on my side). could that be part of the problem?

thanks.

hass’s picture

Status: Active » Closed (won't fix)

With this explanation and without the urls showing the issue I cannot repro/help. http://drupal.org/node/73179

debonator’s picture

sorry for the delay. steps to reproduce

1. go to www.longdistancevoter.org/california
2. under voter registration, choose the recommended method (our voter registration widget)
3. clicking that link *should* show up as a google analytics event, but does not.

it's driving me slightly crazy, since clicks on our voter registration widget are one of our primary metrics.

thanks in advance for your help.

debra

hass’s picture

I cannot solve such ultra special click events in the module, but you could extend your page code yourself. Please try to append pageTracker._trackEvent('Registration', 'Click', 'Voter Registration Widget'); to your click event. This is an example how you could name your event... change the naming how you like it.

<a id="rtvwaw-launch" onclick="if(typeof(WAReg)=='object')return false;if(!/WebKit\/[4-7]|MSIE [6-9]|Gecko\/200(51[12]|[6-9])|Opera\/9/.test(navigator.userAgent))return true;WAReg={launcherHtml:this.innerHTML,isStandalone:0};var d=document;var s=d.createElement('script');s.src='http://www.registrationbyworkingassets.com/client/wareg.js?popin=1&amp;api_key=Xii0uoCGG_Zl4Ohr281RbxyYTsA&amp;lang=&amp;%72eg_id=&amp;r='+Math.random();d.body.appendChild(s);return false;pageTracker._trackEvent('Registration', 'Click', 'Voter Registration Widget');">Voter Registration Widget</a>
debonator’s picture

thank you so much. i'll try that out and see what happens!

debonator’s picture

one last question: do i just need to add

pageTracker._trackEvent('Registration', 'Click', 'Voter Registration Widget');"

or is it

onClick="pageTracker._trackEvent('Registration', 'Click', 'Voter Registration Widget');

thanks again for your help!

debra

hass’s picture

Not tested, but I think it should be something like ... onclick="javascript:pageTracker._trackEvent('Registration', 'Click', 'Voter Registration Widget');" ...

BradleyT’s picture

It's not an issue with this module, I've been using both (well 5.x) for a long time.

I use this a lot when there's an image and a text link that both link to the same destination page. Put the code on both links and easily track which one gets clicked more often.

<a href="/sign-up" onclick="javascript:pageTracker._trackPageview('/sign-up/banner/83');"><img src="banner83.gif" alt="banner 83" border="0" /></a>
<a href="/sign-up" onclick="javascript:pageTracker._trackPageview('/sign-up/text/click-here-to-sign-up');">Click Here to Sign Up</a>

Also great for tracking clicks on PDF files.

Also note the lowercase onclick so you don't get validation errors :)

frob’s picture

This is not an issue for this module, however, I wrote a module that allows tracking based on css class selectors that integrates with the google analytics module. It is aptly name Google Analytics Event Tracking.

It deploys a simple php api to allow tracking of javascript events through google analytic's event tracking api. This mean no more ugly custom javascript to do event tracking.