Mahara and Google Analytics

As of Mahara 1.8.x, you can add the Google Analytics script snippet to a configuration parameter called additionalhtmlhead.

For example in your config.php you can add something like this:

But what if you are on a Mahara version less than 1.8.x? I propose a small customisation to your theme so you can do something similar:

Instead of $CFG->additionalhtmlhead, I’m going to use $CFG->googleanalytics to avoid confusion when upgrading Mahara. So you would have a similar entry in your config.php:

Now we need to add some code to the theme to load this variable. The place I’m putting this is in the head.tpl file, for example in the default theme: theme/default/templates/header/head.tpl

Just before the end of the head tag, add the following lines:

Hopefully that works and you don’t get any errors. You should then be able to check the view source of any page and find your Google Analytics UA- code, or simply confirm that things are working in Google Analytics.