AffiseSDK is a lightweight JavaScript library for tracking affiliate marketing campaigns in web applications. It enables seamless integration with the Affise platform to track user interactions without redirecting through third-party tracking systems.
Key features:
- Client-side click generation without redirecting users
- Conversion tracking with support for product feeds
- Multiple storage mechanisms with fallbacks for browser restrictions
- Cross-browser compatibility with built-in polyfills
npm run build<script src="path/to/bundle.js"></script>After including the script, the SDK will be available globally as ASDK.
Configure the SDK with your tracking domain before using it:
<!-- Load the SDK -->
<script src="https://{your-tracking-domain}/websdk.js"></script>The click() method generates a click without redirecting the user, ideal for landing pages:
// Basic click tracking
ASDK.click({
offer_id: 'OFFER123', // Required
affiliate_id: 'AFF456' // Required
})
.then(clickId => {
console.log('Click tracked successfully:', clickId);
})
.catch(error => {
console.error('Error tracking click:', error);
});The conversion() method tracks when a user completes a desired action (purchase, signup, etc.):
// Basic conversion tracking using click ID
ASDK.conversion({
click_id: ASDK.clickId('OFFER123'), // Get the stored click ID for this offer
offer_id: 'OFFER123',
status: '1', // 1 = confirmed
sum: '99.99'
})
.then(() => {
console.log('Conversion tracked successfully');
})
.catch(error => {
console.error('Error tracking conversion:', error);
});
// Alternative: conversion tracking using promo code
ASDK.conversion({
promo_code: 'SUMMER20',
offer_id: 'OFFER123',
status: '1',
sum: '99.99'
})
.then(() => {
console.log('Conversion tracked successfully');
})
.catch(error => {
console.error('Error tracking conversion:', error);
});document.addEventListener('DOMContentLoaded', function() {
// 1. Get tracking parameters from URL
const offerId = ASDK.urlParameter('offer_id') || 'DEFAULT_OFFER';
const affiliateId = ASDK.urlParameter('aff_id') || 'DEFAULT_AFFILIATE';
// 2. Generate a click
ASDK.click({
offer_id: offerId,
affiliate_id: affiliateId,
user_agent: navigator.userAgent
})
.then(clickId => {
console.log('Tracking initialized:', clickId);
})
.catch(error => {
console.error('Tracking error:', error.message);
});
});document.addEventListener('DOMContentLoaded', function() {
// 1. Get order information
const orderDetails = {
id: 'ORD-12345',
total: 149.99,
currency: 'USD',
products: [
{ id: 'SKU001', name: 'Product 1', price: 99.99, quantity: 1 },
{ id: 'SKU002', name: 'Product 2', price: 24.99, quantity: 2 }
]
};
// 2. Get the offer ID and click ID
const offerId = ASDK.urlParameter('offer_id') || 'DEFAULT_OFFER';
const clickId = ASDK.clickId(offerId);
// 3. Track the conversion with product feed
ASDK.conversion({
click_id: clickId,
offer_id: offerId,
status: '1', // 1 = confirmed
sum: orderDetails.total.toString(),
order_currency: orderDetails.currency,
comment: `Order ${orderDetails.id}`,
items: orderDetails.products.map(product => ({
order_id: orderDetails.id,
sku: product.id,
quantity: product.quantity.toString(),
price: product.price.toString()
}))
})
.then(() => {
console.log('Conversion tracked successfully');
})
.catch(error => {
console.error('Error tracking conversion:', error);
});
});ASDK.click({
offer_id: 'OFFER123',
affiliate_id: 'AFF456'
})
.then(clickId => {
console.log('Click tracked successfully:', clickId);
})
.catch(error => {
// Handle specific error types
switch(error.code) {
case 'NETWORK_ERROR':
console.error('Network unavailable:', error.message);
// Retry logic or offline handling
break;
case 'SERVER_ERROR':
console.error('Server error:', error.details.status);
// Log to your monitoring system
break;
case 'MISSING_REQUIRED_PARAMS':
console.error('Missing parameters:', error.details.provided);
// Show feedback about missing data
break;
default:
console.error('Error tracking click:', error.message);
}
});| Parameter | Type | Description |
|---|---|---|
| tracking_domain | string | The domain used for tracking clicks and conversions |
The click() method accepts an options object with the following parameters:
| Parameter | Type | Description | API Parameter |
|---|---|---|---|
| offer_id | string | Required. Identifier for the offer | offer_id |
| affiliate_id | string | Required. Identifier for the affiliate | pid |
| Parameter | Type | Description | API Parameter |
|---|---|---|---|
| tracking_domain | string | Override the default tracking domain | - |
| ip | string | User's IP address | ip |
| user_agent | string | User's browser user agent string | ua |
| ref_id | string | Reference ID | ref_id |
| ref_android_id | string | Android reference ID | ref_android_id |
| ref_device_id | string | Device reference ID | ref_device_id |
| mac_address | string | MAC address | mac_address |
| os_id | string | Operating system ID | os_id |
| user_id | string | User ID | user_id |
| ext1 | string | Extra parameter 1 | ext1 |
| ext2 | string | Extra parameter 2 | ext2 |
| ext3 | string | Extra parameter 3 | ext3 |
| imp_id | string | Impression ID | imp_id |
| unid | string | Unique identifier | unid |
| fbclid | string | Facebook click ID | fbclid |
| landing_id | string | Landing page ID | l |
| sub1 | string | Custom sub-parameter 1 | sub1 |
| sub2 | string | Custom sub-parameter 2 | sub2 |
| sub3 | string | Custom sub-parameter 3 | sub3 |
| sub4 | string | Custom sub-parameter 4 | sub4 |
| sub5 | string | Custom sub-parameter 5 | sub5 |
Note: sub6 through sub30 are also supported with the same pattern.
The conversion() method accepts an options object with the following parameters:
| Parameter | Type | Description | API Parameter |
|---|---|---|---|
| click_id | string | The click ID (obtained via SDK) | afclick |
| promo_code | string | Promotion code (alternative to click_id) | promo_code |
| Parameter | Type | Description | API Parameter |
|---|---|---|---|
| tracking_domain | string | Override the default tracking domain | - |
| offer_id | string | Identifier for the offer | offer_id |
| status | string | Conversion status (see status codes below) | afstatus |
| secure | string | Security token for postback validation | afsecure |
| comment | string | Additional comment about the conversion | afcomment |
| action_id | string | External conversion ID | afid |
| sum | string | Conversion amount | afprice |
| goal | string | Conversion goal identifier | afgoal |
| order_sum | string | Total order amount (for updates) | order_sum |
| order_currency | string | Order currency | order_currency |
| user_id | string | User identifier | user_id |
| custom_field1 | string | Custom field 1 | custom_field1 |
| custom_field2 | string | Custom field 2 | custom_field2 |
| custom_field3 | string | Custom field 3 | custom_field3 |
| custom_field4 | string | Custom field 4 | custom_field4 |
| custom_field5 | string | Custom field 5 | custom_field5 |
Note: custom_field6 through custom_field15 are also supported with the same pattern.
| Value | Description |
|---|---|
| 1 | Confirmed |
| 2 | Pending |
| 3 | Declined |
| 5 | Hold |
Each item in the items array should be an object with the following properties:
{
order_id: string, // Order identifier
sku: string, // Product SKU
quantity: string, // Product quantity
price: string // Product price
}| Method | Description |
|---|---|
| ASDK.urlParameter(name) | Get the value of a URL parameter by name |
| ASDK.clickId(offerId) | Get the stored click ID for a specific offer ID |
Symptoms: No click ID returned, Promise rejected.
Solutions:
- Verify required parameters
offer_idandaffiliate_idare provided - Check that the tracking domain is correctly configured
- Verify network connectivity to the tracking domain
- Check browser console for specific error messages
Symptoms: Click generated but not available when using ASDK.clickId().
Solutions:
- Check if cookies are being blocked by the browser
- Verify your domain is not in Incognito/Private mode
- Ensure the offer ID matches between click and retrieval
Symptoms: Conversion method completes but no conversion appears in dashboard.
Solutions:
- Verify you're providing either a valid
click_idorpromo_code - Check if the click ID matches the one from the original click
- Ensure the
offer_idmatches the one used for the click - Verify status code is correct (use '1' for confirmed)
The SDK uses multiple storage mechanisms with fallbacks:
- Cookies (primary storage)
- localStorage (secondary storage)
- sessionStorage (fallback)
If one mechanism fails, the SDK will try the next one automatically.
The SDK includes polyfills for modern JavaScript features, ensuring compatibility with:
- Chrome 45+
- Firefox 38+
- Safari 9+
- Edge 12+
- Internet Explorer 11
- The SDK stores data in cookies and browser storage, which are subject to browser policies
- Modern browsers restrict third-party cookies, which may affect cross-domain tracking
- The SDK implements a robust storage approach to work around restrictions when possible
- For environments with strict privacy settings, consider additional server-side tracking