@hiveit/core
v1.1.1
Published
hiveit analytics client core: event builder, queue, batching, retries and offline buffer. Zero dependencies.
Maintainers
Readme
@hiveit/core
Zero-dependency analytics client core. Everything else (@hiveit/express, the Next.js and
browser packages) is a thin wrapper around this.
import { HiveitClient } from "@hiveit/core";
const client = new HiveitClient({
endpoint: "https://analytics.example.com/e", // or a proxy route such as "/api/hiveit/e"
apiKey: "hvw_...", // omit when a proxy adds it
});
client.capture({ event: "signup", distinctId: "user-42", properties: { plan: "pro" } });
client.identify({ distinctId: "user-42", anonymousId: "anon-1", properties: { plan: "pro" } });
client.alias({ distinctId: "user-42", alias: "legacy-7" });
await client.shutdown(); // flush before the process exitsFor a single end user (a browser, one request) use client.user(), which keeps the current
identity and turns identify() into a one-time merge of the anonymous history:
const user = client.user({ store: myLocalStorageStore });
user.track("page_view", { path: "/pricing" }); // sent under the anonymous id
user.identify("user-42"); // merges the anonymous id into user-42, once
user.reset(); // log out: fresh anonymous idDelivery: events are batched (flushAt, flushIntervalMs), retried with exponential
back-off on network errors, 429 and 5xx (honouring Retry-After), and kept in a bounded
queue (maxQueueSize, oldest dropped) until they get through. Batches the service rejects
with another 4xx are dropped. Every problem is reported through onError; the client never
throws after construction.
