How to Set Up Google Analytics (GA4) on Shopify

By 

Jonathan Halbrecht

 on July 20, 2022. 
Reviewed by 

Joel Taylor

Laptop screen displaying "Google Analytics"

The new Google Analytics 4 (GA4) offers a number of improvements and enhancements over the previous version, Universal Analytics. Most notably, GA4 provides an updated user interface, as well as enhanced reporting capabilities.

Benefits of Setting up GA4 on Shopify

Google Analytics presents many benefits for e-commerce merchants. Connecting GA4 to Shopify allows you to track your store's performance in addition to your website's performance. This is especially helpful if you are using Shopify as your only online platform. Furthermore, connecting GA4 to Shopify makes it easier to compare your website's data with your store's data, though you'll need to understand UTM codes in Google Analytics. This can help you identify which aspects of your store are performing well and which areas need improvement.

Additionally, consider taking a look at Shopify Analytics vs Google Analytics to see which is right for you.

Setting up Your Google Analytics Account

If you already have a Universal Analytics property, you can set up a GA4 account using GA4 Setup Assistant. To do so, head to the setup wizard from the Admin page of your Universal Analytics property.

For those that don’t have a current Google Analytics account, setting up a Google Analytics 4 account is very easy. After you create a new Google Analytics account, it'll automatically create the Google Analytics property for GA4. To do this, simply:

  1. Head to google.com/analytics
  2. To begin setting up a new account, click “Get started today
  3. Enter your information and agree to the terms of service
  4. You'll be asked to verify your account by phone or mail
  5. Once you've verified your account, you can add your website

Connecting GA4 to Shopify

To manually connect your GA4 account to Shopify, simply follow along with these steps:

Step 1. Add Google Tag Manager to Shopify

You may already have Google Tag Manager (GTM) installed in your online store. To help you find out, read our guide to Google Tag Manager vs. Google Analytics. If so, you can skip this step and move on to the next. If not, the first thing you’ll need to do is create a GTM account.

To do this, first, visit tagmanager.google.com. From the top right-hand side of the homepage, click the “Create Account” button. Run through the setup prompts, including naming your account and adding your details.

Once the setup is complete, it’s time to generate a GTM container code. To do this, log in to your new account, and click on the GTM ID you’ll notice in the top right-hand corner (as an example, it’ll be something like "GTM-POGK4BD"). Once you’ve clicked on the code, a panel will pop out.

You want to copy the code that appears in the box under the message: “Paste this code as high in the <head> and of the page as possible."

For now, leave the code that appears in the panel that reads: "Additionally, paste this code immediately after the opening <body> tag." We will use this later.

Step 2: Backup Your Shopify Store’s Theme Files

Now we’ve got your GTM code ready to go, it’s time to edit your store’s theme files. Before we proceed, it’s a good idea to make a backup copy of your current theme’s code, just in case something goes wrong when inserting the GTM tag. To duplicate your store’s theme, from your Shopify store’s dashboard, navigate to “Online Store” > “Themes”.

Next, click on the “Actions” drop-down menu and select “Duplicate”.

Step 3: Insert the GTM <head> Tag Into Your Store’s Theme Files

Once you’ve got a backup sorted, take the copied GTM code and, from your Shopify admin, navigate to “Admin” > “Online Store” > “Themes”.

Once again, click on the “Actions” drop-down menu, and instead of selecting “Duplicate,” this time select “Edit”.

This will bring you to the backend portion of your store, where all the website’s HTML, CSS, JavaScript, etc. code exists. From the left-hand side, located under the “Search files” search bar and “Layout” portion of the panel, click on “{/}theme.liquid”.

Now, for the most important part, take your copied GTM code and paste it within the “Head” portion of this part of your store’s code. You won’t need to scroll down. Specifically, paste the GTM code under the meta tags. If you’re not sure what that is, look for the <head> tag, then the few lines of <meta> tags, and paste the code directly under them.

Step 4: Insert the GTM <body> Tag Into Your Store’s Theme Files

Okay. Now for the <body> tag.

Head back to your GTM admin page, and copy the <body> code. Go back to your store’s theme, where you just pasted the <head> tag, and scroll all the way down to the bottom of the “{/}theme.liquid” code. At the very bottom, you’ll see the <body> tag, followed by an <html> tag. Just above the <body> tag, paste the code you just copied from GTM.

Step 5: Finalize These Edits

To complete these edits, from the top right-hand corner, click the “Save” button. To confirm you’ve completed these steps correctly, head to the front end of your store.

Step 6: Add the GTM Code to Your Store’s Thank You Page

If you are on the Shopify Plus plan, you can add the GTM code to the Checkout page. For the rest of us, the code will not work for either the checkout or cart pages.

However, you can paste the code into a portion of your backend to track purchases.

To do this, from the Admin page, navigate to “Settings” > “Checkout” > “Order Processing”. From here, scroll down until you see the “Additional scripts” panel. Paste the GTM container code where it says “<!--Google Tag Manager -->".

Step 7: Double-Check the Setup Was Successful Using GTM

Once the above steps are complete, head back to GTM and click the “Preview” button in the top right-hand corner of your account’s admin page. Next, type in your store’s URL and click the “Next” button. If everything is installed correctly, you will see the prompt “Debugger Connected”.

And that’s it. Your Shopify store is now connected with GTM and GA4.

Can't find what you're looking for?