rss

Automatically add Google Analytics to your footer

21 Apr, 2010 Featured,Functions

It should be noted that using Google’s Asynchronous Analytics code (triggers analytics reporting via javascript) is a much preferred option because it does its reporting in the background without hampering page load speeds. If however you need to use the standard method of inserting Google Analtyics, then here’s a quick tip to insert the analytics code into your site’s footer:

// add google analytics to footer
function add_google_analytics() {
 echo '<script src="http://www.google-analytics.com/ga.js" type="text/javascript"></script>';
 echo '<script type="text/javascript">';
 echo 'var pageTracker = _gat._getTracker("UA-XXXXX-X");';
 echo 'pageTracker._trackPageview();';
 echo '</script>';
}
add_action('wp_footer', 'add_google_analytics');

Remember to change UA-XXXXX-X to your own analytics ID.

Enjoy!

1 Comment

  1. goddd you really suck

Leave a Reply

About The WordPress Guru

Over the last 4 or 5 years, I’ve been digging into the Wonders of WordPress. From the days when the Classic theme was the shizz until now, WordPress has gone from strength to strength both as the blogging platform of choice for many big players and as a CMS with...

Learn more »