@newly/sdk-web
v0.1.0
Published
Newly analytics SDK for web apps and PWAs
Readme
@newly/sdk-web
Newly analytics for web apps and PWAs.
Install
npm install @newly/sdk-webNo peers. No runtime dependencies.
Initialize
import { Newly } from '@newly/sdk-web';
Newly.init({ ingestKey: NEWLY_INGEST_KEY, apiUrl: NEWLY_API_URL });Track
Newly.analytics.track('item_purchased', { item_id: 'x', amount_cents: 999 });
Newly.analytics.identify('user_123', { plan: 'pro' });
Newly.analytics.screen('Cart');
Newly.analytics.flush();Platform notes
- Identity keys persist in
localStorage; the offline queue lives in IndexedDB (falling back tolocalStorage, then memory). - Bodies gzip via
CompressionStreamwhen the browser has it; identity encoding otherwise. visibilitychange/pagehidetrigger flushes (withkeepalivefetch), so closing the tab does not lose the last batch.- On first init the SDK captures
utm_source,utm_medium,utm_campaign,utm_content,utm_term,gclid,fbclid,ttclid,msclkidfrom the URL as immutablefirst_touch_*properties and emits one$install. - The SDK never throws into the host app; failures surface only through the
optional
onErrorhook.
