February 17th, 2013, 06:20 AM
Google analytics custom tracking
I have a form on a site that pretty much pops up when the user clicks on an link with event.preventDefault(). In other words, the page doesn't reload.
Now I thought It would be nice to track this with google analytics. If I read the documentation well it offers two methods I think.. (please correct me if I am wrong)
Than the documentation states:
<a href="#" onClick="_gaq.push(['_trackEvent', 'Videos', 'Play', 'Baby\'s First Birthday']);">Play</a>
So clearly that introduces a second method namely: #2 _trackEvent()
Now the question:
If I were to use the second method, would I need to declare the _gaq.push still at the top of the page? or can i just do this
_trackEvent('Some_wicked_category', action, opt_label, opt_value, opt_noninteraction)
So in other words, only use the function call without declaring the _gaq variable globally like so:
<head><meta charset="UTF-8" />
/* Standard google stuff here */
var _gaq = _gaq || ;
// Should I add my custom _gaq.push here??
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script'); s.parentNode.insertBefore(ga, s);
bla bla bla
/* ### custom tracking here ### */
//use the tracking event
* category (required); The name you supply for the group of objects you want to track.
* action (required)A string that is uniquely paired with each category, and commonly used to define the type of user interaction for the web object.
Last edited by aeternus; February 17th, 2013 at 06:21 AM.
February 18th, 2013, 07:03 PM
For anyone interested.
After a full day google gave back some results. conclusion
this is wrong:
this is right
_gaq.push(['_trackEvent', 'form', 'clicked']);