Where to Add Google Analytics Code in Shopify?

Cody Schneider8 min read

Setting up Google Analytics for your Shopify store opens up a whole new world of understanding who your customers are and how they shop. While Shopify reports tell you what happened, Google Analytics helps you understand the why. This guide will walk you through exactly where and how to add the Google Analytics code to Shopify, breaking down the best method for most users and explaining how to make sure it's working correctly.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Before You Add the Code: Why It's Worth the Effort

You might be wondering, "Doesn't Shopify already have analytics?" Yes, it does - and they are great for tracking sales, top-selling products, and order values. But GA4 goes so much deeper into the customer journey before a purchase is made.

Connecting your store to Google Analytics allows you to:

  • See the Full Customer Journey: Track how users find your site (from social media, Google search, email campaigns), which pages they visit, how long they stay, and where they drop off.
  • Understand Marketing Performance: Get a clear picture of which channels are driving quality traffic that actually converts, helping you invest your marketing budget more wisely.
  • Analyze On-Site Behavior: Discover which product page layouts encourage add-to-carts, which blog posts lead to sales, and how users interact with your navigation menu.
  • Unlock Better Ad Targeting: Build highly specific audiences in GA4 based on user behavior (e.g., people who viewed a specific product category but didn’t buy) and use them for retargeting campaigns in Google Ads.

Think of it this way: Shopify analytics gives you the final score of the game. Google Analytics gives you the full play-by-play, showing you every move that led to that score.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

First Things First: Getting Your GA4 Measurement ID

Before you place any code in Shopify, you need to have a Google Analytics 4 property set up for your store. The key piece of information you’ll need from it is the "Measurement ID." This unique tag identifies your data stream so Google knows where to send the tracking information from your site.

If you already have a GA4 property, finding your Measurement ID is simple. If not, creating one takes just a few minutes.

Here’s how to create a property and find your ID:

  1. Log into your Google Analytics account.
  2. Click the Admin gear icon in the bottom-left corner.
  3. In the Property column, make sure your desired property is selected. If you need to create a new one, click the + Create Property button and follow the on-screen instructions (you’ll enter your store name, time zone, and currency).
  4. Once your property is created, click on Data Streams in the Property column.
  5. Select your web data stream (it will show your store’s URL). If you don’t have one yet, click Add stream and choose Web.
  6. On the Web stream details page, you'll see your Measurement ID in the top-right corner. It will look like this: G-XXXXXXXXXX.

This "G-" tag is your golden ticket. Copy it and keep it handy for the next step.

The Recommended Method: Using Shopify’s Built-in Integration

For over 99% of Shopify store owners, this is the easiest, safest, and most effective way to install Google Analytics. Shopify has a native integration through its "Google & YouTube" app that's designed to make this process seamless. Best of all, it automatically sets up crucial e-commerce tracking for events like viewing products, adding items to a cart, starting the checkout process, and completing a purchase.

Manually trying to set up that level of tracking can be incredibly complex, so using Shopify's built-in feature is a huge win.

Follow these steps to connect GA4 the easy way:

  1. From your Shopify Admin dashboard, go to Online Store > Preferences in the left-hand navigation menu.
  2. Scroll down to the Google Analytics section.
  3. You'll likely see a message prompting you to set up Google Analytics. Click the Manage pixel here button. This will redirect you to the Google & YouTube sales channel app. (If you don't have it installed, Shopify will prompt you to add it - which is completely free).
  4. In the Google & YouTube app setup screen, you’ll be asked to connect your Google account. Choose the account that has Admin access to the GA4 property you just created.
  5. Once connected, you will see a list of your GA4 properties in a dropdown menu. Select the correct one for your store, or click Create new if needed.
  6. Ensure the correct GA4 Measurement ID is displayed and click the Connect button.
  7. Shopify will confirm that pixel tracking is active. Save your settings.

That's it! You've successfully added Google Analytics to your Shopify store without touching a single line of code. Shopify will now automatically send page views and e-commerce conversion data directly to your GA4 property.

GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

For Custom Needs: Manually Adding the GA4 Code to Your Theme

