Adding Google Analytics to Orchard

Google Analytics can show you all kinds of funky stuff about who's viewing your website, what they're viewing and how they're mooching from page to page, and it's very easy to add to your site as Google supply a tiny bit of JavaScript that you need to add to your pages. This bit of JavaScript will look something like this:

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-105103281-1', 'auto');
  ga('send', 'pageview');

// Please don't just copy and paste this - the IDs above are specific to this site and won't work for you - use the markup that Google have given *you* !!
</script>

Adding Google Analytics

The easiest way that I've found to add Google Analytics to an Orchard site is to:

  1. Login to the /Admin portal
  2. Go to the "Widgets" part of the portal
  3. Create a new layer (the reason for this step will become clear later), perhaps called "Google Analytics"
  4. Add a new Html Widget to the "Footer" part of the layer
  5. Use the "Edit Source" button for the Html Widget and paste in the Google Analytics code that they've provided
  6. Save the widget

Once this is done, you should see Google Analytics traffic for all the pages in your site. You could also use your web browsers Developer Tools to confirm that traffic is going out to Google on each page that is loaded.

Excluding you from Google Analytics

Of course, if you add this to every page on the site then when you add a new page, blog entry, whatever, all the "clicking around" that you do will result in analytics data being captured which can pollute the information that you get from Google. Whilst you can use the "Global Filters" feature that's built in to Google Analytics to exclude traffic that comes from your IP address(es) this won't exclude any traffic that you get when you're not visiting from one of these IP addresses (particularly an issue if you have a lot of remote workers). One way I've found to cater for this is to:

  1. Login to the /Admin portal
  2. Go to the "Widgets" part of the portal
  3. Select the "Google Analytics" layer that you previouly created and click the Edit button
  4. Set the text of the "Layer Rule" to be "not authenticated" (without the quotes)
  5. Press Save

This means that any traffic from authenticated users (i.e. someone who's logged into the dashboard) won't have the Google Analytics code added to the page markup. It's not perfect, some of the pages requested by your users will still show up in Google Analytics until they login to the /Admin portal, but with that and using the Global Filters feature you should keep it to a minimum!

About Rob

I've been interested in computing since the day my Dad purchased his first business PC (an Amstrad PC 1640 for anyone interested) which introduced me to MS-DOS batch programming and BASIC.

My skillset has matured somewhat since then, which you'll probably see from the posts here. You can read a bit more about me on the about page of the site, or check out some of the other posts on my areas of interest.

No Comments

Add a Comment