GA4 PageView Event on Shopify using GTM
by ShahzadaAliHassan - 31st October 2023
Introduction
Setting up your Shopify store with Google Analytics 4 (GA4) is essential for keeping track of your site's performance and user behavior. Leveraging the power of Google Tag Manager (GTM) simplifies this process. Here's how you can integrate them seamlessly.
Initial Steps: Setting Up Google Analytics and Tag Manager Accounts
- If you've already set up your Google Analytics and Google Tag Manager accounts, you can skip to the next section. If not, you'll need to create your Google Analytics and Google Tag Manager accounts.
- Ensure that you have the Google Tag Assistant Chrome extensions installed.
Installing the Google Tag Manager (GTM) Container on Shopify
- Log in to your GTM account.
- Navigate to the Admin section and select Container Settings.
- Under the install section, you'll find two tracking snippets. One is for the
<head>
and the other is for the<body>
section of your site. - Copy the tracking code for the
<head>
. - On your Shopify dashboard, navigate to Online Store > Themes.
- Click on Edit Code and locate the
theme.liquid
file. - Find the
<head>
tag and paste the GTM tracking code you copied. - Return to GTM and grab the tracking code for the
<body>
. - Back in the
theme.liquid
file, search for the<body>
tag and paste the second tracking code in the next line. - Save your changes.
Optional: Click on 'format' to pretify the code, to ensure it's readable.
Verifying GTM Installation
- Visit your Shopify store.
- Use the Google Tag Assistant Chrome extensions to check if GTM is correctly implemented. It should indicate that a GTM container has been found on the website.
Integrating Google Analytics 4 (GA4)
- In your GA4 account, click on Admin located at the bottom left.
- Go to Property Settings > Data Streams.
- Locate the relevant data stream (e.g., Web for Shopify) and copy the Measurement ID (G-XXXXXXXX).
- Return to your GTM workspace.
- Navigate to Variables and create a constant variable named "GA4 Measurement ID" with the copied ID.
- Now, go to Tags > New.
- Select Google Tag as the tag type.
- Insert your "GA4 Measurement ID" variable in Google Tag.
- Save your changes, rename the Tag to "GT GA4 Configuration Tag" and preview the workspace to ensure everything is functioning correctly.
- If all goes well, GA4 should now be capturing data from your Shopify store!
Tip: Remember to periodically check both your GA4 and GTM accounts to ensure data is being captured accurately and to leverage the insights gained for business growth.
Conclusion
Integrating Google Analytics 4 with your Shopify store using Google Tag Manager is a straightforward process. By following these steps, you'll be well on your way to gaining valuable insights about your store's performance and user behavior.