by ShahzadaAliHassan - 1st November 2023
In this blog, we will walk you through the process of configuring the 'view_item' event for GA4 using Google Tag Manager, so you can track user visits to your product pages, the items they view, and various event details. This will be achieved using Google Tag Manager with a Shopify store and Google Analytics 4.
Before we dive in, ensure you have the following:
Tip: The Measurement ID is crucial for configuring GA4 in Google Tag Manager. Make sure to copy it.
To successfully trigger the "view item" event, the Shopify store must also be configured. This requires some coding:
Certainly! Let's break down the code snippets and provide a detailed explanation along with steps on how to add these snippets to a Shopify store.
This section outlines the process of setting up and integrating the dataLayer
object on a Shopify site for effective data tracking and analytics, particularly for view item events.
The initial step involves a code snippet that activates the dataLayer
array. This snippet also checks if the page is a product page. On identifying a product page, it triggers a special code segment, 'datalayer-product'.
The core functionality of the 'datalayer-product' snippet lies in capturing key product data when a user lands on a product page. It performs the following:
itemObject
containing detailed product information.dataLayer
upon the document’s load.For complete integration, include the 'head-datalayer' snippet in your theme. Typically, this part of the code is placed in the GTM Body Code area, depending on your Shopify theme's configuration.
Backup Your Theme: Start by backing up your existing theme.
Navigate to Theme Files: Log into your Shopify Admin, head to Online Store > Themes. Under "Actions," select "Edit code" for the active theme.
Incorporate Head Data Layer Code: Locate theme.liquid
in the sidebar. Insert the "Head DataLayer Code" within the <head>
section.
Insert Product Data Layer Code: Create a new snippet (name it datalayer-product.liquid
if necessary) and add the "Product DataLayer Code" there. Save your changes.
Apply Theme Data Layer Code: Determine the appropriate spot within the <head>
section of theme.liquid
for the "Theme DataLayer Code." Place it there and save.
Verify Functionality: Test by visiting a product page. Open the developer console in your browser and confirm that the custom_view_item
event activates and the dataLayer
displays accurate product details.
Following these instructions will ensure your Shopify site is well-equipped to capture and leverage data for tracking and analysis.
Although the basic "view item" event is now configured, to get detailed e-commerce metrics such as item id or item name, further integration is needed.
Review: Before implementing, ensure that you've correctly followed each step, double-check your codes, variable names, and ensure that you're seeing the expected results in both GTM and GA4. Proper setup will ensure accurate data tracking and invaluable insights for your e-commerce business.
Configuring the "view item" event using Google Tag Manager, Shopify, and Google Analytics 4 can provide detailed insights into user behavior on your product pages. By following this tutorial step-by-step, you can effectively set up and track this crucial e-commerce event.