Your use of the information on Hobbs Knowledge Base is at your own risk and I accept no responsibility for any damage caused. More info here.

How to Get Google Analytics Onto Your Wiki

From Hobbs Knowledge Base

Jump to: navigation, search

Method 1: "Google Analytics Integration" extension

In order to insert Google Analytics code at the bottom of every page on your wiki you must first have a Google Analytics account, of course! This, i cannot help you with, but http://www.google.com/analytics/ is probably a good place to start!

You then need to install the Google Analytics Integration extension.

This is by far the best method as you are theoretically protected against future Wiki and skin upgrades.

Method 2: Hard-coding the Skin file

The method i used before i know about this extension is documented below.

Image:Warning.gif WARNING: By doing this method, you will have to re-apply any changes you make every time you upgrade your Wiki, because you will be editing the main skin for the site!

You must first have a Google Analytics account, of course! This, i cannot help you with, but http://www.google.com/analytics/ is probably a good place to start!

There is only one step to this, and that is to add the code from Google Analytics into your "Skin.php" file (in my case "MonoBook.php"). Example lines from my own code are shown in red below:

<!-- Debug output:
<?php $this->text( 'debug' ); ?>

-->
<?php endif; ?>
<!-- BEGIN GOOGLE ANALYTICS -->
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-12345-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>
<!-- END GOOGLE ANALYTICS -->
</body></html>
<?php
	wfRestoreWarnings();
	} // end of execute() method
} // end of class
?>

Once that's done, you should be able to "View Source" of your wiki in a web browser and see the code at the bottom of the page, and once Google is happy that it can see the code, you are all set!

Image:Notepad.gif NOTE: You should be able to restrict the Google Analytics code to only certain namespaces by applying the same principle used on How to Get Google AdSense Adverts Onto Your Wiki. Search the page for references to the following:

if($ns==0) {


Image:Envelope.gif If the information on this page is either out-of-date, incorrect, or if you'd just like more information then please Contact Me.
Personal tools
Help