GTM CustomHTML DeDupe

From Wiki

Jump to: navigation, search

Português

Contents

[-] Google Tag Manager - Custom HTML Integration

Google Tag Manager - Template Integration

Step 1 - Installing the Journey Tag

The Awin Journey Tag is a JavaScript library that contains all the necessary functions for the Awin tracking to work as expected.

The Journey Tag NEEDS to fire on all possible landing pages of your website! We ask this is done, because the Journey Tag is responsible for the creation of a first party cookie when the user reaches the website. As the user can enter the website through multiple possible landing pages apart from the website's home page, we need to cover all entrance possibilities, therefore, we need the Journey Tag to fire on all pages.


If the user enters through a page, that does not contain the Journey Tag, we won't measure anything.


1) Navigate to "Tags"


2) Click “New” and choose the Custom HTML tag.

4) Paste the following code in this tag (UPDATE XXXXX to your MID, provided to you by your integrator):

<script defer="defer" src="https://www.dwin1.com/XXXXX.js" type="text/javascript"></script>


5) Select "All Pages" as the trigger, and block if from firing in the success page.

6) Name and save this tag "Awin - Journey Tag".

Step 2 - Automatic de-duplication and the Channel Parameter

This allows Awin’s conversion tag to identify which was the last paid media to generate the last click in the user’s journey before the checkout, this way, Awin’s platform can determine which transactions came from Awin and which didn’t, thus having an automatic de-duplication performed.

1) Create a new variable and name it “Awin - ChannelCookie”, this should be a First Party cookie variable:

2) Name the cookie this way “AwinChannelCookie”:

3) Create a new tag and name it “Awin - Last Click Identifier”, this should be a Custom HTML type tag:

4) Add the following code to this tag:

<script>
    var Data = new Date();
    var latency; 
    var cookieLength = 30; // Cookie length in days;
    var origin;
    var sourceParameter = ["utm_source", "gclid"]; // The parameters used by paid medias to determine the origin of the click
    var queryString = window.location.search;
    var urlParams = new URLSearchParams(queryString);
    var sourceValue;
    var domain = ".{INSERT_YOUR_DOMAIN_HERE.COM}"; // UPDATE TO YOUR TOP LEVEL DOMAIN
    var organicFilter = false; //"true" will consider SEO as other channels, "false" Awin will measure organic traffic after interactions with an Awin link.
 
    Data.setTime(Data.getTime() + (cookieLength * 24 * 60 * 60 * 1000));
    latency = Data.toUTCString();
 
    //Check if user is merely navigating the website's pages or if it is the first access.
    if(!document.referrer.includes(window.location.hostname)){
        //Check if user accessed the website through parallel tracking links.
        if(window.location.href.indexOf("awaid") > -1){
            origin = "aw"; 
        } else {
            //check if the user came from SEO links and de-dupe against it if organic filter is enabled.
            if(organicFilter == true && window.location.referrer.includes("google") || window.location.referrer.includes("yahoo") || window.location.referrer.includes("bing") || window.location.referrer.includes("yandex") || window.location.referrer.includes("duckduckgo")){
                origin = "other";
            } else {
                //Check if Awin was the last paid click referring channel
                for (var i = 0; i < sourceParameter.length; i++) {
                    if (queryString.includes(sourceParameter[i])) {
                        sourceValue = urlParams.get(sourceParameter[i]);
                        if (sourceValue == "awin" || sourceValue == null || sourceValue == "undefined") {
                            origin = "aw";
                        } else {
                            origin = "other";
                        }
 
                        break;
 
                    } else {
                        //No source parameter found, store "aw" as origin as a fallback to account for tracking errors.
                        origin = "aw"
                    }
                }
            }        
        }
        //Store the origin
        document.cookie = "AwinChannelCookie=" + origin + "; expires=" + latency + ";path=/; Domain=" + domain; 
    }
</script>

5) Edit the code above where it says “INSERT_YOUR_DOMAIN_HERE.COM”, to reflect your website’s domain, please keep the "." before your domain as it will take into consideration any subdomain from your website.

6) Use an all pages trigger on this tag.

Step 3: Define the Awin sale tracking

1) Create a new tag and select the Custom HTML type.

2) Copy and paste the following code:

//UPDATE THE VARIABLES TO REFLECT YOUR GTM VARIABLES. UPDATE XXXXX TO YOUR MID
<img border="0" height="0" src="https://www.awin1.com/sread.img?tt=ns&tv=2&merchant=XXXXX&amount={{Awin - Transaction Total}}&ch={{Awin - Channel Cookie}}&parts=DEFAULT:{{Awin - Transaction Total}}&ref={{Awin - Transaction ID}}&cr={{Currency}}&vc={{VoucherCode}}&testmode=0" style="display: none;" width="0">
 
<script type="text/javascript">
 
