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 -->
<script>
(function (w,d,s,u,o,c,e,x) {
w['TrackingSystemObject']=o;
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','http://cdn.refersion.com/refersion.js','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 r.storage.get("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) {
r.storage.set("current_cart", cookieObject["cart"])
const requestParams = {
id: await r.storage.get(r.dataPrefix + '_id'),
url: window.location.href,
aid: await r.storage.get(r.dataPrefix + '_aid'),
cs: await r.storage.get(r.dataPrefix + '_cs'),
cart: await r.storage.get("current_cart")
};
r.sendCheckoutEvent(requestParams.cart, requestParams.id, requestParams.url, requestParams.aid, requestParams.cs);
}
};
*/
// Initialize
r.initializeXDLS().then(() => {
r.launchDefault();
/*
Implementation of the example checkCart method above
window.setInterval(checkCart, 500);
*/
});
});
</script>
<!-- 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).
<!-- REFERSION TRACKING: BEGIN -->
<script src="http://cdn.refersion.com/refersion.js"></script>
<script>
r.addTrans({
'order_id': '3123123',
'shipping': '12.90',
'tax': '8.23',
'discount': '4.32',
'discount_code': 'TESTCOUPON',
'currency_code': 'USD'
});
r.addCustomer({
'first_name': 'Nancy',
'last_name': 'Parker',
'email': '[email protected]',
'ip_address': '808.53.77.22'
});
_rfsn._addItem({
'sku': 'DD23444',
'quantity': '2',
'price': '100'
});
r.addItems({
'sku': 'DD25444',
'quantity': '6',
'price': '13'
});
r.addItems({
'sku': 'MP39592',
'quantity': '2',
'price': '1000'
});
r.sendConversion();
</script>
<!-- REFERSION TRACKING: END -->
Variable Descriptions
Transaction Data
A transaction represents the entire order that occurred, and contains the following values:
Value | Type | Required | Description |
---|---|---|---|
order_id | String | Yes | Unique shopping cart order ID or transaction number used to reference the purchase that you're reporting. |
shipping | Number | No | Total shipping and handling the customer was charged for the order. |
tax | Number | No | Total tax the customer was charged for the order. |
discount | Number | No | Total in discounts that were applied to the order. |
discount_code | String | No | The discount or coupon code that was used on the order. |
currency_code | String | Yes | The 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:
Value | Type | Required | Description |
---|---|---|---|
first_name | String | No | Customer’s first name. |
last_name | String | No | Customer’s last name. |
String | No | Customer’s email address. | |
ip_address | String | No | The IP address of the customer. |
Item Data
An item represents an individual product that the customer had ordered, and contains the following values:
Value | Type | Required | Description |
---|---|---|---|
sku | String | Yes | A unique Product SKU or identifier ID. Can be blank, but we highly recommend that you populate the field. |
quantity | Number | Yes | Total quantity ordered of the product. |
price | Number | Yes | Price 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. |