Adding Google Analytics to WordPress can be done by using a plugin or by modifying the code of your template.

Adding Google Analytics By Modifying WordPress Template Code

If you are concerned about the speed of your WordPress site then this is the best method.

1) Login to you wordpress panel. (example.com/wp-admin)
2) Click the “Appearance” on the left

 

 

 

 

 

3) Click the “Editor” on the left

 

 

 

 

 

 

 

4)Locate the footer.php and click it to edit this page.

5)The footer.php will have the </body> tag, which can be found near the end of the page.

6) Paste the Google Anayltics code just before </body> tag.

Example: The red code is the Google Analytics Code. The blue code is the original code that is found in your template..

<script type=”text/javascript”>

var _gaq = _gaq ||

[];
_gaq.push([‘_setAccount’, ‘UA-27779897-1’]);
_gaq.push([‘_trackPageview’]);

(function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
})();

</script>

</body>
</html>

7) Click the update button to save the changes that you have made to the footer.php page.

8) Your done. Make sure you go to your Go0gle Analytics Account and check that Analytics is recording visitors.

Note: If you use this method you will lose your Analytics code if you change templates.  Other than that this is best method to use regarding performance.

Adding Google Analytics By A WordPress Plugin

There are a few ways that we can pull this off and I will mention the most common methods with various plugins and or themes.

Most themes these days offer a section within the theme to either supply your full analytics code or the Google Anylytics ID. If your theme or plugin makes use of the ID option you can simply paste your ID from the Google Analytics Tracking Code. In the example below is the tracking code for my site.The red code is your Analytics ID.

<—————Start Sample Analytics Code————–>

<script type=”text/javascript”>

var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-27779897-1‘]);
_gaq.push([‘_trackPageview’]);

(function() {
var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’;
var s = document.getElementsByTagName(‘script’)[0]; s.parentNode.insertBefore(ga, s);
})();

</script>

<————— End Sample Analytics Code————–>

If you theme or plugin accepts the ID option then we would paste this id UA-27779897-1, of course this is my ID so you would supply your ID which is found in the code that you acquired from your analytics account.

Google Analytics Plugins For WordPress

Google Analyticator
This is a plugin that is dedicated to only implementing the Google Analytics Tracking Code. Within the admin section all you have to do is specify is the domain that you wish to track. Even if you don’t know your analytics ID this plugin will still work as long as you specify the domain you want to track.

Header-Footer

This plugin allows for access to your WordPress Header and or Footer. There are numerous other reasons as to why you would want access to the header or footer but in this case its makes for an easy way to implement your code. Once you have installed this plugin you will paste the entire Analytics code in the bottom Footer text box.

 

Where Do I Find My Google Aalytics Code

1) Logon to Google Analytics

2) Click the Admin button in the top right corner of your account

3) Within your Admin panel click the “Tracking Code” tab

4) Copy the tracking code from the panel and then use the code in one of the methods mentioned above.

If you have any questions about getting you code going do leave me a message and I will cheerfully guide you through the process.
Author: Geoff Dyck