DYDouyin setup
ads.conversions.track() call fans the event out to Douyin server-side — no per-platform code.Setup guide
Overview
adscapi posts server-side conversion callbacks to Ocean Engine, the ad platform behind
Douyin (抖音) and Toutiao (今日头条). This is the landing-page ("H5") 转化回传
(conversion callback) API. Attribution is entirely callback-keyed: every ad click
lands on your page with a click token (clickid) in the URL. You capture that token,
adscapi carries it as event.clickIds.clickid, and it is sent back as
context.ad.callback when the visitor converts. Ocean Engine has no other way to match
the conversion, so no hashed email/phone and no API secret are used — the callback
token is the whole identity.
Prerequisites
- An Ocean Engine (巨量引擎) advertising account.
- An event asset ("事件资产") set up in Event Manager (事件管理).
- Your landing page must capture the click token from the ad URL macro
__CLICKID__and pass it into adscapi asclickIds.clickidon the conversion event.
1. Create an account
- Go to https://www.oceanengine.com/ and register a 巨量引擎 advertiser account.
- Open Event Manager at https://event-manager.oceanengine.com/.
- Create a landing-page ("落地页/H5") event asset for your site.
2. Get your credentials
Ocean Engine's landing-page callback endpoint is unauthenticated — the click token
you send in context.ad.callback both routes and attributes the event, so there is no
API key to fetch. The only real setup is capturing that token on your page. adscapi
still needs one opt-in switch, DOUYIN_ENABLED, so it never fans out to Ocean Engine for
an account that has not turned the destination on.
| Secret | Where to get it |
|---|---|
DOUYIN_ENABLED |
Not a credential. Set it to any non-empty value (e.g. 1) to enable the Douyin destination. |
3. Configure adscapi
export DOUYIN_ENABLED=1
Then make sure each conversion event carries the click token:
// on the landing page, read the clickid the ad appended to the URL, then later:
adscapi.track({
name: 'purchase',
value: 100,
currency: 'CNY',
clickIds: { clickid: capturedClickId },
consent: { adUserData: true, adPersonalization: true },
});
Without clickIds.clickid (or without adPersonalization consent), the Douyin
dispatcher no-ops — there is nothing to attribute.
4. Verify
adscapi verify --platform douyin
Douyin has no live credential check (there is no token to test); verification only confirms the platform is registered. Confirm real delivery in Event Manager's event debugging view (事件调试) after firing a test conversion with a valid click token.
5. Event mapping
adscapi's canonical events map to Ocean Engine's event_type values (from events.ts).
Unmapped names pass through unchanged.
| Canonical | Ocean Engine event_type |
|---|---|
| purchase | purchase |
| lead | form |
| signup | active_register |
| checkout_created | initiate_checkout |
| page_view | page_view |
Troubleshooting
- Nothing arrives / event no-ops — the click token is missing. Confirm your landing
page captured
__CLICKID__and passed it asclickIds.clickid, and that the visitor grantedadPersonalizationconsent. HTTP 4xx— the callback token is expired or malformed, the timestamp is out of range, or theevent_typeis not one Ocean Engine recognizes. Thetimestampfield is UNIX epoch milliseconds, not seconds.- Common gotcha — click tokens are short-lived. Fire the conversion callback soon after the click; a stale token will not match.
1. Install adscapi
npm install adscapi # or run without installing: npx adscapi platforms
2. Get Douyin's tokens
Douyin activates once all of these are set. Run npx adscapi platforms to see them, then get each value from Douyin’s ads or events dashboard.
DOUYIN_ENABLED3. Set them for adscapi
Export the tokens in the environment that runs your server or the adscapi CLI.
export DOUYIN_ENABLED="…"
4. Verify
check confirms the secrets are present; verify calls Douyin’s API to confirm they are valid.
npx adscapi check npx adscapi verify --platform douyin
5. Track a conversion
One call, sent to Douyin and every other configured platform. Pass raw email — adscapi hashes per platform. Consent is required.
import { createAdscapi } from 'adscapi';
const ads = createAdscapi();
const results = await ads.conversions.track({
name: 'purchase',
value: 49,
currency: 'USD',
user: { email: 'buyer@example.com' },
consent: { adUserData: true, adPersonalization: true },
});See the exact request on the Douyin payload preview.