track()
Send a named event from any Node backend, fire-and-forget.
track() sends one event to Atune for a customer account. It works in any
Node 18+ runtime and needs atune 0.1.3 or later.
import { track } from "atune";
// Where your code already knows the customer account (team, org or company)
// and the signed-in user. Don't await it: tracking never delays the response.
void track("feature.report.generated", {
accountId: session.orgId,
userId: session.userId,
properties: { reportType: "activation" },
});Signature
track(event: string, input: TrackInput, options?: AtuneRequestOptions): Promise<void>
type TrackInput = {
accountId: string; // the customer you bill
userId?: string;
properties?: Record<string, unknown>;
subscription?: AtuneSubscription; // stage, plan, seats, mrr, currency, trialEndsAt
};Properties are stored as sent. Keep them to ids and categories: no special-category data, ID numbers, passwords, payment details or free text your users typed. See Identity, PII & the DPA.
Options: { apiKey, url, fetch, timeoutMs, retries }. apiKey and url fall back to
ATUNE_API_KEY and ATUNE_URL; timeoutMs defaults to 1000 and retries to 2.
Behavior
- Never throws. Network errors and timeouts are swallowed, so
void track(...)can't break a request. - Retries, without duplicates (0.1.6 and later). A network error, timeout,
429 or 5xx is retried up to
retriestimes with backoff. Each event carries amessageId, so Atune stores it once even when a retry repeats it. - Sends nothing without an event name, an
accountId, an API key or a URL. - Posts to
/api/v1/eventson yourATUNE_URLhost. See the events API.
On Next.js, the middleware already captures every
signed-in request. Use track() there only for named business events.
Busy servers: the queue
For a long-running server or worker that sends many events, use a queue
(0.1.6 and later). It batches up to 100 events per request to
/api/v1/events/batch (see the events API), retries with backoff, and keeps
events in memory while Atune is unreachable.
import { createAtuneQueue } from "atune";
const atune = createAtuneQueue({ maxQueueSize: 1000 }); // one per process
atune.track("feature.report.generated", { accountId: org.id, userId: user.id });
process.on("SIGTERM", () => void atune.close()); // send what is lefttrack()on the queue returnsfalsewhen the event was not queued: invalid, over 16 KB, no API key, or the queue is full.atune.stats()returns{ queued, sent, deduped, rejected, dropped, failed, retries }.- Options:
flushAt(20),flushIntervalMs(1000),maxQueueSize(1000),maxBatchSize(100),maxRetries(5),retryBaseMs(500),retryMaxMs(30000), plus thetrack()options. - The queue lives in memory. A crash loses what is still queued. On serverless,
await atune.flush()before the function returns, for example in Next.jsafter().