This guide explains how to integrate Affise Web SDK with your WooCommerce store to track affiliate clicks and conversions (orders) without redirects.
What is Affise Web SDK?
The Affise Web SDK is a lightweight JavaScript library that tracks affiliate campaigns directly on your website. It offers:
No redirects: Faster page loads and better user experience.
Reliable tracking: Captures clicks and conversions accurately.
Privacy compliance: Works within data protection regulations.
🔍 Read more about Affise Web SDK here.
Prerequisites:
Affise account with an offer setup for your WooCommerce store. Make sure you have the Offer ID and know your Affise tracking domain (e.g., https://YOUR_DOMAIN.g2afse.com or similar) for the Web SDK script.
WooCommerce store (WordPress admin access) where you can add custom code or plugins.
A test affiliate tracking link for your offer (containing the offer_id and aff_id parameters) to simulate an affiliate click.
Integration flow:
The integration flow includes three steps:
Add Affise Web SDK script to WooCommerce
First, include the Affise Web SDK script in your WooCommerce site pages.
The script initializes the global ASDK object used for tracking. You should add it to all pages (usually in the <head> section) for it to capture affiliate clicks on a landing and conversions on thank-you page.
To add the script, do the following:
Use a plugin to insert header scripts (for example, Insert Headers and Footers or Code Snippets). This avoids editing theme files and works across any theme. Alternatively, you can manually add the script tag in your theme’s header.php (preferably via a child theme to preserve changes).
2. Get the Web SDK URL.
It’s usually in the format https://<your-tracking-domain>/websdk.js.
⚠️ Replace <your-tracking-domain> with the domain provided by Affise for tracking
3. Insert the script in the “Scripts in Header” section of your plugin or right before </head> in your theme.
<!-- Affise Web SDK script -->
<script src="https://YOUR_TRACKING_DOMAIN.g2afse.com/websdk.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Read affiliate link parameters from the URL
const offerId = ASDK.urlParameter('offer_id');
const affId = ASDK.urlParameter('aff_id');
// If this is an affiliate click (parameters present), record the click
if (offerId && affId) {
ASDK.click({
offer_id: offerId,
affiliate_id: affId,
user_agent: navigator.userAgent // optional, helps capture device info
})
.then(clickId => {
console.log('Affise click tracked:', clickId);
// Store offer ID for later use (e.g., conversion tracking)
localStorage.setItem('affise_offer_id', offerId);
})
.catch(error => {
console.error('Affise click tracking error:', error.message);
});
}
});
</script>
The <script src=".../websdk.js"> line loads the Affise SDK script from your tracking domain. Once loaded, the SDK is available globally as ASDK.
The inline script performs the following functions:
Checks for offer_id and affiliate_id in the URL.
Calls ASDK.click() to register a click in Affise (without a redirect).
Saves the offer_id in localStorage for later use (e.g., conversion tracking).
Set up conversion tracking
After capturing the click, track conversions on the WooCommerce “Order Received” page (thank-you page).
The SDK method ASDK.conversion({...}) sends a conversion event to Affise.
To set up conversions tracking, do the following:
1. Install a plugin to add to code to the action page ("Order" Recieved page)
🔎 You can use the Code snippets WordPress plugin to add the code.
2. Go to Code snippets > Add new > Add your custom code:
PHP snippet:
3. Paste the code below into the text area:
Add this PHP snippet:
add_action('woocommerce_thankyou', 'affise_track_conversion', 10, 1);
function affise_track_conversion($order_id) {
if (!$order_id) return;
$order = wc_get_order($order_id);
if (!$order) return;
$order_total = $order->get_total();
$order_currency = $order->get_currency();
$order_number = $order->get_order_number();
?>
<script>
document.addEventListener('DOMContentLoaded', function () {
const orderDetails = {
id: "<?php echo esc_js($order_number); ?>",
total: <?php echo number_format($order_total, 2, '.', ''); ?>,
currency: "<?php echo esc_js($order_currency); ?>",
};
let offerId = ASDK.urlParameter('offer_id');
if (!offerId) {
offerId = localStorage.getItem('affise_offer_id');
}
const clickId = offerId ? ASDK.clickId(offerId) : null;
if (clickId && offerId) {
ASDK.conversion({
click_id: clickId,
offer_id: offerId,
status: "1",
sum: orderDetails.total.toString(),
order_currency: orderDetails.currency,
comment: "Order " + orderDetails.id,
})
.then(() => {
console.log("Affise conversion tracked successfully");
})
.catch(error => {
console.error("Affise conversion tracking error:", error);
});
} else {
console.log("Affise conversion not fired (no affiliate data).");
}
});
</script>
<?php
}
How it works:
Gathers order ID, currency, total, and products.
Builds a JavaScript snippet on the thank-you page.
Retrieves the stored click ID using ASDK.clickId(offer_id).
Fires ASDK.conversion() if click ID is valid.
Install the snippet via:
Code Snippets plugin (preferred).
Or directly in functions.php (if using a child theme).
Test the integration
To make sure everything operates correctly, test your integration:
Set up your test:
Enable Cash on Delivery in WooCommerce.
Add a test product (e.g., “Test Item”, €10).
Use a test affiliate link like:
Test the flow:
Open the tracking link in Incognito.
Check console for Affise click tracked: [clickId]
Place an order.
On the thank-you page, check that Affise conversion tracked successfully.
In Affise Admin Panel > Statistics > Conversions, confirm click and conversion are recorded.
Troubleshooting
Issue | Possible fix |
No click | URL missing offer_id or wrong script domain |
No conversion | click_id not found or JS errors |
Conversion doesn’t appear | Delay, incorrect ID, or rejected by targeting |
Please contact the Affise Customer Support team regarding all raised questions via the e-mail: [email protected].




