Appearance
API reference
The SDK exports a default singleton. Every method returns the singleton so you can chain calls.
ts
import packedge from '@packedge/js-sdk';init(publicKey, options?)
Configure the SDK with your product's public key. Safe to call multiple times — later calls merge into the existing state.
ts
packedge.init('pk_your_public_key', {
licenseKey: 'XXXX-XXXX-XXXX-XXXX',
site: 'subdomain.example.com',
baseUrl: 'https://api.packedge.dev',
debug: false,
});| Option | Type | Default | Notes |
|---|---|---|---|
licenseKey | string | — | Attributes events to a customer license |
site | string | window.location.hostname | Domain identifier |
baseUrl | string | https://api.packedge.dev | Override for staging/local |
debug | boolean | false | Logs send failures to console.warn |
track(event, properties?)
Record a feature-usage event. Fire-and-forget — never throws, never blocks the caller.
ts
packedge.track('feature_used', { feature: 'export', format: 'pdf' });Returns true if the request was dispatched, false if the SDK was not initialized or the input was invalid.
setLicense(key | null)
Update the active license key without re-initializing.
ts
packedge.setLicense('MYPLUGIN-XXXX-XXXX-XXXX-XXXX');
packedge.setLicense(null); // clearsetSite(site | null)
Update the site/domain identifier.
ts
packedge.setSite('shop.example.com');Transport behavior
navigator.sendBeaconwhen available — queued by the browser, survives page unload, never blocks.fetch(..., { keepalive: true })fallback for Safari, older browsers, and Node/edge runtimes.- No transport → returns
false; withdebug: truea warning is logged.
Errors are always swallowed. track() never rejects a promise and never throws.
TypeScript
Type declarations ship with the package — no @types/... install needed.
ts
import packedge, { Packedge } from '@packedge/js-sdk';
// Singleton (default export)
packedge.init('pk_…');
// Or instantiate your own for advanced cases
const custom = new Packedge();
custom.init('pk_…', { baseUrl: 'https://staging.api.packedge.dev' });