Ad platforms and webshops

TikTok Events API for Shopify: setup and deduplication

The TikTok Events API sends Shopify purchases to TikTok from your server. Learn the events, ttclid and _ttp, event_id deduplication and testing.

·Updated ·10 min read·By the ROASaurus team

Key takeaways
  • The TikTok Events API sends conversion events from a server to TikTok, so a purchase does not depend on the TikTok pixel running in the shopper's browser.
  • TikTok renamed CompletePayment to Purchase but still accepts the old name; for deduplication, the pixel and the server must use the same name.
  • TikTok deduplicates a pixel event and a server event when both have the same event name and the same event_id, and it records the first copy it receives.
  • The click id ttclid, the _ttp cookie, hashed email and phone, the IP address and the user agent are the keys TikTok uses to match an event to a person.
  • Test with a test event code first, and disconnect the pixel in any other app that sends it, or TikTok counts purchases twice.

The TikTok Events API is TikTok's server-to-server connection for conversion data. Instead of relying only on the TikTok pixel in the shopper's browser, your store, or a tool such as ROASaurus, sends events like purchases straight to TikTok. TikTok recommends running the Events API next to the pixel and deduplicating the two with a shared event_id.

This guide covers what the Events API sends from a Shopify store, the Purchase and CompletePayment event names, the click id and cookie TikTok matches on, how deduplication works, how to test in TikTok Events Manager, and how to set it all up in ROASaurus.

What is the TikTok Events API?

The TikTok pixel is a script on your store. It fires events from the shopper's browser, so it only counts what happens while the script loads and runs. An ad blocker, a script error or a shopper who closes the tab before the order confirmation loads can all stop it.

The Events API sends the same kind of event from a server. On Shopify, the most dependable record of a purchase is the order itself. Shopify reports every paid order by webhook, whether or not the browser script ran. That is the idea behind server-side tracking on Shopify.

The two are not alternatives. TikTok's advice is to share events through both, keep them consistent along the shopping journey, and let TikTok remove the duplicates.

TikTok pixel (browser)
  • Runs in the shopper's browser
  • Can be stopped by ad blockers and script errors
  • Shares the IP address and user agent by default
  • Fires page views and browsing events as they happen
Events API (server)
  • Runs on a server, from your order data
  • Does not depend on a script loading in the browser
  • The sender must add the IP address and user agent
  • Sends every paid order, even when the pixel did not fire
TikTok recommends both: the pixel for browser signals, the Events API for every order, deduplicated with one event_id.

Which events does ROASaurus send to TikTok?

Four moments in a Shopify store matter for TikTok's optimization: a product view, an add to cart, the start of checkout and the purchase. ROASaurus sends all four to the Events API and fires the same four through the TikTok pixel, with the same event ids. Page views go through the pixel only.

Shopper actionTikTok eventPixel (browser)Events API (server)
Views a pagePage viewYesNo
Views a productViewContentYesYes
Adds to cartAddToCartYesYes
Starts checkoutInitiateCheckoutYes, with the checkout pixelYes
Completes an orderCompletePaymentYes, with the checkout pixelYes, from the order
Every event that goes both ways carries one event id, so TikTok can keep a single copy.

In the pixel settings you can untick server events you do not want to send, and add filters such as a country or a minimum order value.

Purchase or CompletePayment?

TikTok renamed its purchase event. The current name is Purchase. The old name, CompletePayment, still works: TikTok converts legacy names on its side, shows them under the new name in reporting, audiences and optimization, and says CompletePayment will be supported indefinitely. TikTok asks new pixel setups to use Purchase.

ROASaurus sends CompletePayment, in the pixel and in the Events API. In TikTok Events Manager and Ads Manager, those events show as Purchase. For deduplication, what counts is that both copies of a purchase use the same event name, and they do.

How does TikTok match an event to a shopper?

An event only helps your campaigns if TikTok can link it to the person who saw or clicked the ad. TikTok calls these identifiers match keys, and its Events API guide asks you to pass back all relevant match keys to increase match rates. Events Manager shows the result as an Event Match Quality score, a weighted average of how often each match key is present.

Match keyWhere it comes fromSent as
ttclidA click id TikTok adds to the landing page URL when someone clicks an adPlain value
_ttp cookieA first-party cookie of the TikTok pixel on your store's domainPlain value
EmailThe Shopify orderSHA-256 hash
PhoneThe Shopify orderSHA-256 hash
external_idThe Shopify customer id, or the ROASaurus visitor idSHA-256 hash
IP address and user agentThe shopper's checkout session or the orderPlain value
TikTok asks for email, phone and external_id to be hashed. The click id, cookie, IP address and user agent are sent as they are.

TikTok notes that the pixel shares the IP address and user agent by default, but the Events API needs them added by hand. ROASaurus takes them from the shopper's checkout session, or from the order if there was no session. Two other keys need attention on Shopify.

