Update: This article has been updated as of March 2021 to make note of Google's introduction of Google Analytics 4 and a change in how to create a Google Analytics property.
As my friend Ahmad Kanani notes, Shopify storeowners are provided with a seemingly easy way to integrate Google Analytics into their account. On a high level, it is easy. The only requirement after creating your GA account is copying/pasting a script into your Shopify administration panel. Once that is complete, the account will begin to track store data. But, for merchants looking to more effectively track their ecommerce performance, there is more information and data waiting to be uncovered and you can do so by following Ahmad's 9 easy steps:
Step 1: Create a Google Analytics account
Follow the steps from this link to create your GA account, or sign in to your GA account if you already have one.
Once logged in to your GA account, go to Admin and create a new account:
Here you’ll need to enter some basic details about your account. Make sure that you click on Show advanced options > Select the toggle for Create a Universal Analytics property
Until further changes are implemented by Shopify, select Create a Universal Analytics property only as you'll need the UA- tracking ID in order to sync Google Analytics with Shopify.
The most important fields in this step are:
Website URL: make sure to select the correct protocol for your website, if your shop uses SSL (which comes with every Shopify store) then you should choose https:// here.
Reporting Time Zone: Make sure to select the correct time zone here. It should be the same timezone you use in your Shopify admin, Facebook Ads reports etc. because otherwise, it will result in inconsistencies between metrics reported by different tools.
Step 2: Add tracking script to your Shopify store
Copy your tracking script:
then go to Shopify Admin > Online Store > Preferences and paste your tracking code into Google Analytics Account field:
Save the settings, and you’ll see a result like this:
* Don’t forget to check Use Enhanced eCommerce, this enables sending enhanced eCommerce data from Shopify to GA, you’ll then need to activate this feature in your GA account as well.
Step 3: Google Analytics Property settings
Now that you’ve added the tracking code to your Shopify store, it’s time to configure property settings in Google Analytics. Each Google Analytics account can have several properties.
Expert Tip: When you create a GA account, a property will be created by default. Each property comes with its own unique Tracking ID, in the form of UA-12345678-1. The tracking ID of the first property of each account ends in “-1”. Any subsequent property gets an incremental suffix like “-2”, “-3” etc., in order to combat some methods of referral spam which is done through sending hits to Google Analytics via measurement protocol, it’s helpful to first create a couple of new properties and then remove the first few properties and only keeping the last one which its Tracking ID ends in “-3” or “-4”. Spammers who send hits using measurement protocol, usually generate random Tracking IDs ending in “-1”, because most GA accounts have only one property.
Now let’s get back to property settings.
In Google Analytics admin in Property > Tracking Info > Data Collection, enable Remarketing and Advertising Reporting Features.
Then go to Property > Property Settings. Under Advertising Features, enable Demographics and Interest Reports and under In-Page Analytics, enable Use Enhanced Link Attribution.
Enabling Demographic and Interest Reports makes Age, Gender and Interest data about your users available in your GA reports which are helpful in understanding your target market and their characteristics. For example, you can compare the conversion rate across different age ranges or genders.
Enabling Enhanced Link Attribution makes In-page Analytics reports available in GA. If this setting is disabled, GA won’t differentiate between clicks on identical links placed at different parts of a page, hence making it impossible for you to understand the performance of each individual link. For example, let’s say on your Homepage you have 3 different links to your Shop page, one in the main menu, one in the middle of the page, and one in the footer. If you don’t enable Enhanced Link Attribution, you can only track how many people clicked on a link to go from Homepage to Shop page, but you can’t measure the number of clicks on each link individually.
In order for Enhanced Link Attribution to work correctly, you also need to add a little bit of code to your GA tracking script on every page. To do this, follow the below steps:
1. Go to Shopify Admin > Online Store > Preferences > Google Analytics and click on Add Custom JavaScript
2. Enter the following code in the text area:
ga(‘require’, ‘linkid’);
Note: For the most accurate link attribution, each link on the page should have a unique element ID.
Step 4: Referral Exclusion
This is a very important step if you want to be able to accurately attribute revenue to different traffic sources, especially if you use payment gateways that process payments off-page on their own domain like Paypal.
In your GA admin, go to Property > Tracking Info > Referral Exclusion List
Click Add Referral Exclusion as many times as necessary and add the following domains (one domain at a time):
- myshopify.com
- yoursite.com
- Paypal.com (if you use Paypal as a gateway)
- Checkout.shopify.com
- pay.apple.com
- pay.google.com
- pay.shopify.com
- NEW: Make sure you are adding shop.app for Shopify's Shop app
You should also add any other domain that is part of user’s on-site journey on your website, but you don’t want it to steal attribution from the main referrer source for that session.
For example, many Shopify stores use services like FourSixty to embed shoppable Instagram feeds into their pages. In case a user comes organically from Google, but then clicks on an Instagram photo loaded by FourSixty as part of their on-site experience and views a product, what FourSixty does is that they redirect the user to 460.io and then immediately to the products page for tracking purposes.
This will overwrite user’s traffic source to 460.io rather than organic search. Thus, if the user ends up buying something later on in that session, the sale will be attributed to 460.io instead of organic search, skewing reports and making it impossible to properly attribute sales to their original traffic sources.
In this case, we’ll need to add 460.io as a Referral Exclusion.
The final referral exclusion list for one of my clients looks like this:
Step 5: Setting up views
Now it’s time to move on and create some views. For each property in Google Analytics, you can have up to 25 views. According to Google a view:
“…is the level in an Analytics account where you can access reports and analysis tools.”
It is recommended that always have at least 3 views for each GA property, the first view “All website data” is automatically created when you create a property. You should keep this view intact without any filters or additional settings so you can always have a backup of all raw data that’s being tracked by your property. The other two views you need to create are:
Main View: Which will be the view you’ll use for accessing the reports
Test View: Which you can play with and apply settings and filters to before rolling them out live on your Main View.
To explain the reason for this, I should first explain what views are and why we use them. Think of a view as a lens through which you look at the data gathered in your property. For example, you can set a view to only see traffic from a single country, effectively filtering out all the hits from other countries, or you can setup filters on a view to filter out spam traffic, bots, your internal IP addresses etc. The problem is, when you filter out a portion of your data in a view, that data is removed from that view forever, and there’s no way to undo it or any backup. So imagine you only have one view, and you add some filters to filter spam traffic, but after a week you realize that you’ve made a simple mistake in writing a RegEx filter and actually filtered legitimate traffic from your view. In this case, there’s no way to retrieve that part of data in your view. That’s why you need to test all filters and changes on a Test View first and apply them to your Main View once you make sure everything is working as they should.
Thus, your Main View is filtered, your Test View is there for playing around with new filters, settings, and quality control, and the All website data view is there as an unfiltered, raw backup of all the data that are being gathered in your property.
From this point, you can add additional views with different settings and filters based on your business needs.
First create your Main View and then, after you’ve gone through the View Settings part of this article, then duplicate your Main View to create a Test View, so that your Test View has the exact same settings as your Main View.
View settings:
In your GA admin, go to Main View> View Settings:
1. Set your timezone
Note that each view can have its own time zone. So for example, if there’s a use case that you like to measure user behaviour based on hour of the day, and you have two main markets with very different time zones (i.e. US vs the UK) then you can create a separate view for each time zone in addition to your Main View to be able to see accurate hourly reports.
2. Set your currency
You can set Currency on a view level. This is especially useful for stores with multiple localized versions that actually charge customers different currencies. Other than that, you should enter your base store currency of you just show different currencies but always charge your store’s default currency during checkout.
3. Check “Exclude all hits from known bots and spiders”
You should always check this on, Google filters out bot traffic from most known sources and it helps keep your data clean and trustworthy.
4. Exclude query parameters:
In this field, you can enter Query parameter to be ignored by GA in content reports. The reason for having this setting is that every page URL in your store might be loaded with different Query parameters, which are used for tracking purposes and don’t affect page content at all, but when you want to analyse content reports, you’ll see several rows for each page URL, which are only different based on their query parameters, resulting in reports which are not clean and hard to analyse. It’s a bit tricky to set every single query parameter here when you’re setting up your GA account for the first time, as it hugely depends on the marketing apps and services you use.
A standard query parameter I’d like to exclude is variant. If not excluded, it results is many rows to be recorded for each single product based on its variant ID. Services like Nosto or Receiptful (Currently Conversio) also add their own query parameters to track and attribute sales to their apps, which I always exclude in view settings.
5. Turn on Site search tracking
Put q in query parameter (case sensitive). This allows you to see what queries do people enter into your site search field. This is one of the few places in Google Analytics reports that you can actually analyse user intent.
Enhanced Ecommerce Setting
After setting up the basics, it’s time to configure Enhanced E-commerce to be able to measure more advanced metrics and user interactions like product impressions, shopping behaviour, add to cards etc.
To do this, in your GA admin go to Main View > E-commerce Settings, and turn on E-commerce and Related Products:
Click Next Step, and then turn on Enhanced E-commerce:
Next, under Checkout Labeling, add four steps in the exact same order shown below:
The checkout labeling configured in this step is the first step required for enabling Checkout Behaviour Analysis report like this:
Which is hugely useful for understanding user behaviour during checkout and identifying bottlenecks in the checkout funnel to fix. But Shopify doesn’t send information about checkout steps to AG automatically, so I’ll cover how to set that part up in another article because it’s out of the scope of this article and needs Google Tag Manager and some manual JavaScript code.
Step 6: Setting up filters for Main View
For the Main View which we use to check reports and look at the data, we don’t want the data to be skewed by irrelevant hits and page views from internal IPs and spam bots, so we need to set up filters to exclude those hits from being recorded in the data.
Filtering internal traffic
Filtering out internal IPs is easy, first go to Main View > Filters and click Add Filter:
And then set it up according to the below screenshot:
Replace 123.123.123.123 with your own IP address. You can find your IP by doing a Google search for “What’s my IP?”. If you work in a company or where your internal team might use your website from different but similar IP addresses, you can also use RegEx in the IP field to match exactly the range of IPs you’re trying to exclude. If all your IPs are within the same range and only the final 3 digits are different, then instead of “that are equal to” you can choose “that begin with” from the drop-down menu and enter the subset of IP addresses that all your internal IPs begin with.
Filtering traffic from other hosts
Setting up this is a bit more complex, but it hugely helps in keeping your data clean. The idea behind setting up this filter is that you only want to include hits when they originate from Google Analytics tracking code that is loaded on your own website and not when someone tries to send hits to your GA account and using your Tracking IDbut from their own server, which is the main way of sending spam traffic to your GA account.
In the above example from a client eCommerce website that hasn’t setup Hostname filter, you can see that fake hits are being sent to their account from various spam domains, skewing their data and making their Referral reports inaccurate. Setting up Hostname filter prevent these hits from being recorded in their view.
To set this up, we need to add two filters:
1. The first filter combines the Host Name and Path together to create a single string value that can later be used by the second filter to exclude hits from hosts that don’t match your own domain or Shopify’s checkout URL.
To do this, create a new filter and name it Merge Hostname and Request URI.
For filter type, choose Custom, and then choose Advanced.
For Field A, select Hostname and enter (.*) in the input field.
The Hostname is the full domain name of the page that GA code loads on, and Request URI is the part of the URL that comes after the Hostname. For example, if the page is http://www.yoursite.com/collections/all then the hostname would be www.yoursite.com and Request URI would be /collections/all.
For Field B, select Request URI and enter (.*) in the input field
In the Output field select Custom Field 1 from the drop-down menu and enter $A1$B1 in the text area. This basically gets the value from Hostname ($A1) and the value from Request URI ($B1) and merges them together as Custom Field 1 to be used by our second filter.
Now, create another filter and name it Hostname Filter.
Select Custom, then Include and choose Custom Field 1 from the drop-down menu. In the text field, enter:
.*yoursite\.com.*|/checkout.*|.*\/checkout.shopify.com.*|.*yoursite\.myshopify\.com.*
This ensures that only hits that match either your store domain, your .myshpoify.comsubdomain or checkout.shopify.com get included in the reports in this view.
Please compare your settings with the below screenshot to make sure they are correct:
Note: If you’re on a Shopify Plus plan, the only thing you need is to simply add a Hostname filter and include only hits from yoursite.com, But for the majority of the shops that are on lower plans and use checkout.shopify.com, it’s needed to merge Hostname and Request URI first, so we can filter based on it later with a RegEx expression.
Another thing to note is that if you use this GA tracking code on other legitimate domains that are part of your business and have cross-domain tracking setup, then you’ll need to include those domains in this filter as well, otherwise all the hits from your other domains will get filtered. For example, if you have yoursite-uk.com and yoursite-usa.com and you’re using the same GA script on both websites, then you need to make sure to both domains are included in this filter.
In such case, it’s also recommended to add another filter to add Hostname to Request URI and then overwrite them to Request URI field so when you look at content reports, you can distinguish between pages with the same path that are located on different domains. For example, if you don’t set the above-mentioned filter to merge Hostname and Request URI and you check your pages report, the number of page views for “/” which is the homepage will be the aggregate number of page views for yoursite-uk.com/ and yoursite-usa.com/ website, because the page path of both those pages is “/”.
Now your Filters page should look like this:
Please note that the rank of Merge Hostname and Request URI filter should be lower than that of Hostname Filter because filters apply in their specific order, and Hostname Filter needs the result of the previous filter to work properly.
You can click on Assign Filter Order in case you need to change the order of filters at any time.
Step 7: Setting up goals and funnels
Goals are specific objectives and user interactions that are meaningful and valuable for your business. Every event or user behaviour that has a meaningful value for your business can be set up as a goal, and if there is a logically expected path to achieving that goal (i.e. several steps or pages), a funnel can be setup to measure the progress of users towards the goal and the performance of each page across the funnel.
Some types of goals you might like to set up for your eCommerce store are:
- Engagement goals based on the number of pageviews and or time on site, scroll depth etc.
- Paying videos
- Submitting a form (i.e. Contact us)
- Outbound links (i.e. to your social media accounts)
It all depends on your business and what’s important for you other than a purchase. The reality is that only a small fraction of users end up with a transaction during a session, the industry average tends to be around 2%. The natural question that comes after is “What about the other 98% of users? Are they all the same? Or some are more valuable, more engaged, or more likely to buy in the future?”
To answer those questions, you must figure out the signals of engagement/likelihood to buy for your business and set them up as goals so you can have a clearer understanding of how different segments of users behave on your site and be able to take meaningful actions based on your data.
The most important goal for any eCommerce website is a transaction, so let’s go through setting up a purchase goal and build a funnel report to see how users progress towards that goal on your website.
Set up a Purchase goal + Funnel
The most important goal you want to set up in your eCommerce store is a purchase goal together with a purchase funnel.
To set up a purchase goal, follow the below steps:
- Go to View > Goals and click “+ New Goal”
- Choose Custom as goal type
- Name it Purchase + Funnel
- For goal type, choose Destination
At the next step, choose Regular Expression from the drop-down menu under destination, and enter below code into the text field:
\/checkout\/thank_you
Keep Value off, and turn on the Funnel.
Now we’re going to define a set of steps that we expect a user take towards this goal, so we can analyse user behaviour at each stage and optimise the funnel for more conversions later.
At this moment, your screen should look like this:
For the first step of the funnel, name it Homepage and enter the following in the Screen/Page field:
^\/(\?.*)?$
Leave Required? as No
If we make the step required, then we won’t be able to track the path to purchase for those transactions that are started on a different page other than Homepage, i.e. when a user lands on a category page after clicking on a link.
Enter the following values for the next steps:
Name: Screen/Page
Collection: ^\/collections\/([a-z0-9]|-)*\/?(\?.*)?$
Product: .*\/products\/.*
Cart: ^\/cart.*
Contact Info: \/checkout\/contact_information
Shipping Method: \/checkout\/shipping
Payment Method: \/checkout\/payment
Review Order: \/checkout\/review
Processing: \/checkout\/processing
Note: Only include Review Order step if you’ve activated this step in your Shopify admin in checkout section.
To access the report for this funnel, go to Conversions > Goals > Funnel Visualisation.Your report should look like this:
As you can see, a funnel allows us to see the number of entrances to each step, plus the portion of users who proceed to the next step, and those who drop off. A funnel report is a great way to spot bottlenecks and weakness points on your website which you can then fix to increase your goal conversion rates.
Step 8: Content Grouping
By default, Google Analytics doesn’t distinguish between different types of pages on your website, and only records page path and URL of each page when it’s visited by a user. Content grouping allows to defining groups of pages on your website that reflects the way you categorise content in your business or your website structure. This allows you analyse the performance of each group of pages independently and with more flexibility in content reports. For example, you can view the performance of products pages in aggregate to see how your product page template is performing, and you can also drill down and check the performance of each product page.
Examples of content groups for an eCommerce website are Product pages, Collection Pages, and Normal Pages.
Each free Google Analytics account can have up to 5 content groupings per view. We’re going to set up content grouping for Collections, Products, Blog Posts, and Pages. Luckily, Shopify’s clean URL structure makes it relatively easy for us to setup content grouping rules for each of those page groups.
To setup content grouping, go to View > Content Grouping and click “+ New Content Grouping”
Collections
- Add a new content grouping and name it “Collections”
- Under “Group Using Extraction” click “Add Extraction”
- Click page and in the input field enter: ^\/collections\/([a-z0-9-]*)\/?\??.*?$
- Click Done and then click Save
Here’s how it should look like at the end:
Now let’s create the rest of our content groupings.
Products
- Add a new content grouping and name it “Products”
- Under “Group Using Extraction” click “Add Extraction”
- Click page and in the input field enter: ^.*\/products\/([a-z0-9-]*)\??.*?$
- Click Done and then click Save
Pages
- Add a new content grouping and name it “Pages”
- Under “Group Using Extraction” click “Add Extraction”
- Click page and in the input field enter: ^\/pages\/([a-z0-9-]*)\/?\??.*?$
- Click Done and then click Save
Blog Posts*
- Add a new content grouping and name it “Blogs”
- Under “Group Using Extraction” click “Add Extraction”
- Click page and in the input field enter: ^\/blogs\/([a-z0-9-]*)\/?\??.*?$
- Click Done and then click Save
* Only in case you’re using Shopify’s built-in blogging feature for your blog. The rule should be different if you have setup your blog on another domain/platform i.e. blog.yoursite.com
Step 9: AdWords and Search Console Integration
You can integrate your Google Analytics account with your Google Search Console and Google AdWord accounts to be able to see data from those accounts integrated into your reports. For example, cost data for your AdWord campaigns and Keyword and Queries from Search Console.
These integrations are done at the property level. To do this, go to Property > Product Linking > All Products and follow the on-screen instructions to link your AdWords and Search Console accounts to Google Analytics.