- 16 Oct 2024
- DarkLight
Direct S2S Integration
- Updated on 16 Oct 2024
- DarkLight
Server-to-Server (S2S) allows you to send data directly to Awin’s servers (via an HTTPS request) to circumvent tracking restrictions placed by a customer’s browser.
While you have the option to integrate this via your own custom code as shown below, we highly recommend the use of our authenticated Conversion API instead. Alternatively, you have the option to integrate this tracking method via Google Tag Manager.
Request Template
https://www.awin1.com/sread.php?tt=ss&tv=2&merchant={{advertiserId}}&amount={{totalAmount}}&ch={{channel}}&parts={{commissionGroup}}:{{totalAmount}}&vc={{voucher_code}}&cr={{currencyCode}}&ref={{orderReference}}&testmode={{isTest}}&cks={{awc}}
{{awc}}
must be replaced by the unique Awin Click checksum which may be recorded when the end user lands on the site.
For other parameter references, please see the Fall-back Conversion Pixel’s reference sheet.
Capturing the AWC
The AWC value is a parameter that is appended to the landing page URL by Awin to identify the source of a click. You must configure your site to record the AWC’s value when a customer lands on your site.
The relevant scripts should run on all pages of your site aside from those where payment or personally identifiable data may be captured or processed.
This value will be used to populate the cks
parameter within the conversion request.
If you are using a cookie to capture the AWC, please respect the following guidelines:
The cookie must be set via an HTTP response header and not in a client-side script. For example, a cookie set in PHP would be fine.
The cookie must be set with the
HTTPOnly
andSecure
flags.
Code Examples
The following examples should serve to provide you with an understanding of methods to accomplish the implementation of this tracking method. Other languages may be available upon request to your integrations point of contact.
PHP
Cookie Set
On your landing page, this script will set an AWC cookie based on the value found in the page URL. You should replace example.com
with your website’s URL.
<?php
function setAwc() {
if (!empty($_GET['awc'])) {
setcookie("awc",$_GET['awc'],time()+ 60 * 60 * 24 * 365,"/", "example.com", true, true);
}
}
?>
Confirmation Page
Once a conversion has occurred, this will send the relevant data to our servers.
<?php
$url = "https://www.awin1.com/sread.php?tt=ss&tv=2&merchant=1001";
$url .= "&amount=" . $totalAmount;
$url .="&ch=aw";
$url .= "&cr=" . $currencyCode;
$url .="&ref=" . $orderReference;
$url .="&parts=DEFAULT:" . $totalAmount;
$url .= "&testmode=0&vc=" . $voucherCode;
if (isset($awc)) {
$url .="&cks=" . $awc; // 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);
?>
ASP .NET (C#)
Cookie Set
private void writeAwcCookie() {
// Check if awc query parameter is present in the url.
if (Request.QueryString["awc"])
{
// Create a cookie.
HttpCookie cookie = new HttpCookie("_awin_awc");
// Set cookie value to the value of awc query parameter.
cookie.Value = Request.QueryString["awc"];
// Set cookie to expire in ...
cookie.Expires = DateTime.Now.AddDays(30d);
// Set httponly
cookie.HttpOnly = true;
// Set secure
cookie.Secure = true;
// Insert the cookie in the current HttpResponse.
Response.Cookies.Add(cookie);
}
}
Confirmation Page
private void awinRequest() {
var awCookie = Request.Cookies.Get("_awin_awc");
// Check if _awin_awc cookie is present.
//Build the s2s request URL.
//If advertiser uses deduplication (last click), complete request generation must be embedded in If statement, if (awCookie) {var url .... response.Close();}
var url = "https://www.awin1.com/sread.php?tt=ss&tv=2&merchant=ADVERTISER_ID_HERE" + "&amount=" + {amount} +"&ch=aw" + "&cr=" + {currencyCode} +"&ref=" + {orderId} +"&parts=DEFAULT:" + {amount} + "&vc=" + {voucherCode} +"&cks=" + awCookie;
// Create a request for the URL.
WebRequest request = WebRequest.Create(url);
// Add referer
request.Referer ="https://www.mydomain.com";
// Get the response.
WebResponse response = request.GetResponse();
using (Stream dataStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
}
response.Close();
}
Java
Cookie Set
//get awc and write a cookie on the landing page
if (request.getParameter("awc") != null) {
// Create a cookie
Cookie cookie = new Cookie("_awin_awc", request.getParameter("awc"));
// setDomain() method
cookie.setDomain(".yourdomain.com");
// setMaxAge() method
cookie.setMaxAge(60*60*24*365);
// setSecure() method
cookie.setSecure(true);
// setHttPonly() method
cookie.setHttpOnly(true);
// add the cookie to the response
response.addCookie(cookie);
}
Confirmation Page
//get all cookies
Cookie[] cookies = request.getCookies();
String awc = "";
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals("_awin_awc")) {
awc = cookie.getValue();
}
}
}
//build the request url
URL obj = new URL("https://www.awin1.com/sread.php?tt=ss&tv=2&merchant=8771&amount=1&ch=aw&cr=EUR&parts=CG:1&ref=11111&vc=&cks=" + awc);
//generate request
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestProperty ("Referer", "https://www.mydomain.com");
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
System.out.println("GET Response Code :: " + responseCode);
Python
Cookie Set
from urlparse import urlparse
from http import cookies
def setcookie(name, value, expiresDays, domain):
morsel = Morsel()
name, value = safestr(name), safestr(value)
morsel.set(name, value, quote(value))
morsel['max-age'] = expiresDays * 86400 #86400 sec is 1 day
morsel['domain'] = "topleveldomain"
morsel['secure'] = True
value = morsel.OutputString()
value += '; httponly'
header('Set-Cookie', value)
# get awc and write a cookie on the landing page
url = urlparse('requestUrl')
for i in url.query.split('&'):
# if awc is present in the url
if "awc" in i:
awc = i.split("=")
# drop a cookie
setcookie("awcCookie", awc[1],30, "topleveldomain")
break
Confirmation Page
import urllib2
from os import environ
import cgi, cgitb
# retrieve cookies and find awc
if environ.has_key('HTTP_COOKIE'):
for cookie in map(strip, split(environ['HTTP_COOKIE'], ';')):
(key, value ) = split(cookie, '=');
if key == "awc":
awc = value
else:
awc = ""
# build the request url and generate request
request = urllib2.Request("https://www.awin1.com/sread.php?tt=ss&tv=2&merchant="+"{merchantId}"+"&amount="+"{amount}"+"&ch=aw&cr="+"{currency}"+"&parts="+"{commissionBreakdown}"+"&ref="+"{orerReference}"+"&vc="+"{voucherCode}"+"&cks="+awc)
request.add_header('Referer', 'https://www.mydomain.com')
r = urllib2.urlopen(request)
Ruby on Rails
Cookie Set
# check if awc query parameter is present in the url
if params[:awc]
# create a cookie
cookies[:_awin_awc] = {
value: params[:awc],
expires: 1.year.from_now,
domain: 'domain.com',
secure: true,
httponly: true
}
end
Confirmation Page
require 'net/https'
# Build the s2s request URL
url = URI.parse('https://www.awin1.com/sread.php?tt=ss&tv=2&merchant=8771&amount=' + 'totalAmount' + '&ch=aw&cr=EUR&parts=' + 'CommissionGroup' + ':' + 'totalAmount' + '&ref=' + 'orderReference' + '&vc=' + 'voucherCode' + '&cks=' + cookies[:awc])
req = Net::HTTP::Get.new(url.to_s)
req['Referer'] = "https://www.mydomain.com";
res = Net::HTTP.start(url.host, url.port, :use_ssl => true) {|http|
http.request(req)
}