Public Clickout API

The Public Clickout endpoint takes in an affiliate link with user data. This data gets registered in our database as a click and a modified affiliate URL with a tracking value added into the Sub ID will be returned. This modified URL has to be used for the redirect in order to correctly attribute the click with sale(s). This public endpoint is IP throttled to 30 requests per minute.

POST:  https://wct-1.com/api/public/v1/clickout
Request
Header
Content-Type: application/json
Body Parameters
Parameter
Data Type
Requirement for Click Tracking
Requirement for Attribution
Description
uid

String

Required

Required

The User ID of your account. Can be found here

affiliate_url

String | URL-encode according to RFC 3986

Required

Required

The Affiliate URL which will be used to direct the user to it

clickout_url

String | URL-encode according to RFC 3986

Optional

Required

The URL where the user clicked out from (to get this value you could use a cookie approach to find the previous URL, there’s an example on this underneath)

redirect_url

String | URL-encode according to RFC 3986

Optional

Optional

The URL where the user is redirected from

_ga

String

Optional

Recommended

This is the Google Analytics cookie called _ga

_wctrck

String

Optional

Required

This is the We Can Track cookie set by our Javascript Tag called _wctrck

metadata

JSON

Optional

Optional

Custom data that needs to be attached with the clickout

custom_index_1..5

String

Optional

Optional

Custom indexed 1 to 5 to be used on complex queries.

user_click_reference

String (case insensitive)

Optional

Optional

This ID needs to reference back to a click in your database. Currently this is a custom functionality, please reach out to us to make use of this parameter. Note: please make sure you keep this ID as short as possible.

click_id_placeholder

String

Optional

Optional

Define a click ID placeholder variable through which you can control where exactly our click ID should be placed within the URL you provide us. This can be helpful for (affiliate) URLs that are currently not recognised by our system due to unknown link pattern. If the placeholder field is available in the request, our system will user the placeholder functionality and not any link patterns provided in the system. If no placeholder field is given in the request it will use the available link patterns from our system.

Body example
				
					{
    "affiliate_url" : "https%3A%2F%2Fwww.awin1.com%2Fcread.php%3Fawinmid%3DXXXX%26awinaffid%3DXXXXX%26clickref%3DXXXXX",
    "clickout_url" : "https%3A%2F%2Fexample.com%2Fpage",
    "_ga" : "GA1.2.XXXXXX.XXXXXX",
    "_wctrck" : "9jInZ4YnZuZlPjx...",
    "metadata" : {
      "deal_id" : 123,
      "deal_title" : "title",
      "anything" : "anything"
    },
    "custom_index_1" : "index1",
    "custom_index_2" : "index2",
    "user_click_reference" : "CLICK_ID_1234"
}
				
			
Response
Header
				
					Content-Type: application/json
X-RateLimit-Limit: 30
X-RateLimit-Remaining: 29
				
			
200 Body - OK

The affiliate_url attribute will contain the modified affiliate URL which will be needed to direct the user to it.

				
					{
  "affiliate_url": "https%3A%2F%2Fwww.awin1.com%2Fcread.php%3Fawinmid%3DXXXX%26awinaffid%3DXXXXX%26clickref%3DXXXXXWCT191123233005gxs9q"
}
				
			
400 Body - Errors
				
					{
  "error": "Error Message"
}
				
			
299 Body - Warnings

These requests are successful but currently failing because of some user configuration, the warning message will explain what to do.

				
					{
  "warning": "Warning message"
}
				
			
Javascript code example

This is an extensive example of how to implement this API. In the payload variable is where you would fill in the body parameters. The function redirectToAffiliateURL takes in the payload and a timeout parameter. With the timeout parameter you may decide when to fallback to the original affiliate URL. Please keep in mind that the timeout varies per user primarily due to internet speed, 3 seconds seems to cover most cases.

				
					/*---- HELPER FUNCTIONS ----*/
function getCookie(name) {
    let cookie = {};
    document.cookie.split(';').forEach(function(el) {
        let [k,v] = el.split('=');
        cookie[k.trim()] = v;
    })
    return cookie[name];
}
function setCookie(variable, value, expires_seconds) {
    var d = new Date();
    d = new Date(d.getTime() + 1000 * expires_seconds);
    document.cookie = variable + '=' + value + '; expires=' + d.toGMTString() + ';';
}
// RFC 3986 Compatible
function fixedEncodeURIComponent(str) {
  return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
    return '%' + c.charCodeAt(0).toString(16);
  });
}
/*--------------------------*/

function redirectToAffiliateURL(payload, timeoutMs) {
    return new Promise((resolve, reject) => {
        // Set timeout timer
        let timer = setTimeout(
            () => reject(new Error('Request timed out')),
            timeoutMs
        );

        fetch('https://wct-1.com/api/public/v1/clickout', {
            method: 'POST',
            headers: {'Content-Type': 'application/json'},
            body: JSON.stringify(payload)
        }).then(
            response => resolve(response),
            err => reject(err)
        ).finally(() => clearTimeout(timer));
    })
}

let payload = {
    'uid' : 'xxxxxx',//your user ID
    'affiliate_url' : fixedEncodeURIComponent('https://www.awin1.com/cread.php?awinmid=12116&awinaffid=334243&p=https://www.mcdrogerie.ch/aktionen'),
    'redirect_url' : fixedEncodeURIComponent(window.location.href),
    'clickout_url' : getCookie("previousUrl"),// explained at (1)
    '_ga' : getCookie("_ga"),
    '_wctrck' : getCookie("_wctrck"),
    'metadata' : {'key':'value'},
    'custom_index_1' : 223,
    'custom_index_2' : 'male'
};

// redirect to affiliate URL, if the loading takes more than 3 seconds then redirect to payload.affiliate_url
redirectToAffiliateURL(payload, 3000).then((response) => {
    if (!response.ok) {
        throw new Error('Invalid request');
    } else {
        response.json().then(function(data) {
            if ('affiliate_url' in data) {
                window.location.replace(decodeURIComponent(data.affiliate_url));
            } else {
                throw new Error('Could not find affiliate url in response');
            }
        })
    }
}).catch(function(err) {
    console.log('failed.. falling back', err);

    // fallback to original redirect
    window.location.replace(payload.affiliate_url);
});

// (1) in this example we will be using the cookie as a way to log the previousUrl and set that as the clickout URL.
setCookie("previousUrl", window.location.href, {path:"/"});