TikTok Ads Integration

Capture ttclid on landing, attribute affiliate conversions, and send CompletePayment events to the TikTok Pixel and Events API — with Advanced Matching and server-side deduplication.

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.

JavaScript
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 Click ID Lifetime

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.

01

Add base pixel to all pages

Place the TikTok Pixel base code snippet inside <head> on every page.

02

Load Affclix SDK

AffclixSDK.init() captures ttclid and UTM params on each page load.

03

Fire CompletePayment on thank-you page

Use AffclixSDK.adPlatforms.tiktok.sendConversionEvent() on the order confirmation page only.

HTML (all pages, inside &lt;head&gt;)
<!-- 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.

JavaScript
// 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'
});
ParameterTypeRequiredDescription
eventName (1st argument)stringYesStandard event: CompletePayment, AddToCart, InitiateCheckout
valuenumberYesConversion value
currencystringYesISO 4217 currency code
order_idstringNoUsed as event_id for deduplication with Events API
content_idsstring[]NoProduct SKUs in the order
content_typestringNoproduct 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.

Pixel + Events API together

TikTok recommends both browser Pixel and server Events API for every conversion. Pass the same event_id in both calls — TikTok deduplicates them automatically.

HTTPS POST (from your server)
// 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.

JavaScript
// 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'
});
Hashing

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.

SignalPixel (browser)Events API (server)
event_idorderIdorderId (must match)
event_nameCompletePaymentCompletePayment
ttclidread from cookiepassed in payload
user datahashed 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.

JavaScript
AffclixSDK.init({
  trackingDomain: 't.yourdomain.com',
  testMode:       true,
  debug:          true
});
Test Event Tool

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.

Rate this article
★★★★★
Thanks for rating!

Was this article helpful?