How To Install Google Analytics On A WordPress Blog Without Using A Plugin

Wed, Aug 19, 2009

Adding To WordPress

If you’ve been blogging for longer than a few months, you’ve probably heard of the ever so popular site analytics program, Google Analytics.

It allows blog owners to do such things as:

  • Discover how your site visitors found your blog
  • View how many visitors your blog receives each day
  • View areas on your blog where people have clicked
  • . . . and a ton more.

If you blog, it’s inevitable that you are going to try Google Analytics at some point. It really is a great analytics program; however, I must admit that it can seem quite complex at times and if you’re new to the program and you might feel a bit intimidated. In the near future I’ll try to post some examples on how to use the program.

When it comes to plugging Google Analytics into your blog, you have a couple of options available to you.

  1. Download and use a plugin . . . or
  2. Copy and paste code into your blog’s footer file

Why I don’t like plugins

Simply put, plugins slow down the load time of your website and also pose security risks which could leave your blog open to intruders. Even if the plugin is secure today, it might not be when a newer version of WordPress is released or if the plugin author abandons the program and stops issuing updates.

In my opinion, the best way (and just as easy) to install this is to simply copy and paste Google’s supplied code into your theme’s footer file. That’s it, no plugin, done and move on.

Step 1: Sign up for a new Google Analytics account.

Step 2: Copy the JavaScript code.

During the sign up process you’ll be asked things like your name, email address, etc. At some point, you’ll come to a page that looks like the image seen below. You will will need to copy this code and paste it into your blog.

As a side note, even if you used a plugin to install Google Analytics, you would still need to copy and paste this code at some point; so plugins don’t necessarily make things any easier.

Step 3: Pasting the code into your footer.php file

At this point, log into your WordPress blog and navigate to your theme’s editor by going to Dashboard -> Appearance –> Editor.

Then on the right you should see a list of your theme’s files. Click on the Footer.php file.

Paste the code you copied from Google Analytics just above the ending </body> tag.

Click Update File

And that’s it. No plugins and no worries about updates.

To view your site’s statistics now, log into your Google Analytics account and view your stats. It may take a day or so to start receiving your traffic stats, so if you don’t see it right away, just be patient.

,
John's Wishlist

