by ShahzadaAliHassan - 13th November 2023
In this tutorial, we'll explore configuring the 'View Content' event for Facebook Pixel on a Shopify store using Google Tag Manager (GTM). This is particularly useful if you're not using Shopify's built-in Facebook and Instagram app.
<head>
tag in the theme.liquid
file on Shopify.<body>
tag in Shopify.This section details the setup and implementation of a data layer script on a Shopify website, crucial for tracking and analytics. It involves initializing and populating the dataLayer
object to accurately capture key data.
Firstly, a script snippet is used to initialize the dataLayer
array, assuming it's not already set up. This snippet also checks if the current page is a product page, indicated by the template type, and if so, triggers the 'datalayer-product' snippet.
The 'datalayer-product' snippet plays a critical role in capturing product information. Its process involves:
itemObject
containing detailed product information.dataLayer
object when the document loads.To incorporate the theme-specific data layer code, the 'head-datalayer' snippet must be rendered. This is typically found in the head section of the Shopify theme. It should be added to the GTM Body Code section.
Backup Creation: Start by backing up your current theme.
Theme File Access: Navigate to Online Store > Themes in your Shopify Admin, and choose "Edit code" from the "Actions" menu of your active theme.
Head DataLayer Code Addition: Locate theme.liquid
in the sidebar, and embed the "Head DataLayer Code" snippet within the <head>
section.
Product DataLayer Code Insertion: Form a new snippet (name it datalayer-product.liquid
if required), and include the "Product DataLayer Code" snippet. Save the changes.
Theme DataLayer Code Placement: Identify the appropriate spot within the <head>
section in theme.liquid
for the "Theme DataLayer Code" snippet and insert it. Save the modifications.
Verification: To test, visit a product page on your Shopify site, open the browser's developer console, and confirm that the custom_view_item
event fires and the dataLayer
correctly reflects the product details.
By following these steps, you ensure your Shopify site effectively gathers and leverages data for tracking and analytics.
By following these steps, you can successfully configure the 'View Content' event for Facebook Pixel on your Shopify store using Google Tag Manager. This setup is crucial for accurate tracking and data collection for your marketing efforts.