Appearance
Sending from your server
Browser events can be blocked by ad blockers or forged by anyone who opens the developer console. For events that matter, such as purchases, refunds or subscription changes, send them from your backend.
Authentication
Server requests use your secret key, starting with sk_, in the Authorization header. There's no origin check.
Keep the secret key secret
Never put the secret key in browser code, a mobile app, or a public repository. Anyone with it can send events as your site. Load it from an environment variable on your server.
Example
POST a batch to the same endpoint the browser uses. Leave out the key field.
js
import { ulid } from 'ulid' // npm install ulid
const res = await fetch('https://INGEST_HOST/v1/batch', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.VECTELLE_SECRET_KEY}`,
},
body: JSON.stringify({
sdk: { name: 'my-backend', version: '1.0.0' },
sent_at: new Date().toISOString(),
context: {
anonymous_id: `user:${order.userId}`,
user_id: order.userId,
session_id: 'server',
},
events: [
{
event_id: ulid(),
name: 'purchase',
ts: order.paidAt.toISOString(),
properties: {
order_id: order.id,
value: order.total,
currency: order.currency,
items: order.lines.map((l) => ({ item_id: l.sku, price: l.price, quantity: l.qty })),
},
},
],
}),
})
if (res.status !== 202) {
// 429 and 503: retry later with the same event_id. Other errors won't succeed on retry.
}Fields you provide
event_id: a ULID you generate. If you retry a request, reuse the same id: duplicates are stored once.context.anonymous_idandcontext.session_id: required. Any non-empty string up to 128 characters works on the server.ts: when the event happened, as an ISO 8601 timestamp. Events more than 7 days old are rejected.
A batch can hold up to 100 events and 64 KB. See the HTTP API reference for every field, limit and response.