@packedgedev/sdk
v0.1.0
Published
Tiny browser/Node SDK for tracking PackEdge feature-usage events.
Maintainers
Readme
@packedgedev/sdk
Tiny browser/Node SDK for the PackEdge feature-usage tracking endpoint.
npm install @packedgedev/sdkUsage
import packedge from '@packedgedev/sdk';
packedge.init('pk_your_public_key', {
licenseKey: 'XXXX-XXXX-XXXX-XXXX', // optional, attributes events to a customer
});
packedge.track('feature_used', { feature: 'export', format: 'pdf' });
packedge.track('settings_changed', { setting: 'theme', value: 'dark' });Script tag
<script src="https://unpkg.com/@packedgedev/sdk/dist/index.global.js"></script>
<script>
packedge.init('pk_your_public_key');
packedge.track('feature_used', { feature: 'export' });
</script>API
packedge.init(publicKey, options?)
| 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 |
packedge.track(event, properties?)
Fire-and-forget. Never throws, never blocks. Uses navigator.sendBeacon when
available so events survive page unload, then falls back to
fetch(..., { keepalive: true }).
packedge.setLicense(key | null) / packedge.setSite(site | null)
Update credentials after init — useful after a customer activates a license mid-session.
REST fallback
If you don't want a build step (e.g. inside a WordPress plugin), POST directly:
wp_remote_post('https://api.packedge.dev/public/v1/event', [
'body' => json_encode([
'public_key' => 'pk_your_key',
'event' => 'feature_used',
'license_key'=> $license_key, // optional
'site' => parse_url(home_url(), PHP_URL_HOST),
'properties' => ['feature' => 'export'],
]),
'headers' => ['Content-Type' => 'application/json'],
'blocking' => false,
]);fetch('https://api.packedge.dev/public/v1/event', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
public_key: 'pk_your_key',
event: 'feature_used',
properties: { feature: 'export' },
}),
keepalive: true,
});