Implementing sales tracking

Prev Next

If we do not support your e-commerce platform follow the below guide to implement the Awin tracking code.

Awin uses hybrid tracking technologies by default, meaning both client-side and server-side, including the various tracking code components, such as client-side conversion tag & conversion pixel as well as server-side request.

We also recommend supporting cookie signals.

if user accept (Awin) cookies:

if user reject (Awin) cookies:

<script>
var AWIN = AWIN || {};
AWIN.Tracking = AWIN.Tracking || {};
AWIN.Tracking.Consent.setAdvertiserConsentStatus(true); 
//cookie consent was obtained for Awin
</script>
<script>
var AWIN = AWIN || {};
AWIN.Tracking = AWIN.Tracking || {};
AWIN.Tracking.Consent.setAdvertiserConsentStatus(false); 
//cookie consent was not obtained for Awin
</script>

MasterTag

The MasterTag is a JavaScript library containing all functions required for our tracking solution and should be unconditionally appended to every page on the site.

<!--Master Tag add just before the closing </body> tag--> 

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

Replace XXXXX with your Advertiser ID (AID).

Log into the platform, in the top right-hand corner of the screen you will find your AID.

Conversion Tag

The Conversion Tag, or Tracking Code as it also might be referred to, is the declaration of the AWIN.Tracking.Sale JavaScript object, which is done on the confirmation page to instruct the MasterTag that a conversion has taken place. It will then subsequently perform the necessary tracking requests.

Place the following code onto the confirmation page (the page that appears after a customer makes a successful purchase).

<!—Image Pixel - Mandatory -->
<img src="https://www.awin1.com/sread.img?tt=ns&tv=2&merchant=XXXXXX&amount={{order_total}}&cr={{currency_code}}&ref={{order_ref}}&parts=DEFAULT:{{order_total}}&vc={{voucher_code}}&ch=aw&testmode=0" border="0" width="0" height="0">

<!-- JavaScript Tracking - Mandatory -->
<script type="text/javascript">
//<![CDATA[ /*** Do not change ***/
var AWIN = AWIN || {};
AWIN.Tracking = AWIN.Tracking || {};
AWIN.Tracking.Sale = {};

/*** Set your transaction parameters ***/
AWIN.Tracking.Sale.amount = "{{order_total}}";
AWIN.Tracking.Sale.orderRef = "{{order_ref}}";
AWIN.Tracking.Sale.parts = "DEFAULT:{{order_total}}";
AWIN.Tracking.Sale.voucher = "{{voucher_code}}";
AWIN.Tracking.Sale.currency = "{{currency_code}}";
AWIN.Tracking.Sale.test = "0";
AWIN.Tracking.Sale.channel = "aw";
//]]>
</script>

<!--Master Tag add just before the closing </body> tag--> 
<script src="https://www.dwin1.com/XXXXX.js"" type="text/javascript" defer="defer"></script>

Replace XXXXX with your Advertiser ID.

The text in { brackets } are placeholders (for example used in GTM) - it will need to be replaced with the variables your shop site uses for the following information:

  • {{order_total}} - The total transaction amount set to two decimal places. Can include or exclude delivery/VAT charges.

  • {{currency_code}} - To be populated with the ISO currency code of the currency that was used in the transaction. Example: GBP, EUR, SEK, USD, etc.

  • {{order_ref}} - A unique booking/order reference ID per order. - it could be a number you already use in your system to keep track of sales or a randomly generated number. The number must be unique as a different ID needs to be generated for each Sale. The ID is required for later recognition of the order within your own system.

  • {{voucher_code}} - The coupon/voucher code used.

  • Important

    This code contains values ​​twice (from image and javascript) - please change them all. Example: {{order_ref}} or {{currency_code}}

Final output client code example (with example values)

For example, if a customer purchases a product for £5.99 using the voucher code “HALFPRICE” the code should load as:

<!—Image Pixel - Mandatory --> 
<img src="https://www.awin1.com/sread.img?tt=ns&tv=2&merchant=XXXXXX&amount=45.99&cr=GBP&ref=9-815162342a&parts=DEFAULT:45.99&vc=HALFPRICE&ch=aw&testmode=0"" border="0" width="0" height="0">

<!-- JavaScript Tracking - Mandatory -->
<script type="text/javascript">
//<![CDATA[ /*** Do not change ***/
var AWIN = AWIN || {};
AWIN.Tracking = AWIN.Tracking || {};
AWIN.Tracking.Sale = {};

