All guides
TikTok35 min· Advanced

Set up TikTok Pixel + Events API via sGTM

Install the TikTok Pixel through GTM web, then add the TikTok Events API in sGTM using TikTok's official gtm-template-eapi. Includes ttclid capture, dedupe, and match-strength verification.

Before you start — you'll need
  • TikTok Ads Manager → Events Manager access
  • TikTok Pixel Code + Access Token
  • Server-side GTM container on a first-party subdomain
By the end you'll have
  • TikTok Pixel firing PageView + ecommerce events
  • Events API mirroring server-side with ttclid + hashed PII
  • Match strength 'Good' in TikTok Diagnostics
Step 1

Capture ttclid on landing

TikTok appends ttclid to every ad click. You must capture it before the user navigates away.

(function () {
  var p = new URLSearchParams(window.location.search);
  var ttclid = p.get("ttclid");
  if (ttclid) {
    document.cookie = "_ttclid=" + ttclid + ";path=/;max-age=" + 60*60*24*30 + ";SameSite=Lax";
  }
})();
Tip: Fire this before GTM if possible — first-party cookie set on the very first hit.
Step 2

Install TikTok Pixel via GTM web

GTM web → Templates → Gallery → 'TikTok Pixel' by tiktok → Add. Tag → New → TikTok Pixel. Pixel Code: C-XXXXXXXXX. Action: Init & PageView. Trigger: All Pages.

Add per-event tags for ViewContent, AddToCart, InitiateCheckout, CompletePayment. Map value, currency, content_id, content_type='product'.

Tip: Generate event_id (UUID) for every conversion and pass it in both the Pixel and the EAPI tag.
Step 3

Import the official EAPI template in sGTM

Download the latest template.tpl from tiktok/gtm-template-eapi. In sGTM → Templates → Tag Templates → New → ⋮ menu → Import. Pick the .tpl file. Save.

Step 4

Create the Events API tag

Tags → New → TikTok Events API (your imported template). Paste Pixel Code + Access Token. Event: CompletePayment. Map:

· email, phone_number (raw — template hashes) · ttclid from cookie / event data · ttp from _ttp cookie · ip, user_agent from event · event_id from event data

Trigger: Custom Event matching the forwarded event name.

Step 5

Verify in TikTok Events Manager

TikTok Events Manager → your pixel → Diagnostics. Send 5–10 test events. Within an hour:

· Deduplication rate should be >90% (means Pixel + EAPI matched). · Match strength per event should be ≥ Good.

If match strength is Low, you're missing hashed PII or the IP.

Common pitfalls
  • Currency defaults to USD — set it explicitly on every event or revenue will be miscounted.
  • TikTok's event names differ from GA4's — map them per tag (AddToCart vs add_to_cart).
  • ttclid lifetime is short — capture into a 1P cookie on landing or you'll lose attribution.
  • Not passing event_id from the same source on Pixel + EAPI — no dedupe, doubled conversions.
Official references
Keep going