Article

Tracking – Product categorization

Notes:
  • Advanced integration
  • Mastery of the e-commerce DataLayer
  • Knowledge of GTM variables and their structure
  • JavaScript skills for customization
  • Access to product IDs in the e-commerce system

Product-category integration is an advanced solution that lets you segment and track conversions based on the types of products purchased.

What is a product categorization integration?

This integration consists of:

  • Segmenting products by business categories (e.g., 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
Technical prerequisites
Required configuration
  • E-commerce Data Layer correctly configured
  • Available variables
Integration is possible via manual implementation and via GTM.
  • 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);
}
}
Custom configuration
Define your categories according to your needs.


Example: Books, fashion, games, furniture, etc.

Map your product IDs
  • List all product IDs for each category
  • Use the IDs exactly as they appear in your DataLayer
  • Verify consistency with your available variables in the DataLayer
Configure your Affilae KEYS
  • One unique key per category
  • Format provided by your Affilae account manager
  • Testing is mandatory before going live

To find these elements, go to your program settings ➜ tracking ➜ integration via an Affilae module.

Points of attention
Data validation
  • Check your DataLayer structure.
  • Test with real orders.
  • Verify calculated amounts and the various category triggers.
Help
Tracking not working?
  • Untracked clicks: check the Program_ID
  • Missing conversions: verify dataLayer variables, product IDs, and KEYS.
Support
  • Test step by step
  • 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