//<![CDATA[
/*** Do not change ***/
var AWIN = {};
AWIN.Tracking = {};
AWIN.Tracking.Sale = {};
/*** Set your transaction parameters ***/
AWIN.Tracking.Sale.amount = {{Awin - Transaction Total}}; //REPLACE WITH A VARIABLE THAT RETURNS THE TRANSACTION TOTAL
AWIN.Tracking.Sale.channel = "{{Awin - Channel Cookie}}"; 
AWIN.Tracking.Sale.orderRef = "{{Awin - Transaction ID}}"; //REPLACE WITH A VARIABLE THAT RETURNS THE TRANSACTION ID
AWIN.Tracking.Sale.parts = "DEFAULT:" + {{Awin - Transaction Total}}; //REPLACE WITH A VARIABLE THAT RETURNS THE TRANSACTION TOTAL
AWIN.Tracking.Sale.currency = "{{Currency}}"; //REPLACE WITH A VARIABLE THAT RETURNS THE TRANSACTION CURRENCY 
AWIN.Tracking.Sale.voucher = "{{VoucherCode}}"; // REPLACE WITH A VARIABLE THAT RETURNS THE DISCOUNT CODE ADDED BY THE USER
AWIN.Tracking.Sale.test = "0";
//]]>
</script>
 
<!--UPDATE "XXXXX" to your MID-->
<script defer="defer" src="https://www.dwin1.com/XXXXX.js" type="text/javascript"></script>

2) Update the variables in the code to reflect your GTM variables. Here is a list of what needs to be updated:

* {{Awin - Transaction Total}} - Needs to reflect the array of products inside of the shopping cart..
* {{Awin - Transaction ID}} - Needs to receive the order ID.
* {{VoucherCode}} - Needs to receive the discount code added to the purchase by the user.
* {{Currency}} - Needs to receive the ISO code for the currency used in the transaction, eg. "USD", "GBP", "EUR".
* XXXXX - Should be changed to your MID (Merchant ID), There are two instances of this in the previous code, please update both!

You can use DataLayer variables to populate the mentioned parameters, in case you don't know how to map DataLayer variables, here is a guide you can follow on How to map DataLayer variables in GTM

3) Select the trigger that fires once a conversion or the desired event occurs. (The "success" page for conversions, or an confirmation event for leads).

4) Name the tag "Awin - Conversion Tag" and click ‘Save’. Your tag should look something like this:

5) Click ‘save’ and you should now have two Tags listed in the Tags table.

Step 4 - Product Level Tracking (PLT)


This step should only be followed by e-commerces, if you do not have an e-commerce, please ignore this step.

Product Level Tracking allows the advertiser to generate much detailed deports, it shows the performance for each product in the shopping cart individually, this is specially relevant for e-commerce advertisers.

1) Create a new tag of type "Custom HTML" and paste the following Code:

<script type="text/javascript">
var transactionProducts = {{transactionProducts}};
AWIN.Tracking.Sale.plt = '';
for (i = 0; i < transactionProducts.length; i++) {
AWIN.Tracking.Sale.plt += "AW:P|XXXXX|{{Awin - Transaction ID}}|" +
transactionProducts[i]['id'] + "|" +
transactionProducts[i]['name'] + "|" +
transactionProducts[i]['price'] + "|" +
transactionProducts[i]['quantity'] + "|" +
transactionProducts[i]['sku'] + "|" +
"DEFAULT" + "|" +
transactionProducts[i]['category'] + "\n";
}
var basketForm = document.createElement('form');
basketForm.setAttribute('style', 'display:none;');
basketForm.setAttribute('name', 'basket_form');
var basketTextArea = document.createElement('textarea');
basketTextArea.setAttribute('wrap', 'physical');
basketTextArea.setAttribute('id', 'aw_basket');
basketTextArea.value = AWIN.Tracking.Sale.plt;
basketForm.appendChild(basketTextArea);
document.getElementsByTagName('body')[0].appendChild(basketForm);
<!----End Product Level Tracking--->
</script>

2) Adjust the variables so that they reflect the variables in your GTM container. Here is a description of the necessary variables:

* {{transactionProducts}} - Needs to reflect the array of products inside of the shopping cart..
* {{Awin - Transaction ID}} - Needs to receive the order ID.
* XXXXX - Should be changed to your MID (Merchant ID), There are two instances of this in the previous code, please update both!

3) This tag shouldn't have a trigger, instead, open the "Awin - Conversion Tag" previously created, and use the tag sequencing to fire this tag before the Awin Conversion Tag, like so:

Step 5 - Tests

1) All done! Now just publish the changes!

2) You can follow this guide on How to Test the Awin Tags or contact your Integrator for further assistance!

Privacy

Due to new European legislation regarding how websites store information about you, AWIN is updating its privacy policy. You can see the new version of our policy here. If you would like to see the information we capture on this website, please click here for further details. In order to accept cookies on this site please click the 'I ACCEPT' button