How to use Google Analytics for your Moodle 2.0 site

Do you want to obtain detailed statistics about the visitors to your Moodle site? If the answer is yes then you need to use Google Analytics to track the site traffic. Google Analytics is a free yet very powerful web analytics tool, and is widely used by all types of websites nowadays.

Essentially there are only two steps involved to start gathering information : Step 1 – Get your tracking code from Google Analytics. Step 2 – Add the tracking code to your Moodle site.

Ok, let’s get cracking!

Step 1

You need to have an account with Google to be able to use Google Analytics, so sign up for one here if you don’t already have Google account for your organisation. Once you’ve got a Google account, you can create your website profile in Google Analytics and get the tracking code for your Moodle site.

screenshot
screenshot

The tracking code should look something like below, where “UA-xxxxxxxx-x” is your site ID.

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

Step 2

Log into your Moodle site as an admin user, and navigate to the Additional HTML option:

Settings > Site administration > Appearance > Additional HTML

Paste the tracking code into the first box which is called “Within HEAD” and save.

screenshot

Ta da! All done. Now you can sit back and relax. Give it 24 hours, and Google Analytics will work it’s magic and give you insight of your Moodle site traffic.