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.
This information was helpful, thank you.
Hi aubrey,
I’m glad you found this information helpful.
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.
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.
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.
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).
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!
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
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?
I didn’t set up goal conversion for my wiki, so I can’t help you out on this one.
This was exactly the information I was looking for.
Thanks a lot and have a nice day 🙂
I didn’t even think of doing this until now. I previously used Piwik but it didn’t work correctly — appending the updated Google Analytics code to the skin works correctly too, so this hint is still relevant four years later 😀
Do you also know how to integrate the code before the end head tag? (that is, to paste code inside the head of a page)
You’ll need to edit your skin. The post has the instructions for the default skin, which it seems you are using too.
Information here is obsolete, as the skin is written in PHP and has no tag.
No tag….it is a PHP file…..