While the native integration is ideal for most, there are rare scenarios where you might need to add the GA4 tracking code directly into your Shopify theme’s code. For example, some third-party apps might require it, or you may have a very specific custom tracking need that isn't covered by the standard setup.

A Quick Word of Warning

You should only attempt this method if you are comfortable editing theme code. A mistake here can potentially break your site's functionality or appearance. Crucially, if you use this method, you should disable Shopify's native integration to avoid tracking every page view twice. This will inflate your traffic numbers and ruin your data quality.

Here’s how to add the code manually if you're absolutely sure it's what you need:

  1. First, get your full global site tag (gtag.js) script. In GA4, go to Admin > Data Streams, click your web stream, and scroll down to View tag instructions under the "Google tag" section. A pop-up will appear, select the Install manually tab. This will give you a code snippet that looks something like this:
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
    window.dataLayer = window.dataLayer || [],
    function gtag(){dataLayer.push(arguments),}
    gtag('js', new Date()),

    gtag('config', 'G-XXXXXXXXXX'),
</script>
  1. Copy this entire block of code.
  2. In your Shopify Admin, navigate to Online Store > Themes.
  3. On your current theme, click the three-dot menu (...) and select Edit code.
  4. In the file editor on the left side, under the Layout folder, find and click on the theme.liquid file.
  5. Scroll through the code until you find the closing </head> tag. It's usually near the top of the file.
  6. Paste the entire Google tag snippet on a new line right before the closing </head> tag.
  7. Click Save in the top-right corner.
GraphedGraphed

Still Building Reports Manually?

Watch how growth teams are getting answers in seconds — not days.

Watch Graphed demo video

Did It Work? How to Verify Your Google Analytics Setup

Don't just set it and forget it. You need to confirm that Shopify is actually sending data to Google Analytics. The single best way to do this is with the Realtime report inside GA4.

  1. Keep your Google Analytics account open in one browser tab.
  2. In a new tab or window, open your Shopify store's homepage. Navigate to a couple of different product or collection pages.
  3. Switch back to your Google Analytics tab and go to Reports > Realtime.

You should see a "1" on the "Users in last 30 minutes" map. In the "Event count" card, you should also see activity for events like page_view and session_start. If you used the native integration and added an item to your cart, you might even see the add_to_cart event appear. If you see activity here, congratulations - your tracking is working!

Common Sticking Points and How to Fix Them

Running into trouble is common, but most issues are easy to fix.

  • No Data is Appearing: Be patient! It can sometimes take 24-48 hours for data to fully populate in standard GA4 reports (though the Realtime report should work almost instantly). Double-check that you copied and pasted the correct Measurement ID without any extra spaces. Also, disable any ad or script blockers on your browser while you test.
  • You Have Double the Traffic: This is a classic symptom of installing the code twice - once via the native integration and again manually in theme.liquid. Go back and remove the manual code snippet from your theme file. Always stick with just one method.
  • Shopify and GA4 Data Don't Match: This is perfectly normal and expected. The two platforms measure data in fundamentally different ways. Shopify tracks every single transaction flawlessly from its server. GA4 tracks user sessions in a browser, which can be blocked by ad blockers or impacted by cookie settings. Use Shopify analytics for your official sales and revenue numbers, and use Google Analytics for understanding marketing attribution and user behavior trends. The numbers will never be identical, and that’s okay.

Final Thoughts

Connecting Google Analytics to your Shopify store is one of the most impactful things you can do to get serious about data-driven growth. Using the built-in "Google & YouTube" app is a safe, simple, and powerful way to unlock deep insights into how shoppers discover and interact with your brand, all without writing a single line of code.

Once your data is flowing, the real challenge becomes turning those numbers into actionable insights. Making sense of GA4's complex interface and stitching reports together with data from your ads platforms and Shopify itself can turn into a full-time job. We ran into this bottleneck ourselves, which is why we built Graphed. It connects to all your analytics and SaaS tools, letting you build dashboards, pull reports, and get clear answers just by asking an AI Analyst a simple question. It's the fastest way to get from data to decision without drowning in spreadsheets beforehand.

Related Articles