WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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) {
   _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


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