ttclid: the TikTok click id

When a shopper clicks a TikTok ad, TikTok adds ttclid to the landing page URL. If your store does not save it on that first page, it is gone by the time the order arrives, several pages later. ROASaurus reads ttclid on the landing page, stores it with the visitor id, writes it to the Shopify cart, and adds it to the server event when the order comes in.

_ttp: the pixel cookie

The _ttp cookie is a first-party cookie that the TikTok pixel uses on your domain. ROASaurus reads it on the storefront and in checkout and sends it as ttp in the server event. It is one more reason to keep the pixel running next to the Events API.

Example: a purchase as ROASaurus sends it to the Events API (hashes shortened)
{
  "event_source": "web",
  "event_source_id": "CXXXXXXXXXXXXXXXXXXX",
  "data": [{
    "event": "CompletePayment",
    "event_time": 1793016000,
    "event_id": "order-5512345678901",
    "user": {
      "email": "a3f1…9c2e",
      "phone": "7b40…11d8",
      "external_id": "e05c…4a7f",
      "ttclid": "E.C.P.v3…",
      "ttp": "2Xb7…",
      "ip": "203.0.113.24",
      "user_agent": "Mozilla/5.0 (iPhone; …)"
    },
    "page": { "url": "https://example-store.com/checkouts/…/thank-you" },
    "properties": {
      "currency": "USD",
      "value": 84,
      "content_type": "product",
      "contents": [{ "content_id": "44123456789", "content_name": "Linen shirt", "quantity": 2, "price": 42 }],
      "order_id": "5512345678901"
    }
  }]
}

How does deduplication work?

When the pixel and the Events API both report the same purchase, TikTok receives two events for one order. To keep only one, TikTok needs two values to be identical in both copies: the event name and the event_id. TikTok then records the first copy it receives for measurement and reporting, so the order counts once. This works for matching copies that arrive within a 48-hour window from the first one.

ROASaurus builds the event id for a purchase from the Shopify order id. The purchase from order 5512345678901 has the event id order-5512345678901, in the checkout pixel and on the server. Storefront events, such as product views and adds to cart, get a random id when they happen, and the browser copy and the server copy share it.

Checkout completedThe checkout pixel fires CompletePayment with event_id order-5512345678901.
Order paidShopify sends the paid order to ROASaurus by webhook.
Events APIROASaurus sends CompletePayment with the same event_id and hashed order data.
TikTokSame name and same event_id: one purchase is counted.
Two copies of one purchase reach TikTok. The shared event_id lets TikTok count it once.

Here is what that means for the numbers. Take an example store with 200 orders in a week. The pixel fires for 150 of them. The other 50 shoppers used an ad blocker, declined marketing cookies or left before the confirmation page loaded. The Events API sends all 200.

Purchase events TikTok records in one week (example store, 200 orders)
Pixel only
150
Events API only
200
Pixel and Events API, different ids
350
Pixel and Events API, shared event_id
200
Without a shared event_id, 150 orders are counted twice. With it, TikTok records each of the 200 orders once.

The 350 is the number to worry about. It would make TikTok's purchase count, and the ROAS based on it, 75% higher than reality, because 350 ÷ 200 = 1.75. TikTok also uses these events for optimization and targeting, so its bidding would learn from 150 purchases that did not happen.

Why do purchases get counted twice on Shopify?

Double counting happens when TikTok receives two copies of a purchase that it cannot match. Check these causes before you trust a jump in TikTok purchases:

  • Two tools send the same pixel. The TikTok sales channel app on Shopify can also send events for your pixel. Its event ids do not match the ids ROASaurus uses, so TikTok counts each order twice. Disconnect the pixel in that app.
  • The pixel is also in your theme code. A pixel snippet pasted into the theme fires its own events without your event ids. Remove it and let one tool load the pixel.
  • One side has no event_id. A server purchase without an event_id, or with a new random id, cannot be matched to the pixel copy.
  • The event names differ. TikTok deduplicates only identical events. Both copies of a purchase must use the same event name.

The help article on double counting walks through the same checks for Meta and the other platforms.

How do you test the Events API in TikTok Events Manager?

TikTok Events Manager has a Test events tab for both browser and server events. Use it before you rely on the data:

  1. Copy a test event code

    In TikTok Events Manager, open your pixel and go to Test events. Copy the test event code.

  2. Paste it in ROASaurus

    Open Tracking & platforms, edit the TikTok pixel and paste the code in the Test event code field. Server events now carry it.

  3. Place a test order

    Visit your store, view a product, add it to the cart and complete an order.

  4. Check both sides

    In Test events, filter on browser and on server events. You should see the purchase from both. In ROASaurus, the Event log shows each server delivery as sent or failed.

  5. Remove the test code

    Delete the test event code when you are done, so your live server events are no longer sent as test events.

