Node and other servers

Server-side tracking with our Node SDK and a Server key: what a trusted writer may set, batching and retries, the plain-HTTP recipe for other languages, and importing history.

Server-side tracking uses our own Node SDK, @intelligent-page/analytics-node, with a Server key (ipa_sec_…). A Server key is a trusted writer: it may set the distinct id directly, label the event's Source, write a person's profile and, on import, keep historical timestamps. It can also read every report in the Project and change its settings, so it lives in your server environment and never in a bundle, a mobile app or a repository. From a language we do not ship a package for, the same calls are one JSON POST; that recipe is further down.

At a glance

Note

The package is built in this repository; npm publish is a human release step that has not run yet. Until it does, build it from packages/analytics-node (node build.mjs) and vendor dist/, or use the plain HTTP calls below. They produce identical events, so moving to the package later changes no data.

What "trusted" buys you

did is the one that matters most day to day. A backend usually knows exactly who acted and has no anonymous id to reconcile, so it sets did and skips identity work entirely.

Install

npm install @intelligent-page/analytics-node

Init

import { createServerAnalytics } from '@intelligent-page/analytics-node';

export const analytics = createServerAnalytics({
  serverKey: process.env.ANALYTICS_SERVER_KEY,
  host: 'https://t.intelligent.page',
});

process.on('SIGTERM', () => analytics.close());

Passing a Project token here throws: it can neither import nor read, and the whole point of this package is the trusted path.

Track

analytics.track({ event: 'Order Paid', userId: 'user_1024', props: { revenue: 42.5, currency: 'GBP', items: 3 } });
analytics.track({ event: 'Order Placed', distinctId: 'shop-1', groupKey: 'shop', groupId: 'acme.myshopify.com' });

track returns nothing and never throws: it buffers in process and flushes at 50 events or after 2 seconds, so analytics can never slow down or fail the request that produced the event. Delivery problems arrive on onError, not on your request path. Give an event your own id when you have a stable one; otherwise the SDK derives a deterministic id from the event, the person, the timestamp and the properties, and the service inserts ON CONFLICT DO NOTHING, so a retry never double counts.

Identify, alias, group, profile

await analytics.identify({ distinctId: 'anon_9f2c41', userId: 'user_1024', traits: { plan: 'pro', email: 'ada@example.com' } });
await analytics.alias({ distinctId: 'user_1024', alias: 'legacy-42' });
await analytics.group({ distinctId: 'user_1024', groupKey: 'shop', groupId: 'acme.myshopify.com', traits: { name: 'Acme' } });
analytics.people.set('user_1024', { plan: 'growth' });

The three identity calls answer, so they are awaited: each returns { accepted, events } naming the reserved events it produced. people.set is fire-and-forget like track.

The same operations can ride a normal batch instead, which is better when you are already sending one:

{
  "v": 1,
  "events": [
    { "id": "…", "ts": "2026-09-28T09:15:00.000Z", "event": "$identify",
      "aid": "anon_9f2c41", "uid": "user_1024", "did": "user_1024" },
    { "id": "…", "ts": "2026-09-28T09:15:00.001Z", "event": "$set",
      "did": "user_1024", "props": { "plan": "pro", "email": "ada@example.com" } },
    { "id": "…", "ts": "2026-09-28T09:15:00.002Z", "event": "$group",
      "did": "user_1024", "props": { "$group_key": "company", "$group_id": "acme" } }
  ]
}

A $profile event is the trusted-only richer form: its profile object writes the known profile columns (email, name, plan, subscription status, signed-up and onboarded timestamps) rather than free properties. See Reserved events.

Delivery, and the three rules behind it

  1. Never await it on the request path. The SDK's track already guarantees this; keep the guarantee if you write your own client.
  2. Bound the retry queue. A refused batch waits 2 s, then 8 s, then 30 s, and is dropped with a warning; the queue is capped at 5 000 events and sheds the oldest batch past that. An unbounded retry queue turns a brief outage into an out-of-memory crash.
  3. Flush on shutdown. close() flushes, then refuses further events and clears every timer. The timer is unref'd, so a queued event never holds an idle process open. A SIGTERM handler is the difference between losing the last two seconds of events on every deploy and losing none.