/*** Set your transaction parameters ***/
AWIN.Tracking.Sale.amount = "45.99";
AWIN.Tracking.Sale.orderRef = "9-815162342a";
AWIN.Tracking.Sale.parts = "DEFAULT:45.99";
AWIN.Tracking.Sale.voucher = "HALFPRICE";
AWIN.Tracking.Sale.currency = "GBP";
AWIN.Tracking.Sale.test = "0";
AWIN.Tracking.Sale.channel = "aw";
//]]>
</script>

<!--Master Tag add just before the closing </body> tag--> 
<script src="https://www.dwin1.com/XXXXXX.js"" type="text/javascript" defer="defer"></script>

You may wish to use PHP to load these variables (see example below). Alternatively, if you are using a third-party eCommerce platform, their support team may be able to provide you with the variables to use.

PHP example

<img border="0" height="0" src="https://www.awin1.com/sread.img?tt=ns&tv=2&merchant=XXXXXX&amount=<?php echo $totalAmount; ?>&ch=aw&cr=<?php echo $currencyCode; ?>&parts=DEFAULT:<?php echo $totalAmount; ?>&ref=<?php echo $orderReference; ?>&testmode=0&vc=<?php echo $voucherCode; ?>" style="display:none;" width="0">
<script type="text/javascript">
//<![CDATA[
/*** Do not change ***/
var AWIN = AWIN || {};
AWIN.Tracking = AWIN.Tracking || {};
AWIN.Tracking.Sale = {};
/*** Set your transaction parameters ***/
AWIN.Tracking.Sale.amount = "<?php echo $totalAmount; ?>";
AWIN.Tracking.Sale.channel = "aw";
AWIN.Tracking.Sale.currency = "<?php echo $currencyCode; ?>";
AWIN.Tracking.Sale.orderRef = "<?php echo $orderReference; ?>";
AWIN.Tracking.Sale.parts = "DEFAULT:<?php echo $totalAmount; ?>";
AWIN.Tracking.Sale.test = "0";
AWIN.Tracking.Sale.voucher = "<?php echo $voucherCode; ?>";
//]]>
</script>

Server-side tracking

Also mandatory for our hybrid tracking is the support of at least one server side tracking request method like Conversion API and/or over direct integration or per Tag System (e.g. GTM). In some shop or tag system the naming can be also webhook or http request or similar.

simple example for orientation in PHP:

<?php
$AwAdvID = "1001"; // replace with your Awin advertiser ID - exampleID here: 1001
$totalAmount = "1.00"; // in case of leads mostly static one (for one lead)
$cookieName = "source"; // Name of the cookie to use for last click referrer de-duplication
$currencyCode = "GBP";
$orderReference = microtime(true);
$commissiongroupcode = "DEFAULT";
$voucherCode = "";
$cks = $_COOKIE["awc"]; // Populate the Awin click checksum if one is associated with the conversion

if (isset($_COOKIE[$cookieName])) {
$paidchannel = $_COOKIE[$cookieName]; // for other paid channels only
} else {
$paidchannel = "aw"; // No paid channel assisted
}

$url = "https://www.awin1.com/sread.php?tt=ss&tv=2";
$url .= "&merchant=" . $AwAdvID; 
$url .="&amount=" . $totalAmount;
$url .="&ch=" . $paidchannel;
$url .="&cr=" . $currencyCode;
$url .="&ref=" . $orderReference;
$url .="&parts=" . $commissiongroupcode;
$url .=":" . $totalAmount;
$url .= "&testmode=0&vc=" . $voucherCode;
$url .="&cks=" . $cks; // Populate the Awin click checksum if one is associated with the conversion

$c = curl_init();
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_URL, $url);
curl_exec($c);
curl_close($c);
?>

Note: The server-side PHP code is executed when the (purchase-/booking-)thankyou-page is requested in user browser, but is not directly visible in the client-side source code, the client browser developer console, or similar. For further examples or in other programming languages, please visit the topic-specific page for server-side integration or for the channel parameter.

To differentiate between new and existing customers, there is also the optional parameter customer acquisition. If CommissionGroupCode (default value: DEFAULT inside parameter called parts) is renamed, it can also be dynamically replaced (for example with SALE, or similar), but then it must also be set up in the commission manager. Ideally, the CommissionGroupCode description or program description (profile) contains more detailed information about the type of commission or what type of sale is meant. Typical sale use cases can include:

  • purchase or booking (over web or app)

  • subscription (e.g. annual or monthly fees) or

  • online contract or applications (often, after approval).

Last step - tracking tests

After integrating the Awin tracking you will need to create a test transaction via the Awin platform to check the tracking is working correctly.

Complete the steps to conduct a test transaction via our test transaction guide.

For more information on how to set up and track sales on Awin, watch our tutorial video.