Google Analytics Plugin for WordPress

This is the first beta release of a WordPress plugin that can add Google Analytics to your website without you needing to code one single set of <>’s.
I have it running on this site and it seems to be working just fine so far.

Installation instructions

To use it:

  1. If you have a previous version of the plugin, delete it.
  2. Download this fileDownload this file
  3. Rename the file googleanalytics.php and copy it to your /wp-content/plugins directory.
  4. Enable it on the plugins page.
  5. Enter your Google Analytics User Account string (it’ll be something like UA-12345-6. It appears when you “Add a channel”)
  6. That’s it.

You don’t need to look alter the code in any way to make it run; of course you’re welcome to improve it and send me any updates for inclusion.


  • Zero Coding
    A zero coding install enables both the default tracking and the use of different channels for specific posts.
  • Outgoing links
    Track which outgoing links your users click on – i.e. the ones that don’t traditionally register in your logs. Separate tracking streams for outbound links that are in the main article, comments, and comment author URL’s
    A graph showing clicks on outbound links - something not possible with stats based on server logs alone
  • Multiple Channels
    Assign a specific channel to any article by entering the channel ID as metadata. i.e. simply type “analytics” as the metadata field name and the channel ID as the value and you can run a channel for each specific post

Requested Features

  • Filtering the Sidebar
    WordPress provides hooks for filtering articles and comments, but not for filtering the sidebar and footer. Since the sidebar often includes the blogroll there are page-exit clicks that cannot be tracked. If anyoen has a clean solution to filtering the sidebar then please speak up!
  • 100% Point’n’Click UI
    I’ve asked on the forums to see if there’s away to automate the retrieval of the account id, so hopefully the plugin can become a configuration free install.
  • Per Category Channels
    Assign a different channel ID to each category.
  • Versions

    A historical list of releases.


    Please neatly tuck any feedback, comments, suggestions & requests onto the forum!

    329 thoughts on “Google Analytics Plugin for WordPress

    1. Version 0.30 adds rudimentary support for tracking exit pages (described here). For any link that the user selects which is in a different domain to the source blog, a record of /outgoing/hostname is stored.

    2. Ah… I see. Outbound link tracking is enabled for links appearing within the loop, but not the sidebar, for example. I’ll be looking forward to an update that adds support for that, as I’m sure will others. It’ll be interesting to see how one’s blogroll is directing traffic.

    3. Hi C – a great idea re the blogroll – I’ll look into enabling it for the whole page.

      Cavemonkey, yo, yeah, your’s is the 5th plugin I’m now aware of! I think we ought to get at least one of them into SVN and centralise efforts!

    4. Hi

      I’ve tried to install and configure your plugin, but when I’m trying to validate the setup on Google’s page it says that it can’t detect the tracking code.

    5. Hi Dado, I’ll need a little more information to begin with. What’s the URL of the blog where you’re installing the plugin? I’m guessing it’s the one in your email address since that site does indeed have the tracking code present, with the UA number of UA-119977-1. So my next question is, can you confirm that 119977 is correct? The codes I’ve seen so far have only had 5 digits in the middle section (but then, Google have been very busy so this may have increased massively. From what I can see so far it looks like it’s working properly, so it may be a case of sit and wait whilst Google catches up with you.

    6. Hi Michael, I just looked at the source of your blog and I notice 2 things.

      1. The plugin is working (do a find on the word “urchin” and you’ll see that every externally directed link has been re-written to include a javascript call to teh google code).

      2. You’re corrct that the script-bit is missing, my guess is that there is no call to wp_footer in your theme. As a workaround I’m going to change the hook in the next release to use wp_head rather than wp_footer.


    7. I’ve just uploaded verion 0.40 to the site which shoudl fix michael’s issue of not having a blog footer.

      There are also two new features, firstly, comment author URL’s are now included in the outbound link tracking and secondly, it’s now possible to assign a channel to a specific post by giving the channel if (i.e. UA-12345-6) as the valeu of an “analytics” filed in the metadata.

    8. It’s spitting the correct code on my site, but Google Analytics claims not to see it. I suspect GA is sensitive to placement and wants the code to immediately follow the last meta tag. I’ll fiddle some more and let you know if I find out.

      Nit: on your web site here, your link to v4.0 in the “list of releases” points to instead of

      Thanks for the cool plugin!

    9. Thanks for the plugin – sounds great.
      On clicking to enter my UA string, though, I get this message:

      Fatal error: Cannot redeclare analytics_config_page() (previously declared in /home/joefoote/public_html/blogs/wp-content/plugins/googleanalytics.php:30) in /home/joefoote/public_html/blogs/wp-content/plugins/googleanalytics.php on line 29

      My blogis at

      Thanks in advance for any help!
      Joe Foote

    10. Osh, thanks for the heads up, I’ve fixed the nit. I’m fairly certain the problem will just be that Google are oversubscribed right now (which is a blinkin’ pain for testing but i suppose that’s the price of popularity!).

      Joe, that’s a curious one. Have you (perhaps) installed the plugin twice? Maybe once in the directory and once not?

    11. Rich,
      You said, 4) Enter your Google Analytics User Account string (it’ll be something like UA-12345-6. It appears when you “Add a channel”)
      Add a channel – What do you mean by that?
      I have done steps 12&3, after I enabled it in the plugin screen, it
      it tells me Google Analytics is not active. You must enter your
      UA String to work. But where do I do that? When I click on the link I get: Fatal error: Cannot redeclare analytics_config_page() (previously declared in C:xampplitehtdocswp-contentpluginsgoogleanalytics.php:30) in C:xampplitehtdocswp-contentpluginsgoogleanalytics.php on line 33

    12. Rich,

      I am getting the same error as Joe. The only copy of the PHP file I have resides in the plugins directory.

    13. Hello Rich,

      I have the same bug with Joe:

      Fatal error: Cannot redeclare analytics_config_page() (previously declared in /…/wp-content/plugins/googleanalytics.php:30) in /…/wp-content/plugins/googleanalytics.php on line 33

      I checked the plugin dir and there is only one copy of googleanalytics.php. Is this problem related to php version? I’m using php5.

      Thanks for your great work!

    14. dhchen, Kevin, Mike & Joe,

      Thanks for your feedback! dhchen mentions PHP5, and having looked around the issue it appears that others have had similar problems.

      So, I’m going to assume it’s a PHP5 issue and attack it from that angle. Watch this space :)

    15. Release 0.50
      Download it!
      I’ve re-written the method defintions and filters in the plugin to be more defensive than they previously were, which means it should now play nicely with PHP5 based installations.
      Hopefully this will solve the “Cannot redeclare analytics_config_page()” errors – RSVP!
      I’ve also added a few words to the instructions to make the activation provess more obvious, and included a little feedback message to give warm feelings when a User Account number has been entered.

    16. Hi Lerakpo, I’ve looked at your home page source and everything seems to be in order. Google took 48 hours bewfore I saw my first reports so sit tight, the result really is very impressive for a free service, it just takes a whilto get started.

    17. Hi,

      What is the difference between this plugin and Cavemonkey50’s
      Google Analyticator? Both seem to be doing the same exact thing.
      I am trying to select one but not sure if one has an advantage
      over the other.

      Thank you


    18. Hi Chris, the output you describe is what you’d see if you tried loading the plugin as a standard PHP page. Plugins don’t work like normal pages – they just provide capabilities to wordpress so you (999 times out of 1000) don’t need to load the file directly as you’re trying to do.

      Go into the admin interface (where you normally write articles) and look for the Plugins tab, under that is a Google Analytics tab, like this:

      That’s where you have to enter the magic number.

      If you have any more questions, let me know, but hopefully that should be enough of a leg-up.

    19. Hi Chris, that certainly doesn’t look right!

      The good news is that I can immediately see something that may be causing your trouble: the version string reads “1.5-beta-1 2005-01-01”.

      Yes, it really is over 12 months old, and beta level code, so it’s not bug free. You are strongly urged to upgrade to the newer codebase, or at the very least to a release version of the code.

      I’m guessing that will fix your problem, and if it doesn’t, at least we’ll be on a more level playing field for me to hypothesize about.

    20. It seems to be working fine (the urchin code’s there; will be a day or so before I see results at Thanks for the simple way to get analytics code onto my site.


    21. Hi dede, sure. Currently four types of content are filtered so that they have their outgoing links tracked, they are:
      the post content (the articles you write)
      the post excerpt
      the comment text (the things others write) and
      the comment author’s url

      What’s not translated at the moment (because there are no filter hooks for the plugin to use – so if anyone knows a neat way to achieve this, let me know) is the header, the footer and the sidebar.

    22. Hi A Samuel, can you be a bit more descriptive? I have no idea what you are seeing sorry. I’ve had a look at your site and the plugin is currently disabled, so I’m a bit limited in what I can diagnose so far!

    23. Aha, got it. Yes, this is a most curious one and it’s down to the combination of the that Analytics works and the way Technorati do their indexing. The analytics plugin updates every link to include the onClick code which can be seen in each of your tags, but technorati don’t seem to like this.

      Two solutions spring to mind (in advance of me being able to code a workaround).

      Contact Technorati and raise a tech support ticket (they’re usually very quick to respond), ’cause this is likely to be something that many people will eventually endure.
      You might want to try the autometa plugin which does work ok with the analytics plugin (and it does a fairly good job at automatically generating the meta tags for you).

    24. Thanks for the response, I appreciate your help. I have raised a ticket and await to hear from them. I will try the scenario you suggested if no solution can be found. Ill keep you posted.

      Cheers once again!

    25. re: a clean solution to filtering the sidebar, I see that the “Ultimate Google Analytics” plugin facilitates this by having the user manually edit their sidebar template to wrap the get_links call with a call to the uga plugin. not entirely “clean” I suppose, but a great option to have for folks who don’t mind editing their templates. chance of the Boakes GA plugin supporting similar?

    26. I tried installing this plugin and got a Fatal error: Cannot access empty property…My ISP is using PHP5. Has anyone else seen this issue? Soultion? I would like to use this plugin.

    27. Just a quick comment to say that 0.51 (and I assume earlier ones) don’t validate as XHTML 1.1. It’s the version=”0.51″ part that does it.

    28. Rich

      The plugin sounds great. I installed it and put in the acct # in the plugin manager and all seemed to go well except Google says the tracking is not installed.

      I went to view source and it says:

      <!– Google Analytics Plugin for WordPress –>
      <!– The plugin is enabled but no channel account number is available. –>

      Any thoughts?



    29. Hi Russ, that message shows up if you’ve installed the plugin but not entered your account number as described in the installation steps above.

      I see that your site is currently showing the correct script (with the account number in the right place, so you already sussed that bit).

      My assumption is that the Analytics server is just a bit behind. It’s often several hours before they show data, so let me know in a day or two if it hasn’t started recording data for you.

    30. I have my blog set up at word press. Is there another way to install Analytics if they do not have a plug in section? I really want to utilize this program but don’t know where to put it without a plug in page.

      Any help would be great! If not, do you know of other sites that work with program that are similar to word press as far as format, tools, easier pictures, and clean format?

      Thank you!

    31. One problem I can forsee is that already use Google Analytics, so your blog is analysed as part of their whole general blog mish-mash.

      Your best bet is to ask the Automattic folks who run WordPress,com if they can help.

    32. This rocks! This is great and works perfect. Thank you very much for this brilliant and handy plugin.

    33. Hi. I have installed your plugin in my WP blog. It seems ok so far. My question is, how does this thing really work? I mean, should i be going inside my google analytics account and view the reports there? or are there ways to view the reports inside my blog admin?


    34. Could someone invite me to Google Analytics?


      I’d really appreciate it! :)

    35. Hi Ruel, as you suggest, just login to to view the reports. There are other plugins that enable you to view your reports within the WP admin UI, but I’ve not used any of them.

    36. Rich:
      I have installed the plug-in and have been playing with the reports. I only wonder if the whole point behind the release of Analytics is to train Google how to charge more for the best performing AdWords ads. Are there any other analytics programs you have seen that don’t report their findings to the advertising space vendor?

    37. Thanks a bunch for this great plugin. It automatically attaches the code to all outgoing links and has proven very helpful in tracking page statistics. Not to mention it’s very easy to install.

      THANK YOU! Great Plugin.

    38. Hi Rich,
      I am using your plugin from three months and it works perfectly. But today I noticed a little but not fundamental bug. Your plugin modifies the html code in this way: when there is an hyperlink it don’t leaves no space by the href tag and the title tag. Furthermore It modifies the rss feed adding an onclick tag whose presence is not an error but it is a warming according to the wc3’s feed validator. Is it possible to correct it? I hope I have been clear because my english is not perfect. Thank you. Bye.

    39. I’m a beginner and don’t know much about creating web pages. Navigating through the various files and folders of WordPress only furthers my confusion. So where do insert my Account Sting among my WordPress files? I was able to do it without any problems for my regular (non-Wordpress) pages.

    40. Hi Rich,
      I found the little bug and I solved it.
      I added a space on line 219.
      I also bypassed the feed validation by changing in the file wp-rss2.php (belong to wordpress) the function the_content with the function the_content_rss.
      Thanks for your job!

    41. Pingback:
    42. Pingback: CypherHackz.Net
    43. Hello,

      I just installed this plugin, but after 30 minutes, google analytics is still showing as “Tracking not installed”.

      Where exactly does this add the code?


    44. I have installed the plug-in, it says it has the tracking code installed but when I log in to google analytics there are no statistics tracked. whats up?

    45. Why do I get
      Warning: Cannot modify header information – headers already sent by (output started at /home/opmr/public_html/wp-admin/admin-header.php:16) in /home/opmr/public_html/wp-includes/functions.php on line 2448

      What can be the reason for that? Tried to find the answers in the post but no luck…


    46. First, thanks for this nice plugin :)

      When the user install Adblock and block Google Analytics, the original code will cause Javascript error:


      Just check if it has been loaded:

      echo("if (window.urchinTracker) urchinTracker();n");

    47. Hi –

      First Excuse my poor english , i ‘m french.

      Thank you for this excellent plugin , but in my blog google analytics don’t detect my code …

      however installation is really easy .. i don’t understand the problem. Can you help me ?

      Thanks you for your help :) And sorry for my mistakes :x


    48. Hi rdg/mathieu,

      Once you have installed, configured and enabled the plugin, Analytics should confirm that it has found the tracking code and is “gathering data”.

      It then takes a little while before the data starts to appear – usually around 4 to 8 hours.

      Mathieu, looking at the source code on your blog I can see that you’ve enabled the plugin, but not configured it, scrool back up to the installation instructions and check the penultimate bullet point.

      RDG, your code looks fine, you shoudl be seeing stats anytime soon.

    Comments are closed.