Setting up Google Analytics 4 on Shopify
Loves Data
There are several ways to install Google Analytics ecommerce tracking on Shopify, each with its own set of advantages and disadvantages. In this guide, we will explore four methods: using a Shopify Custom Pixel, the Google and YouTube App, and other third-party apps and editing the theme code. We will explain why using a Shopify Custom Pixel is the recommended method for advanced users and why editing the theme code is now deprecated and no longer recommended. We will also look at Shopify and GA4 events, specifically the purchase event for tracking transactions.
Here are the ways you can install Google Analytics on Shopify:
1. Shopify Custom Pixel
Overview
A Shopify Custom Pixel is a powerful way to implement Google Analytics on your store. This method involves creating a custom pixel that works independently of your store's theme and other files, providing a reliable and flexible solution for tracking.
Pros
- Advanced Tracking: Custom pixels allow for detailed and advanced tracking, including ecommerce events and user interactions.
- Flexibility: Custom pixels work independently of your theme, ensuring consistent tracking even if you change your store's design.
- Compatibility with GTM: This method is ideal for those who want to use Google Tag Manager (GTM) to manage their tracking codes.
Cons
- Complexity: Setting up a custom pixel requires a bit more technical knowledge compared to other methods.
- Initial Setup Time: The initial setup can be more time-consuming, especially for beginners.
Recommended For
This method is recommended for users who want advanced tracking options and plan to use Google Tag Manager to manage their tracking codes.
View the steps to setup the Shopify Custom Pixel
2. Google and YouTube App
Overview
The Google and YouTube App is a straightforward way to install Google Analytics on your Shopify store. This method involves using the app to link your Google Analytics account to your Shopify store.
Pros
- Ease of Use: The app provides a simple and quick way to install Google Analytics without needing to edit any code.
- Basic Tracking: This method is suitable for basic tracking needs and provides the essential data required for most users.
Cons
- Limited Flexibility: The app does not offer the same level of customization and advanced tracking options as a custom pixel.
- No GTM Integration: This method does not integrate with Google Tag Manager, limiting the ability to manage multiple tracking codes.
Recommended For
This method is ideal for users who want a quick and easy way to implement Google Analytics without the need for advanced tracking or Google Tag Manager.
View the steps to setup the Google and YouTube app
3. Other Third-Party Apps
Overview
There are various third-party apps available in the Shopify App Store that can help you install Google Analytics. These apps offer different features and levels of customization.
Pros
- Variety of Options: There are many apps to choose from, each offering different features and levels of support.
- Ease of Use: Many of these apps provide a user-friendly interface for setting up Google Analytics.
Cons
- Cost: Some third-party apps come with a subscription fee.
- Compatibility Issues: Not all apps are compatible with every Shopify theme or setup, which can lead to potential issues.
Recommended For
This method is suitable for users looking for a variety of options and features, and who are willing to pay for additional functionality.
View third-party Shopify apps you can use
4. Editing the Theme Code
Overview
This traditional method involves manually adding the Google Analytics tracking code to your theme's theme.liquid file and the 'Order Status Page Additional Scripts' option in Shopify's settings.
Pros
- Direct Control: This method provides direct control over where the tracking code is placed within your store's code.
Cons
- Deprecated Method: This method is no longer recommended due to its complexity and the potential for errors.
- Lack of Flexibility: Changes to your store's theme can disrupt the tracking code, requiring additional maintenance.
- Missing steps: Unless you're using Shopify Plus, you won't be able to add Google Tag Manager to the check out pages.
Recommended For
This method is not recommended for modern setups. It is deprecated and should be avoided in favor of more reliable and flexible options.
View the steps to edit your Shopify theme code
Installing Google Analytics on Shopify
Now that we’ve covered the different methods you can use to setup Google Analytics on Shopify, we’re going to walk through the installation steps for each of these options. We recommend using a Shopify Custom Pixel for the greatest flexibility and the Google and YouTube app if you just want to install Google Analytics and Google Ads conversion tracking without needing Google Tag Manager.
1. Shopify Custom Pixel
To add a custom pixel to your Shopify store, follow these steps:
- Navigate to Settings: In your Shopify admin, go to 'Settings'.
- Select Customer Events: Look for 'Customer Events' on the left and select it.
- Add Custom Pixel: Click 'Add Custom Pixel' and name your pixel (we suggest 'Google Tag Manager' or something similar).
Here’s our video tutorial covering how to install Google Tag Manager on Shopify using a custom pixel:
Configuring the Custom Pixel
Once you've added the custom pixel, you'll need to configure it:
- Privacy Settings: Choose the appropriate privacy settings. If you're not using Shopify's built-in cookie banner, select 'Permission' and choose 'Not Required'. This ensures GTM will fire for all actions on your site.
- Data Sale Settings: If you're not using Shopify’s built-in data sales opt-out page, select 'Data collected does not qualify as data sale'.
Adding the Code
You'll need to add the code for your custom pixel. Here is an example code snippet:
The custom pixel above only tracks the purchase event. But you can get a copy of our pre-configured Shopify Custom Pixel code for GTM by filling out this form.
Get the Pre-Configured Shopify Code
Our pre-configured custom pixel tracks a whole range of ecommerce actions and will save you a whole lot of time.
Configuring Google Tag Manager
After adding the custom pixel to your Shopify store, the next step is to configure Google Tag Manager:
- Import Pre-configured Container: In GTM, navigate to 'Admin' and select 'Import Container'. Choose the pre-configured container provided by Loves Data (you will receive a copy of this container with our pre-configured custom pixel, so if you haven’t already, fill out this form to get your copy).
- Edit GA4 Measurement ID: Go to 'Variables', select 'Change, GA4 Measurement ID', and replace the placeholder ID with your GA4 Measurement ID from Google Analytics.
- Test and Publish Your Container: Use the options below to test your implementation, and when you’re happy everything is working correctly, you can click ‘Submit’ to publish your container.
Testing and Validation
To ensure everything is working correctly, use the following methods:
- Legacy Tag Assistant Extension: Install the legacy Tag Assistant extension for Chrome to see the events pushed to the data layer.
- Google Analytics Realtime Report: Use the realtime report in Google Analytics to verify that events are being captured accurately.
FAQs and Troubleshooting Tips
Q: What if I see duplicate events in Google Analytics?
A: Ensure that you have removed any previous Google Analytics implementation from your Shopify store, such as code added to the theme or checkout pages.
Q: How can I check if my custom pixel is working correctly?
A: Use the legacy Tag Assistant extension for Chrome or the Google Analytics Realtime Report to verify events.
Q: Can I customize the code for my custom pixel?
A: Yes, you can customize the code to capture additional details or adjust the information being tracked. Refer to the pre-configured code provided by Loves Data for guidance.
Q: What if it doesn’t work?
A: Check out our Google Analytics ecommerce troubleshooting tips that walk through a range of issues you might encounter and how to fix them.
2. Google and YouTube App
Using the Google and YouTube app is the quickest and easiest way to install Google Analytics on your Shopify store. The app will automatically track your pages and a range of ecommerce actions into your reports once you’ve linked to your GA4 property.
Watch this tutorial for all of the steps to get up and running:
3. Other Third-Party Apps
Overall, we don’t recommend using third-party apps to install Google Analytics or Google Tag Manager on your Shopify store. We prefer to manage the implementation ourselves, but you can review the following apps if you decide to take this approach.
1. Elevar
- Description: Elevar offers comprehensive data layer integration and server-side tracking for GA4, GTM, and Facebook. It provides pre-built GTM containers and ensures accurate tracking across your Shopify store.
- Features: Advanced ecommerce tracking, server-side tracking, pre-built GTM containers.
- Website: Elevar
2. Trackify X
- Description: Trackify X is known for its robust Facebook Pixel integration but also supports Google Tag Manager and GA4. It helps you track and optimize your ad campaigns with precise data.
- Features: Advanced event tracking, seamless GTM and GA4 integration, custom event creation.
- Website: Trackify X
3. Littledata
- Description: Littledata connects your Shopify store with GA4 and GTM, providing detailed ecommerce tracking and insights. It helps bridge the gap between your store and your analytics.
- Features: Enhanced ecommerce tracking, seamless GTM integration, accurate data flow between Shopify and GA4.
- Website: Littledata
4. Analyzify
- Description: Analyzify offers a comprehensive Google Tag Manager setup for Shopify, including GA4 integration. It provides a full GTM container and setup service, ensuring accurate tracking.
- Features: Full GTM setup, GA4 integration, enhanced ecommerce tracking.
- Website: Analyzify
Apart from these solutions, other apps include:
4. Editing the Theme Code
This option is where you add the tracking code to your theme and you adjust the settings for your checkout in Shopify. While this method is no longer recommended, it’s still commonly used, which is why we’re including the steps.
You can follow these steps to check if the method is being used on your website and identify any code that needs to be removed if you’re shifting to one of the other methods we’ve covered.
This method can be used to install the Google Tag Manager container code on your Shopify store or the dedicated Google Tag for Google Analytics. We’re going to include code examples for each of these options as we travel through the steps.
Also, if you’re using Shopify Plus, you can install code on all of the pages of your Shopify store, including the checkout pages. However, if you’re using the standard version of Shopify, you cannot install code on the checkout pages. This has always been a disadvantage of using this method.
Add the tracking code to your theme
Navigate to ‘Online Store’, then ‘Themes’, and edit the theme.liquid file. You will then need to paste your code between the head tags.
Here’s an example of the Google Tag Manager container code:
And here’s an example of the Google Tag code:
Important: you will need to replace all instances of G-EXAMPLE or GTM-EXAMPLE in the above code snippets with your GA4 measurement ID or GTM container ID.
Add the tracking code to your order confirmation page
Navigate to ‘Settings’, then ‘Checkout’, add a modified tracking code to the ‘Additional Scripts’ section (under ‘Order Status Page’).
Here’s an example of the Google Tag Manager code:
And here’s an example the Google Tag code:
Important: you will need to replace all instances of G-EXAMPLE or GTM-EXAMPLE in the above code snippets with your GA4 measurement ID or GTM container ID.
Configure Google Tag Manager
If you’ve opted to add the Google Tag Manager container code using the steps above, you will then need to configure your tag and trigger (and variables if you need them) to send data to Google Analytics.
You can get our pre-configured GTM container that includes everything you need to get up and running quickly. Otherwise, you will need a create ‘Custom Event’ trigger with a value of purchase to trigger a GA4 event tag.
Exclude Shopify as a referral in GA4
Since this method doesn’t let us add code to the checkout pages in Shopify, this can result in self-referrals appearing in your reports.
To ensure that your sales are attributed to the correct marketing channels, you will need to prevent the Shopify checkout pages from showing up as referrals in your reports. To do this, open your data stream in Google Analytics, then choose ‘More Tagging Settings’ and select ‘List Unwanted Referrals’. You will then need to enter myshopify.com as an exclusion.
Shopify and GA4 Events
When you install GA4 on your Shopify store, you can track a range of GA4 events in your reports. This can include:
- page_view is automatically tracked when people view the pages on your Shopify store. This will include your home page, category, product, and other pages.
- view_item helps you track interest in particular products.
- select_item captures user interactions with product lists or search results.
- add_to_cart tracks items users are considering for purchase.
- view_cart helps you understand how many people review their cart before checkout.
- begin_checkout is triggered when a user starts the checkout process.
- add_shipping_info and add_payment_info let you understand people’s progression through your checkout.
- purchase captures transaction details, including revenue, tax, and shipping.
Conclusion
When it comes to installing Google Analytics on your Shopify store, the method you choose depends on your needs and technical skills:
- Shopify Custom Pixel: Recommended for users who need advanced tracking options and want to use Google Tag Manager.
- Google and YouTube App: Ideal for users seeking a quick and easy setup without advanced tracking requirements.
- Other Third-Party Apps: Suitable for those looking for additional features and willing to pay for them.
- Editing the Theme Code: Deprecated and not recommended due to its complexity and lack of flexibility.
At Loves Data, we're here to help you make the most of your online analytics. Whether you're a beginner or an advanced user, we offer the resources and support you need to succeed. For more in-depth tutorials and expert tips, explore our online courses and resources.
Comments