Knowledge blog

How to use Data Layer variables with Google Tag Manager

Let’s take the scenario that you need to pass the Data Layer variables to google AD conversion tracking using Google Tag Manager. This article assumes that you have already setup the Data Layer properly in your website. If not, read this article about Data Layer and how to set it up .

  1. Login to your Google Tag Manager Account.
  2. Click Variables then New.
  1. Give a Name for your GTM Variable. I am naming it DataLayerTransactionTotal.
  2. Then Edit the Variable Configuration. Ref: below image.
  1. Select Data Layer Variable.
  1. Now enter your actual Data Layer variable name. In my case I store my total transaction value into the dataLayer variable called ‘transactionTotal’, so just entering that.
  2. Let’s leave the Data Layer Version and Set Default Value as they are. Set Default Value keeps a constant value as a backup in case the actual value can’t be retrieved from your website. So if need you can place some value there.

And that’s it. The Data Layer Variable for the Total Order value has been set in GTM. You can repeat this process to set your Order Id (transactionID), currency (if you use dynamically on your page) and any other parameter. After you set all your required variables go to next step.

Now I am going to use these variables with my AdWords Conversion Tracking Tag.

  1. Click Tags and New.
  2. Name your Tag then Edit Tag Configuration.
  3. Select AdWords Conversion Tracking.
  1. Enter your conversion Id and Conversion label.
  2. Edit the Conversion Value. (See the green highlight on below picture)
  1. Select your GTM variable you created for the total transaction value. So in my case I am selecting DataLayerTransactionTotal.
  1. Repeat the step for Order ID. If you are using dynamic currency then repeat the step for that as well. Otherwise just pass your currency value statically there.

Save it and that’s all about using Data Layer with Google Tag Manager. There are so many occasions you may need to use Data Layer on GTM for example with remarketing tag, facebook pixel and may with your other tracking system too. So the Data Layer and creating GTM Data Layers are reusable and can help shorten your work in future.

To use your Data Layer variables with custom HTML tags on GTM, please see the below code block and the yellow highlights.

<script>

gtag('event', 'conversion', {

'send_to': 'AW-968150475/2IHcCOKI9X0Qy5vTzQM',

'value': {{DataLayerTransactionTotal}},

'currency': 'EUR',

'transaction_id': {{DataLayerTransactionID}}

});

</script>

If you have basic questions on what is Data Layer is then this article would help.

Scroll to Top