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.
How to Add the Landing Page Script:
Replace
XXXXXX
with your unique Program ID. If you don’t know your Program ID, please reach out to your Webgains Integration Manager.Insert the script into the
<head>
or at the very top of the<body>
tag on all pages.
<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:
Replace
XXXXXX
with your Program ID andYYYYYY
with your Event ID. If you are unsure on any of these details, please reach out to your Webgains Integration Manager.Fill in all required variables accurately.
<script>
var programid = 'XXXXXX';
var eventid = 'YYYYYY';
(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: 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 |
---|---|---|
| Yes | Your Webgains Program ID. Unique to your account. Contact your Integration Manager for assistance. |
| No | The Event ID for your commission. Specify this if you’re tracking multiple commission types. |
| 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. |
| 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. You should use the three-letter currency code (e.g., USD, GBP). Please find a full list of currencies we accept here. |
| Yes | The language of the order. Format: |
| 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. |
| No | A JSON object with additional tracking data (e.g., |
| No | An array of purchased items. Details provided below. |
| No | Classify the customer as 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. |
| No | A unique identifier for the customer. |
| 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 array, a single voucher code can be applied to the entire transaction by using the ' 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. |
| 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
array. Each product object will contain necessary properties such as name, price, product ID, and any other attributes like category or brand, passed as arrays instead of JSON objects.
The items
array should consist of objects, where each object represents a product, and each product can have an array of properties, such as custom data.
How to Implement the items
Array
Include product-specific data like product name, price, and product ID, as well as any other necessary properties (such as category or brand).
Ensure all values are stringified to maintain uniformity when submitting the data.
Example:
// 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 array
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)], // Pass category as an array with name and value
['brand', String(product.brand)] // Pass brand as an array with name and value
]
});
}
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 usingString()
. 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 array of arrays, where each sub-array contains a key-value pair (e.g., category and brand). Both the key (e.g., category) and value (e.g., Apparel) are stringified.
Example Output:
After processing the loop, the items
array will look like this:
[
{
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
Array Variables
Each item in the items
array 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 | No | The voucher code applied to this product, if any. Should be a string. |
event | Yes | The Event ID representing the type of commission for this product. Should be a string. |
customData | No | An array of key-value pairs for custom tracking data (e.g., category, brand). Each entry should be an array containing the key and value, and both should be strings. |
Important Considerations:
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 theitems
array.
Handling Custom Data:
The
customData
field is passed as an array of arrays, where each sub-array contains the name and value of the custom data. For example,['category', 'Apparel']
represents a custom data point with the keycategory
and the valueApparel
. Both the key and value should be strings.
Array Structure:
The
items
array must be structured as an array of objects, where each object represents a product. Each product object contains properties such as name, price, code, voucher, event, and customData.
Consistency in Formatting:
Ensure that the structure of each item in the
items
array follows the same format. This helps maintain consistency and ensures that all products are tracked correctly.
Example Conversion Script Output With Item Tracking:
<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.