TikTok can answer a request with HTTP 200 and still reject the event, with an error code in the response body. ROASaurus reads that code, so a rejected event shows as failed in the Event log instead of passing silently.

After a day of live traffic, open the pixel's overview in Events Manager. It lists each event with its connection method, Event Match Quality score and when it was last received. The event details include matching and deduplication information, and Diagnostics lists quality issues with guidance on how to fix them.

How to set up the TikTok Events API on Shopify with ROASaurus

You need a Shopify store with the ROASaurus app and access to TikTok Events Manager. The TikTok integration page lists every field ROASaurus sends.

  1. Connect your Shopify store

    Go to Add a store › Shopify, click Install app and switch on the ROASaurus app embed in the theme editor. The embed captures ttclid and the _ttp cookie on every page. The Shopify setup guide shows each step.

  2. Add the checkout pixel

    In Shopify admin › Settings › Customer events, add a custom pixel named ROASaurus and paste the snippet from your Tracking & platforms page. It fires the TikTok pixel in checkout, including the browser copy of the purchase.

  3. Create an access token

    In TikTok Events Manager, open your pixel and generate an Events API access token in its settings. Copy the token and the pixel code.

  4. Add the TikTok pixel in ROASaurus

    Go to Tracking & platforms, click Add pixel on the TikTok card and fill in Pixel code and Events API access token. Keep Also load the browser pixel (recommended, deduplicated) ticked, so browser and server events share ids.

  5. Add spend (optional)

    Fill in Advertiser ID for spend and a Marketing API token. ROASaurus then imports TikTok spend, so TikTok campaigns show ROAS and CPA next to your other channels.

  6. Test, then go live

    Send a test order with a test event code as described above, then remove the code.

With Respect visitor consent on, which is the default, ROASaurus follows the shopper's choice in Shopify's cookie banner. When a shopper declines marketing cookies, ROASaurus does not load the TikTok pixel for them, sets no visitor id, so their clicks are not linked to them, and does not send their browsing events to TikTok. Their paid order is still sent to the Events API from the server, with hashed order data and the order's IP address and user agent, but without ttclid or _ttp. The consent and privacy guide explains what is stored and sent.

With spend synced, TikTok campaigns appear in attribution reports next to Meta, and creative analytics adds TikTok's video stats per ad. ROASaurus credits orders to the ad clicks and UTMs it recorded, and counts view-through conversions only as a modelled estimate in its Clicks & views model, so its totals usually differ from TikTok Ads Manager. For the other server-side platforms, see the Pinterest Conversions API guide and the Meta Conversions API guide.

Sources

  1. TikTok For Business: About Events API
  2. TikTok Ads Manager: About Event Deduplication
  3. TikTok Ads Manager: How to Adopt TikTok's Updated Standard Events
  4. TikTok Ads Manager: How to set up matching events with Events API
  5. TikTok Ads Manager: About diagnostic and monitoring tools in TikTok Events Manager

In ROASaurus

Keep reading

Ad platforms and webshopsCash on delivery conversion tracking and external checkoutsCash on delivery conversion tracking: why pixels miss COD and external checkout orders, when to send the purchase, and how to handle refused orders.Ad platforms and webshopsCCV Shop conversion tracking: a setup guideCCV Shop conversion tracking: send paid orders to Meta and TikTok with a signed webhook, link them to ad clicks, set up, test and handle late payments.Ad platforms and webshopsGoogle Ads enhanced conversions on ShopifyEnhanced conversions add hashed customer data to Google Ads purchases on Shopify. How they work, how they differ from offline imports, and the setup.
FAQ

Questions, answered

Is CompletePayment the same as Purchase on TikTok?

Yes. CompletePayment is the legacy name of TikTok's purchase event. TikTok converts it on its side, shows it as Purchase in reporting and says it will keep supporting the old name.

Do I still need the TikTok pixel if I use the Events API?

TikTok recommends using both. The pixel adds browser signals such as the _ttp cookie, the Events API sends every order, and a shared event_id stops TikTok from counting a purchase twice.

What is ttclid?

ttclid is the click id TikTok adds to your landing page URL when someone clicks an ad. Store it when the shopper lands and send it with the purchase, so TikTok can link the order to the click.

How long does TikTok wait to deduplicate events?

TikTok deduplicates events with the same event name and event_id that arrive within a 48-hour window from the first one. It records the first copy it receives for measurement and reporting.

Do I need the TikTok app on Shopify as well?

No. If you keep it, disconnect the pixel in the TikTok app. Its events have different ids, so TikTok would count each purchase twice.

Are purchases still sent when a shopper declines cookies?

With Respect visitor consent on, ROASaurus does not load the pixel or link click ids to that shopper. The paid order is still sent server-side with hashed order data and the order's IP address and user agent.

Every sale, traced to the ad that earned it

Server-side tracking, profit and lifetime value in one app. 14-day free trial, no credit card.

Start your free trial →