Shopify - GTM

Shopify Data Layer Code Blocks & Tutorials

Guide 8 min read

Data layer is one of the most important aspects of data tracking & analytics. To help you make the most of your tracking experience, we have created a custom code block that will allow your Google Tag Manager to read & process your purchase and product page data on your Shopify store.

Shopify doesn’t have data layers by default. That’s why we have created open-source Shopify data layers for all Shopify merchants to use at no cost!

You can find two different data layers (purchase + product) for your Shopify store in this page. You will get the code blocks and also our support with Google Tag Manager, in addition to the GTM variable names and a guide on how to use these data layers.

Here’s an important point for you before we get down to business: Although dataLayer won’t perform anything magical by itself, you can follow along with our Free Shopify GTM Course on Youtube to discover more about how to utilize it in the best way possible.

Let’s have a sneak peek before you see how the two major data layer code blocks work for you:

  • Purchase data layer: You can use the purchase data layer for your Google Analytics 4 e-commerce tracking, Google Ads & Facebook pixel conversion tracking wherever you see it. The purchase data layer includes all the order data & purchased product details.

  • Product View data layer: You should use this data layer on product pages as it includes all product-level data. You can trigger Google Analytics 4 product view e-commerce events and any product view-related tag you wish by using it. You are going to find out more, below. ⬇️

  • Complete GA4 Setup Tutorial: Follow our in-depth, step-by-step tutorial and set up data layers, Google Tag Manager, and Google Analytics 4 including e-commerce events on your Shopify store.

GA4 Setup On Shopify

GA4 Setup On Shopify

Here’s another important suggestion for you: You should consider using Analyzify or another Shopify GTM app for the other data layer events such as add to cart, remove from cart, product impression, and product click to have a deeper understanding of your data.

Purchase Datalayer

The following dataLayer code block will get the essential data from your “order completed” page and make it available for the GTM to read and process. The code block includes the following variables: purchased products, page type, currency, shipping price, total price, tax price, payment type, and transaction ID. By following our course, you will be able to pass all this data to Google Ads, Facebook Pixel, Google Analytics 4, and other parties you want to share with.

1- Copy the Shopify dataLayer (Checkout – Purchase)

We have made a code update here and added product details in the purchase data layer. Make sure to visit step 4 and add related dynamic data layer variables into your GTM. Go ahead and copy the code from the following paragraph:

2- Paste the code into Shopify Checkout

shopify-gtm-datlayer-U3bsitXr.webp Go to your Shopify Admin > Settings (Left bottom) > Checkout and then Navigate to Order Processing > Additional Scripts.

You should paste the code right below your GTM container code. If you don’t have a GTM container here yet, check out our free Shopify - GTM video course.

3- Create Custom Variables in GTM

You need to create custom variables and custom events on Google Tag Manager to be able to use the values in dataLayer. You can watch the related video of our course if you need some support here. These are the steps that you need to take on Google Tag Manager:

difficulty levelEasy
duration15 min
Step 1Step 1: GTM Variables
Collapse Icon
Step 2 Step 2: Data layer variable
Collapse Icon
Step 3Step 3: Naming the variables
Collapse Icon
Step 4Step 4: Create all variables
Collapse Icon
Step 5Step 5: Product Data in data layers
Collapse Icon

If you are seeking more technical information on this topic, feel free to visit Google’s official data layer documentation.

You are currently viewing the "Shopify Data Layer Code Blocks & Tutorials"

Guide 2 How to Setup Google Tag Manager on Shopify arrow-right Previous
Guide 4 GTM - Shopify Free Course Next arrow-right
Sign up for our newsletter
Be the first to know about releases and industry news and insights.
We care about your data in our privacy policy.
Take the first step towards reliable tracking Join 3,000+ merchants who trust their tracking with Analyzify.