Shopify dataLayer for GTM & GA4 & Conversion Tracking
dataLayer is one of the most important concepts of the data tracking & analytics topic. We prepared a special code block for you that will allow Google Tag Manager to read/process your purchase data.
Step 1- Copy the Shopify dataLayer (Checkout - Purchase)
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: page type, currency, shipping price, total price, tax price, payment type and transaction ID. By following our 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.
Go ahead and copy the code from the following pharagraph:
Make sure that you copied it correctly.
Step 2: Paste the code into Shopify Checkout
Now it time to activate this code by pasting it into your Shopify Checkout (order processing) page. If you are not using Shopify Plus, you can only add the code into your checkout completed (thank you) page. That’s more than enough to track your purchases and send the data to other parties.
Go to your Shopify Admin > Settings (Left bottom) > Checkout and then find order processing (see the screenshot below)
And then find 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, follow along our free Shopify – GTM video course.
Step 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 are not familiar. These are the steps that you need to take on Google Tag Manager.
- Go to your Google Tag Manager account. Click Variables from the left menu.
- Scroll down and find “User Defined Variables” and then click “Add New” button on the right top corner of that section.
- Choose Data Layer Variable from the list.
- It is very important to name them properly. The first one should be name: 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 need to create all of the following variables. Make sure to write the correct names to the correct places:
- dlv-shipping / shipping
- dlv-tax / tax
- dlv-shipping / shipping
- dlv-transaction_id / transaction_id
- At the end of this step, your GTM variable settings should look like belong. Watch the GIF video again and make sure everything matches with your setup.
Now your custom dataLater variables are ready to use. You can jump into the related section of the video in order to verify if all the passing correctly.