Tom Nason Team : Producer Tags : Web Development SEO Analytics

A bulletproof Google Analytics setup you can trust

Tom Nason Team : Producer Tags : Web Development SEO Analytics

Setting up Google Analytics at its most basic level is as simple as spinning up a Google account, setting up a GA property and dumping the tracking code directly into your HTML.

What many don’t know is that a vanilla set up, like the one described above, can lead to headaches down the line.

Playing with fire

A rushed set up can result in polluted data and significantly inflated (or deflated) metrics. This is a disaster for anyone looking to gather business intelligence and make smart, data driven decisions. What's worse, there is no way to correct inaccurate data retrospectively.

There are several risks with an out of the box Google Analytics set up:

  1. Cross domain pollution - Google Analytics will attribute visits to your property based only on the tracking ID unless instructed otherwise. This means that you could start accruing hits for a site that isn’t even yours, should someone accidentally use your code. Worse, consider a spiteful competitor who might want to deliberately pollute your stats and thwart your costly marketing campaign. Once the data is there, there is no way to remove it.
  2. Environmental ambiguity - Your website likely exists on several servers. Your developer will have a local environment, then they probably push it into a UAT or staging environment for you to review before going live. Analytics doesn’t display the hostname out of the box so it could be years before you realise all your test cases are being logged as conversions that you thought were real customers. This might not have a huge impact if testing occurs manually, but consider a developer who has automated test cases that run on every build.
  3. Prone to double tracking - A vanilla set up can often result in hits to pages being tracked twice for every visitor. Throwing a tracking code in might seem simple on the surface but I often find double up tags being output in the HTML. Testing for this without the proper tools can be difficult so issues often go unnoticed.
  4. Missing data - Advanced reporting options like user demographics are disabled out of the box and require a little trickery to implement. Unfortunately turning this on later doesn’t backfill your reports.


So how do we avoid these pitfalls?

Every Analytics account I set up is built on a consistent foundation which can then be extended to suit the project at hand.

Disclaimer: This guide won’t help you set up complex conversion funnels, custom metrics or e-commerce tracking. Instead, you’ll walk away with stable baseline reporting that you can build on with confidence.


Part 1 - Installing Tag Manager

We’ll be using Google Tag Manager to trigger the Google Analytics Universal Tracker. GTM makes testing a breeze (we’ll get to that shortly), but there are also a number of other benefits that extend well beyond the scope of Analytics. It’s well worth setting it up now, if you haven’t already.

Instructions:

  1. Log in to https://tagmanager.google.com
  2. Set up a new “Account” and “Container” following the naming conventions in Google’s examples.
  3. Insert the HTML into your pages as instructed. I recommend going the extra mile and exposing two fields in your CMS to set this, if only as a future proofing measure.

Expected result:

The Tag Manager scripts should now be visible in your HTML. They won’t do anything just yet as we haven't set up any tags or triggers.


Part 2 - Setting up Google Analytics

Now it’s time to set up your new property and associated views. Here’s what we’re shooting for in terms of structure:

Instructions:

  1. Log in to https://analytics.google.com
  2. Set up a new “Account” and “Property”, following the prompts for each.
  3. Review the Property Settings and ensure “Enable Demographics and Interest Reports” and “Use enhanced link attribution“ are on. You will also need to enable “Advertising Reporting Features” in the Tracking info - Data collection settings.
  4. Jump into the Property Views and rename the default “All website data” View to “Catch All - Unfiltered” or similar. We don’t actually want anyone to use this view, it’s just there as a safety net, should we make a mistake with the other views.
  5. Create a new view for one of your testing environments. I like to use the following naming convention for consistency: “UAT - https://uat.developmentenvironment.com
  6. Add a new filter to the view you just created: “Force Lowercase”. This is important, and often overlooked. Out of the box GA is case sensitive, meaning /thankyou and /ThankYou will track as two different pages. It’s also important that this filter is listed first, as filters are executed sequentially.

  7. Set up one more filter: “Include only uat.developmentenvironment.com”. This tells GA that you’re only interested in traffic to this specific domain and that it should ignore everything else.
  8. Clone out your testing environment view for any other environments you might have for this particular site. The Copy View feature can be found on the View Settings page. For me this will usually include Staging and Production, which both follow the same naming convention. Be sure to triple check you have adjusted the host name filters appropriately for each.

Expected result:

You now have your empty Tag Manager Container and Analytics Property set up, but don’t expect to see any data flowing through just yet. The two still need to be connected.


Part 3 - GTM Tags and Triggers

A Tag is a snippet of code that GTM can output to your page, while a Trigger determines when it should be fired. We only need one Tag and one Trigger in this instance.

Instructions:

  1. Open up the GTM container you set up in Part 1
  2. Add a new Tag and select the Universal Analytics preset. Be sure to set “Enable Display Advertising Features” and “Enable Enhanced Link Attribution” to true.

Expected result:

Our Container, Tag and Trigger are now all in order, or so we hope. We need to do a little testing to be sure.


Part 4 - Testing using GTM

One of GTM’s most valuable features (at least in my opinion) is Preview mode. It lets us see exactly which tags are being triggered in any given scenario, making it easy to see if we’ve made any mistakes.

Instructions:

  1. Hit the preview button at the top of your GTM container window. Nothing happened huh?
  2. Open a new tab and navigate to your site. I always check a test environment first. You should see the GTM debug console appear at the bottom of the screen, as if by magic.
  3. Click around the site and check the Tag fires being reported. In our case you should see the Universal analytics tag being fired once, and only once, on every page load. If fired more than once you’ll find your Pageviews to be multiplied out in GA.
  4. Now open GA and navigate to the Real time - Overview report. You should see yourself listed as an active user. If there are multiple active users at this stage there could be a problem as we haven’t yet published the Container to the public.
  5. Repeat steps 3 and 4 for each View that you set up in GA.

Expected result:

We’re seeing it all come together now and can track an end user's page view through our GTM Trigger, Tag and all the way through to the GA reports.


Part 5 - Publish and review

All going well you’ll now be ready to publish your Container and watch your reports fill up with customer statistics. Good work, but it’s not over just yet.

Set yourself a reminder to log in to GA tomorrow and spot check the data flowing in. Are the Audience numbers realistic? Is the bounce rate abnormally low (classic sign of double tracking)? Are referrers being listed as you would expect? It’s much easier to spot issues while traffic is ramping up so check in regularly over the first week in the wild.

So there you have it, a basic Google Tag Manager and Analytics setup that’s reliable and ready for extension.