Guy Rutenberg

Keeping track of what I do

Track MediaWiki Statistics using Google Analytics

with 11 comments

Google Analytics is one of the best free web-statistics services available. It’s also quite easy to use with MediaWiki. To install Google Analytics in you MediaWiki you should put the tracking code, which is something that looks like:

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct="UA-xxxx-x";
urchinTracker();
</script>

in every page, preferably just above the </body> tag. The best way to do so will be to put the tracking code inside the base skin php file. That means that unless you changed the default skin for MediaWiki you need to edit /wiki/skins/MonoBook.php. In this file you will find the </body> tag towards the bottom of the file. Insert the tracking code just above it, save the file, and you’re done, as all pages will now show the script. Google Analytics will start gathering statistics usually in about 24-28 hours.

Update:
If you also want to track external links to files and other websites take a look at
Tracking Mediawiki External Links Statistics Using Google Analytics.

Share and Enjoy:
  • del.icio.us
  • StumbleUpon
  • Digg
  • Facebook
  • Mixx
  • Google Bookmarks
  • Simpy

Written by Guy

July 13th, 2007 at 8:53 am

Posted in Google Analytics, MediaWiki

Tagged with ,

11 Responses to 'Track MediaWiki Statistics using Google Analytics'

Subscribe to comments with RSS or TrackBack to 'Track MediaWiki Statistics using Google Analytics'.

  1. This information was helpful, thank you.

    aubrey

    14 Mar 08 at 16:34

  2. Hi aubrey,

    I’m glad you found this information helpful.

    Guy

    14 Mar 08 at 19:13

  3. But what about people who set another skin in their preferences? As far as I can see (not too far, I’m rather new to MediaWiki) they would fall off the grid unless I add the code to every skin I’ve got available.

    Lasar

    12 Apr 08 at 22:09

  4. You can easily adjust it to use other skins too. Just look in the skins folder for the main PHP file of the skin, you’ll find there the tag which you should place the code snippet above.

    If you got multiple skins, and allow your users to switch them, you’ll need to repeat this procedure for every skin.

    Guy

    13 Apr 08 at 16:28

  5. What do you set the “Website URL” and “default page” settings to in the website profile settings for google analytics. I’ve inserted the script, and can see it in the served source, but when I attempt to have google analytics check the tracking status, it doesn’t detect the tracking code.

    Sancho

    18 Apr 08 at 18:36

  6. Hi Sancho,

    Please note that it may take up to 48 hours for the code to start working. When you view the HTML source-code of the site (in your browser) can you see the code snippet? Are you sure you copied the correct code snippet from Google? (you are provided by Google with your own unique code snippet).

    Guy

    18 Apr 08 at 18:52

  7. Adding the code to all templates (MediaWiki comes with a handful of them by default) is the way to go, I guess. It’s just not too elegant, so I was hoping for some sort of mechanism to automatically include it in all templates at once.

    Thanks for the writeup!

    Lasar

    28 Apr 08 at 15:25

  8. Here’s a way to include your scripts, including google analytics in every page, no matter what template is used:
    http://skypher.com/wiki/index.php?title=Google_analytics

    SkyLined

    3 Jul 08 at 13:25

  9. I have gotten google analytics to work with mediawiki, but I cannot seem to get goal conversion tracking set up and working. How did you guys do yours?

    AlphaDogWiki

    11 Mar 09 at 15:39

  10. I didn’t set up goal conversion for my wiki, so I can’t help you out on this one.

    Guy

    11 Mar 09 at 15:54

  11. This was exactly the information I was looking for.
    Thanks a lot and have a nice day :)

    Stefahn

    11 Oct 09 at 22:47

Leave a Reply