Lukaswins
Lukaswins

Reputation: 5

How to insert a variable from the DataLayer into custom HTML in Google Tag Manager?

I have a DataLayer variable holding the sum of a purchase. I wish to insert this variable into a custom HTML tag. The value variable in the following code should hold the value of the DataLayer variable.

<!-- Facebook Conversion Code for Checkouts -->
<script>(function() {
  var _fbq = window._fbq || (window._fbq = []);
  if (!_fbq.loaded) {
    var fbds = document.createElement('script');
    fbds.async = true;
    fbds.src = '//connect.facebook.net/en_US/fbds.js';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(fbds, s);
    _fbq.loaded = true;
  }
})();
window._fbq = window._fbq || [];
window._fbq.push(['track', '', {'value':'0.00','currency':'USD'}]);
</script>

Upvotes: 0

Views: 2045

Answers (1)

nyuen
nyuen

Reputation: 8907

You can insert datalayer variables by direct reference through double curly braces, {{value}}. Make sure it is defined as a datalayer variable first.

Upvotes: 1

Related Questions