25 Responses to “How To Install Google Analytics On A WordPress Blog Without Using A Plugin”

  1. fazal wadood Says:

    your instruction is very very helpfull and easy

  2. John Hoff Says:

    Hi fazal, I’m glad you found it useful. Thank you for taking the time to let me know you stopped by. It’s always nice to see a new face/name around here.

    Don’t forget to add your IP address to the Google Analytics Filter so you don’t record your own visits.

  3. Dan Says:

    Thank you for the fabulous and SIMPLE explanation of how to get google analytics installed onto my wordpress website without using a plugin. I tried numerous plugins and every one of them gave me the same problems and issues. I followed your instructions and did it correctly myself in about 5 minutes.

    I like the old KISS method – keep it simple stupid. forget plugins, they all stink, and so do their ‘newsgroup forum’ style support.

    Much appreciated!!!!!

  4. John Hoff Says:

    Hi Dan. Thanks for the comment and I’m happy you found the article useful. It really is just as easy as installing a plugin, isn’t it.

    I love the KISS method, in just about everything!

  5. iris Says:

    Hi John,

    Why that is not Save File or Update file button in the Footer (footer.php) platform ? I even change the file attributes but still unable to save the tracking code. Please advice.

    Thanks

    iris chan

  6. John Hoff Says:

    Hi iris, that’s odd, you should be able to edit the footer.php file just fine. The only thing I can think of is your theme is blocking it somehow.

    Are you using your own self-hosted WordPress blog, opposed to having a free one on WordPress.com?

    If so, log into your web hosting file manager and navigate to your /wp-content/themes/your-theme-folder

    You should then see the footer.php file in there. Use your control panel’s file editor to edit the footer.php file by clicking a check mark next to the file and then click “Edit” up at the top.

    Then paste the code inside the file as I show in the tutorial, save, and close.

  7. Gary Says:

    Do you have to install the code on each page of your blog, or only once on the appearance/editor/footer? You didn’t say.

    Thanks for the great info!

    Gary

  8. John Hoff Says:

    Hi Gary. Just once in the footer.php file will do just fine.

    My pleasure and thanks for watching.

  9. Debbie Yost Says:

    John,
    This was very helpful! Thank you so much for directing me here and for actually having this post. I love video tutorials. They make things much easier for me to actually see what you are talking about. Just reading stuff is confusing at times. I’m a visual learner!

  10. Henry Says:

    The problem with your method is it doesn’t have the functionality which GA plugins provide. The most important feature is not logging Dashboard visits and admin visits.

    To make this article very useful, you could write a simple piece of code which detects if the user is the blog owner (logged in), if so, that person isn’t tracked.

    I have something simple I wrote myself, as I don’t like plugins either, if you would like it, just let me know.

    Henry.

  11. greg Says:

    Thanks for the tutorial. Your website is a goldmine of very useful information.
    Will visit again.
    Cheers.

  12. John Hoff Says:

    Hi Greg. Thanks, that’s nice to hear. We’ll see you soon.

  13. jeff Says:

    Hi, John,

    I did what you said and added the new (asynchronous) code to the footer file, and it works fine for all my blog’s internal pages. However for some reason the blog homepage still is still showing the ga.js code.

    Any idea why that might be? (I had some other people working on my site prior to this, so that may be part of it…)

    -Jeff

  14. John Hoff Says:

    Hi Jeff,

    That’s odd. The only thing I can think of is that your index page uses a different footer, maybe? You can try adding the code also to your Main Index page… the index.php file.

    Other than that, I couldn’t be sure without really getting in a toying with it. If it doesn’t work for you, the plugin might be the better option for you.

  15. boss Says:

    Excellent tutorial. I don’t use google analytics, but I use the same method to place the tracker code of the software I do use.

  16. free DSi points Says:

    There is some solid information in this post. I am in love with your blog so far. I’ve added the feed to my Google Reader RSS subscriptions and will give you a mentioning over at my blog. I did have an issue with how fast this post loaded. Might be an issue to check out.

  17. Keith Davis Says:

    Hi John
    My footer.php doesn’t contain a closing body tag.
    It ends with a php function.

    Presumably I just paste the Google Analytics code after the end of the info in the footer.php.

  18. John Hoff Says:

    Hi Keith.

    Themes these days are starting to get a lot more complicated code-wise in order to make it seem easier for users. While this is great for newbies, as you can imagine it makes it hard sometimes doing tutorials.

    If it’s working for you, great, you’re done. If not, here’s what I’d do. Either:

    A) Try putting the code in your header.php file just after the body tag
    B) Contact your theme owner and ask them where you can put the code.

    A) should work just fine though.

  19. Keith Davis Says:

    “B) Contact your theme owner and ask them where you can put the code.”

    Sounds good to me.

    Cheers John

  20. Kevin Leary Says:

    For most of the Word­Press sites I design I imple­ment this basic Google Ana­lyt­ics func­tion into functions.php to keep things light­weight and not depen­dent on plu­g­ins. The only extra fea­ture added to Google Ana­lyt­ics is 404 error track­ing, which I always add.

  21. John Hoff Says:

    Hi Kevin.

    Out of curiosity, what’s the difference by putting the code in the functions.php file?

  22. Avenir Says:

    It Allows usage of custom variables in Google Analytics to track meta data on pages. Thanks for your support will try soon.

  23. Jennifer Says:

    This was a great article! Very easy to follow (esp. for technical illiterate folk like me!)

    I had installed google analytics on my WP account the wrong way and couldn’t for the life of me figure out why it wasn’t working! I’m excited to see if this fixes the problem!

    Thank you!

  24. John Hoff Says:

    Hi Jennifer. That’s awesome. I’m glad it worked and you’re all set up. Thanks for leaving a nice comment.


Trackbacks/Pingbacks

  1. [...] original here:  How To Install Google Analytics On A WordPress Blog Without Using …Share this on del.icio.usDigg this!Share this on RedditBuzz up!Stumble upon something good? Share it [...]

Leave a Reply