Overview
When a visitor clicks a TikTok ad and lands on your site, TikTok appends ttclid to the URL. Affclix captures this alongside utk_click_id so conversions are attributed to both your affiliate and your TikTok campaign.
- ttclid auto-capture — stored in cookie + localStorage on landing automatically
- TikTok Pixel (browser-side) — fires CompletePayment from the thank-you page
- Events API (server-side) — sends events from your server, bypassing ad blockers
- Advanced Matching — hashed PII for improved attribution across devices
ttclid Capture
Affclix captures ttclid automatically after init(). The value is stored in a first-party cookie (cookieTTL days) and in localStorage as a fallback.
AffclixSDK.init({
trackingDomain: 't.yourdomain.com',
cookieDomain: '.yourdomain.com'
});
// Read captured ttclid at any time
var ttclid = AffclixSDK.getAttribution().ttclid;
console.log(ttclid); // e.g. "7eCi8zrR..." TikTok's ttclid is valid for 7 days. Set cookieTTL to 7 or less in AffclixSDK.init() to align with TikTok's attribution window and avoid crediting stale clicks.
Pixel Setup
Load the TikTok Pixel base code on all pages, then fire events on the order confirmation page using the Affclix SDK.
Add base pixel to all pages
Place the TikTok Pixel base code snippet inside <head> on every page.
Load Affclix SDK
AffclixSDK.init() captures ttclid and UTM params on each page load.
Fire CompletePayment on thank-you page
Use AffclixSDK.adPlatforms.tiktok.sendConversionEvent() on the order confirmation page only.
<!-- TikTok Pixel base code -->
<script>
!function(w,d,t){w.TiktokAnalyticsObject=t;var ttq=w[t]=w[t]||[];
ttq.methods=["page","track","identify","instances","debug","on","off",
"once","ready","alias","group","enableCookie","disableCookie"];
ttq.setAndDefer=function(t,e){t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}};
for(var i=0;i Send Conversion
Call sendConversionEvent() on the order confirmation page. It fires both the TikTok Pixel event and the Affclix postback.
// The Pixel ID comes from your ttq base code — no need to repeat it.
AffclixSDK.adPlatforms.tiktok.sendConversionEvent('CompletePayment', {
value: 99.00,
currency: 'USD',
order_id: 'ORDER-1001',
content_ids: ['SKU-42', 'SKU-99'],
content_type: 'product'
}); | Parameter | Type | Required | Description |
|---|---|---|---|
eventName (1st argument) | string | Yes | Standard event: CompletePayment, AddToCart, InitiateCheckout |
value | number | Yes | Conversion value |
currency | string | Yes | ISO 4217 currency code |
order_id | string | No | Used as event_id for deduplication with Events API |
content_ids | string[] | No | Product SKUs in the order |
content_type | string | No | product or product_group |
Events API (Server-side)
TikTok Events API sends conversion events directly from your server, bypassing iOS restrictions and ad blockers. Use it alongside the browser Pixel for maximum coverage.
TikTok recommends both browser Pixel and server Events API for every conversion. Pass the same event_id in both calls — TikTok deduplicates them automatically.
// 1. Configure a serverSideEndpoint at init — the SDK then POSTs the
// TikTok payload to YOUR server instead of calling ttq directly:
AffclixSDK.init({
trackingDomain: 't.yourdomain.com',
serverSideEndpoint: 'https://api.yourdomain.com/capi/forward'
});
AffclixSDK.adPlatforms.tiktok.sendConversionEvent('CompletePayment', {
value: 99.00, currency: 'USD', order_id: '{ORDER_ID}'
});
// 2. Your endpoint receives this payload — forward it to the TikTok
// Events API (business-api.tiktok.com) with your access token:
{
"platform": "tiktok",
"event": "CompletePayment",
"event_id": "d5f1c2...", // pass to TikTok for Pixel deduplication
"timestamp": "2026-07-16T12:00:00.000Z",
"context": { "page": { "url": "...", "referrer": "..." }, "user_agent": "..." },
"properties": { "value": 99.00, "currency": "USD", "order_id": "{ORDER_ID}", "ttclid": "{ttclid}" }
} Advanced Matching
Pass hashed customer data to improve TikTok's ability to match conversions, especially for users who have not consented to tracking or use cross-device journeys.
// Advanced matching goes through TikTok's own identify call —
// ttq normalises and SHA-256 hashes these values before transmission.
ttq.identify({
email: 'customer@example.com',
phone_number: '+919876543210'
});
AffclixSDK.adPlatforms.tiktok.sendConversionEvent('CompletePayment', {
value: 99.00,
currency: 'USD',
order_id: 'ORDER-1001'
}); All PII fields are SHA-256 hashed by the SDK before transmission. Raw values are never sent to Affclix or TikTok in plain text.
Deduplication
When both Pixel and Events API fire for the same order, TikTok uses event_id to count only one conversion. Always pass orderId as the event_id in both calls.
| Signal | Pixel (browser) | Events API (server) |
|---|---|---|
| event_id | orderId | orderId (must match) |
| event_name | CompletePayment | CompletePayment |
| ttclid | read from cookie | passed in payload |
| user data | hashed via setUserData() | hashed in server payload |
Testing
Use TikTok Ads Manager → Events → Test Events to verify your Pixel and Events API are receiving data correctly.
AffclixSDK.init({
trackingDomain: 't.yourdomain.com',
testMode: true,
debug: true
}); In TikTok Ads Manager go to Assets → Events → Manage → Web Events → Test Events. Enter your website URL and TikTok will detect Pixel and Events API calls in real time.