Server events
Capture conversions your backend confirms, such as a completed payment.
Use server events for conversions your backend confirms: a deposit credited to an account, a KYC check passed, a perps account funded.
This page uses the Node.js SDK. From another language, send the same event with the HTTP API.
Identify in the browser too
Use the same user ID in the browser SDK and server events so Specify can connect conversions to the visitor's ad activity. You can also send events directly from the server using a wallet address.
Runnable example
node-typescript is this page as a working Node.js app.
1. Install the SDK
npm i @specify-sh/advertiser-sdk2. Capture the event
Call capture() once the conversion is confirmed, with the user ID your site identified.
import { capture } from '@specify-sh/advertiser-sdk/server';
export async function onPaymentConfirmed(order: Order) {
await capture({
advertiserKey: process.env.SPECIFY_ADVERTISER_KEY!,
event: 'purchase',
identity: order.userId,
dedupeKey: order.id
});
}await it in serverless functions, so the request finishes before the function stops. It settles within about 18 seconds even if Specify is unreachable.
Options
| Option | Required | Description |
|---|---|---|
advertiserKey | yes | Your advertiser key, which starts with sak_ |
event | yes | The event name, such as purchase |
identity | yes | The user ID your site passes to identify(), or a wallet address |
dedupeKey | no | Your own ID for this event, such as an order ID |
url | no | The page where the event happened, as an absolute URL |
apiUrl | no | Leave unset unless Specify gives you another API URL |
Avoid double counting
Pass a dedupeKey whenever the same event could be sent twice, such as from a webhook that retries. Events with the same name and dedupeKey count once. Without one, every call counts.
Errors
capture() throws ValidationError before sending anything when an option is invalid:
- an invalid advertiser key
- an empty event name
- an identity that is blank, contains
@, is longer than 256 bytes, or starts with0xwithout being a wallet address - a
urlthat isn't absolute, or adedupeKeythat is empty or longer than 256 characters - a request larger than 16 KiB
If Specify is unreachable, capture() still resolves so your handler can continue. A resolved call doesn't confirm delivery.
Catch ValidationError if the identity comes from data you don't control:
import { capture, ValidationError } from '@specify-sh/advertiser-sdk/server';
try {
await capture({ advertiserKey, event: 'purchase', identity: order.userId });
} catch (error) {
if (error instanceof ValidationError) {
console.error(error.message);
}
}