Guides
Events API
Send web, offline and CRM events with SHA-256 data, deduplicate with the Pixel and attribute sales to ads through the ttclid.
The Events API 2.0 receives the conversions that happen outside TikTok (a purchase on your site, an order closed in the CRM) and ties them to the ads. In Mimicr, an event with the ttclid of a click on a sandbox ad shows up in that ad's reports.
The ttclid path
- Someone taps the ad. TikTok appends
ttclidto the landing page URL. In the sandbox, thetraffic.clickaction or the /mimicr/click/{ad_id} page plays that role:
npx mimicr action tiktok-ads traffic.click adId=1700013373458754
{ "ok": true, "action": "traffic.click", "message": "Clique registrado: E.C.P.JKOubGTKTAK3Fp9-F31nqwAAAAMdHslkau2bb-JgWfRPwHKPq4-TVg", "data": { "ttclid": "E.C.P.JKOubGTKTAK3Fp9-F31nqwAAAAMdHslkau2bb-JgWfRPwHKPq4-TVg", "landingUrl": "https://popgas.example/pedido?ttclid=E.C.P.JKOubGTKTAK3Fp9-F31nqwAAAAMdHslkau2bb-JgWfRPwHKPq4-TVg" } }- Your landing page stores the
ttclid. - When the conversion happens, your server sends the event with that
ttclid.
Send events
curl --request POST \
--url https://tiktok-ads.mimicr.dev/open_api/v1.3/event/track/ \
--header 'Access-Token: <token>' \
--header 'Content-Type: application/json' \
--data '{
"event_source": "web",
"event_source_id": "X6R0U4QQZJSZ84ABSF9Q",
"data": [{
"event": "Purchase",
"event_time": 1793956720,
"event_id": "pedido-48213",
"user": {
"ttclid": "E.C.P.JKOubGTKTAK3Fp9-F31nqwAAAAMdHslkau2bb-JgWfRPwHKPq4-TVg",
"email": "13e2c3f390a91763c2b83e0e6222dfc3c967ef82fc86c3648b00a90d977490de"
},
"page": { "url": "https://popgas.example/pedido/obrigado" },
"properties": { "currency": "BRL", "value": 120.5 }
}]
}'{ "code": 0, "message": "OK", "request_id": "20261106124340B63AA0D4F8EFBC937D", "data": {} }| Field | Rule |
|---|---|
event_source | web (Pixel), offline or crm (event set). app is allowlist-only: 40118 |
event_source_id | The pixel_code (web) or the event set id (offline and CRM). Both are in GET /v1/tiktok-ads |
data | 1 to 1,000 events. Beyond that the whole request is refused |
event | Standard events (Purchase, CompleteRegistration, Lead, AddToCart, InitiateCheckout, SubmitForm…) or a custom name on web and CRM. Offline accepts standard ones only |
event_time | Unix seconds, in UTC. In Mimicr, at most 7 days in the past and 10 minutes in the future |
event_id | For deduplication with the browser Pixel |
user.email, user.phone, user.external_id | SHA-256 in lowercase hex, a string or a list. Unhashed: 40002 Invalid value for data.0.user.email: not a valid SHA256-hashed string. |
user.ttclid, ttp, ip, user_agent, locale | Not hashed. Without user.ttclid, Mimicr reads the ttclid= from page.url |
page.url | Required on web |
properties | currency, value, contents, content_type, content_ids, order_id… |
lead.lead_id | Required on CRM: a lead from the forms |
test_event_code | The source's test code; test events never reach reports |
Tokens
Two kinds of token work:
- a Marketing API token with scope 5 (Measurement) that reaches the Pixel's account;
- the Pixel's own Events API token, in
advertisers[].pixels[].events_tokenofGET /v1/tiktok-ads. It only works for that Pixel; thepixel.rotate_events_tokenaction issues another one and the old one starts answering 40105.
Errors with HTTP status
Unlike the Marketing API, the Events API answers 4xx, and error bodies have no data:
| HTTP | code | When |
|---|---|---|
| 400 | 40002 | Missing or invalid field, unhashed PII, more than 1,000 events. The message points at the first invalid event (data.1.user.email) |
| 400 | 40001 | No permission to operate pixel code: <code>: unknown source or out of the token's reach |
| 400 | 40105 | Unknown or revoked token |
| 401 | 40104 | No token |
| 401 | 40100 | Over the limit (1,000 events per second) |
Deduplication
The key is (event_source_id, event, event_id):
- a copy within 5 minutes is merged (fields missing from the first one are filled in);
- a copy within 48 hours is dropped;
- events without an
event_idare never deduplicated.
The response is always code 0; deduplication is invisible to the sender.
Attribution in Mimicr
TikTok does not publish how it attributes. Mimicr does this:
- a web event whose
ttclidcame from a click on an ad of the same account, within the ad group's click window (7 days by default), is attributed to that ad; - without a
ttclid, an event whose hashed e-mail or phone matches a lead of the account is attributed to the lead's ad (on CRM and offline, also bylead_id); - the rest is
unmatched: accepted, but left out of reports.
An attributed event counts at the click's date and hour: in conversion and result when it is the ad group's optimization_event, and always in the matching website metric (Purchase in complete_payment and value_per_complete_payment, CompleteRegistration in user_registration, Lead and SubmitForm in form). The real_time_* metrics count at the event's date.
To see each event's outcome:
npx mimicr get '/v1/tiktok-ads/events?limit=5'
The status is accepted, merged, deduplicated, test, unmatched or attributed. The conversion.set_outcome action forces attributed or unmatched by eventId or ttclid. The (hashed) e-mail reject@mimicr.dev is always unmatched.