Google Tag Manager (GTM) for Postback Tracking

We have a great article on how Google Tag Manager (GTM) can be used to set up Cookies Based Tracking. However, GTM can also be used for setting up Postback Tracking, which is more reliable and accurate nowadays.

This guide will explain how to set up GTM for Postback Tracking.

Scaleo Configuration

1
Create an Offer the regular way in Scaleo.
2
Make sure you configure sending unique Click ID with every click. This is required for Postback Tracking. To do that, just add the {click_id} to your Landing Page URL.
For example:
https://yourcompany.com/?click_id={click_id}	
3
Select that Offer, go to Goals. Edit the Goal and scroll to Tracking Method section.
4
Select: Tracking Method > Postback. Copy that Postback URL.
For example:
https://demo.scaletrk.com/track/goal-by-click-id?click_id={CLICK_ID}

Google Tag Manager Configuration

Step 1. Save Click ID within the site cookies.

In this section, we will do the following:

  • Read Click ID from the Landing Page URL
  • Store Click ID in Cookies to make it available for every site page, including the Conversion Page.
1
Create a Trigger which will indicate if the visitor landed from the Affiliate channel (Click ID exists). Set name as Visitor from Affiliate
Go to Triggers, click on New button. Select: Trigger Type as Page View, fire on Some Page Views, Page URL  contains   click_id=

2
Now we need to pass Click ID from the Landing Page to GTM Variables. Go to Variables, click on New button.  Set name as URL-Click-ID (which means that this variable will only be available on the landing page, where Click ID is available within URL).
Select Variable Type as URL, Component Type as Query and Query Key is  click_id

3
Now we will save Click ID into the 1st Party Cookie and make it available on every page of the site. 
Go to Tags, click on New button. Select Tag Type as Custom HTML. Place the following code into the HTML field:
<script>
 (function(){
 var cookieName = "click_id"; // Name of your cookie
 var cookieValue = "{{URL-Click-ID}}"; // Value of your cookie
 var expirationTime = 2592000; // One month in seconds
 expirationTime = expirationTime * 1000; // Converts expirationtime to milliseconds
 var date = new Date(); 
 var dateTimeNow = date.getTime(); 


 date.setTime(dateTimeNow + expirationTime); // Sets expiration time (Time now + one month)
 var date = date.toUTCString(); // Converts milliseconds to UTC time string
 document.cookie = cookieName+"="+cookieValue+"; SameSite=None; Secure; expires="+date+"; path=/; domain=." + location.hostname.replace(/^www\./i, ""); // Sets cookie for all subdomains
})();
</script>
	
Note: you can change the Cookie expiration time. For the example above it is one month.

Select Triggering = Visitor from Affiliate. And click Save

Note: Please make sure at line number 4, as the value of the cookie is selected, the GTM Variable we created in the #2.

4
We now have our Click ID available on every page of the site within cookie parameters and can read it into GTM Variables. 
Go to Variables, click on New button. Set name as Cookie-Click-ID (which means that this variable will be available on every page). Select Variable Type as 1st Party Cookie, Cookie Name as click_id. And click Save.

Step 2. Fire the Postback on the Conversion page.

1
The Postback should fire on the conversion page only (also called "Thank You Page"). We need to create a Trigger. 
Go to Triggers, click on New button. Select Trigger Type as Page View - DOM Ready. And to fire pixel on Some DOM-Ready Events. You can select that by URL / Path mask.
For Example:

3
To fire a Postback we will use IMG Pixel with Postback URL in it.
Go to Tags: click on New button. Select Tag Type as Custom HTML. Then place the following pixel into the HTML field. Just make sure you use the Scale Postback URL and Cookie-Click-ID GTM Variable:
<img src="https://demo.scaletrk.com/track/goal-by-click-id?click_id={{Cookie-Click-ID}}" height="1" width="1" />
Select Triggering the trigger you created before. And click Save
4
Publish your GTM, and the conversions should be tracked now.

Advanced GTM Configuration to pass Sale Amount

If you run an E-Commerce campaign and Revenue Share offer (CPS - Cost per Sale), you must pass the Sale Amount within your Tracking Pixel.

We need the Sale Amount passed to GTM via Data Layer. Some software does that already, and some don't. In this case, you need technical team involvement.

1
Review your Thank You page code and find the HTML element where Sales Amount and Order ID (optional) stored. Then push them to GTM Data Layer.
For Example:
<script type='text/javascript'>
   var order_amount = document.getElementById("order_amount").value;
   var order_id = document.getElementById("order_id").value;

  dataLayer.push({ 
    'order_amount': order_amount,
    'order_id': order_id }); 
</script>
2
Review your Thank You page code and find the HTML element where Sales Amount and Order ID (optional) stored. Then push them to GTM Data Layer.
For Example:
<script type='text/javascript'>
   var order_amount = document.getElementById("order_amount").value;
   var order_id = document.getElementById("order_id").value;

  dataLayer.push({ 
    'order_amount': order_amount,
    'order_id': order_id }); 
</script>
2
Go to Variables in GTM, click on New button. Select Variable Type as Data Layer Variable. Add Variables: Order Amount with name  order_amount and Order ID with name  order_id.
Example:

3
Go to Tags and use that Variables inside your Tag. Just type {{ , and you will receive a list of available variables. Select  the Order Amount and Order ID
Example:
<img src="https://demo.scaletrk.com/track/goal-by-click-id?click_id={{Cookie-Click-ID}}&amount={{Order Amount}}&adv_order_id={{Order ID}}" height="1" width="1" />
4
Publish your GTM and the conversions should include Sale Amount and Order ID.
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us