ionblink-js 0.0.0-stage → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.md +131 -0
  2. package/LICENSE +21 -0
  3. package/README.md +289 -2
  4. package/THIRD-PARTY-NOTICES.txt +66 -0
  5. package/dist/cjs/index.cjs +3318 -0
  6. package/dist/cjs/package.json +1 -0
  7. package/dist/cjs/protocol.cjs +79 -0
  8. package/dist/cjs/proxy.cjs +103 -0
  9. package/dist/esm/c-7SPQIMCH.js +893 -0
  10. package/dist/esm/c-EMLSQ5BC.js +97 -0
  11. package/dist/esm/c-FF5JPOWW.js +120 -0
  12. package/dist/esm/c-ILAGKULG.js +431 -0
  13. package/dist/esm/c-LULHYRWR.js +154 -0
  14. package/dist/esm/c-MNMQMJ5I.js +59 -0
  15. package/dist/esm/c-UMIKYUMF.js +222 -0
  16. package/dist/esm/index.js +1317 -0
  17. package/dist/esm/package.json +1 -0
  18. package/dist/esm/protocol.js +16 -0
  19. package/dist/esm/proxy.js +82 -0
  20. package/dist/i-729781ba45.js +1 -0
  21. package/dist/integrity.json +11 -0
  22. package/dist/ionblink.min.js +1 -0
  23. package/dist/r-a4f89dccd1.js +1 -0
  24. package/dist/r-a4f89dccd1.js.LICENSE.txt +66 -0
  25. package/dist/snippet.html +1 -0
  26. package/dist/snippet.min.js +1 -0
  27. package/dist/types/auto.d.ts +30 -0
  28. package/dist/types/automation.d.ts +2 -0
  29. package/dist/types/consent.d.ts +43 -0
  30. package/dist/types/context.d.ts +20 -0
  31. package/dist/types/core.d.ts +10 -0
  32. package/dist/types/dom.d.ts +7 -0
  33. package/dist/types/idb.d.ts +2 -0
  34. package/dist/types/index.d.ts +5 -0
  35. package/dist/types/inspect-cdn.d.ts +1 -0
  36. package/dist/types/inspect.d.ts +29 -0
  37. package/dist/types/mask.d.ts +64 -0
  38. package/dist/types/phone-replay.d.ts +42 -0
  39. package/dist/types/props.d.ts +5 -0
  40. package/dist/types/protocol.d.ts +728 -0
  41. package/dist/types/proxy.d.ts +21 -0
  42. package/dist/types/rage.d.ts +9 -0
  43. package/dist/types/replay-npm.d.ts +2 -0
  44. package/dist/types/replay.d.ts +5 -0
  45. package/dist/types/replayctl.d.ts +2 -0
  46. package/dist/types/scrub.d.ts +18 -0
  47. package/dist/types/session.d.ts +30 -0
  48. package/dist/types/signals.d.ts +31 -0
  49. package/dist/types/storage.d.ts +17 -0
  50. package/dist/types/transport.d.ts +63 -0
  51. package/dist/types/types.d.ts +255 -0
  52. package/dist/types/util.d.ts +27 -0
  53. package/dist/types/vitals.d.ts +11 -0
  54. package/dist/types/x-cdn.d.ts +1 -0
  55. package/dist/types/x.d.ts +2 -0
  56. package/dist/v1.js +1 -0
  57. package/dist/x-8b414fa290.js +1 -0
  58. package/package.json +69 -4
