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:
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. View on Youtube.
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.
Update on February 2022: We have updated the purchase data layer that we initially prepared for our ‘GTM course 2021’. We have added new variables and details.
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.
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:
{% comment %} Purchase data layer v2.1 - part of "Shopify GA4 Kit" by Analyzify
Visit https://analyzify.com/shopify-google-analytics/ga4 for complete tutorial
{% endcomment %}
{% assign template_name = template.name %}
Make sure that you have copied it correctly.
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.
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:
It is very important to name them properly. You should name the first one as: dlv- transaction-id – Add this to the name field.
Then you need to write the field name that comes from your dataLayer. This should 100% match with your Shopify dataLayer, otherwise, it won’t work. Data Layer Variable Name should be "transaction_id"
Save the first one when you are done.
You have created one of the variables in step 3. Now you will need to create all the rest.
Make sure to write the correct names to the correct places
- dlv-shipping / shipping
- dlv-tax / tax
- dlv-totalValue / totalValue
- dlv-payment_type / payment_type
- dlv-currency / currency
At the end of this step, your GTM variable settings should look like in the screenshot.
It is more complex and technical to add the product level data as GTM variables as there can be multiple products in an order.
Follow our detailed, step-by-step tutorial and validation guide.
If you are seeking more technical information on this topic, feel free to visit Google’s official data layer documentation.
This will send your product-level information to the data layer. All you need to do is just copy the code and paste it into your theme.liquid file and follow the steps below carefully.
If you are familiar with Google Tag Manager or our course, you should be able to use this with ease.
We need to edit your theme files. You can copy your existing theme and work on a duplicated theme if you like to. Technically there is no reason for this as Shopify already saves the change history – so all the changes are actually risk-free.
Code block:
{% comment %} Product view data layer v2.1 - part of "Shopify GA4 Kit" by Analyzify
Visit https://analyzify.com/shopify-google-analytics/ga4 for complete tutorial
{% endcomment %}
{% assign template_name = template.name %}
Your Shopify product view data layer is ready to be processed. You can now go to Google Tag Manager and create the trigger for “analyzify_productDetail” event and create data layer variables for “name, id, price, currency, sku, category, variant_id” - just like we did in the above section for the purchase data layer.
Alternatively, you can follow our detailed GTM Tutorial on the product data layer and learn how it is used in-depth.
Analyzify offers you an advanced data layer that includes 35+ variables (data points such as product ID, name, brand, category, etc) and 8 different event sets that cover all standard e-commerce tracking and further.
We also do offer a comprehensive GTM container tailored for your store so that you don’t need to deal with tags, triggers, variables.
Fully customizable data layers & GTM. No secrets, no behind-the-door actions. We inject the data layers into your theme/store openly. We don’t use any external files or scripts.
Definitely yes. You can always use the variables and triggers in Analyzify’s GTM container to make new tags according to your needs.
A data layer is a JavaScript object that collects data on your website in a standardized way. You can learn more about data layers and their use for Shopify merchants in this video.
Technically no, but practically, yes. You can use GTM without using data layers, but if you do that, you won’t be able to pass specific data (e.g. product ID, name, order total revenue, etc.).
You can only use the general tags like Google Analytics 4 – which works on all pages. However, you can’t use Google Ads Conversion Tracking properly, because you again need some information like the order ID, revenue, currency, and a few others.
Analyzify provides open-source data layers for Shopify merchants.
The “Purchase” data layer is made to allow you to track purchases and set up conversion tracking properly.
Analyzify’s “Shopify purchase” data layer can be used in the following tags / conditions:
The “Product View” data layer is created to be triggered on Shopify’s single product pages and send the product-relevant data to GTM. This will allow you to have proper “Products” reports on Google Analytics 4, in addition to many other benefits.
Analyzify’s open-source “Shopify Product View” data layer can also be used in the following tags / conditions:
You are on this content series:
Check out our complete guides: