Skip to main content
Skip table of contents

Webgains Default Tracking Guide

Welcome to your guide for integrating Webgains tracking scripts into your website. With this setup, you’ll enable accurate conversion tracking and ensure proper attribution for your affiliate campaigns.

Since the data you provide through the tracking scripts is used to calculate affiliate commissions, it’s essential to ensure all values are accurate and reflect your commission policy. For instance:

  • If you are not paying commission on VAT, shipping, or other non-commissionable amounts, ensure these are excluded from the values submitted.

  • Similarly, any discounts or promotions applied to a customer’s order should also be deducted from the total.

This document outlines the steps to integrate Webgains tracking scripts effectively and highlights how to configure each variable. Let’s get started!

To comply with the regulations governing cookies under the GDPR and the ePrivacy Directive you must receive users' consent before you use any marketing cookies, including the landing page script.

Step 1: Adding the Landing Page Script

The Landing Page Script is essential for tracking affiliate traffic and must be included on every page of your website.

Beyond tracking, this script enables "The Tag", a Webgains feature that provides seamless integration with various tech partner publishers on the Webgains network, enhancing your campaign’s performance and simplifying publisher interactions.

To partner with TopCashback, please review this setup guide. It explains how to identify traffic from TopCashback and implement the necessary changes to comply with their terms of service using our platform.

How to Add the Landing Page Script:

  1. Replace XXXXXX with your unique Program ID. If you don’t know your Program ID, please reach out to your Webgains Integration Manager.

  2. Insert the script into the <head> or at the very top of the <body> tag on all pages.

JS
<script>
(function(src) {
    var o = 'ITCLKQ';
    window[o] = window[o] || function() {(window[o].q = window[o].q || []).push(arguments)};
    window[o].l = 1 * new Date();
    var s = document.createElement('script');
    var f = document.getElementsByTagName('script')[0];
    s.async = 1; s.src = src; f.parentNode.insertBefore(s, f);
})('https://analytics.webgains.io/XXXXXX/main.min.js');
ITCLKQ('set', 'internal.api', true);
ITCLKQ('set', 'internal.cookie', true);
ITCLKQ('click');
</script>

Step 2: Adding the Conversion Script

The Conversion Script must be added to the order confirmation page — the page displayed after a customer completes a purchase (/conversion). This script sends transaction details to Webgains for commission calculations.

How to Add the Conversion Script:

  1. Replace XXXXXX with your Program ID. If you don’t know your Program ID, please reach out to your Webgains Integration Manager.

  2. Fill in all required variables accurately.

JS
<script>
var programid = 'XXXXXX';
(function(src) {
    var o = 'ITCVRQ';
    window[o] = window[o] || function() {(window[o].q = window[o].q || []).push(arguments)};
    window[o].l = 1 * new Date();
    var s = document.createElement('script');
    var f = document.getElementsByTagName('script')[0];
    s.async = 1; s.src = src; f.parentNode.insertBefore(s, f);
})('https://analytics.webgains.io/' + programid + '/main.min.js');
ITCVRQ('set', 'trk.programId', programid);
ITCVRQ('set', 'cvr', {
    value: '', 
    currency: '', 
    language: '', 
    eventId: '', 
    orderReference: '', 
    customData: {}, 
    items: [], 
    customerType: '', 
    customerId: '', 
    voucherId: '', 
    location: document.location.href
});
ITCVRQ('conversion');
</script>

Step 3: Conversion Script Variables

Below is a breakdown of the variables in the Conversion Script. Some are optional, and some are mandatory, but each variable used must be populated carefully to ensure accurate reporting and commission calculation.

Variable Name

Required?

Description

programid

Yes

Your Webgains Program ID. Unique to your account. Contact your Integration Manager for assistance.

value

Yes

The total order value. Ensure this excludes VAT, shipping, and discounts where applicable. Discounts from promotions and/or voucher codes need to be subtracted from this total order value.

currency

Yes

The order currency. This value needs to match the Checkout currency of the sale. We then convert to the currency your Webgains program is set up as.
This is crucial to ensure that your values and commissions are calculated accurately.

You should use the three-letter currency code (e.g., USD, GBP).

Please find a full list of currencies we accept here.

language

Yes

The language of the order. Format: en_EN.

orderReference

Yes

A unique identifier for the order (e.g., order number).

Please ensure that the same unique order number that is presented to the customer on their order invoice is also passed into this variable. This will be the reference displayed for the transaction in your Webgains reporting, and so you should ensure it matches the reference in your internal shop system records so you can locate the sale.

customData

No

A JSON object with additional tracking data (e.g., {"membershipTier": "Gold"}).

items

No

An object of purchased items. You can view the specific details for item tracking below.

customerType

No

Classify the customer as New or Existing. Custom values (e.g., Subscription) are also supported.

We recommend sending this data as it allows the use of our Smart Commissioning tool so you can automatically set different commission schemes based on if the customer is tracked as New or Existing.

customerId

No

A unique identifier for the customer.

voucherId

No

A voucher code applied to the entire order.

We recommend sending this data as it allows for voucher code reporting, as well as additional voucher tracking features such as voucher commission.

Although voucher codes can be applied to particular products in the items object, a single voucher code can be applied to the entire transaction by using the 'voucherId' variable.

If a voucher code has been set in voucherId, any items within items without individual voucher codes assigned will have the voucherId applied to them.

location

Yes

The URL of the order confirmation page.

Step 4: Items Tracking

To enable detailed product-level tracking, as well as utilise our Smart Commission product level commission feature, you'll need to include specifics for each product in the items object. Each product object will contain necessary properties such as name, price, product ID, and any other attributes like category or brand, passed as objects instead of JSON objects.

The items object should consist of multiple product objects, where each object represents an individual product. These product objects can include various properties such as custom tracking data or any other relevant attributes.

How to Implement the items Object

  1. Include product-specific data like product name, price, and product ID, as well as any other necessary properties (such as category or brand).

  2. Ensure all values are stringified to maintain uniformity when submitting the data.

Example:

JS
// Example list of purchased products with raw data
var products = [
    { name: 'Red Dress', price: 49.99, id: '499912', voucher: 'SUMMER10', event: '123', category: 'Apparel', brand: 'FashionCo' },
    { name: 'Blue Dress', price: 29.99, id: '499942', voucher: '', event: '123', category: 'Apparel', brand: 'FashionCo' }
];

// Initialize the items object
var items = [];

// Loop through each product to transform it into the required format and ensure stringification
for (var product of products) {
    items.push({
        name: String(product.name),                  // Convert name to string
        price: String(product.price),                // Convert price to string
        code: String(product.id),                    // Convert product ID to string
        voucher: String(product.voucher || ''),      // Ensure voucher is a string, empty if not available
        event: String(product.event),                // Ensure event is a string
        customData: {
            category: String(product.category),      // Use category as a key-value pair
            brand: String(product.brand)             // Use brand as a key-value pair
        }
    });
}

Explanation:

  • Name, Price, and Code:

    • These fields are explicitly converted to strings using String(). This ensures that even if the data is not in string format (e.g., number), it will be passed as a string.

  • Voucher:

    • The voucher field is stringified, ensuring that if no voucher is applied, it will be passed as an empty string ('').

  • Event:

    • The event field is treated as a string by using String(). This ensures that even if the event ID is numeric, it is passed as a string.

  • Custom Data:

    • The customData field is passed as an object with key-value pairs, where each key (e.g., category, brand) and its corresponding value (e.g., Apparel, FashionCo) are stringified.

Example Output:

After processing the loop, the items object will look like this:

JS
{}
    {
        name: 'Red Dress',
        price: '49.99',
        code: '499912',
        voucher: 'SUMMER10',
        event: '123',
        customData: {
            category: 'Apparel',
            brand: 'FashionCo'
        }
    },
    {
        name: 'Blue Dress',
        price: '29.99',
        code: '499942',
        voucher: '',
        event: '123',
        customData: {
            category: 'Apparel',
            brand: 'FashionCo'
        }
    }
}

Explanation of the items Object Variables

Each item in the items object contains specific properties that you need to provide for effective product-level tracking:

Property Name

Required?

Description

product name

Yes

The name of the product. Should be a string (max 255 characters).

product price

Yes

The price of the product (excluding VAT, discounts, and shipping). Should be a string. Please omit any currency symbols (£).

The total sum of the tracked Product Prices should equal the tracked total Order Value.

product ID/code

Yes

A unique identifier for the product (e.g., SKU, product ID). Should be a string. Max 100 characters.

If you are using our Smart Commission tool, please ensure this ID matches the Product ID you provide in your Product Feed.

voucher code

Yes

This field represents the voucher code applied to the product, if any. It should be a string. If no voucher code is used, please provide an empty string ("").

event

Yes

The Event ID representing the type of commission for this product. Should be a string.

customData

Yes

This field contains an object of key-value pairs for custom tracking data (e.g., category, brand). Each key and value should be a string. If no custom data is used, please provide an empty object ({}).


Important Considerations:

  1. Stringify all values:

    • Ensure that all values are converted to strings using String() where necessary. This includes price, name, event, and any other variables passed in the items object.

  2. Handling Custom Data:

    • The customData field should be passed as an object, where each key-value pair represents custom tracking data. For example, { category: 'Apparel' } represents a custom data point with the key category and the value Apparel. Both the key and value must be strings.

  3. Array Structure:

    • The items object should be structured as an object of objects, where each key represents a unique product identifier (e.g., product ID) and the corresponding value is an object containing product properties such as name, price, code, voucher, event, and custom data.

  4. Consistency in Formatting:

    • Ensure that the structure of each product in the items object follows a consistent format. This is crucial for maintaining uniformity and ensuring that all products are tracked correctly.

Example Conversion Script Output With Item Tracking:

CODE
<script>
var programid = '123456';
var eventid = '98765';
(function(src) {
    var o = 'ITCVRQ';
    window[o] = window[o] || function() {(window[o].q = window[o].q || []).push(arguments)};
    window[o].l = 1 * new Date();
    var s = document.createElement('script');
    var f = document.getElementsByTagName('script')[0];
    s.async = 1; s.src = src; f.parentNode.insertBefore(s, f);
})('https://analytics.webgains.io/' + programid + '/main.min.js');

ITCVRQ('set', 'trk.programId', programid);
ITCVRQ('set', 'cvr', {
    value: '100.00',
    currency: 'GBP',
    language: 'en_EN',
    eventId: eventid,
    orderReference: 'ORDER12345',
    customData: {"membershipTier": "Gold"},
    items: [
        {
            name: 'Red Dress',
            price: '50.00',
            code: '499912',
            voucher: 'SUMMER10',
            event: '98765',
            customData: {"category": "Apparel", "brand": "FashionCo"}
        },
        {
            name: 'Blue Dress',
            price: '50.00',
            code: '499942',
            voucher: '',
            event: '98765',
            customData: {"category": "Apparel", "brand": "FashionCo"}
        }
    ],
    customerType: 'New',
    customerId: 'CUSTOMER789',
    voucherId: 'SUMMER10',
    location: document.location.href
});
ITCVRQ('conversion');
</script>

For any questions or support during your tracking set up, please contact your Webgains Integration Manager, or support@webgains.com.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.