13.07.07
Track MediaWiki Statistics using Google Analytics
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.







aubrey said,
March 14, 2008 at 4:34 pm
This information was helpful, thank you.
Guy said,
March 14, 2008 at 7:13 pm
Hi aubrey,
I’m glad you found this information helpful.
Lasar said,
April 12, 2008 at 10:09 pm
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.
Guy said,
April 13, 2008 at 4:28 pm
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.
Sancho said,
April 18, 2008 at 6:36 pm
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.
Guy said,
April 18, 2008 at 6:52 pm
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).
Lasar said,
April 28, 2008 at 3:25 pm
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!
SkyLined said,
July 3, 2008 at 1:25 pm
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