
Company News
Free Business Plan Upgrades for Open Source Maintainers
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.
@sapiom/analytics-core
Advanced tools
Zero-dependency usage analytics emitter shared by Sapiom SDK packages — consent-aware, batched, and guaranteed to never throw or block the host application.
Zero-dependency usage analytics emitter shared by Sapiom SDK packages.
Sapiom packages use it to send usage events to the Sapiom analytics collector so we can understand real-world usage and improve the SDK. It is designed to be invisible to the host application:
track() is a synchronous enqueue; every
failure inside analytics is silently swallowed.data._truncated).This section is the complete disclosure for the analytics this package can emit. The full wire contract lives in CONTRACT.md.
Each event is a small JSON envelope:
command.run, capability.call)
and a JSON payload describing it.cli, tools, mcp, ...), and a schema version.data.context.Analytics never reads your environment variables, credentials, or files beyond its own identity file described below.
Any of these disables analytics entirely (highest precedence first):
createAnalytics({ ..., disabled: true }) — packages
built on this emitter expose their own equivalent switch in their options.SAPIOM_TELEMETRY_DISABLED=1 in the environment.DO_NOT_TRACK=1 in the environment (the ecosystem-wide convention).For packages wiring a custom consentProvider: returning undefined defers
to the default, which is enabled — return false to keep analytics off.
When opted out, nothing is sent, nothing is written to disk, zero network calls are made — and no notice is printed.
When analytics is active, the first-ever tracked event on a machine prints a one-line notice to stderr, so collection is never silent.
A single file, ~/.sapiom/analytics.json (permissions 0600), holding a
random anonymous machine id and the first-run-notice marker. It contains no
personal information. Delete it at any time to reset the identity; it is
never created while analytics is disabled.
The emitter delivers to the hosted Sapiom collector by default — the URL is
exported as the constant SAPIOM_COLLECTOR_ENDPOINT, and an explicit
endpoint in the config sends somewhere else (for example, the mock
collector in tests). Everything in Opting out above applies
unchanged: disabled: true in the config, SAPIOM_TELEMETRY_DISABLED=1, or
DO_NOT_TRACK=1 disables analytics entirely — nothing is sent, nothing is
written to disk, zero network calls are made, and no notice is printed.
import { createAnalytics } from "@sapiom/analytics-core";
const analytics = createAnalytics({
source: "cli",
sdkName: "@sapiom/cli",
sdkVersion: "1.0.0",
// Delivers to the hosted Sapiom collector (SAPIOM_COLLECTOR_ENDPOINT)
// by default; pass `endpoint` to send somewhere else.
});
analytics.track("command.run", { command: "dev" });
await analytics.flush(); // best-effort send, never rejects
await analytics.shutdown(); // flush + stop timers, never rejects
track(eventType, data?, overrides?) accepts an arbitrary event type, a JSON
payload, and optional per-event envelope overrides (for example
{ user_id: "usr_123" } when a signed-in identity is known).
@sapiom/analytics-core/testing ships an in-process mock collector — a real
HTTP server on a random loopback port with contract-shaped responses and
scriptable failure modes — for use in any package's tests:
import { createAnalytics } from "@sapiom/analytics-core";
import { startMockCollector } from "@sapiom/analytics-core/testing";
const collector = await startMockCollector();
const analytics = createAnalytics({
source: "tools",
sdkName: "@sapiom/tools",
sdkVersion: "1.0.0",
endpoint: collector.url,
});
analytics.track("capability.call", { capability: "search" });
await analytics.flush();
expect(collector.events()).toHaveLength(1);
collector.setMode({ kind: "status", status: 500 }); // or "down", "slow"
// ... assert your instrumentation degrades silently ...
await collector.close();
fixtures/contract/ — machine-readable request
fixtures (valid + invalid) for contract conformance tests, shipped with
the package.MIT
FAQs
Zero-dependency usage analytics emitter shared by Sapiom SDK packages — consent-aware, batched, and guaranteed to never throw or block the host application.
We found that @sapiom/analytics-core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.

Security News
The supply chain control that delays freshly published gems now covers lockfile generation and gem vendoring in Ruby projects.

Security News
During a UK cyber test, a Mythos 5 agent used sockpuppets, social engineering, and prompt injection to try to get a maintainer to merge malware.