package/CHANGELOG.md ADDED
@@ -0,0 +1,131 @@
1
+ # Changelog: ionblink-js
2
+
3
+ ## 0.1.6 - Unreleased
4
+
5
+ The first version published by CI (npm trusted publishing), with npm provenance; npm and the CDN serve the same bytes
6
+ again. No change to what the SDK sends.
7
+
8
+ - Consent, sampling and the remote config's guards come from `packages/shared` (`consent.ts`), shared with
9
+ ionblink-react-native. The core's code is the same, in a different order (same size), so it needs its own version.
10
+
11
+ ## 0.1.5 - 2026-12-02
12
+
13
+ Capture gaps from the 2026-12-02 capture audit (what PostHog records that IonBlink didn't), all in the extras chunk
14
+ (8,129 -> 8,187 bytes brotli, +58, inside its 8 KB budget with 5 to spare; the core changes only by the chunk's new
15
+ name and integrity, 11,026 -> 11,022). On the CDN only (cdn.ionblink.com/sdk/0.1.5): npm goes from 0.1.2 to 0.1.6.
16
+
17
+ - A choice made in a form sends `$field` with `action: "change"`: a select, checkbox or radio, from the `input` event
18
+ the core already forwards. It says which control (type, label, name), never what was chosen. PostHog's autocapture
19
+ records these; IonBlink saw only focus and blur.
20
+ - `$vitals` carries `lcp_el`, the largest paint's element as a short selector (the same one as a click's `sel`), so a
21
+ slow-page fix can name what was slow. It was a number only.
22
+ - `$signals` carries the page's `scroll_pct` and `engaged_ms`, as `$page_leave` has them. A page hidden for good
23
+ without a pagehide (Facebook's and Instagram's in-app browsers, a tab the phone kills) sends no `$page_leave`, so its
24
+ depth and engaged time were lost: on one site, 81 leaves for 140 pages.
25
+
26
+ ## 0.1.4 - 2026-12-02
27
+
28
+ Fixes from the 2026-12-02 audit of IonBlink against PostHog and the live page. On the CDN only
29
+ (cdn.ionblink.com/sdk/0.1.4): npm goes from 0.1.2 to 0.1.6.
30
+
31
+ - Batches cut while the page is hidden carry `hidden: true` (PROTOCOL.md): mobile Safari and Chrome often hide a tab
32
+ and then freeze or kill it without a `pagehide`, so the server can end that session minutes later instead of after
33
+ 30 idle minutes. What the page captures while hidden (such as an event from its own hide handler, which runs after
34
+ the SDK's) goes at once by beacon instead of waiting for a 5 s timer a phone may never run: one site's engagement
35
+ event was lost in 6 of 51 sessions that way.
36
+ - A report-only Content-Security-Policy violation is no longer recorded as an error or warned about as a block (only
37
+ an enforced policy blocks anything).
38
+
39
+ - PostHog's markers hide in IonBlink too: class `ph-no-capture` and `data-testid="ph-no-capture"` block an element in
40
+ replay (and `ph-no-capture` stops autocapture inside it); `data-ph-mask`, class `ph-mask` and class `ph-sensitive`
41
+ mask its text and attributes. A site with both tools used to show IonBlink controls' labels and images inside regions
42
+ it had hidden from PostHog only.
43
+ - Images whose file name carries a build's content hash load in the player again: `wave.a9a981030fa052f3d366b65f41052068.webp`
44
+ (Expo web) and `christmas-in-london-614a30287eb2.webp` kept their path, where the scrubber took the hash for a token
45
+ (or `Q12345678-7daf…` for a phone number) and redacted the segment. Tokens, UUIDs and emails in image paths are
46
+ still redacted.
47
+ - A full snapshot stays under ingest's 2 MB cap when a browser extension injects megabytes of inlined fonts and images:
48
+ in an inlined stylesheet over 1 MB, each base64 `data:` URI over 32 KB becomes `data:,`. The Readwise highlighter's
49
+ shadow root (3 MB of CSS) made every snapshot about 2.05 MB gzipped, on any site its user visited; one went past the
50
+ cap, was refused (413) and its page couldn't play. Now about 220 KB. Smaller stylesheets keep every data URI.
51
+
52
+ ## 0.1.3 - 2026-12-02
53
+
54
+ Console and network in replays, off by default. On the CDN only (cdn.ionblink.com/sdk/0.1.3): npm goes from 0.1.2 to
55
+ 0.1.6.
56
+
57
+ - When a site's owner turns them on in IonBlink (remote config `replay.console`, `replay.network`), recorded sessions
58
+ also carry the page's console lines (`log`, `info`, `warn`, `error`, uncaught errors, unhandled rejections) as
59
+ `rrweb/console@1` plugin events, and its fetch and XHR requests (method, URL without its query and fragment, status,
60
+ start, duration, transfer size, initiator type, phases from resource timing; never headers or bodies) as
61
+ `rrweb/network@1` plugin events, on the replay lane (PROTOCOL.md, "Console and network").
62
+ - Console lines are masked like page text (values under secret-named keys starred; emails, card and phone numbers,
63
+ IBANs, SSNs, JWTs, API keys and long tokens scrubbed), cut to 2,000 characters, and limited to 1,000 lines a page at
64
+ 20 a second after a burst of 100; requests to 1,000 a page. The SDK's own requests and lines are never recorded.
65
+ - `replay: { console: false }` and `replay: { network: false }` refuse either whatever the site says;
66
+ `replay: { network: { keepParams: ['page'] } }` keeps named query parameters (values scrubbed).
67
+ - The capture code is its own lazy chunk (`i-<hash>.js` on the CDN, 3.42 KB brotli; a dynamic import in the npm build),
68
+ loaded by the replay chunk only for a recording the site turned it on for; its name and integrity live in the replay
69
+ chunk. The core grows 21 bytes brotli (the two config keys; budget 10.75 -> 10.77 KB).
70
+ - From the 2026-12-01 security review of the capture: `Authorization`, `sid`, CSRF and signature keys are starred, and a
71
+ credential after `Bearer`/`Basic` in a string; every string is masked raw, before it is cut or JSON-escaped; URLs in
72
+ a line lose their query and fragment; only plain objects and arrays are opened (a React event, Location or a store is
73
+ its class name, a typed array its length); the `text` mask level stars console text; a reused XHR gets its listeners
74
+ once; the buffer of earlier requests is read only on the landing page and only when the recording didn't wait for
75
+ consent; the SDK's own batches are recognised whatever the key looks like; an unhandled fetch failure still reaches
76
+ the page's `unhandledrejection`; a later config that turns capture off stops it on the page.
77
+
78
+ ## 0.1.2 - 2026-12-02
79
+
80
+ Visitors who leave in the first seconds are no longer lost. Served from `cdn.ionblink.com/sdk/0.1.2` (2026-12-02); the
81
+ first version on npm (2026-12-02). No change to the wire format or the events sent.
82
+
83
+ - The page's first batch (its `$page`) goes as soon as the SDK boots instead of after the 5 s cadence, so a visit that
84
+ ends in a second still starts a session. A first visit's batch still waits for the config answer (the region may ask
85
+ for consent). Later events coalesce as before; the automation hints, read at idle, ride the next batch's context.
86
+ - When the page is hidden, what is queued goes by `sendBeacon` at once, as on `pagehide`, instead of being compressed
87
+ and fetched: a phone may close a hidden tab without a `pagehide`, and a compressed request may never leave. What the
88
+ browser refuses goes to the offline queue, as before.
89
+ - A beacon round sends the events batches before the replay chunks, so a replay chunk can't use up the browser's 64 KB
90
+ keepalive quota first.
91
+
92
+ ## 0.1.1 - CDN only
93
+
94
+ Served from `cdn.ionblink.com` only; npm starts at 0.1.2. 0.1.0 (2026-12-01) was CDN-only too and lacks `headers()`
95
+ and `proxy()`'s country forwarding; its URL keeps working.
96
+
97
+ First public release.
98
+
99
+ - `init`, `event`, `set` / `identify`, `page`, `reset`, `consent`, `mask`, `flush`, `ready`, `ids`, `state`.
100
+ - `headers()`: the browser's ids as `x-ionblink-anon` / `x-ionblink-session` request headers, so the site's server can
101
+ bind the session to the person it signed in (ionblink-node `identify({ userId, ...whoFrom(req.headers) })`), which
102
+ IonBlink shows as verified.
103
+ - Automatic page views (SPA navigations included), page leave with engaged time and scroll depth, clicks, rage and dead
104
+ clicks, field focus and form submits (never values), JS errors and unhandled rejections, web vitals, agent signals.
105
+ - Session replay with rrweb, loaded only for recorded sessions; masking levels `inputs`, `controls` and `text`;
106
+ never-captured fields; PII scrubbing of text, attributes and URLs.
107
+ - Replay masks what rrweb's own masking misses: typing in `contenteditable` editors, hidden fields' values, `<meta
108
+ content>`, `data-*` values, text inside a masked shadow host, and cross-origin iframe URLs (security review).
109
+ - Consent modes `off`, `basic` (cookieless, id-free counts), `full` and `replay`; opt-in regions start in `basic`.
110
+ - Batching, gzip, backoff with `Retry-After`, 413 splitting, `sendBeacon` on page hide, an offline queue in IndexedDB.
111
+ - Script tag and inline snippet (`https://cdn.ionblink.com/sdk/v1.js`), npm ESM and CJS builds, a pinned CDN build
112
+ with Subresource Integrity (`dist/integrity.json`), and `ionblink-js/proxy` for a first-party route.
113
+ - `ionblink-js/proxy` forwards only `GET`, `HEAD`, `POST` and `OPTIONS` and refuses bodies over 4 MB; the README no
114
+ longer suggests a plain rewrite, which forwards the site's cookies (security review).
115
+ - `proxy()` forwards the visitor's country and region (`x-ib-client-country`, `x-ib-client-region`) from Cloudflare,
116
+ Vercel or Netlify, so IonBlink's consent rule sees the visitor's location rather than the proxy's. `clientGeo()` is
117
+ exported beside `clientIp()`.
118
+ - Stays out of the page's way: `init()` defers its work to an idle moment, replay starts only after the `load` event,
119
+ scroll position is read in `requestAnimationFrame`, sends pause while offline. Budgets in CI: core 10.7 KB brotli (10.6 KB today); the replay controller ships in the extras chunk.
120
+ - No cookies by default; `storage: 'cookie'` writes one first-party cookie of about 80 bytes (never the person).
121
+ - Scrubbing (security review): every pattern runs in linear time (a crafted 80 KB string took 6.7 s), `ib_sk_` keys
122
+ are scrubbed, a `key=value` path segment (an OAuth token in a hash route) is redacted, a padded or upper-case secret
123
+ key is refused too, and a `__proto__` prop key is dropped. Core budget 10.7 -> 10.75 KB.
124
+ - `https://cdn.ionblink.com/sdk/<version>/ionblink.min.js`, a pinned, immutable URL beside the moving `/sdk/v1.js`.
125
+ - Third-party notices: `THIRD-PARTY-NOTICES.txt` (rrweb and base64-arraybuffer, MIT, bundled in the CDN replay
126
+ chunk) ships in the package and beside the chunk as `dist/r-<hash>.js.LICENSE.txt`.
127
+ - Clear console errors for a malformed key, a secret key in a page (the SDK refuses to start), a Content-Security-Policy
128
+ block, and refused events (401, 403).
129
+ - Consent (security review): through a first-party proxy the timezone guess stays a floor (the server sees the
130
+ proxy's IP, not the visitor's); Global Privacy Control turns replay off unless `consent()` grants it; `off` sends
131
+ nothing, not even the config request.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Winding Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,290 @@
1
- # Temporary Holding Version
1
+ # ionblink-js
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ IonBlink for the browser: product analytics built for agents. Page views, autocapture, agent signals, and masked
4
+ session replay that loads only when a session is recorded. The core is 10.8 KB brotli, starts when the browser is
5
+ idle, sets no cookies and never throws into your page.
6
+
7
+ > IonBlink serves this package's CDN build at `https://cdn.ionblink.com/sdk/v1.js`, which always loads the current
8
+ > release. npm installs update when you bump the package.
9
+
10
+ ## Quickstart
11
+
12
+ ```sh
13
+ npm i ionblink-js
14
+ ```
15
+
16
+ ```ts
17
+ import { ionblink } from 'ionblink-js'
18
+ ionblink.init('ib_pk_…') // your site key, from Sites in the IonBlink app
19
+ ```
20
+
21
+ Importing is safe during server rendering: nothing touches `window` until `init()` runs in a browser. Your bundler
22
+ splits out the two lazy chunks (extras, and replay with rrweb). For React and Next.js, use
23
+ [`ionblink-react`](../react) on top of this package. For React Native and Expo, use
24
+ [`ionblink-react-native`](../react-native).
25
+
26
+ ## Other ways to install
27
+
28
+ ### Script tag (one line, no build step)
29
+
30
+ ```html
31
+ <script src="https://cdn.ionblink.com/sdk/v1.js" crossorigin="anonymous" data-key="ib_pk_…" async></script>
32
+ ```
33
+
34
+ Attributes: `data-key` (required), `data-api-host` (a first-party proxy), `data-mode` (`basic`, `full`, `replay`),
35
+ `data-require-consent` (treat every visitor as opt-in until `consent()`). The global is `window.ionblink`.
36
+ `/sdk/v1.js` always serves the current release, so your site gets fixes with no change: cached for 5 minutes, then
37
+ revalidated in the background. It has no `integrity` because it moves; the chunks it loads are checked against their
38
+ own integrity hashes.
39
+ `cdn.ionblink.com` serves static files from Cloudflare's edge, brotli or gzip, and never sets or reads a cookie.
40
+
41
+ ### Pinned version with Subresource Integrity (the strict option)
42
+
43
+ For a Content-Security-Policy or SRI policy that wants an `integrity` hash on every script, or to hold a version. Each
44
+ release has a URL that never changes, cached for a year; it updates only when you change it. The core then loads its
45
+ lazy chunks from the same folder, each with its own integrity hash built in:
46
+
47
+ ```html
48
+ <script src="https://cdn.ionblink.com/sdk/0.1.6/ionblink.min.js"
49
+ integrity="sha384-…" crossorigin="anonymous" data-key="ib_pk_…" async></script>
50
+ ```
51
+
52
+ The `integrity` value for each release is in `dist/integrity.json` of the package (and in the release notes). Every
53
+ npm release is also on jsDelivr and unpkg with no extra step, for example
54
+ `https://cdn.jsdelivr.net/npm/ionblink-js@0.1.6/dist/v1.js` (same bytes, same integrity). Batches still go to
55
+ `https://api.ionblink.com` (or your `data-api-host`).
56
+
57
+ ### Inline snippet (call the API before the SDK loads)
58
+
59
+ Calls made before the SDK arrives are queued with their timestamps and replayed in order (a queued `consent()` goes
60
+ first, so nothing it forbids ever starts). The minified copy is `dist/snippet.html` (0.28 KB brotli):
61
+
62
+ ```html
63
+ <script>
64
+ (function(i,n,a,s){if(!i.ionblink){var c=[],o=i.ionblink={_q:c,_k:a,_o:s||{}};"init event set identify page reset consent mask flush ready".split(" ").forEach(function(r){o[r]=function(){c.push([r,Array.prototype.slice.call(arguments),Date.now()])}});var e=n.createElement("script"),t=n.currentScript;e.async=!0,e.src=(o._o.apiHost||"https://cdn.ionblink.com")+"/sdk/v1.js",t&&t.nonce&&(e.nonce=t.nonce),(n.head||n.documentElement).appendChild(e)}})(window,document,"ib_pk_…",{});
65
+ </script>
66
+ ```
67
+
68
+ The last argument takes the `init` options (`{ apiHost: '/ib' }`). A CSP nonce on the snippet's tag is copied to the
69
+ SDK's tags.
70
+
71
+ ### Next.js without React helpers
72
+
73
+ Next.js 15.3+ runs `instrumentation-client.ts` before your app, with no provider needed:
74
+
75
+ ```ts
76
+ // instrumentation-client.ts
77
+ import { ionblink } from 'ionblink-js'
78
+ ionblink.init(process.env.NEXT_PUBLIC_IONBLINK_KEY!, { apiHost: '/ib' })
79
+ ```
80
+
81
+ Route changes are page views on their own. Add the `/ib` route with `ionblinkRoute()` from
82
+ [`ionblink-react/next`](../react#nextjs-app-router), or drop `apiHost` to send straight to IonBlink.
83
+
84
+ ## API
85
+
86
+ | Call | What it does |
87
+ |---|---|
88
+ | `init(key, options?)` | Starts the SDK. Once per page. |
89
+ | `event(name, props?)` | An app event: a name of 1-64 characters (not starting with `$`) and JSON props. |
90
+ | `set(person)` / `identify(id, traits?)` | Who the person is. Use your user id, never an email, as `id`. Raises masking to `controls`. |
91
+ | `page(path?, props?)` | A page view by hand: only for virtual pages or with `pages: false`. |
92
+ | `reset()` | On sign-out: new anonymous id and session, the person forgotten. |
93
+ | `consent(choice)` | From your banner: `'off' \| 'basic' \| 'full' \| 'replay'` or `{ analytics, replay }`. |
94
+ | `mask(level)` | `'inputs' \| 'controls' \| 'text'`. |
95
+ | `flush()` | Sends what is queued; resolves after one attempt, never rejects. |
96
+ | `ready(cb)`, `ids()`, `state()` | Ready callback; ids to join server events (undefined in `basic`); mode, masking and replay state. |
97
+ | `headers()` | This browser's ids as `{ 'x-ionblink-anon', 'x-ionblink-session' }` (`{}` without ids) for your own server. See [Verified people](#verified-people). |
98
+
99
+ Options: `apiHost`, `mode` (the most this site captures, default `replay`), `requireConsent`, `mask`, `storage`
100
+ (`local` default, `cookie` with `cookieDomain` for subdomains, `memory`), `pages`, `autocapture` (or per family:
101
+ `clicks`, `forms`, `errors`, `vitals`, `signals`), `replay: { sample, maskSelectors, blockSelectors, blockPaths,
102
+ console, network }`, `keepQuery`, `app: { version, build }`, `debug`, `beforeSend`. See `src/types.ts`.
103
+
104
+ **Console and network in replays.** When a site's owner turns them on in IonBlink (Settings, Sites), recorded sessions
105
+ also carry the page's console lines (`log`, `info`, `warn`, `error`, uncaught errors and unhandled rejections) and its
106
+ fetch and XHR requests (method, URL without its query and fragment, status, timings and size; never headers or bodies),
107
+ shown beside the replay. Both are off by default and load a small chunk only when on. Console lines are masked like
108
+ page text (secret-named keys and `Authorization` values starred, emails, cards and tokens scrubbed, URLs without their
109
+ query; all text starred at the `text` mask level), only plain objects and arrays are opened, and a line is cut to 2,000
110
+ characters. Your code can refuse either whatever the site says, or keep named query parameters in request URLs:
111
+
112
+ ```js
113
+ ionblink.init('ib_pk_…', { replay: { console: false, network: { keepParams: ['page'] } } })
114
+ ```
115
+
116
+ Console capture wraps `console.log`, `info`, `warn` and `error`, so DevTools shows those lines as coming from the SDK's
117
+ file; network capture wraps `fetch` (it hands back a promise that settles as fetch's did) and `XMLHttpRequest`. The
118
+ format is in [PROTOCOL.md](../../PROTOCOL.md#console-and-network).
119
+
120
+ **Sent for you:** page views (SPA navigations included), page leave with engaged time and scroll depth, clicks with a
121
+ masked target, rage clicks (3 in 1 s within 30 px), dead clicks, field focus and form submits (never values), JS
122
+ errors and unhandled rejections, web vitals, and `$signals`: a compact per-page summary of how the page was driven
123
+ (pointer, keys, scroll, timing), which IonBlink uses to tell people from agents. No raw coordinate streams leave the
124
+ page.
125
+
126
+ **Every batch carries** the page URL (query values masked), path, referrer, UTM and click ids, screen, viewport,
127
+ locale, time zone, the SDK version, and automation hints.
128
+
129
+ ## Consent
130
+
131
+ | Mode | What happens |
132
+ |---|---|
133
+ | `off` | Nothing, not even the remote config request. |
134
+ | `basic` | No storage, no ids, no device reads. One aggregate beacon per page with event-name counts. |
135
+ | `full` | Events, identity, autocapture, agent signals. |
136
+ | `replay` | Full plus session replay (sampled by remote config). |
137
+
138
+ In the EEA, UK, Switzerland and Quebec (the server decides from the request; the time zone guesses until it answers),
139
+ visitors start in `basic` until you call `consent()`. Elsewhere they start at your `mode`. `requireConsent: true` makes
140
+ every visitor opt-in. Through a first-party proxy the server sees the proxy's address, not the visitor's, so there a
141
+ European time zone keeps asking whatever the server says, and `proxy()` forwards the visitor's country from your
142
+ platform (Cloudflare, Vercel, Netlify). A proxy that sends no country makes the server ask every visitor. A browser that sends Global Privacy Control starts without
143
+ replay (`full` at most) until `consent()` says otherwise.
144
+
145
+ ```ts
146
+ banner.onAccept(() => ionblink.consent({ analytics: true, replay: true }))
147
+ banner.onReject(() => ionblink.consent({ analytics: false }))
148
+ ```
149
+
150
+ Lowering consent purges everything queued, deletes the SDK's storage, and sends one last `$consent` so the server
151
+ can carry out the withdrawal. The choice is kept for 6 months.
152
+
153
+ ## Masking
154
+
155
+ - Password, email, phone, card, one-time-code and hidden fields are never captured at any level: no value, no
156
+ length, no keystroke timing. Replay shows a fixed `********`.
157
+ - What people type in a `contenteditable` editor (or a `designMode` document) is masked at every level, like an input.
158
+ - Emails, card numbers, phone numbers, IBANs, SSNs, JWTs, API keys and long tokens are scrubbed from all text,
159
+ attributes and URLs before they leave the browser.
160
+ - Levels: `inputs` (default when signed out: input values hidden), `controls` (default after `identify()`: all text
161
+ hidden except buttons, links and labels), `text` (all text and images hidden). Remote config can only make it
162
+ stricter.
163
+ - Markup: `data-ib-mask` (or class `ib-mask`) masks an element's text and attributes, its open shadow root
164
+ included; `data-ib-unmask` keeps a control's label at `controls`; `data-ib-block` (or `ib-block`) replaces an
165
+ element with a placeholder in replay and stops autocapture inside it; `data-ib-no-capture` stops autocapture only;
166
+ `data-ib-name="checkout"` names a target.
167
+ - PostHog's markers work too, so a page moving from PostHog keeps hiding what it hid: class `ph-no-capture` (and
168
+ `data-testid="ph-no-capture"`, React Native Web's `testID`) blocks like `data-ib-block`; `data-ph-mask`, class
169
+ `ph-mask` and class `ph-sensitive` mask like `data-ib-mask`.
170
+ - Attributes in replay: `data-*` values are masked like text (a short lowercase word such as `open` or `dark` stays,
171
+ so styles keep working), `<meta content>` is masked (CSRF tokens, keys) except `viewport`, `theme-color` and
172
+ `color-scheme`, a cross-origin iframe's URL is masked like a link, and inline handlers, `nonce` and `srcdoc` are
173
+ dropped.
174
+ - `blob:` and `data:` images and file inputs are always blocked in replay.
175
+
176
+ ## First-party proxy
177
+
178
+ Serving the SDK and ingest from your own domain keeps requests same-origin (ad blockers, Safari ITP) and passes the
179
+ visitor's IP. Point the SDK at the path: `init('ib_pk_…', { apiHost: '/ib' })`, or
180
+ `<script src="/ib/sdk/v1.js" data-key="ib_pk_…" async>` (the SDK then sends to `/ib` by itself).
181
+
182
+ **Cloudflare Worker** on `example.com/ib/*`:
183
+
184
+ ```ts
185
+ import { proxy } from 'ionblink-js/proxy'
186
+ export default { fetch: (req: Request) => proxy(req, { path: '/ib' }) }
187
+ ```
188
+
189
+ **Next.js** route handler, `app/ib/[...path]/route.ts`:
190
+
191
+ ```ts
192
+ import { proxy } from 'ionblink-js/proxy'
193
+ export const GET = (req: Request) => proxy(req, { path: '/ib' })
194
+ export const POST = GET
195
+ export const OPTIONS = GET
196
+ ```
197
+
198
+ **Not a plain rewrite.** A Vercel or Next.js rewrite to another host forwards every request header, your site's
199
+ cookies included: the script load and `sendBeacon` are same-origin, so they carry them. `proxy()` forwards only
200
+ `/v1/*` and `/sdk/*` with `GET`, `HEAD`, `POST` and `OPTIONS`, never cookies or `Authorization`, strips `Set-Cookie` from
201
+ answers, and refuses bodies over 4 MB. It adds the visitor's IP (`x-ib-client-ip`) and country and region
202
+ (`x-ib-client-country`, `x-ib-client-region`, from `request.cf`, `x-vercel-ip-country`, `cf-ipcountry` or `x-nf-geo`),
203
+ which IonBlink needs for rate limits and the consent rule.
204
+
205
+ ## Size and performance
206
+
207
+ | File | brotli | gzip | Loads |
208
+ |---|---|---|---|
209
+ | `v1.js` (core) | 10.76 KB | 11.82 KB | always, `async` |
210
+ | `x-<hash>.js` (signals, autocapture, vitals, offline queue, the replay controller) | 7.91 KB | 8.76 KB | when the core boots (idle) |
211
+ | `r-<hash>.js` (rrweb, masking, chunking) | 22.87 KB | 25.67 KB | only when this session is recorded, after the page's `load` event, at idle |
212
+ | `i-<hash>.js` (console and network capture) | 3.42 KB | 3.78 KB | loaded by the replay chunk, only when the site turned console or network capture on |
213
+ | snippet | 0.28 KB | 0.34 KB | inline |
214
+
215
+ CI fails when a file outgrows its budget (`scripts/size.ts`). How it stays out of your page's way:
216
+
217
+ - `init()` only checks the key and returns. Storage, the first page view, listeners and the config request wait for
218
+ `requestIdleCallback` (at most 1 s); calls made meanwhile are queued with their timestamps. Leaving the page first
219
+ still sends them.
220
+ - Listeners are passive. Scroll position is read once per frame in `requestAnimationFrame`, never inside an event
221
+ handler, and nothing else reads layout while the page scrolls or the pointer moves.
222
+ - The page view goes as soon as the SDK boots; then events go out every 5 s or at 20 events, replay every 10 s, at
223
+ most one request in flight per lane, each request gzipped (`CompressionStream`) when over 1 KB and at most 60 KB.
224
+ Requests use `fetch` with `keepalive`; when the page is hidden or left, what is left goes by `sendBeacon`, and so
225
+ does anything captured while it stays hidden, without waiting for the 5 s cadence. No synchronous XHR, ever.
226
+ - Failed requests back off exponentially (2 s to 5 min, with jitter, honouring `Retry-After`). Offline, nothing is
227
+ tried until the browser is back online; batches wait in IndexedDB for the next page if they must.
228
+ - Every SDK task is timed and reported in `perf` (total main-thread ms, longest task, tasks over 4 and 50 ms), so the
229
+ SDK's own cost is visible per page. Failures are reported once per page as `$sdk_error` and never reach your code.
230
+
231
+ ## What it stores
232
+
233
+ No cookies by default, and never a third-party cookie. Everything is first-party, on your origin, and keyed by a
234
+ short hash of your site key (`<h>` below). `basic` and `off` store nothing at all.
235
+
236
+ | Where | Key | What | Size |
237
+ |---|---|---|---|
238
+ | localStorage | `ib_<h>` | anonymous id, session id, session start and last activity, person id after `identify()` | ~150 B |
239
+ | localStorage | `ib_consent_<h>` | the consent choice and when it was made (kept 6 months) | ~40 B |
240
+ | localStorage | `ib_cfg_<h>` | the site's remote config (replay sampling, masking), so the next page needn't wait | ~200 B |
241
+ | sessionStorage | `ib_w_<h>` | this tab's window id and batch counters | ~90 B |
242
+ | IndexedDB | `ib-<h>` | batches that could not be sent yet (offline), dropped after 24 h | usually empty |
243
+ | cookie (only `storage: 'cookie'`) | `ib_<h>` | anonymous id, session id and last activity, so subdomains share a visitor; never the person | ~80 B |
244
+
245
+ `storage: 'cookie'` (with `cookieDomain: '.example.com'`) is the one way to get a cookie: first-party, `SameSite=Lax`,
246
+ `Secure` on https, a year. `storage: 'memory'` stores nothing and keeps ids for one page load. Lowering consent deletes
247
+ all of it.
248
+
249
+ ## Debugging
250
+
251
+ `debug: true` (on by default on localhost, and with `?ib_debug=1` in the URL) logs what the SDK does. These say what to
252
+ fix even without it:
253
+
254
+ | Console says | Fix |
255
+ |---|---|
256
+ | `That does not look like a site key` | Copy the `ib_pk_…` key from Sites in the IonBlink app. |
257
+ | `That is a secret key: never put one in a page` | You pasted a server key (`ib_sk_…`). The SDK refuses to start. Revoke it in Sites and use the site key. |
258
+ | `Your Content-Security-Policy blocked https://api.ionblink.com` | Add it to `connect-src`, and `https://cdn.ionblink.com` to `script-src`, or use a first-party proxy. |
259
+ | `IonBlink refused events (403)` | Add your origin to Allowed origins in Sites (staging and preview hosts too), or turn capture on. |
260
+ | `IonBlink refused events (401)` | The key is unknown: check for a typo or a deleted site. |
261
+
262
+ `ionblink.state()` shows the mode, masking level and replay state; `ionblink.ids()` shows the ids (undefined until
263
+ consent allows storage).
264
+
265
+ ## Verified people
266
+
267
+ Any page can call `identify()` with any id, so IonBlink shows an id the browser set as *claimed*. It turns *verified*
268
+ when your server binds the session after sign-in, with [ionblink-node](https://github.com/Winding-Labs/ionblink-node)
269
+ and a secret key:
270
+
271
+ ```ts
272
+ // in the page: send the session's ids with the sign-in request
273
+ await fetch('/api/login', { method: 'POST', headers: { ...ionblink.headers(), 'content-type': 'application/json' }, body })
274
+
275
+ // on your server, once sign-in succeeded (userId from your own session, never from the request body)
276
+ ib.identify({ userId: user.id, ...whoFrom(req.headers) })
277
+ ```
278
+
279
+ If your API is on another origin, allow `x-ionblink-anon, x-ionblink-session` in its CORS allowed headers.
280
+
281
+ ## Development
282
+
283
+ ```sh
284
+ bun run check # typecheck, tests, build, size budgets
285
+ bun run demo # mock ingest + demo pages on http://localhost:8787, batches printed as they arrive
286
+ bun run verify # the same pages in headless Chrome (system install): every install path, no secret in any lane
287
+ ```
288
+
289
+ The wire format is in [`PROTOCOL.md`](../../PROTOCOL.md). `src/protocol.ts`, `scrub.ts`, `props.ts` and `rage.ts` are
290
+ generated from `packages/shared`: edit them there and run `bun run sync` from the repository root.
@@ -0,0 +1,66 @@
1
+ Third-party software in ionblink-js
2
+
3
+ ionblink-js's own code is MIT licensed (LICENSE). Its CDN builds bundle the software below:
4
+
5
+ dist/r-<hash>.js, the session replay chunk (also https://cdn.ionblink.com/sdk/r-<hash>.js), bundles
6
+ - rrweb: @rrweb/record, rrweb, rrweb-snapshot, @rrweb/types and @rrweb/utils (MIT)
7
+ - base64-arraybuffer, through rrweb (MIT)
8
+ dist/v1.js, dist/ionblink.min.js, dist/x-<hash>.js and dist/snippet.min.js hold only ionblink-js's own code.
9
+
10
+ The npm builds (dist/esm, dist/cjs) don't bundle it: @rrweb/record is a dependency, installed with its own licence.
11
+ The build writes this file beside the replay chunk as dist/r-<hash>.js.LICENSE.txt.
12
+
13
+ ================================================================================
14
+ rrweb: @rrweb/record, rrweb, rrweb-snapshot, @rrweb/types, @rrweb/utils
15
+ https://github.com/rrweb-io/rrweb
16
+ ================================================================================
17
+
18
+ MIT License
19
+
20
+ Copyright (c) 2018 Contributors (https://github.com/rrweb-io/rrweb/graphs/contributors)
21
+
22
+ Permission is hereby granted, free of charge, to any person obtaining a copy
23
+ of this software and associated documentation files (the "Software"), to deal
24
+ in the Software without restriction, including without limitation the rights
25
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26
+ copies of the Software, and to permit persons to whom the Software is
27
+ furnished to do so, subject to the following conditions:
28
+
29
+ The above copyright notice and this permission notice shall be included in all
30
+ copies or substantial portions of the Software.
31
+
32
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38
+ SOFTWARE.
39
+
40
+ ================================================================================
41
+ base64-arraybuffer
42
+ https://github.com/niklasvh/base64-arraybuffer
43
+ ================================================================================
44
+
45
+ Copyright (c) 2012 Niklas von Hertzen
46
+
47
+ Permission is hereby granted, free of charge, to any person
48
+ obtaining a copy of this software and associated documentation
49
+ files (the "Software"), to deal in the Software without
50
+ restriction, including without limitation the rights to use,
51
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
52
+ copies of the Software, and to permit persons to whom the
53
+ Software is furnished to do so, subject to the following
54
+ conditions:
55
+
56
+ The above copyright notice and this permission notice shall be
57
+ included in all copies or substantial portions of the Software.
58
+
59
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
60
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
61
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
62
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
63
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
64
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
65
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
66
+ OTHER DEALINGS IN THE SOFTWARE.