Two Yoast google-analytics-plugin hacks for WordPress

SAN JOSE, CA - JULY 22:  A plug-in Toyota Priu...
Image by Getty Images via Daylife

I love WordPress. And I love Yoast’s Google Analytics plugin for WordPress. It makes installation of GA so much swifter. And I really hate hacking plugins because that means I have to be careful when I upgrade them. But there are two things that really stick in my craw:

  1. The RSS campaign tags are configured so that each article is it’s own campaign.
  2. I’d love to be able to implement additional tricks, like using a timer to make my Bounce-rate a function of time, not pageviews.

Campaign Tagging URL for RSS hack in WP

Since the (super-awesome) plugin doesn’t allow you to manually configure the tagging for the RSS feed, I had to go in and do it myself. You find the code for RSS tracking around line 560 in the plugin code. It’s all hard-coded and easy enough to adjust.

I set mine up so that the post headline is matched up with the utm_content tag, so that it accurately reflects the content of whatever it was someone clicked on.

Time-based bounce-rate for Google Analytics and WordPress

I got the idea to make a time-based bounce-rate from Padicode. But instead of hardcoding WP into my site template, I had to hack the Yoast plugin. You’ll find the location to insert a timer into your GA tracker around line 400 of the plugin code. You’ll need to escape some characters so the line will ultimately look something like this:

echo "\t\t".'setTimeout(\'pageTracker._trackEvent(\'NoBounce\',\'NoBounce\', \'Over 20 seconds\')\',20000);'."\n";

Good luck and have fun!

Join the Conversation


  1. Great post!

    Can you say where you precisely insert the code? For example what is there before and after where you put the code?

    Incidentally annoying that you do not have a Subscribe to Comments feature 🙂

    1. I think I would probably deprecate the info in this post and just go for using the fancy new tag manager if I were starting from scratch today.

      Also, so sorry that this free resource isn’t convenient enough for you. 😉

Leave a comment

Your email address will not be published. Required fields are marked *