I’m trying to record the url of a page when a user clicks a submit button using google analytics event trackers.
I have found a javascript function that should do the job but i cannot get it to work. Any suggestions?
I have dropped this is the underneath the google analytic s snippit.
function recordOutboundLink(link, category, action) {
try {
var myTracker=_gat._getTrackerByName();
_gaq.push(['myTracker._trackEvent', ' + category + ', ' + action + ']);
setTimeout('document.location = "' + link.href + '"', 100)
}catch(err){}
}
And Added this to the sumbit button.
<a href="/confirmation.html" onClick="recordOutboundLink(this, 'Outbound Links', 'example.com'); return false;">
but google anayltics isn’t recording anything.
Several problems with the
_trackEventcall — The syntax for the async version should beAlso, it looks like you’re mixing old style analytics code with with async style code — you don’t need to use
_getTrackerByNamein this case.Try the following version: