Where do I add my Google Analytics Tracking code on a WordPress Site?

January 31, 2008

If your website is built using a package like WordPress, Joomla/Mambo, Durpal or anyone of a number of other pre-built CMS-type applications then I am that there may be a little confusion as to where the tracking code goes. The confusion exists because the PHP modules that WordPress uses form a complete page. For instance let’s say that the main page of your WordPress is constructed from a Header PHP object, Page Template PHP object and a Footer PHP object (all included in the WordPress Package available from WordPress.org) it is easy to get confused as to just where the code goes. On the Google Analytics Help site it asks you to install the code just before the end of the </body> tag. Here is an example as to what that looks like in WordPress…

<div id=”footer”>

 Your Footer Code

<?php wp_footer(); ?>

 

<!– Start of Google Analytics GA.JS Tracking Code –>

<script type=”text/javascript”>

var gaJsHost = ((”https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);

document.write(unescape(”%3Cscript src=’” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));

</script>


<script type=”text/javascript”>

var pageTracker = _gat._getTracker(”UA-XXXXXXX-X”);

pageTracker._initData();

pageTracker._trackPageview();

</script>

<!– End of Google Analytics GA.JS Tracking Code –>


</body>

</html>

Keep in mind that Joomla/Mambo, Durpal and other website package deployment tools are different but if you run into any issues please post a question and we’ll get back to you with an answer.

Luc

Related Articles:

Comments

2 Responses to “Where do I add my Google Analytics Tracking code on a WordPress Site?”

  1. tim on February 4th, 2008 10:29 am

    can you please tell me axactly where to paste the google analytics code at on this theme http://www.wpthemesfree.com/view.php?theme_id=1267

  2. Lucas on February 8th, 2008 12:20 pm

    Hi Tim!

    All you need to do is insert the Google Analytics Tracking Code (GATC - provided in your Google Analytics Account) into the footer.php file (viewable under the Presentation tab in the WordPress administration backend) and install it and you should be good to go! Let me know if you have any other issues or questions,

    Luc

Got something to say?





*
To prove you're a person (not a spam script), type the answer to the math equation shown in the picture. Click on the picture to hear an audio file of the equation.
Click to hear an audio file of the anti-spam equation