Article

Tracking – Product categorization

Product categorization is an advanced integration that splits your conversions by the type of product purchased. Each category gets its own Affilae key, and the script triggers the conversion matching the products actually present in the cart.

You can therefore reward a furniture sale and a book sale differently, with one commission rule per category.

Before you start: this is an advanced integration. It requires mastery of the e-commerce DataLayer, knowledge of GTM variables and their structure, JavaScript skills for customization, and access to product IDs in your e-commerce system.

What a product categorization integration does

This integration consists of:

  • segmenting products by business categories (for example electronics, apparel, books);
  • assigning specific Affilae KEYS to each category;
  • automatically calculating amounts by category for each order;
  • triggering the appropriate conversions according to the products in the cart.
Not to be confused: this page covers the tracking of conversions by category. It does not cover the product feed, which is the catalogue file (CSV, XML or JSON) you make available to your publishers. For that topic, see Product feeds: what they are for and what your file must contain.

Technical prerequisites

Required configuration

  • An e-commerce Data Layer correctly configured.
  • The product variables available in that Data Layer.

Two ways to install the integration

  • GTM integration (client-side): with a Custom HTML tag.
  • Custom integration (native code): direct integration in the confirmation page code.

Example code

Below is an example implementation for 4 product categories.

// Check if certain products are present in the shopping cart and trigger the corresponding Affilae KEY.

// Variables GTM
var items = {{dl_ecommerce.items}} || [];
var orderId = '{{dl_ecommerce.transaction_id}}';
var coupon = '{{dl_ecommerce.coupon}}' || '';
var currency = 'EUR';

// Mapping product -> KEY Affilae
var amountCategorie1 = 0;
var amountCategorie2 = 0;
var amountCategorie3 = 0;
var amountCategorie4 = 0;

var productIdsCategorie1 = [];
var productIdsCategorie2 = [];
var productIdsCategorie3 = [];
var productIdsCategorie4 = [];

var keysMap = {
"Categorie1": {
ids: ["PROD001", "PROD002", "PROD003"],
key: "example-key-categorie1-affiliate-id"
},
"Categorie2": {
ids: ["PROD101", "PROD102", "PROD103"],
key: "example-key-categorie2-affiliate-id"
},
"Categorie3": {
ids: ["PROD201", "PROD202", "PROD203"],
key: "example-key-categorie3-affiliate-id"
},
"Categorie4": {
ids: ["PROD301", "PROD302", "PROD303"],
key: "example-key-categorie4-affiliate-id"
}
};

// Update amount and product ids
items.forEach(function (product) {
var product_id = String(product.item_id);

// Check each group of IDs
if (keysMap.Categorie1.ids.includes(product_id)) {
amountCategorie1 = product.price * product.quantity;
productIdsCategorie1.push(product_id);
//sendAffilae(keysMap.Categorie1.key, product);
} else if (keysMap.Categorie2.ids.includes(product_id)) {
amountCategorie2 = product.price * product.quantity;
productIdsCategorie2.push(product_id);
//sendAffilae(keysMap.Categorie2.key, product);
} else if (keysMap.Categorie3.ids.includes(product_id)) {
amountCategorie3 = product.price * product.quantity;
productIdsCategorie3.push(product_id);
//sendAffilae(keysMap.Categorie3.key, product);
} else if (keysMap.Categorie4.ids.includes(product_id)) {
amountCategorie4 = product.price * product.quantity;
productIdsCategorie4.push(product_id);
//sendAffilae(keysMap.Categorie4.key, product);
}
});

if (amountCategorie1 > 0) {
sendAffilae(keysMap.Categorie1.key, productIdsCategorie1, amountCategorie1);
}
if (amountCategorie2 > 0) {
sendAffilae(keysMap.Categorie2.key, productIdsCategorie2, amountCategorie2);
}
if (amountCategorie3 > 0) {
sendAffilae(keysMap.Categorie3.key, productIdsCategorie3, amountCategorie3);
}
if (amountCategorie4 > 0) {
sendAffilae(keysMap.Categorie4.key, productIdsCategorie4, amountCategorie4);
}

// Push conversion to Affilae
function sendAffilae(key, products, amount) {
var aeEvent = {
key: key,
Conversion: {
id: orderId,
amount: amount.toFixed(2),
payment: 'online',
voucher: coupon,
currency: currency,
product: products.join(';')
}
};

if (('AeTracker' in window) && typeof AeTracker.sendConversion === 'function') {
AeTracker.sendConversion(aeEvent);
} else {
(window.AE = window.AE || []).push(aeEvent);
}
}

Adapting the code to your shop

  1. Define your categories according to your needs, for example books, fashion, games, furniture.
  2. Map your product IDs. List all product IDs for each category, use them exactly as they appear in your DataLayer, and verify consistency with your available variables.
  3. Configure your Affilae KEYS. One unique key per category, in the format provided by your Affilae account manager. Testing is mandatory before going live.

Where to find your keys and your IDs

  1. In the sidebar, open Manage programs, then click your program name.
  2. Click Configuration.
  3. Open the Tracking tab.
  4. Expand the Integration via an Affilae plugin section: it shows the Program ID, the Rule ID, the Currency and the Key of each rule.
The Integration via an Affilae plugin section showing the Program ID, Rule ID, Currency and Key values
The Integration via an Affilae plugin section of the Tracking tab, where the values used in the code are shown.
Tip: create your commission rules first, one per category, then collect their key. One key matches one rule: if you add a category later, you will need a new rule and a new key.

Points of attention

  • Check your DataLayer structure before installing the tag.
  • Test with real orders.
  • Verify calculated amounts and the various category triggers.
  • A product missing from your ID lists triggers no conversion at all: keep those lists up to date every time you add references to your catalogue.

Related articles

Frequently asked
questions

Check the Program ID. That is the value tying the click script to your program. You find it in Manage programs, your program, Configuration, Tracking tab, Integration via an Affilae plugin section.

Check three things, in this order. The variables of your dataLayer, the product IDs you listed in the code, and the Affilae KEYS used for each category. A single wrong value among those three is enough to make the conversion disappear with no error message.

In your program configuration, Tracking tab, Integration via an Affilae plugin section. It shows the Program ID, the Rule ID, the Currency and the Key. The key format is provided by your Affilae account manager.

Yes. In Affilae, an event, here the sale of a product in a given category, corresponds to a commission rule, and therefore to a key. You create as many rules as there are categories to track.

No conversion is triggered for that product, since its ID matches none of the lists in the code. Remember to update those lists every time you add references to your catalogue.

No, testing is mandatory before going live. Place a real order per category, then check the calculated amounts and the trigger of each conversion. If in doubt, contact Affilae support with the details of your configurations.

Need help?

Stay up to date with the latest trends in affiliate marketing and never miss any of our articles.

Contact Us