pending() returns { queued, retrying, retryBatches, retryTimerArmed } if you want to expose the queue depth on a health endpoint. A non-2xx answer from an awaited call raises a ServerAnalyticsError carrying the status and the body.

Importing history

import { buildImportEvent } from '@intelligent-page/analytics-node';

const events = rows.map((row) => buildImportEvent({
  event: 'Order Paid',
  userId: row.customerId,
  ts: row.placedAt,                       // historical timestamps are kept, not clamped
  props: { revenue: row.total, currency: 'GBP' },
}));

const result = await analytics.import(events);
// { accepted, rejected, rateLimited, quotaExceeded }

import() posts to /v1/import in 2 000-event chunks, the service's per-request ceiling, and adds the answers up. A quota answer stops the run and comes back as quotaExceeded: true, so you can resume from the event after the accepted head.

The same call by hand:

curl -X POST https://t.intelligent.page/v1/import \
  -H 'content-type: application/json' \
  -H "Authorization: Bearer $ANALYTICS_SERVER_KEY" \
  -d '{"events":[{"id":"order-8821","ts":"2024-03-02T11:04:00.000Z",
       "event":"Order Paid","did":"user_88","source":"server",
       "props":{"revenue":19.99,"currency":"GBP"}}]}'
{ "accepted": 1, "rejected": 0 }

/v1/import keeps every event's ts exactly as sent. Use your own stable id per row (an order id, a row key) so a re-run after a failure is idempotent. Only /v1/ingest clamps timestamps to the last 24 hours.

Other languages

We do not ship a package for every runtime yet. The contract is one JSON POST, so any HTTP client does, and the events are indistinguishable from the ones the Node SDK sends:

import json, os, urllib.request, uuid
from datetime import datetime, timezone

def track(event, distinct_id, props=None):
    body = json.dumps({"v": 1, "events": [{
        "id": str(uuid.uuid4()),
        "ts": datetime.now(timezone.utc).isoformat().replace("+00:00", "Z"),
        "event": event, "did": distinct_id, "source": "server",
        "props": props or {},
    }]}).encode()
    req = urllib.request.Request(
        "https://t.intelligent.page/v1/ingest", data=body, method="POST",
        headers={"content-type": "application/json",
                 "authorization": "Bearer " + os.environ["ANALYTICS_SERVER_KEY"]})
    urllib.request.urlopen(req, timeout=5).read()
curl -X POST https://t.intelligent.page/v1/ingest \
  -H 'content-type: application/json' \
  -H "Authorization: Bearer $ANALYTICS_SERVER_KEY" \
  -d '{"v":1,"events":[{"id":"'"$(uuidgen)"'","ts":"'"$(date -u +%FT%TZ)"'",
       "event":"Order Paid","did":"user_1024","source":"server",
       "props":{"revenue":42.5,"currency":"GBP"}}]}'

Do the same batching the Node SDK does: a per-event HTTP call will hit the 6 000 events a minute limit on one key far sooner than you expect, and it costs a round trip per event.

Generated clients for Python, Go, Ruby, Java and PHP are described by packages/sdk-generate.sh, which runs openapi-generator against the service's own OpenAPI description. That script has not been run and no generated client exists yet, so the recipe above is the supported path for those languages today. When they land, their shapes will match the API reference exactly, because both come from the same spec.

Verify

curl -N https://t.intelligent.page/v1/live -H "Authorization: Bearer $ANALYTICS_SERVER_KEY"

Trigger the action in a staging environment with the stream open. Check that source reads server and that did is the id you meant: a wrong did is the most common server-side mistake, and it silently splits one person into two.

Next