The Complete Guide to Setting up Google Analytics
Our in-depth guide to help you fully setup Google Analytics for your startup.
In this post we’re going to look at how you should be setting up Google Analytics to get the data you need to make growth based decisions for your startup.
This guide will focus purely on the latest iteration of Google Analytics javascript code, analytics.js
. Many of the principles in the guide will be useful however any code snippets will not work if you’re still using ga.js
.
To get started simply place the javascript snippet before the head
tag in your template. You will see this snippet in Account > Profile > Admin > Tracking Info.
<!-- Google Analytics -->
<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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXX-Y');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
Note that the UA- number is specific to your Google Analytics profile.
If a user comes to your site from anything other than the domain Google Analytics is configured for then it’ll get tagged as a referral.
Referrals wipe out any original source information which can prove problematic when you send a user to a subdomain to complete the payment for their order. This means that you can attribute the correct channel to that user in order to credit the channel for the conversion.
Analytics provides a simple way to correct this with your referral exclusion list located in Settings > Tracking Info > Referral Exclusion List
Any domains or subdomains added to this list will not get assigned as a Referral now.
How you structure your Analytics account often comes down to personal preference, usually as a rule of thumb I keep separate sites on different accounts but for specific sites I add everything related as a new property.
The Analytics structure is very simple, you have:
Accounts: This is the top level, you should have a different account for each website you have.
Properties: All the properties of a specific account (Web App, Blog, Facebook, Mobile App etc)
Profiles: Sub aggregation of a Property, allows you to view specific parts of a property as their own entity using filters.
Here it is visualised using our setup:
You can see that we have the main Gleam account, then a Gleam property with 4 profiles created to break out traffic based on specific rules.
You should always create one profile that remains unfiltered, I normally name this “Raw” or “All Traffic.” This allows you to see all data being picked up by your tracking code without any filtering.
Profiles can be used to track all manner of things, here’s a few examples:
- Main site traffic
- Mobile site traffic
- Specific subdomain traffic
- Specific subfolder traffic
- Paid traffic
- Partner traffic
- Blog traffic
- Specific channels
- Specific behaviours
The list above is just an example, but the thing to remember is that isolating specific things using profiles & filters allows you to view your data on a more granular level.
Let’s say for example that you’re Ebay & you need to look at the performance of each category. Having one rollup account will show you combined performance across all categories:
If you created a new profile for each category & filtered the traffic in properly you can see traffic, conversion rates & other performance metrics at an individual category level. This allows you to make better decisions on how you might spend marketing dollars, or which areas are underperforming.
Filters are an extremely important & useful way to ensure that your profiles behave in the ways that you want them to. In the above example, all of the profiles we added would technically show the same data until we use filters to tell them how to behave.
Filters are located in Account > Filters, these are global filters that can be applied to any profile within the property. To apply it you need to go to Account > Property > Filters.
When you go to create a filters you’ll be able to name it then decide what rules you want it to follow. Here’s a few common filters that are useful:
Blog Traffic – Subfolder
If your blog is included in a subfolder (i.e. /blog/) then this filter will isolate that traffic.
Filter Name: Blog
Filter Type: Predefined
Include Only
Traffic to subdirectories
That contain /blog/
Blog Traffic – Subdomain
If your blog is included on a subdomain (i.e. blog.yoursite.com) then this filter will isolate that traffic.
Filter Name: Blog
Filter Type: Predefined
Include Only
Traffic to hostname
That contain blog.yoursite.com
Exclude Internal Traffic
If you have a lot of people working on a website your metrics can get diluted, many businesses filter our their internal traffic to avoid this. You can also use these filters to exclude agencies or external contractors.
Filter Name: Internal Filter
Filter Type: Predefined
Exclude Only
Traffic from IP Addresses That are equal to Your Internal IP
Prevent GA Code Hijacking
It’s entirely possible for someone to take your Google Analytics snippet & put it on their own site. This will greatly impact your metrics & cause a lot of annoyance. You can use a filter to ensure you’re only collecting data on certain sites:
Filter Name: Default Websites
Filter Type: Predefined
Include Only
Traffic to hostname
That contain yoursite.com
In the above example you can get more advanced with regex if you have subdomains or other domains that you are tracking.
Create a Segment For PPC traffic
If you have an internal team working on paid search engines like Google Ads it makes no sense for them to look at the unfiltered web traffic. Create a more specific segment that allows them to drill down on the performance of just the traffic they are driving to the site.
Filter Name: PPC Traffic
Filter Type: Custom
Include
Filter Field: Campaign Medium
Filter Pattern: cpc
Real Referring URL’s
This is probably one of my favourite filters. Google Analytics by default doesn’t show you the full URL’s of referral traffic, just the domain it comes from. This can be annoying if you want to see which specific pages are sending you traffic. We can get around this with a filter:
Filter Name: Real Referring URL’s
Filter Type: Custom
Advanced
Field A -> Extract A: Referral
Value: (.*)
Field A -> Extract B: –
Output To -> Constructor: User Defined
Value: $A1
Field A Required: Yes
Field B Required: No
Override Output Field: Yes
Once you implement this you can go to your referrals report, click Secondary Dimension > Behaviour > User Defined Value then you should see this report:
Goals are a way for you to track the actions that are important to your website performance. Before I continue it’s important to understand the difference between goals & events.
Goals: Goals are important conversions that happen on your website. Even if a Goal gets completed multiple times by the same person you it will only get counted once. Important goals are Path to Purchase or Newsletter Signup.
Events: Events are important events that happen on your website, events will get counted multiple times if repeated. Important events are Views of a Video, Clicks, Plays, Opens or Closes.
The important thing to remember is that if it’s designed to happen just once, it’s a goal. If it’s designed to happen many times then use events. Google has recently allowed you to use events as goals, however it still will only count the first unique instance of that event as the goal & not subsequent ones (your event tracking will show that though).
Usually Goals are triggered when a user views a specific page, this could be the thank-you page of your shopping cart or a specific step in the process to purchase.
You can also use a few other metrics to trigger a goal:
URL Destination: This is incredibly simple, just add the rule for the page to match in the goal. If you have multiple variations for the goal you can use a Regex.
Visit Duration: You can use this to trigger a goal based on visit time. Not entirely useful imo, but some publishers like it.
Page/Visit: You can use this to trigger a goal based on Pages per visit. Personally I think there’s better ways to do this which have more actionable data (i.e. Advanced Segments)
Event: This is a recent addition, you can now specific certain event triggers as a goal.
Goals are located in Account > Property > Profile > Admin > Goals, here’s an example of a very basic URL destination goal setup for the thank-you page of a purchase:
Since we call goals via visits to a particular page it’s important to note that on some occasions you will have to call a page virtually. This can happen for a number of reasons:
- One page form with multiple steps – You’ll need to call a virtual pageview at each step so we can create a funnel
- Inconsistent URL structure – You can override the current URL with Analytics so it’s clean in your reports
- Ajax or Javascript elements – Often these elements will change content without changing the URL, so you can call a virtual pageview to compensate.
To call a virtual pageview you can use the following snippet (title is not necessary unless you want to change that too):
ga('send', 'pageview', { 'page': '/my-new-page', 'title': 'My New Page Title' });
Goal funnels are a necessary part of any signup process, they enable you to see the effectiveness of your product at converting customers – plus it can also help highlight any barriers that are preventing people from commiting to the sale.
Setting up a goal funnel is easy, provided you’ve done the preparation I’ve previously highlighted (know the pages, setup virtual pageviews etc):
Once your funnel is setup correctly you can start looking at the information in the Reporting > Conversions > Goals > Funnel Visualization report. You should see something like this:
Events are a great way to track multiple instances of a certain event happening on your website, they are easy to use & will show up in the Content > Events area of Google Analytics. To trigger an event you use the following piece of code:
ga('send', 'event', 'category', 'action', 'label');
So for example when someone clicks on an entry method on our Gleam Competitions app, we call the following event:
ga('send', 'click', 'facebook', 'like', 'label');
Then when the person successfully enters the competition via that entry method we call the following event:
ga('send', 'enter', 'facebook', 'like', 'label');
If you look at your top events report you’ll see something like this:
If you want to attribute multiple events to a certain part of a page with it’s own unique URL (for tracking) then you can use the set command to set the page URL then use the send command to send the events that you want.
ga('set', 'page', '/my-custom-page');
ga('send', 'pageview');
ga('send', 'event', 'image1', 'clicked');
ga('send', 'event', 'image2', 'clicked');
One of the most common reports that marketers will look at is the Traffic Sources > Sources > All Traffic report. However if you don’t properly get all your sources tagged up properly then you’ll find it difficult attributing revenue or conversions to the correct source.
Here’s all of the different parameters you can use to tag a campaign with:
- Source: This is what you will see in your Sources > All Sources report. It’s important to be consistent with your naming.
- Medium: This is the marketing medium you used, use cpc for paid search, email for email & banner for banner advertising.
- Campaign Term: For paid search you might also want to send the term you’re bidding on. This is especially useful for non-google related search engines as there’s no other way to send it.
- Campaign Content: If you’re split testing a campaign with different content you can use this to see conversion rates between them.
- Campaign Name: Use this to name the campaign. Help’s you to see which campaigns have been most effective.
Some of the important things to ensure that you tag correctly are:
If you send a newsletter, or a welcome email it’s important to know what percentage of people come to your desired location after reading it. Plus what percentage of people does that email convert? What revenue did you generate?
By add Google’s custom URL tags to links within emails we can ensure that any emails that go out get assigned to the email
source, therefore we can see what email as a channel is contributing to our bottom line.
To do this you simply need to use Google’s URL Builder Tool, here’s an example of a typical URL from a newletter campaign:
http://www.yoursite.com/?utm_source=newsletter&utm_medium=email&utm_campaign=june
Another quick important point to remember is that this method will also allow you to attribute visits from desktop email platforms in your Analytics. If you don’t tag up URL’s then that traffic will get attributed to the direct
channel.
In order for Google Ads data to pull through you’ll need to login to your Google Ads account then click the Analytics tab. You’ll be asked to link the accounts from there.
Many Ecommerce sites will use comparison shopping sites like Google Products, Pricegrabber & The Find to drive additional traffic to their site. Make sure you encode your product feeds with the correct tagging so you can correctly attribute the sales:
http://www.yoursite.com/?utm_source=pricegrabber&utm_medium=cpc
If you do any type of advertising, such as banner ads, even Twitter promoted tweets. Make sure you use the URL builder to properly track the URL’s.
http://www.yoursite.com/?utm_source=twitter&utm_medium=cpc&campaign=promoted
If you do a lot of TV advertising or even Billboard advertising you can track visits from these in Google Analytics. Simply set up a vanity URL on your site:
http://www.yoursite.com/tv
Then 301 redirect that URL with your appended Google Analytics tracking:
http://www.yoursite.com/landingpage?utm_source=offline&utm_medium=tv&campaign=latenight
If you run an Ecommerce site, the revenue you generate will be one of your most important metrics. Luckily, Google Analytics has a method to send transaction & product data (you can attach multiple products to a transaction):
ga('ecommerce:addTransaction', { 'id': '1234', // Transaction ID. Required. 'affiliation': 'Acme Clothing', // Affiliation or store name. 'revenue': '11.99', // Grand Total. 'shipping': '5', // Shipping. 'tax': '1.29' // Tax. });</code> <code>ga('ecommerce:addItem', { 'id': '1234', // Transaction ID. Required. 'name': 'Fluffy Pink Bunnies', // Product name. Required. 'sku': 'DD23444', // SKU/code. 'category': 'Party Toys', // Category or variation. 'price': '11.99', // Unit price. 'quantity': '1' // Quantity. }); ga('ecommerce:send');
Once this data is enabled, it opens up so many possibilities at analysing your data. Remember those sources we just setup? Lets look at which ones generate us the most revenue Traffic Sources > All Traffic > Ecommerce:
Previously these were called Custom Variables, but Google has now improved the way you can send data to it. Custom dimensions are a great way to add additional segmentation information to your data, this could include things like:
- Gender
- Income Range
- Demographic Tag
- Persona Tag
- Customer or Non-Customer
- Customer ID
- Avg view time of something
There's some good examples of how you can use custom dimensions in the GA Help Center.
Advanced segments are probably one of the most powerful features within Google Analytics, they are essentially a huge filter that you can apply on top of your data which allows you to view all your metrics in a completely different light. Filtering the profile by just mobile users for example will show very different behaviours & conversion rates than seeing all your data together.
- 100% Bounce Visits
- Converters by Visit Count
- High Value Customers
- Google Image Traffic
- Traffic by Keyword Length
- Filter Common ISPs
- Remove Blog Bounce Traffic From Reports
- Monitor Question Traffic (Who, How, Why? etc)
- Cart Abandonment by Source
- Conversion Rate by Business & Non-Business Hours
- Not Provided Traffic
- Organic Traffic Minus Not Provided
- Google+ Traffic
- Mobile Traffic (Excluding Tablets)
- Organic Traffic With Conversions
- Traffic to Main Website From Blog
- Visit Depth
- Social Visit Depth
You Might Also Like
15 Early Traction Growth Hacking Strategies For Startups
Once you launch, getting that early traction is crucial. Here's 15 tips that worked for us.
15 Ways to Align Your Content Marketing Strategy With Business Objectives
Understand how having a solid content plan in place and executing on it can propel your business upwards.
The 5 Content Pillars That Drive 95% Of Our Inbound Leads
95% of our new customers come from inbound marketing. Here's the content playbook we use.
Stuart McKeown
Stuart McKeown is one of the Co-founders at Gleam. Aside from writing and helping businesses grow, he also enjoys sound design and drinking tea ☕️