How do I install GA4 on a Shopify site?

Applies to: Google Analytics 4 (GA4) with Shopify
Last updated: May 2025


Problem

You want to use Google Analytics 4 to track visitors, purchases, and behavior on your Shopify store, but GA4 is not supported natively in Shopify’s admin like Universal Analytics once was.


Solution

Since Shopify doesn’t currently offer a built-in GA4 integration, you’ll need to manually add the GA4 tag to your Shopify theme, or use Google Tag Manager for more advanced setups (including e-commerce tracking).


Option 1: Add GA4 Using the gtag.js Script

Step-by-Step Instructions:

  1. Go to your GA4 property
    • Admin > Data Streams > Web
    • Copy your Measurement ID (e.g., G-XXXXXXXXXX)
  2. Open your Shopify Admin
    • Go to Online Store > Themes
  3. Click Actions > Edit Code
  4. In the Layout folder, open theme.liquid
  5. Paste the GA4 global site tag just before the </head> tag:
<!-- Google tag (GA4) -->
<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>

Replace both instances of G-XXXXXXXXXX with your actual Measurement ID.

  1. Save the file

This will add GA4 tracking to all pages of your Shopify store.


Option 2: Use Google Tag Manager for More Control

If you need custom event tracking (e.g., purchases, add-to-cart), use GTM:

  1. Set up a GTM container at https://tagmanager.google.com
  2. In Shopify, paste the GTM container code:
    • Into the <head> and <body> sections of theme.liquid
    • Save the file
  3. Inside GTM:
    • Add a GA4 Configuration tag
    • Add event tags for custom actions (requires advanced setup)
  4. Publish your GTM container

This method gives you full flexibility but requires more setup and testing.


Limitations and Considerations

  • Shopify does not natively support GA4 Enhanced Ecommerce
  • For advanced tracking (like product views, add-to-cart, purchases), use:
    • Google Tag Manager with custom data layer events, or
    • A third-party Shopify app that supports GA4 (e.g., Elevar, Littledata)
  • If using Shopify Plus, server-side GTM is also an option for higher accuracy

Testing Your Setup

  • Open your site in a new tab
  • In GA4, go to Reports > Realtime
  • You should see your own visit and pageviews
  • Use Google Tag Assistant or GTM Preview Mode to confirm tracking