Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've got a WP3 custom menu, with a custom link in the menu, How can I add google analytics event tracking to that custom link.

Thanks Alex

share|improve this question

1 Answer 1

Is it an outbound link? Otherwise it should automatically get tracked (as a page view). If it is outbound, I'd set a class on the custom menu item in Wordpress (using the CSS Classes (optional) field). Then you could trigger that link with JavaScript. For example, with jQuery you could do something like this (assuming you are using the Async version of Google Analytics):

$('.custom-classname').delegate('a', 'click', function(e) {
   e.preventDefault();
   _gat._getTrackerByName()._trackEvent('outbound', 'custom link');
   var lnk = $(this).attr('href');
   setTimeout('document.location = "' + lnk + '"', 100);
});

The setTimeout is there to make sure that Google Analytics has time to read the event before the browser sends the user to the outbound link.

I hope that helps.

Link: http://www.google.com/support/analytics/bin/answer.py?answer=55527

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.