How to Seamlessly Set Up Google Analytics 4 on Shopify
Share
For Shopify e-commerce businesses, however, this shift comes with unique challenges. What was once a straightforward setup in Universal Analytics now requires additional steps to enable seamless e-commerce tracking in GA4. And without proper tracking, you may lose out on valuable insights that drive conversions and optimize marketing spend.
Don’t worry, though—we’ve designed a step-by-step guide to help you set up GA4 e-commerce tracking on Shopify quickly and without hiring a developer or installing extra apps. With just a few steps, you’ll have your store ready to capture powerful customer insights that will help you make data-driven decisions.
To get started, make sure you have both Google Tag Manager (GTM) and GA4 installed on your Shopify store. While we’ve made this guide as simple as possible, having a basic understanding of GTM will make the process even smoother. With GA4 and GTM working together, you’ll soon unlock data insights that fuel growth, refine customer journeys, and increase your bottom line. Read on to ensure your Shopify store is fully equipped for the future of data tracking.
Effortlessly Set Up Google Analytics 4 on Shopify
Capture Crucial Data to Drive Shopify Sales and Maximize ROI with GA4
To fully leverage the power of Google Analytics 4 (GA4) on Shopify, it’s essential to set up your GA4 property and tracking tags correctly. GA4 is designed to deliver insights that reveal your customer’s journey, helping you optimize your marketing strategy and boost conversions. Follow these steps to set up GA4 on Shopify, and ensure your store is ready for data-driven success.
Step 1: Create a Google Account and Set Up Google Analytics
To get started, you’ll need a Google account. If you already use Google products like Gmail or Google Ads, you’re set! Just log in and use that same account to set up Google Analytics. If not, create a new Google account to access Google Analytics. Once you’re logged in, go to Google Analytics and create a new account tailored to your Shopify store’s needs.
Step 2: Create or Transfer Your Google Analytics 4 Property
Next, it’s time to create or transfer a GA4 property. This property is where your Shopify data will be stored and analyzed. Navigate to Google Analytics, select “Create Property,” and set up your GA4 property specifically for your Shopify store. If you’re upgrading from Universal Analytics, you can also move your existing property to GA4. Once the property is created, generate a unique Tag ID, which you’ll need for the next steps.
Step 3: Add Google Analytics 4 Tags to Your Shopify Store
Adding GA4 tags is crucial for capturing customer interactions.
- Start by going to your Shopify admin dashboard, and select Online Store > Preferences.
- In the Google Analytics section, click “Manage pixel here,” then select “Connect your Google account.”
- Enter the Tag ID for your GA4 property to connect your store with GA4.
Once set up, GA4 will automatically track essential e-commerce events, like page views, add-to-cart actions, and purchases, allowing you to gain real-time insights into customer activity.
Note: Your online store must be public (remove any password protection) for Google Analytics to track data effectively.
Step 4: Link Google Analytics with Google Ads for Advanced Tracking
To maximize the impact of your analytics, link your Google Analytics account with Google Ads. This connection lets you analyze customer activity, track conversions, and create targeted audiences to improve ad performance and ROI. With both platforms working in sync, you’ll gain a clear view of your customer journey, enabling smarter ad spend and more targeted campaigns.
Setting up Google Analytics 4 on Shopify doesn’t have to be overwhelming. With these simple steps, you’ll ensure accurate data tracking and unlock insights to drive conversions and growth for your Shopify store.
Create a Data Layer in Shopify for Enhanced GA4 Tracking
To effectively capture essential data on every customer interaction, creating a robust data layer in Shopify is a critical first step. The data layer acts as a structured container for all key information about a visitor’s session. When configured correctly, it enables seamless data sharing between Shopify, Google Tag Manager (GTM), and Google Analytics 4 (GA4). This setup empowers you with actionable insights, allowing you to understand your customers better, optimize ad spend, and ultimately drive higher conversions.
To simplify this process, we’ve crafted a data layer script specifically for the Shopify order-complete page. This code captures vital order information—such as transaction ID, order value, tax, shipping cost, currency, and items purchased—and automatically sends it to GTM for advanced tracking in GA4. Follow the steps below to integrate this data layer into your Shopify store and unlock in-depth analytics.
How to Add the Data Layer Script in Shopify
- Go to Your Shopify Admin: Log into your Shopify admin panel.
- Navigate to Checkout Settings: Go to Settings > Checkout & Accounts > Additional Scripts.
- Paste the Code: Copy and paste the script below into the Additional Scripts field. This code will automatically populate the data layer with each order's purchase event data.
{% if first_time_accessed %}
<script>
dataLayer.push({ ecommerce: null }); // Clear the previous ecommerce object.
window.dataLayer.push({
'event': 'purchase',
ecommerce: {
'transaction_id': '{{ order.name || order.order_number }}',
'value': {{ total_price | money_without_currency | remove:',' }}, // Includes tax &
shipping
'tax': {{ tax_price | money_without_currency | remove:',' }},
'shipping': {{ shipping_price | money_without_currency | remove:',' }},
'currency': '{{ shop.currency }}',
'payment_type': '{{ order.transactions[0].gateway }}', //optional parameter
'items': [
{% for line_item in line_items %}
{
'item_id': '{{ line_item.sku || line_item.product_id }}', //if no SKU exists, use product Id
'item_name': '{{ line_item.product.title }}',
'discount': {{ line_item.line_level_total_discount | money_without_currency }},
'item_variant': '{{ line_item.variant.title }}',
'price': {{ line_item.final_price | money_without_currency }},
'quantity': {{ line_item.quantity }}
},
{% endfor %}
]}
});
</script>
{% endif %}
This data layer script pushes a ‘purchase’ event to GTM each time a customer completes an order. It includes details like:
- Transaction ID: Unique ID for each purchase.
- Order Value: Total cost, including tax and shipping.
- Tax and Shipping Costs: Additional charges associated with the order.
- Currency: Automatically tracks currency based on your store’s settings.
- Payment Type: Captures the payment method used.
- Items Purchased: Records details on each item, including SKU, name, variant, price, and quantity.
Once this script is added, it enables your GA4 setup to capture these events automatically, providing a deeper understanding of what drives your sales and where there might be friction in the customer journey.
By implementing this data layer, you’ll gain access to advanced e-commerce tracking without requiring a developer or complex app installations. With detailed insights into each purchase, you can optimize marketing campaigns, tailor your offerings, and maximize revenue growth.
How to Set Up Google Analytics 4 (GA4) with Google Tag Manager (GTM): Creating a Purchase Trigger
To unlock the full potential of Google Analytics 4 on your Shopify store, you need to set up a firing trigger in Google Tag Manager (GTM) that sends detailed order data to GA4 each time a customer completes a purchase. This trigger is essential for tracking conversions accurately, empowering you with insights into your customer’s purchasing journey, and optimizing your marketing strategies.
Setting up this purchase trigger in GTM ensures that every completed transaction is recorded and analyzed, allowing you to better understand which marketing efforts drive the most sales. Here’s how to configure your GA4 purchase trigger in GTM for effective Shopify e-commerce tracking.
Step-by-Step: Setting Up the Purchase Trigger in GTM
-
Log into Google Tag Manager (GTM)
Start by logging into your GTM account and accessing the container that’s linked to your Shopify store. Accurate data tracking begins here, so it’s critical to set this up properly. -
Navigate to the Triggers Section
On the left-hand menu, select Triggers to open the trigger configuration panel. -
Create a New Trigger
Press the blue New button to create a new trigger. Name your trigger descriptively to easily identify it later; for example, “GA4 - Purchase Trigger.” -
Configure Trigger Settings
In the Trigger Configuration window, press the edit icon in the top-right corner. Under Choose trigger type, select Custom Event from the list of options. This type is ideal for tracking unique, user-defined events like purchases. - Define the Purchase Event Conditions
- Event Name: In the Event name field, type purchase. This matches the “purchase” event in your data layer, ensuring GTM accurately captures each transaction.
- Trigger Firing Conditions: Set This trigger fires on to Some custom events. Then, in the event conditions, specify that Event equals purchase. This ensures the trigger activates only when the purchase event occurs.
By setting up this trigger, GTM will send order details to GA4 each time a purchase is completed on your Shopify store. This trigger allows you to capture essential metrics, such as order value, items purchased, and transaction ID—insights that can drive smarter, data-driven decisions for your business.
Why This Purchase Trigger Matters for Your Shopify Success
Without accurate purchase tracking, you’re left guessing which marketing channels, products, and campaigns are most effective. This GTM setup removes the uncertainty by giving you reliable, real-time data about each sale. When you know exactly where your conversions are coming from, you can refine your ad spend, improve customer engagement, and grow your revenue with confidence.
Set up this GA4 purchase trigger today to capture the insights that will take your Shopify store to the next level.
Setting Up Data Layer Variables in Google Tag Manager (GTM) for GA4 on Shopify
To fully harness the power of Google Analytics 4 (GA4) on your Shopify store, it’s essential to create data layer variables in Google Tag Manager (GTM). These variables act as data packets, gathering vital details about each customer transaction—from order revenue and tax to specific items purchased. Without these variables, your Shopify store risks losing valuable insights that are essential for understanding customer behavior, tracking conversions, and optimizing marketing efforts.
Follow these steps to configure data layer variables in GTM, ensuring you capture the critical data that drives sales and informs smarter business decisions.
How to Create Data Layer Variables in GTM
- Access the Variables Section in GTM
- In your GTM dashboard, navigate to the left menu and click on Variables.
- Locate the User-Defined Variables section, then click the New button to start creating a new variable.
-
Configure Each Data Layer Variable
For each type of transaction data, you’ll set up a unique variable to capture essential details. Here’s how to create each data layer variable: - Order Revenue
- Name: dlv - Thank You Page - Order Revenue
- Variable Configuration: Select Data Layer Variable.
- Data Layer Variable Name: ecommerce.value
- Order ID
- Name: dlv - Thank You Page - Order ID
- Variable Configuration: Select Data Layer Variable.
- Data Layer Variable Name: ecommerce.transaction_id
- Currency
- Name: dlv - Thank You Page - Currency
- Variable Configuration: Select Data Layer Variable.
- Data Layer Variable Name: ecommerce.currency
- Tax
- Name: dlv - Thank You Page - Tax
- Variable Configuration: Select Data Layer Variable.
- Data Layer Variable Name: ecommerce.tax
- Shipping Costs
- Name: dlv - Thank You Page - Shipping
- Variable Configuration: Select Data Layer Variable.
- Data Layer Variable Name: ecommerce.shipping
- Items Purchased
- Name: dlv - Thank You Page - Items
- Variable Configuration: Select Data Layer Variable.
- Data Layer Variable Name: ecommerce.items
-
Save Each Variable
After configuring each variable, save it before moving on to the next one. Repeat the process for all variables listed above to ensure a complete and accurate capture of all order data.
Why Data Layer Variables Matter for Your Shopify Success
Without these data layer variables in GTM, you risk missing out on essential insights that drive your Shopify store’s growth. Each variable—from order revenue to items purchased—provides critical information that helps you understand your customers’ buying behaviors, refine marketing strategies, and boost conversions. With these variables in place, GA4 can deliver a detailed view of your sales, allowing you to make data-backed decisions that lead to more revenue and higher customer satisfaction.
Setting up data layer variables may seem technical, but the payoff in actionable insights is well worth the effort. By accurately tracking every purchase detail, you’re equipping your Shopify store with the tools needed to thrive in a competitive market.
Creating E-commerce Tags in Google Tag Manager (GTM) for Powerful GA4 Insights
For Shopify store owners, setting up accurate e-commerce tags in Google Tag Manager (GTM) is crucial for tracking sales performance in Google Analytics 4 (GA4). Without these e-commerce tags, you miss out on valuable insights into each transaction, including revenue, shipping, taxes, and items purchased. Capturing these details empowers you to make data-driven decisions that boost conversions and optimize marketing efforts.
Follow this guide to set up a GA4 purchase tag in GTM, ensuring your e-commerce data flows seamlessly into GA4 reports.
Step-by-Step Guide to Creating E-commerce Tags in GTM
-
Access Tags in GTM
- In your GTM dashboard, click on Tags from the left menu to view or add new tags.
-
Create a New Purchase Tag
- Click on the blue New button.
- Name your tag descriptively, like GA4 Purchase to identify it easily later.
-
Configure the GA4 Purchase Tag
- In the Tag Configuration box, click the edit icon in the top-right corner.
- Choose Google Analytics: GA4 Event as the tag type.
- In the Configuration Tag field, select your previously set up GA4 Config tag.
-
Set the Event Name
- In the Event Name field, enter “purchase.” This signals to GA4 that this tag tracks completed orders, a key action for any e-commerce business.
-
Add Event Parameters to Track Order Details
- Expand the Event Parameters dropdown menu and press Add Row to start adding parameters. Event parameters capture specific order data, such as transaction ID, tax, and shipping.
Key Parameters for GA4 E-commerce Tracking
Each parameter name corresponds to a specific piece of order data GA4 will recognize, and the values are dynamically populated from your data layer variables set up earlier. Follow these steps for each parameter:
-
Parameter Name: Enter the official parameter name recognized by GA4 (e.g.,
transaction_id
,tax
,shipping
). - Value: Select the appropriate data layer variable (prefixed with “dlv”) to dynamically capture the correct value for each transaction. Here’s a guide for common e-commerce parameters:
Parameter Name | Value | |
items | {{dlv - Thank You Page - Items}} | |
value | {{dlv - Thank You Page - Order Revenue}} | |
transaction id | {{dlv - Thank You Page - Order ID}} | |
tax | {{dlv - Thank You Page - Tax}} | |
shipping | {{dlv - Thank you Page - Shipping}} | |
currency |
|
It should look like the following:
Debugging and Verifying Your GA4 Tag Setup on Shopify
Testing your Google Analytics 4 (GA4) tag setup in Google Tag Manager (GTM) is crucial to ensure that every customer action is tracked accurately. Without thorough debugging, you risk missing essential data, making it challenging to analyze customer behavior, optimize marketing campaigns, and increase conversions. Follow this step-by-step guide to verify that your GA4 tags are working correctly and capturing valuable Shopify data.
Step-by-Step Guide to Debugging GA4 Tags in GTM
-
Enter Preview Mode in GTM
- In Google Tag Manager, click the Preview button in the top right corner. This activates GTM’s preview mode, allowing you to test tags in real-time on your Shopify store without affecting live data.
-
Navigate to Your Store’s Front End
- After activating preview mode, GTM will load your store’s front end with a Tag Assistant window in the corner. This Tag Assistant will track all tags as they fire, helping you verify each tag’s activity.
-
Verify Tag Firing in GA4 DebugView
- Open your GA4 account, go to the left menu, and select Configure > DebugView. DebugView provides a real-time view of events, so you can see exactly when and how tags are firing on your site.
- Return to the Tag Assistant window on your Shopify site and complete a test transaction. This will trigger the purchase event, allowing you to monitor its details in DebugView.
-
Check for Purchase Events in GA4 DebugView
- In GA4’s DebugView tab, look for a green “purchase” event in the timeline. If the purchase event appears, click into it to confirm that all order information (e.g., transaction ID, revenue, items purchased) is captured correctly. A successful event here indicates that your GA4 e-commerce tracking is correctly set up.
Publish GTM Changes
Once you’re confident that all transactions are being accurately tracked, publish your changes in GTM. This finalizes your tag setup for live data collection, allowing GA4 to capture customer interactions seamlessly. After publishing, keep a close eye on both your GA4 and Universal Analytics (if still active) accounts to ensure all orders are recorded as expected.
Alternative Method: Installing GA4 with GTAG on Shopify
If you prefer to set up GA4 using GTAG instead of GTM, follow these steps to ensure GA4 works optimally on your Shopify store:
-
Set Up Your GA4 Property in Data Streams
- Start by verifying that your GA4 property is correctly configured. Go to Data Streams > Web and add your Shopify URL if it’s not already there, then click Create Stream.
-
Add GA4 Measurement ID to Shopify Theme Code
- Go to the Data Streams section in your GA4 property and select the new stream. Copy your GA4 Measurement ID, which begins with “G-.”
- In Shopify, go to Online Store > Themes and find your active theme. Click Actions > Edit Code and, under Layout, select theme.liquid. Paste the GTAG script code just before the closing
</head>
tag, replacing G-XXXXXXXXXX with your GA4 Measurement ID.
-
Verify GA4 Installation in Real-Time
- Confirm your GTAG installation by navigating to Realtime in GA4’s left sidebar. Perform a test action on your Shopify site, such as viewing a product page or adding an item to your cart, and check if the event appears in GA4’s Realtime report.
Final Verification and Optimization
Get Expert Help to Elevate Your Shopify Store's Performance
Thank you for reading our guide from Robin Lee Innovations. We hope it has empowered you to set up Google Analytics 4 on your Shopify store effectively. If you’re facing challenges or need tailored advice to optimize your Shopify store’s performance, boost SEO, or maximize marketing impact, our expert team is here to help.
Contact us today for a personalized consultation and let us guide you toward data-driven success that enhances customer experiences and drives sales. Drop us a message, and one of our specialists will reach out to help take your store to the next level!