Skip to content

SDKs

@hostpog/js for browsers and @hostpog/node for servers. Both send to HostPog ingestion with a write-only project key.

The packages build from this repository (packages/sdk-js, packages/sdk-node). They are not published to npm yet; until then use a workspace dependency or pnpm pack.

Browser

import hostpog from "@hostpog/js";

hostpog.init("hp_pk_...", {
  host: "https://ingest.example.com",
  capturePageviews: true,     // default: $pageview on load + SPA navigation
  autocaptureClicks: false,   // default off; never captures input values or text
  optOutByDefault: false,     // set true to wait for consent → hostpog.optIn()
  allowedQueryParams: [],     // query strings are stripped except utm_*
});

hostpog.capture("signed_up", { plan: "free" });
hostpog.identify("user_123", { email: "user@example.com" });
hostpog.reset();      // on logout
hostpog.optOut();     // clears the queue and stops capture
await hostpog.flush();
  • Events are batched (20 or every 3 s), queued in localStorage (max 500) and flushed with sendBeacon when the page is hidden.
  • Retries with exponential backoff on network errors, 429 and 5xx; other 4xx responses are dropped.
  • Each event has a UUID; the server de-duplicates retries.
  • Elements inside [data-hp-no-capture] (or your blockSelector) are never autocaptured.

Node

import { HostPogNode } from "@hostpog/node";

const hostpog = new HostPogNode("hp_pk_...", { host: "https://ingest.example.com" });
hostpog.capture({ distinctId: "user_123", event: "invoice_paid", properties: { amount: 20 } });
hostpog.identify({ distinctId: "user_123", anonymousId: "anon-abc", properties: { plan: "team" } });
hostpog.captureException(err, "user_123");   // $exception with a stable fingerprint
await hostpog.shutdown();

HTTP API

POST /v1/batch    { "api_key": "hp_pk_...", "batch": [ { "uuid", "event", "distinct_id", "timestamp?", "properties?" } ] }
POST /v1/capture  (single event; key in Authorization: Bearer hp_pk_...)
  • Limits: 1 MB per request, 500 events per batch, 64 KB per event, rate limit per key (default 1,200/min).
  • 200 means durably written. The response lists accepted, duplicates and per-event rejected reasons.
  • $identify with $anon_distinct_id merges an anonymous person into an identified one. Two identified persons are never merged.
  • Property names that look like secrets (password, token, api_key, card number…) are dropped server-side; sensitive query parameters in URLs are redacted.

The SDKs are not drop-in replacements for posthog-js or posthog-node, although they use the same property conventions ($pageview, $current_url, $pathname, $session_id).