Siddharth Doshi
Siddharth Doshi

Reputation: 117

How to set up HTML tracking code in Google tag manager with transaction ID data

I have to implement tracking pixel code on my thank you page through google tag manager. There a transaction ID variable in the pixel code to track the transaction. Below is the tracking pixel code.

<iframe src="https://t1.example.com/p.ashx?a=284&e=302&t=TRANSACTION_ID" height="1" width="1" frameborder="0"></iframe>

How do I set up the tracking tag which can pass the transaction ID from thank you page to the tracking code in GTM?

Upvotes: 1

Views: 1309

Answers (1)

kgrg
kgrg

Reputation: 1633

Based on your clarification in your comment, and assuming your visitors arrive on a similar URL: https://www.example.com/thankyou.html?transactionId=1234

You should set up a variable, which reads the ID from the URL. It needs to be URL type variable, with similar settings:

enter image description here

You can now use this variable in your tags and scripts, referring to it as {{Transaction ID}}, or by any GTM variable you choose and provide as a variable name in GTM.

In your specific case, based on my variable name on the image, you can create a Custom HTML type tag:

<iframe src="https://t1.example.com/p.ashx?a=284&e=302&t={{Transaction ID}}" height="1" width="1" frameborder="0"></iframe>

Edit:

An other option would be to push this data into the dataLayer, and set up a Data Layer Variable to read it from there. E.g.

<script>
  var transactionId = //your code to get the variable

  dataLayer.push({
    event: 'transaction',
    transactionId: transactionId
  });
</script>

In this case, your variable setup looked like this:

enter image description here

Please note, that you need to set up the relevant trigger to listen to transaction event. The benefit of this solution is that multiple tags can now rely on this GTM variable.

Nevertheless, a third option could be to use only one custom HTML, with something like this, where you create the iframe with JavaScript, and add the transaction ID to the URL in the src attribute:

<script>
var transactionId = //your code to get the variable

var iframe = document.createElement('iframe');
iframe.style.height = "1px";
iframe.style.width = "1px";
iframe.style.border = "none";
iframe.src = "https://t1.example.com/p.ashx?a=284&e=302&t=" + transactionId;
document.body.appendChild(iframe);
</script>

Upvotes: 2

Related Questions