Specify docs

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-sdk

2. Capture the event

Call capture() once the conversion is confirmed, with the user ID your site identified.

payments.ts
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

OptionRequiredDescription
advertiserKeyyesYour advertiser key, which starts with sak_
eventyesThe event name, such as purchase
identityyesThe user ID your site passes to identify(), or a wallet address
dedupeKeynoYour own ID for this event, such as an order ID
urlnoThe page where the event happened, as an absolute URL
apiUrlnoLeave 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 with 0x without being a wallet address
  • a url that isn't absolute, or a dedupeKey that 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:

payments.ts
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);
  }
}

Next steps

On this page