Client-side Tracking

Step 1 - Tracking Visits

Please copy/paste the following code into the <head> section of every page on your web site where you expect your affiliates to drive traffic. Make sure to replace YOUR-PUBLIC-KEY below with the Public API key from your Refersion account.

<!-- Refersion Tracking -->
	(function (w,d,s,u,o,c,e,x) {
		e=d.createElement(s);e.async=1;e.src=u;e.onload=c;x=d.getElementsByTagName(s)[0];x.parentNode.insertBefore(e, x);
	})(window,document,'script','','r',function () {

		// Configure SDK
		r.pubKey = 'YOUR-PUBLIC-KEY';

		Below is an example of a checkCart method you could use to listen for changes on a "cart" cookie

		const checkCart = async () => {

			// Parses document.cookie into an object
			const cookieObject = Object.fromEntries(document.cookie.split('; ').map(x => x.split('=')));
			const storedCart = await"current_cart");

			// if the cart cookie exists and has updated, sets the current_cart in storage and sends the checkout event
			if (cookieObject["cart"] && cookieObject["cart"] !== storedCart) {"current_cart", cookieObject["cart"])

				const requestParams = {
					id: await + '_id'),
					url: window.location.href,
					aid: await + '_aid'),
					cs: await + '_cs'),
					cart: await"current_cart")

				r.sendCheckoutEvent(requestParams.cart,, requestParams.url, requestParams.aid, requestParams.cs);




		// Initialize
		r.initializeXDLS().then(() => {


			Implementation of the example checkCart method above

			window.setInterval(checkCart, 500);


<!-- End Refersion Tracking -->

Step 2 - Sending orders via Javascript on a "Thank You Page"

For this type of tracking, you must add code into your "thank you" or confirmation page. This would be the page that all customers are directed to after completing their order. Below is sample code which you should use as a starting template.

Within this code, you must dynamically insert the customer's transaction information from the respective order. We've added some dummy order information for your reference. Not all data is required, but all is recommended. A description of each field is available at the end of this article.

For best performance, place this code just before the </body> tag in your HTML.


In order to function properly, the click tracking code described in Step 1 and this code must run on the same domain and security level (http/https).

<script src=""></script>

    'order_id': '3123123',
    'shipping': '12.90',
    'tax': '8.23',
    'discount': '4.32',
    'discount_code': 'TESTCOUPON',
    'currency_code': 'USD'

    'first_name': 'Nancy',
    'last_name': 'Parker',
    'email': '[email protected]',
    'ip_address': '808.53.77.22'

    'sku': 'DD23444',
    'quantity': '2',
    'price': '100'

    'sku': 'DD25444',
    'quantity': '6',
    'price': '13'

    'sku': 'MP39592',
    'quantity': '2',
    'price': '1000'



Variable Descriptions

Transaction Data

A transaction represents the entire order that occurred, and contains the following values:

order_idStringYesUnique shopping cart order ID or transaction number used to reference the purchase that you're reporting.
shippingNumberNoTotal shipping and handling the customer was charged for the order.
taxNumberNoTotal tax the customer was charged for the order.
discountNumberNoTotal in discounts that were applied to the order.
discount_codeStringNoThe discount or coupon code that was used on the order.
currency_codeStringYesThe three letter currency code of the order totals that you are reporting. Example: USD, CAD, GBP.

Customer Data

A customer represents the individual customer who purchased, and contains the following values:

first_nameStringNoCustomer’s first name.
last_nameStringNoCustomer’s last name.
emailStringNoCustomer’s email address.
ip_addressStringNoThe IP address of the customer.

Item Data

An item represents an individual product that the customer had ordered, and contains the following values:

skuStringYesA unique Product SKU or identifier ID. Can be blank, but we highly recommend that you populate the field.
quantityNumberYesTotal quantity ordered of the product.
priceNumberYesPrice of each item. For example, if the customer ordered 10 items at $5 each, you should report $5, not $50. Do not include currency symbols.