Client-side Tracking

Step 1 - Tracking Visits

In order to use our v4 JavaScript tracking for your site, you'll first need to enable v4 tracking in your account. You can do this by navigating to Account > Settings > Tracking and clicking the toggle option to turn on this feature.

Enable v4 tracking

Once completed, please copy/paste the following code into the <head> section of every page on your website where you expect your affiliates to drive traffic; including your order confirmation page. Make sure to replace YOUR-PUBLIC-KEY below with the Public API key from your Refersion account.

! function(e, n, t, i, o, c, s, a) {
    e.TrackingSystemObject = "r", (s = n.createElement(t)).async = 1, s.src = "", s.onload = function() {

        // Replace with your Refersion Public API Key
        r.pubKey = "YOUR-PUBLIC-KEY";

        // Uncomment next line if you need to debug during testing
        // r.settings.dbg_mode = true;

        r.settings.fp_off = true;

        r.initializeXDLS().then(() => {
            r.launchDefault().then(() => {

                // Send a custom  event that can be listened to later
                const rfsnTrackingEvent = new Event("refersion-loaded");

    }, (a = n.getElementsByTagName(t)[0]).parentNode.insertBefore(s, a)
}(window, document, "script");

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 "order 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).

document.addEventListener("refersion-loaded", function() {

        'order_id': '3123123',
        'shipping': '12.90',
        'tax': '8.23',
        'discount': '4.32',
        'discount_code': 'TESTCOUPON',
        'currency_code': 'USD',
        'is_subscription': true,
        'subscription_id': '12345'

        '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. (a code name is required if you send in discount)
currency_codeStringYesThe three-letter currency code of the order totals that you are reporting. Example: USD, CAD, GBP.
is_subscriptionBooleanNoIf the order is a subscription and has a subscription ID then you must include this flag.
subscription_idStringNoSubscription ID to use for the order if is_subscription flag is turned on.

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. (required if you send in first_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.