@vllnt/analytics 0.2.0-canary.d796133 → 0.2.0

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.
package/CHANGELOG.md CHANGED
@@ -5,13 +5,16 @@ All notable changes to this project are documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
6
6
  adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [0.2.0] - 2026-11-27
8
+ ## [0.2.0] - 2026-11-29
9
9
 
10
10
  ### Added
11
11
 
12
12
  - The package ships version-matched docs for coding agents and other readers: `docs/API.md`
13
13
  (every public export with its signature and an example), `llms.txt` and `CHANGELOG.md`.
14
14
  `llms.txt` links to these files and to the TypeScript sources in `src/`, which still ship.
15
+ - `maxQueuedEvents` in `AnalyticsConfig` and the `DEFAULT_MAX_QUEUED_EVENTS` constant (`100`): how
16
+ many `track()` and `trackPage()` calls are queued before `initAnalytics()` runs. `0` queues
17
+ nothing; a value that is not a non-negative safe integer means the default.
15
18
 
16
19
  ### Changed
17
20
 
@@ -28,6 +31,16 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
28
31
  - **Breaking:** when `initAnalytics()` is blocked by Do Not Track or a stored decline, it drops the
29
32
  events queued before it, as `disableAnalytics()` does. Before, they were kept and flushed by a
30
33
  later successful `enableAnalytics()` (after the user accepted, or Do Not Track was turned off).
34
+ - **Breaking:** until `initAnalytics()` runs, only the first 100 `track()` and `trackPage()`
35
+ calls are queued; later calls are dropped. Before, the queue had no size limit.
36
+ To change the limit, set `maxQueuedEvents` in the `config` you pass to `AnalyticsProvider`.
37
+ Without the provider, the limit stays at 100 until `initAnalytics()` runs.
38
+ - The npm description and keywords changed, and `package.json` now lists `homepage`, `bugs`,
39
+ `author` and `funding`.
40
+ - TypeScript users need `@types/react` 18.2.6 or later, because the compiled `./react`
41
+ declarations use `React.JSX.Element`. 0.1.1 shipped TypeScript sources that did not name
42
+ `React.JSX`, so older `@types/react` 18.x versions worked.
43
+ - Internal only: CI, a test that installs the packed package, a docs contract test, and tooling.
31
44
 
32
45
  ### Fixed
33
46
 
@@ -36,6 +49,9 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
36
49
  - In `AnalyticsProvider` and `useConsent`, `acceptAll` and `declineAnalytics` save the choice with
37
50
  their `consentVersion`; `updateConsent` keeps the stored version. Before, they always saved
38
51
  version `1`, so a `consentVersion` above `1` asked the user again on every visit.
52
+ - A stored consent choice is now read even when `localStorage` is full, so a stored decline keeps
53
+ tracking blocked. Before, the failed write check made it ignored, so tracking started and
54
+ `AnalyticsProvider` showed the banner again.
39
55
 
40
56
  ### Security
41
57
 
package/README.md CHANGED
@@ -54,6 +54,7 @@ Every public export. Full signatures and examples: [`docs/API.md`](docs/API.md).
54
54
  | [`disableAnalytics`](docs/API.md#disableanalytics) | `.` | Blocks tracking and empties the queue. |
55
55
  | [`isAnalyticsEnabled`](docs/API.md#isanalyticsenabled) | `.` | `true` when started and not blocked. |
56
56
  | [`getAnalyticsState`](docs/API.md#getanalyticsstate) | `.` | Current instance state, for debugging. |
57
+ | [`DEFAULT_MAX_QUEUED_EVENTS`](docs/API.md#default_max_queued_events) | `.` | Default `maxQueuedEvents`, `100`. |
57
58
  | [`trackTutorialStart`](docs/API.md#tutorial-helpers) | `.` | Tracks a `tutorial_start` event. |
58
59
  | [`trackSectionView`](docs/API.md#tutorial-helpers) | `.` | Tracks a `tutorial_section_view` event. |
59
60
  | [`trackSectionComplete`](docs/API.md#tutorial-helpers) | `.` | Tracks a `tutorial_section_complete` event. |
@@ -77,7 +78,7 @@ Every public export. Full signatures and examples: [`docs/API.md`](docs/API.md).
77
78
  | [`AnalyticsProvider`](docs/API.md#analyticsprovider) | `./react` | Context provider that wires consent to tracking. |
78
79
  | [`useAnalytics`](docs/API.md#useanalytics) | `./react` | Provider context: consent state and actions. |
79
80
  | [`useConsent`](docs/API.md#useconsent) | `./react` | Standalone consent state; does not start tracking. |
80
- | [`AnalyticsConfig`](docs/API.md#types) | `.` (type) | `{ app; debug?; version? }`. |
81
+ | [`AnalyticsConfig`](docs/API.md#types) | `.` (type) | `{ app; debug?; maxQueuedEvents?; version? }`. |
81
82
  | [`AnalyticsEvent`](docs/API.md#types) | `.` (type) | A queued event: name, properties, timestamp. |
82
83
  | [`ConsentCategory`](docs/API.md#types) | `.` (type) | `"analytics" \| "functional"`. |
83
84
  | [`ConsentState`](docs/API.md#types) | `.` (type) | Stored consent: categories, timestamp, version. |
@@ -222,16 +223,19 @@ The package has no error codes. These are every message it throws or logs as a w
222
223
  | Message | Kind | Cause | Fix |
223
224
  | --- | --- | --- | --- |
224
225
  | `useAnalytics must be used within an AnalyticsProvider` | thrown by `useAnalytics()` | The hook ran outside `<AnalyticsProvider>`. | Render the component inside `<AnalyticsProvider>`, or use `useConsent()`. |
225
- | `Failed to save consent:` | `console.warn` from `saveConsent()` | Writing `localStorage` or the cookie threw, for example a full quota. | The new choice applies on this page but is not stored, so later visits load the earlier stored choice, if any. A failed accept over a stored decline stays blocked on this page too, because `initAnalytics` re-reads the stored decline. Free storage, or call `clearConsent()` after a failed save. |
226
+ | `Failed to save consent:` | `console.warn` from `saveConsent()` | The write probe (`isStorageAvailable()`) succeeded, but writing the consent value to `localStorage` or setting the cookie threw, for example because the value did not fit in the space left. On a completely full quota the probe fails first, so `saveConsent()` returns without saving and without this warning. | The new choice applies on this page but is not stored, so later visits load the earlier stored choice, if any. A failed accept over a stored decline stays blocked on this page too, because `initAnalytics` re-reads the stored decline. Free storage, or call `clearConsent()` after a failed save. |
226
227
 
227
228
  ## Limits and gotchas
228
229
 
229
230
  - No transport and no event callback: events never leave the page. With `debug: true` they are
230
231
  logged with `console.log` as `[analytics:track]`, `[analytics:page]` and similar.
231
- - Before the visitor responds, `track()` and `trackPage()` are queued in memory with no size
232
- limit. The first unblocked `initAnalytics()` flushes them; a decline or a Do Not Track block drops
233
- them. After `resetConsent()`, tracking is blocked and events are dropped until the visitor
234
- responds again.
232
+ - Until `initAnalytics()` runs, `track()` and `trackPage()` are queued in memory. The queue keeps
233
+ the first `maxQueuedEvents` calls (default 100, shared by both) and drops later ones; `0` queues
234
+ nothing. `AnalyticsProvider` applies `config.maxQueuedEvents` on mount. Without the provider, the
235
+ default applies until `initAnalytics()` runs; it then keeps only the first `maxQueuedEvents`
236
+ queued events. The first unblocked `initAnalytics()` flushes them; a decline or a Do Not Track
237
+ block drops them. After `resetConsent()`, tracking is blocked and events are dropped until the
238
+ visitor responds again.
235
239
  - `identify()` before init or while blocked does nothing; it is not queued.
236
240
  - `track()` with an empty or non-string name and `identify()` with an empty or non-string id do
237
241
  nothing.
@@ -242,8 +246,11 @@ The package has no error codes. These are every message it throws or logs as a w
242
246
  - `disableAnalytics()` keeps the user id and traits; call `resetAnalytics()` to clear them.
243
247
  - On the server, `track`, `trackPage`, `identify` and `resetAnalytics` do nothing and `loadConsent`
244
248
  returns `null`. `initAnalytics` has no server guard: call it only in the browser.
245
- - When `localStorage` is unavailable, `saveConsent` and `clearConsent` do nothing, so the choice
246
- lasts for the current page only.
249
+ - When `localStorage` cannot be written (`isStorageAvailable()` is `false`, for example blocked or
250
+ completely full storage), `saveConsent` and `clearConsent` do nothing and log nothing, so a new
251
+ choice lasts for the current page only. `loadConsent` still reads a stored choice whenever
252
+ `localStorage` can be read, so a stored decline keeps tracking blocked, also after an accept that
253
+ could not be saved.
247
254
  - `updateConsent("functional", false)` is ignored: functional consent is always on.
248
255
  `updateConsent` does nothing while `consent` is `null`.
249
256
  - `useConsent()` reads and writes stored consent only; it does not start or stop tracking and does
@@ -259,12 +266,14 @@ AnalyticsProvider mounts
259
266
  │ ├─ Do Not Track on ──▶ blocked, queue dropped
260
267
  │ └─ otherwise ──▶ started, queue flushed
261
268
  ├─ Analytics declined ──▶ disableAnalytics(); track() calls dropped
262
- └─ No consent yet ──▶ no init; track() calls queued in memory
269
+ └─ No consent yet ──▶ no init; first maxQueuedEvents track() calls queued in memory
263
270
  ```
264
271
 
265
272
  ## Compatibility
266
273
 
267
274
  - React: peer range `^18.0.0 || ^19.0.0`, used by `./react` only.
275
+ - TypeScript users need `@types/react` 18.2.6 or later: the `./react` declarations use
276
+ `React.JSX.Element`.
268
277
  - Module formats: ESM and CommonJS, with type declarations for both, from `dist/`.
269
278
  - `./react` starts with `"use client"` in both builds; the core entry does not, so server code can
270
279
  import it.
@@ -277,7 +286,8 @@ The analytics state is a module-level singleton with no public reset. In your te
277
286
  `localStorage` between cases and load the module fresh when a case needs a new instance.
278
287
 
279
288
  This repository's own checks: `pnpm lint`, `pnpm typecheck`, `pnpm test:coverage` (Vitest with
280
- jsdom, 100% coverage gate) and `pnpm build`.
289
+ jsdom, 100% coverage gate), `pnpm build` and `pnpm test:package` (installs the packed tarball in a
290
+ clean project with the repo's release-age rule, and imports and type-checks every entry point).
281
291
 
282
292
  ## Security
283
293
 
@@ -292,7 +302,7 @@ None: no other @vllnt package is used together with this one in code.
292
302
  ## Contributing
293
303
 
294
304
  See [CONTRIBUTING.md](https://github.com/vllnt/analytics/blob/main/CONTRIBUTING.md). Setup:
295
- `pnpm install`, then `pnpm lint && pnpm typecheck && pnpm test:coverage && pnpm build`.
305
+ `pnpm install`, then `pnpm lint && pnpm typecheck && pnpm test:coverage && pnpm build && pnpm test:package`.
296
306
 
297
307
  ## Links
298
308
 
@@ -58,6 +58,14 @@ type AnalyticsConfig = {
58
58
  app: string;
59
59
  /** Enable debug mode */
60
60
  debug?: boolean;
61
+ /**
62
+ * How many `track` and `trackPage` calls are queued before `initAnalytics`
63
+ * runs; later calls are dropped. `0` queues nothing. Defaults to
64
+ * `DEFAULT_MAX_QUEUED_EVENTS` (100); any value that is not a non-negative
65
+ * safe integer means the default. `AnalyticsProvider` applies it on mount;
66
+ * without the provider, the default applies until `initAnalytics` runs.
67
+ */
68
+ maxQueuedEvents?: number;
61
69
  /** Application version */
62
70
  version?: number;
63
71
  };
@@ -95,6 +103,11 @@ type AnalyticsState = {
95
103
  userId?: string;
96
104
  version?: number;
97
105
  };
106
+ /**
107
+ * Default `maxQueuedEvents`: how many `track` and `trackPage` calls are kept
108
+ * in memory before `initAnalytics` runs.
109
+ */
110
+ declare const DEFAULT_MAX_QUEUED_EVENTS = 100;
98
111
  /**
99
112
  * Start the shared analytics instance and flush queued events. Blocks tracking,
100
113
  * and drops the queue, when Do Not Track is on or stored consent declines it.
@@ -103,10 +116,13 @@ type AnalyticsState = {
103
116
  declare function initAnalytics(config: AnalyticsConfig): void;
104
117
  /**
105
118
  * Track a custom event. Events with an empty or non-string name are ignored.
119
+ * Before init, only the first `maxQueuedEvents` calls (shared with
120
+ * `trackPage`) are queued.
106
121
  */
107
122
  declare function track(name: string, properties?: Record<string, unknown>): void;
108
123
  /**
109
- * Track a page view
124
+ * Track a page view. Before init, it shares the `maxQueuedEvents` limit with
125
+ * `track`.
110
126
  */
111
127
  declare function trackPage(properties?: Record<string, unknown>): void;
112
128
  /**
@@ -164,5 +180,5 @@ declare function trackTimeSpent(properties: TutorialEventProperties & {
164
180
  time_spent_seconds: number;
165
181
  }): void;
166
182
 
167
- export { disableAnalytics as e, enableAnalytics as f, getAnalyticsState as g, initAnalytics as h, identify as i, isAnalyticsEnabled as j, trackPage as k, trackSectionComplete as l, trackSectionView as m, trackTimeSpent as n, trackTutorialComplete as o, trackTutorialNavigation as p, trackTutorialStart as q, resetAnalytics as r, track as t };
183
+ export { DEFAULT_MAX_QUEUED_EVENTS as D, disableAnalytics as e, enableAnalytics as f, getAnalyticsState as g, initAnalytics as h, identify as i, isAnalyticsEnabled as j, trackPage as k, trackSectionComplete as l, trackSectionView as m, trackTimeSpent as n, trackTutorialComplete as o, trackTutorialNavigation as p, trackTutorialStart as q, resetAnalytics as r, track as t };
168
184
  export type { AnalyticsConfig as A, ConsentState as C, TutorialEventName as T, UseConsentOptions as U, ConsentCategory as a, AnalyticsEvent as b, TutorialEventProperties as c, UseConsentReturn as d };
@@ -58,6 +58,14 @@ type AnalyticsConfig = {
58
58
  app: string;
59
59
  /** Enable debug mode */
60
60
  debug?: boolean;
61
+ /**
62
+ * How many `track` and `trackPage` calls are queued before `initAnalytics`
63
+ * runs; later calls are dropped. `0` queues nothing. Defaults to
64
+ * `DEFAULT_MAX_QUEUED_EVENTS` (100); any value that is not a non-negative
65
+ * safe integer means the default. `AnalyticsProvider` applies it on mount;
66
+ * without the provider, the default applies until `initAnalytics` runs.
67
+ */
68
+ maxQueuedEvents?: number;
61
69
  /** Application version */
62
70
  version?: number;
63
71
  };
@@ -95,6 +103,11 @@ type AnalyticsState = {
95
103
  userId?: string;
96
104
  version?: number;
97
105
  };
106
+ /**
107
+ * Default `maxQueuedEvents`: how many `track` and `trackPage` calls are kept
108
+ * in memory before `initAnalytics` runs.
109
+ */
110
+ declare const DEFAULT_MAX_QUEUED_EVENTS = 100;
98
111
  /**
99
112
  * Start the shared analytics instance and flush queued events. Blocks tracking,
100
113
  * and drops the queue, when Do Not Track is on or stored consent declines it.
@@ -103,10 +116,13 @@ type AnalyticsState = {
103
116
  declare function initAnalytics(config: AnalyticsConfig): void;
104
117
  /**
105
118
  * Track a custom event. Events with an empty or non-string name are ignored.
119
+ * Before init, only the first `maxQueuedEvents` calls (shared with
120
+ * `trackPage`) are queued.
106
121
  */
107
122
  declare function track(name: string, properties?: Record<string, unknown>): void;
108
123
  /**
109
- * Track a page view
124
+ * Track a page view. Before init, it shares the `maxQueuedEvents` limit with
125
+ * `track`.
110
126
  */
111
127
  declare function trackPage(properties?: Record<string, unknown>): void;
112
128
  /**
@@ -164,5 +180,5 @@ declare function trackTimeSpent(properties: TutorialEventProperties & {
164
180
  time_spent_seconds: number;
165
181
  }): void;
166
182
 
167
- export { disableAnalytics as e, enableAnalytics as f, getAnalyticsState as g, initAnalytics as h, identify as i, isAnalyticsEnabled as j, trackPage as k, trackSectionComplete as l, trackSectionView as m, trackTimeSpent as n, trackTutorialComplete as o, trackTutorialNavigation as p, trackTutorialStart as q, resetAnalytics as r, track as t };
183
+ export { DEFAULT_MAX_QUEUED_EVENTS as D, disableAnalytics as e, enableAnalytics as f, getAnalyticsState as g, initAnalytics as h, identify as i, isAnalyticsEnabled as j, trackPage as k, trackSectionComplete as l, trackSectionView as m, trackTimeSpent as n, trackTutorialComplete as o, trackTutorialNavigation as p, trackTutorialStart as q, resetAnalytics as r, track as t };
168
184
  export type { AnalyticsConfig as A, ConsentState as C, TutorialEventName as T, UseConsentOptions as U, ConsentCategory as a, AnalyticsEvent as b, TutorialEventProperties as c, UseConsentReturn as d };
@@ -19,7 +19,7 @@ function isStorageAvailable() {
19
19
  }
20
20
  }
21
21
  function loadConsent() {
22
- if (!isStorageAvailable()) return null;
22
+ if (typeof window === "undefined") return null;
23
23
  try {
24
24
  const raw = localStorage.getItem(CONSENT_STORAGE_KEY);
25
25
  if (!raw) return null;
@@ -95,9 +95,18 @@ function getConsentFromCookie(cookieString) {
95
95
 
96
96
  // src/analytics.ts
97
97
  var analyticsState;
98
+ var DEFAULT_MAX_QUEUED_EVENTS = 100;
98
99
  var eventQueue = [];
100
+ var maxQueuedEvents = DEFAULT_MAX_QUEUED_EVENTS;
99
101
  var isInitialized = false;
100
102
  var isBlocked = false;
103
+ function setMaxQueuedEvents(limit) {
104
+ maxQueuedEvents = typeof limit === "number" && Number.isSafeInteger(limit) && limit >= 0 ? limit : DEFAULT_MAX_QUEUED_EVENTS;
105
+ eventQueue = eventQueue.slice(0, maxQueuedEvents);
106
+ }
107
+ function enqueue(event) {
108
+ if (eventQueue.length < maxQueuedEvents) eventQueue.push(event);
109
+ }
101
110
  function block() {
102
111
  isBlocked = true;
103
112
  eventQueue = [];
@@ -112,6 +121,7 @@ function sendEvent(name, properties) {
112
121
  }
113
122
  function initAnalytics(config) {
114
123
  if (analyticsState) return;
124
+ setMaxQueuedEvents(config.maxQueuedEvents);
115
125
  if (isDoNotTrackEnabled()) {
116
126
  block();
117
127
  debugLog("init", "Do Not Track enabled, analytics blocked");
@@ -154,7 +164,7 @@ function track(name, properties) {
154
164
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
155
165
  };
156
166
  if (!isInitialized) {
157
- eventQueue.push(event);
167
+ enqueue(event);
158
168
  return;
159
169
  }
160
170
  sendEvent(name, properties);
@@ -163,7 +173,7 @@ function trackPage(properties) {
163
173
  if (typeof window === "undefined") return;
164
174
  if (isBlocked) return;
165
175
  if (!isInitialized) {
166
- eventQueue.push({
176
+ enqueue({
167
177
  name: "__page__",
168
178
  properties,
169
179
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
@@ -256,4 +266,6 @@ function trackTimeSpent(properties) {
256
266
 
257
267
 
258
268
 
259
- exports.CONSENT_VERSION = CONSENT_VERSION; exports.CONSENT_STORAGE_KEY = CONSENT_STORAGE_KEY; exports.CONSENT_COOKIE_NAME = CONSENT_COOKIE_NAME; exports.isValidConsentState = isValidConsentState; exports.isStorageAvailable = isStorageAvailable; exports.loadConsent = loadConsent; exports.saveConsent = saveConsent; exports.clearConsent = clearConsent; exports.createAcceptAllConsent = createAcceptAllConsent; exports.createDeclineAnalyticsConsent = createDeclineAnalyticsConsent; exports.updateConsentCategory = updateConsentCategory; exports.needsRePrompt = needsRePrompt; exports.isDoNotTrackEnabled = isDoNotTrackEnabled; exports.getConsentFromCookie = getConsentFromCookie; exports.initAnalytics = initAnalytics; exports.track = track; exports.trackPage = trackPage; exports.identify = identify; exports.resetAnalytics = resetAnalytics; exports.enableAnalytics = enableAnalytics; exports.disableAnalytics = disableAnalytics; exports.isAnalyticsEnabled = isAnalyticsEnabled; exports.getAnalyticsState = getAnalyticsState; exports.trackTutorialStart = trackTutorialStart; exports.trackSectionView = trackSectionView; exports.trackSectionComplete = trackSectionComplete; exports.trackTutorialComplete = trackTutorialComplete; exports.trackTutorialNavigation = trackTutorialNavigation; exports.trackTimeSpent = trackTimeSpent;
269
+
270
+
271
+ exports.CONSENT_VERSION = CONSENT_VERSION; exports.CONSENT_STORAGE_KEY = CONSENT_STORAGE_KEY; exports.CONSENT_COOKIE_NAME = CONSENT_COOKIE_NAME; exports.isValidConsentState = isValidConsentState; exports.isStorageAvailable = isStorageAvailable; exports.loadConsent = loadConsent; exports.saveConsent = saveConsent; exports.clearConsent = clearConsent; exports.createAcceptAllConsent = createAcceptAllConsent; exports.createDeclineAnalyticsConsent = createDeclineAnalyticsConsent; exports.updateConsentCategory = updateConsentCategory; exports.needsRePrompt = needsRePrompt; exports.isDoNotTrackEnabled = isDoNotTrackEnabled; exports.getConsentFromCookie = getConsentFromCookie; exports.DEFAULT_MAX_QUEUED_EVENTS = DEFAULT_MAX_QUEUED_EVENTS; exports.setMaxQueuedEvents = setMaxQueuedEvents; exports.initAnalytics = initAnalytics; exports.track = track; exports.trackPage = trackPage; exports.identify = identify; exports.resetAnalytics = resetAnalytics; exports.enableAnalytics = enableAnalytics; exports.disableAnalytics = disableAnalytics; exports.isAnalyticsEnabled = isAnalyticsEnabled; exports.getAnalyticsState = getAnalyticsState; exports.trackTutorialStart = trackTutorialStart; exports.trackSectionView = trackSectionView; exports.trackSectionComplete = trackSectionComplete; exports.trackTutorialComplete = trackTutorialComplete; exports.trackTutorialNavigation = trackTutorialNavigation; exports.trackTimeSpent = trackTimeSpent;
@@ -19,7 +19,7 @@ function isStorageAvailable() {
19
19
  }
20
20
  }
21
21
  function loadConsent() {
22
- if (!isStorageAvailable()) return null;
22
+ if (typeof window === "undefined") return null;
23
23
  try {
24
24
  const raw = localStorage.getItem(CONSENT_STORAGE_KEY);
25
25
  if (!raw) return null;
@@ -95,9 +95,18 @@ function getConsentFromCookie(cookieString) {
95
95
 
96
96
  // src/analytics.ts
97
97
  var analyticsState;
98
+ var DEFAULT_MAX_QUEUED_EVENTS = 100;
98
99
  var eventQueue = [];
100
+ var maxQueuedEvents = DEFAULT_MAX_QUEUED_EVENTS;
99
101
  var isInitialized = false;
100
102
  var isBlocked = false;
103
+ function setMaxQueuedEvents(limit) {
104
+ maxQueuedEvents = typeof limit === "number" && Number.isSafeInteger(limit) && limit >= 0 ? limit : DEFAULT_MAX_QUEUED_EVENTS;
105
+ eventQueue = eventQueue.slice(0, maxQueuedEvents);
106
+ }
107
+ function enqueue(event) {
108
+ if (eventQueue.length < maxQueuedEvents) eventQueue.push(event);
109
+ }
101
110
  function block() {
102
111
  isBlocked = true;
103
112
  eventQueue = [];
@@ -112,6 +121,7 @@ function sendEvent(name, properties) {
112
121
  }
113
122
  function initAnalytics(config) {
114
123
  if (analyticsState) return;
124
+ setMaxQueuedEvents(config.maxQueuedEvents);
115
125
  if (isDoNotTrackEnabled()) {
116
126
  block();
117
127
  debugLog("init", "Do Not Track enabled, analytics blocked");
@@ -154,7 +164,7 @@ function track(name, properties) {
154
164
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
155
165
  };
156
166
  if (!isInitialized) {
157
- eventQueue.push(event);
167
+ enqueue(event);
158
168
  return;
159
169
  }
160
170
  sendEvent(name, properties);
@@ -163,7 +173,7 @@ function trackPage(properties) {
163
173
  if (typeof window === "undefined") return;
164
174
  if (isBlocked) return;
165
175
  if (!isInitialized) {
166
- eventQueue.push({
176
+ enqueue({
167
177
  name: "__page__",
168
178
  properties,
169
179
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
@@ -241,6 +251,8 @@ export {
241
251
  needsRePrompt,
242
252
  isDoNotTrackEnabled,
243
253
  getConsentFromCookie,
254
+ DEFAULT_MAX_QUEUED_EVENTS,
255
+ setMaxQueuedEvents,
244
256
  initAnalytics,
245
257
  track,
246
258
  trackPage,
package/dist/index.cjs CHANGED
@@ -28,8 +28,8 @@
28
28
 
29
29
 
30
30
 
31
- var _chunkACWD5NRIcjs = require('./chunk-ACWD5NRI.cjs');
32
31
 
32
+ var _chunkBOGMJ4Z4cjs = require('./chunk-BOGMJ4Z4.cjs');
33
33
 
34
34
 
35
35
 
@@ -59,4 +59,6 @@ var _chunkACWD5NRIcjs = require('./chunk-ACWD5NRI.cjs');
59
59
 
60
60
 
61
61
 
62
- exports.CONSENT_COOKIE_NAME = _chunkACWD5NRIcjs.CONSENT_COOKIE_NAME; exports.CONSENT_STORAGE_KEY = _chunkACWD5NRIcjs.CONSENT_STORAGE_KEY; exports.CONSENT_VERSION = _chunkACWD5NRIcjs.CONSENT_VERSION; exports.clearConsent = _chunkACWD5NRIcjs.clearConsent; exports.createAcceptAllConsent = _chunkACWD5NRIcjs.createAcceptAllConsent; exports.createDeclineAnalyticsConsent = _chunkACWD5NRIcjs.createDeclineAnalyticsConsent; exports.disableAnalytics = _chunkACWD5NRIcjs.disableAnalytics; exports.enableAnalytics = _chunkACWD5NRIcjs.enableAnalytics; exports.getAnalyticsState = _chunkACWD5NRIcjs.getAnalyticsState; exports.getConsentFromCookie = _chunkACWD5NRIcjs.getConsentFromCookie; exports.identify = _chunkACWD5NRIcjs.identify; exports.initAnalytics = _chunkACWD5NRIcjs.initAnalytics; exports.isAnalyticsEnabled = _chunkACWD5NRIcjs.isAnalyticsEnabled; exports.isDoNotTrackEnabled = _chunkACWD5NRIcjs.isDoNotTrackEnabled; exports.isStorageAvailable = _chunkACWD5NRIcjs.isStorageAvailable; exports.isValidConsentState = _chunkACWD5NRIcjs.isValidConsentState; exports.loadConsent = _chunkACWD5NRIcjs.loadConsent; exports.needsRePrompt = _chunkACWD5NRIcjs.needsRePrompt; exports.resetAnalytics = _chunkACWD5NRIcjs.resetAnalytics; exports.saveConsent = _chunkACWD5NRIcjs.saveConsent; exports.track = _chunkACWD5NRIcjs.track; exports.trackPage = _chunkACWD5NRIcjs.trackPage; exports.trackSectionComplete = _chunkACWD5NRIcjs.trackSectionComplete; exports.trackSectionView = _chunkACWD5NRIcjs.trackSectionView; exports.trackTimeSpent = _chunkACWD5NRIcjs.trackTimeSpent; exports.trackTutorialComplete = _chunkACWD5NRIcjs.trackTutorialComplete; exports.trackTutorialNavigation = _chunkACWD5NRIcjs.trackTutorialNavigation; exports.trackTutorialStart = _chunkACWD5NRIcjs.trackTutorialStart; exports.updateConsentCategory = _chunkACWD5NRIcjs.updateConsentCategory;
62
+
63
+
64
+ exports.CONSENT_COOKIE_NAME = _chunkBOGMJ4Z4cjs.CONSENT_COOKIE_NAME; exports.CONSENT_STORAGE_KEY = _chunkBOGMJ4Z4cjs.CONSENT_STORAGE_KEY; exports.CONSENT_VERSION = _chunkBOGMJ4Z4cjs.CONSENT_VERSION; exports.DEFAULT_MAX_QUEUED_EVENTS = _chunkBOGMJ4Z4cjs.DEFAULT_MAX_QUEUED_EVENTS; exports.clearConsent = _chunkBOGMJ4Z4cjs.clearConsent; exports.createAcceptAllConsent = _chunkBOGMJ4Z4cjs.createAcceptAllConsent; exports.createDeclineAnalyticsConsent = _chunkBOGMJ4Z4cjs.createDeclineAnalyticsConsent; exports.disableAnalytics = _chunkBOGMJ4Z4cjs.disableAnalytics; exports.enableAnalytics = _chunkBOGMJ4Z4cjs.enableAnalytics; exports.getAnalyticsState = _chunkBOGMJ4Z4cjs.getAnalyticsState; exports.getConsentFromCookie = _chunkBOGMJ4Z4cjs.getConsentFromCookie; exports.identify = _chunkBOGMJ4Z4cjs.identify; exports.initAnalytics = _chunkBOGMJ4Z4cjs.initAnalytics; exports.isAnalyticsEnabled = _chunkBOGMJ4Z4cjs.isAnalyticsEnabled; exports.isDoNotTrackEnabled = _chunkBOGMJ4Z4cjs.isDoNotTrackEnabled; exports.isStorageAvailable = _chunkBOGMJ4Z4cjs.isStorageAvailable; exports.isValidConsentState = _chunkBOGMJ4Z4cjs.isValidConsentState; exports.loadConsent = _chunkBOGMJ4Z4cjs.loadConsent; exports.needsRePrompt = _chunkBOGMJ4Z4cjs.needsRePrompt; exports.resetAnalytics = _chunkBOGMJ4Z4cjs.resetAnalytics; exports.saveConsent = _chunkBOGMJ4Z4cjs.saveConsent; exports.track = _chunkBOGMJ4Z4cjs.track; exports.trackPage = _chunkBOGMJ4Z4cjs.trackPage; exports.trackSectionComplete = _chunkBOGMJ4Z4cjs.trackSectionComplete; exports.trackSectionView = _chunkBOGMJ4Z4cjs.trackSectionView; exports.trackTimeSpent = _chunkBOGMJ4Z4cjs.trackTimeSpent; exports.trackTutorialComplete = _chunkBOGMJ4Z4cjs.trackTutorialComplete; exports.trackTutorialNavigation = _chunkBOGMJ4Z4cjs.trackTutorialNavigation; exports.trackTutorialStart = _chunkBOGMJ4Z4cjs.trackTutorialStart; exports.updateConsentCategory = _chunkBOGMJ4Z4cjs.updateConsentCategory;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as ConsentState, a as ConsentCategory } from './analytics-BxUQktfB.cjs';
2
- export { A as AnalyticsConfig, b as AnalyticsEvent, T as TutorialEventName, c as TutorialEventProperties, U as UseConsentOptions, d as UseConsentReturn, e as disableAnalytics, f as enableAnalytics, g as getAnalyticsState, i as identify, h as initAnalytics, j as isAnalyticsEnabled, r as resetAnalytics, t as track, k as trackPage, l as trackSectionComplete, m as trackSectionView, n as trackTimeSpent, o as trackTutorialComplete, p as trackTutorialNavigation, q as trackTutorialStart } from './analytics-BxUQktfB.cjs';
1
+ import { C as ConsentState, a as ConsentCategory } from './analytics-BGm5JlCM.cjs';
2
+ export { A as AnalyticsConfig, b as AnalyticsEvent, D as DEFAULT_MAX_QUEUED_EVENTS, T as TutorialEventName, c as TutorialEventProperties, U as UseConsentOptions, d as UseConsentReturn, e as disableAnalytics, f as enableAnalytics, g as getAnalyticsState, i as identify, h as initAnalytics, j as isAnalyticsEnabled, r as resetAnalytics, t as track, k as trackPage, l as trackSectionComplete, m as trackSectionView, n as trackTimeSpent, o as trackTutorialComplete, p as trackTutorialNavigation, q as trackTutorialStart } from './analytics-BGm5JlCM.cjs';
3
3
 
4
4
  /** Current consent schema version - bump to re-prompt users */
5
5
  declare const CONSENT_VERSION = 1;
@@ -16,7 +16,9 @@ declare function isValidConsentState(value: unknown): value is ConsentState;
16
16
  */
17
17
  declare function isStorageAvailable(): boolean;
18
18
  /**
19
- * Load consent state from localStorage
19
+ * Load consent state from localStorage.
20
+ * Reads directly (no write probe), so a stored choice is still found when the
21
+ * storage quota is full.
20
22
  */
21
23
  declare function loadConsent(): ConsentState | null;
22
24
  /**
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as ConsentState, a as ConsentCategory } from './analytics-BxUQktfB.js';
2
- export { A as AnalyticsConfig, b as AnalyticsEvent, T as TutorialEventName, c as TutorialEventProperties, U as UseConsentOptions, d as UseConsentReturn, e as disableAnalytics, f as enableAnalytics, g as getAnalyticsState, i as identify, h as initAnalytics, j as isAnalyticsEnabled, r as resetAnalytics, t as track, k as trackPage, l as trackSectionComplete, m as trackSectionView, n as trackTimeSpent, o as trackTutorialComplete, p as trackTutorialNavigation, q as trackTutorialStart } from './analytics-BxUQktfB.js';
1
+ import { C as ConsentState, a as ConsentCategory } from './analytics-BGm5JlCM.js';
2
+ export { A as AnalyticsConfig, b as AnalyticsEvent, D as DEFAULT_MAX_QUEUED_EVENTS, T as TutorialEventName, c as TutorialEventProperties, U as UseConsentOptions, d as UseConsentReturn, e as disableAnalytics, f as enableAnalytics, g as getAnalyticsState, i as identify, h as initAnalytics, j as isAnalyticsEnabled, r as resetAnalytics, t as track, k as trackPage, l as trackSectionComplete, m as trackSectionView, n as trackTimeSpent, o as trackTutorialComplete, p as trackTutorialNavigation, q as trackTutorialStart } from './analytics-BGm5JlCM.js';
3
3
 
4
4
  /** Current consent schema version - bump to re-prompt users */
5
5
  declare const CONSENT_VERSION = 1;
@@ -16,7 +16,9 @@ declare function isValidConsentState(value: unknown): value is ConsentState;
16
16
  */
17
17
  declare function isStorageAvailable(): boolean;
18
18
  /**
19
- * Load consent state from localStorage
19
+ * Load consent state from localStorage.
20
+ * Reads directly (no write probe), so a stored choice is still found when the
21
+ * storage quota is full.
20
22
  */
21
23
  declare function loadConsent(): ConsentState | null;
22
24
  /**
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ import {
2
2
  CONSENT_COOKIE_NAME,
3
3
  CONSENT_STORAGE_KEY,
4
4
  CONSENT_VERSION,
5
+ DEFAULT_MAX_QUEUED_EVENTS,
5
6
  clearConsent,
6
7
  createAcceptAllConsent,
7
8
  createDeclineAnalyticsConsent,
@@ -28,11 +29,12 @@ import {
28
29
  trackTutorialNavigation,
29
30
  trackTutorialStart,
30
31
  updateConsentCategory
31
- } from "./chunk-5COCGKHD.js";
32
+ } from "./chunk-IBYWNCQ4.js";
32
33
  export {
33
34
  CONSENT_COOKIE_NAME,
34
35
  CONSENT_STORAGE_KEY,
35
36
  CONSENT_VERSION,
37
+ DEFAULT_MAX_QUEUED_EVENTS,
36
38
  clearConsent,
37
39
  createAcceptAllConsent,
38
40
  createDeclineAnalyticsConsent,
package/dist/react.cjs CHANGED
@@ -11,7 +11,8 @@
11
11
 
12
12
 
13
13
 
14
- var _chunkACWD5NRIcjs = require('./chunk-ACWD5NRI.cjs');
14
+
15
+ var _chunkBOGMJ4Z4cjs = require('./chunk-BOGMJ4Z4.cjs');
15
16
 
16
17
  // src/react.tsx
17
18
 
@@ -27,13 +28,14 @@ var AnalyticsContext = _react.createContext.call(void 0, null);
27
28
  function AnalyticsProvider({
28
29
  children,
29
30
  config,
30
- consentVersion = _chunkACWD5NRIcjs.CONSENT_VERSION
31
+ consentVersion = _chunkBOGMJ4Z4cjs.CONSENT_VERSION
31
32
  }) {
32
33
  const [consent, setConsent] = _react.useState.call(void 0, () => {
33
- const stored = _chunkACWD5NRIcjs.loadConsent.call(void 0, );
34
+ _chunkBOGMJ4Z4cjs.setMaxQueuedEvents.call(void 0, config.maxQueuedEvents);
35
+ const stored = _chunkBOGMJ4Z4cjs.loadConsent.call(void 0, );
34
36
  if (!stored) return null;
35
- if (_chunkACWD5NRIcjs.needsRePrompt.call(void 0, stored, consentVersion)) {
36
- _chunkACWD5NRIcjs.clearConsent.call(void 0, );
37
+ if (_chunkBOGMJ4Z4cjs.needsRePrompt.call(void 0, stored, consentVersion)) {
38
+ _chunkBOGMJ4Z4cjs.clearConsent.call(void 0, );
37
39
  return null;
38
40
  }
39
41
  return stored;
@@ -42,49 +44,49 @@ function AnalyticsProvider({
42
44
  _react.useEffect.call(void 0, () => {
43
45
  if (!consent) return;
44
46
  if (consent.analytics) {
45
- _chunkACWD5NRIcjs.initAnalytics.call(void 0, config);
47
+ _chunkBOGMJ4Z4cjs.initAnalytics.call(void 0, config);
46
48
  } else {
47
- _chunkACWD5NRIcjs.disableAnalytics.call(void 0, );
49
+ _chunkBOGMJ4Z4cjs.disableAnalytics.call(void 0, );
48
50
  }
49
51
  }, [consent, config]);
50
52
  const acceptAll = _react.useCallback.call(void 0, () => {
51
- const newConsent = { ..._chunkACWD5NRIcjs.createAcceptAllConsent.call(void 0, ), version: consentVersion };
52
- _chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
53
+ const newConsent = { ..._chunkBOGMJ4Z4cjs.createAcceptAllConsent.call(void 0, ), version: consentVersion };
54
+ _chunkBOGMJ4Z4cjs.saveConsent.call(void 0, newConsent);
53
55
  setConsent(newConsent);
54
56
  setHasResponded(true);
55
- _chunkACWD5NRIcjs.enableAnalytics.call(void 0, config);
57
+ _chunkBOGMJ4Z4cjs.enableAnalytics.call(void 0, config);
56
58
  }, [config, consentVersion]);
57
59
  const declineAnalytics = _react.useCallback.call(void 0, () => {
58
60
  const newConsent = {
59
- ..._chunkACWD5NRIcjs.createDeclineAnalyticsConsent.call(void 0, ),
61
+ ..._chunkBOGMJ4Z4cjs.createDeclineAnalyticsConsent.call(void 0, ),
60
62
  version: consentVersion
61
63
  };
62
- _chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
64
+ _chunkBOGMJ4Z4cjs.saveConsent.call(void 0, newConsent);
63
65
  setConsent(newConsent);
64
66
  setHasResponded(true);
65
- _chunkACWD5NRIcjs.disableAnalytics.call(void 0, );
67
+ _chunkBOGMJ4Z4cjs.disableAnalytics.call(void 0, );
66
68
  }, [consentVersion]);
67
69
  const updateConsentHandler = _react.useCallback.call(void 0,
68
70
  (category, value2) => {
69
71
  if (!consent) return;
70
- const newConsent = _chunkACWD5NRIcjs.updateConsentCategory.call(void 0, consent, category, value2);
71
- _chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
72
+ const newConsent = _chunkBOGMJ4Z4cjs.updateConsentCategory.call(void 0, consent, category, value2);
73
+ _chunkBOGMJ4Z4cjs.saveConsent.call(void 0, newConsent);
72
74
  setConsent(newConsent);
73
75
  if (category === "analytics") {
74
76
  if (value2) {
75
- _chunkACWD5NRIcjs.enableAnalytics.call(void 0, config);
77
+ _chunkBOGMJ4Z4cjs.enableAnalytics.call(void 0, config);
76
78
  } else {
77
- _chunkACWD5NRIcjs.disableAnalytics.call(void 0, );
79
+ _chunkBOGMJ4Z4cjs.disableAnalytics.call(void 0, );
78
80
  }
79
81
  }
80
82
  },
81
83
  [consent, config]
82
84
  );
83
85
  const resetConsentHandler = _react.useCallback.call(void 0, () => {
84
- _chunkACWD5NRIcjs.clearConsent.call(void 0, );
86
+ _chunkBOGMJ4Z4cjs.clearConsent.call(void 0, );
85
87
  setConsent(null);
86
88
  setHasResponded(false);
87
- _chunkACWD5NRIcjs.disableAnalytics.call(void 0, );
89
+ _chunkBOGMJ4Z4cjs.disableAnalytics.call(void 0, );
88
90
  }, []);
89
91
  const value = _react.useMemo.call(void 0,
90
92
  () => ({
@@ -117,43 +119,43 @@ function useAnalytics() {
117
119
  return context;
118
120
  }
119
121
  function useConsent(options = {}) {
120
- const { consentVersion = _chunkACWD5NRIcjs.CONSENT_VERSION } = options;
122
+ const { consentVersion = _chunkBOGMJ4Z4cjs.CONSENT_VERSION } = options;
121
123
  const [consent, setConsent] = _react.useState.call(void 0, () => {
122
- const stored = _chunkACWD5NRIcjs.loadConsent.call(void 0, );
124
+ const stored = _chunkBOGMJ4Z4cjs.loadConsent.call(void 0, );
123
125
  if (!stored) return null;
124
- if (_chunkACWD5NRIcjs.needsRePrompt.call(void 0, stored, consentVersion)) {
125
- _chunkACWD5NRIcjs.clearConsent.call(void 0, );
126
+ if (_chunkBOGMJ4Z4cjs.needsRePrompt.call(void 0, stored, consentVersion)) {
127
+ _chunkBOGMJ4Z4cjs.clearConsent.call(void 0, );
126
128
  return null;
127
129
  }
128
130
  return stored;
129
131
  });
130
132
  const [hasResponded, setHasResponded] = _react.useState.call(void 0, () => consent !== null);
131
133
  const acceptAll = _react.useCallback.call(void 0, () => {
132
- const newConsent = { ..._chunkACWD5NRIcjs.createAcceptAllConsent.call(void 0, ), version: consentVersion };
133
- _chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
134
+ const newConsent = { ..._chunkBOGMJ4Z4cjs.createAcceptAllConsent.call(void 0, ), version: consentVersion };
135
+ _chunkBOGMJ4Z4cjs.saveConsent.call(void 0, newConsent);
134
136
  setConsent(newConsent);
135
137
  setHasResponded(true);
136
138
  }, [consentVersion]);
137
139
  const declineAnalytics = _react.useCallback.call(void 0, () => {
138
140
  const newConsent = {
139
- ..._chunkACWD5NRIcjs.createDeclineAnalyticsConsent.call(void 0, ),
141
+ ..._chunkBOGMJ4Z4cjs.createDeclineAnalyticsConsent.call(void 0, ),
140
142
  version: consentVersion
141
143
  };
142
- _chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
144
+ _chunkBOGMJ4Z4cjs.saveConsent.call(void 0, newConsent);
143
145
  setConsent(newConsent);
144
146
  setHasResponded(true);
145
147
  }, [consentVersion]);
146
148
  const updateConsentHandler = _react.useCallback.call(void 0,
147
149
  (category, value) => {
148
150
  if (!consent) return;
149
- const newConsent = _chunkACWD5NRIcjs.updateConsentCategory.call(void 0, consent, category, value);
150
- _chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
151
+ const newConsent = _chunkBOGMJ4Z4cjs.updateConsentCategory.call(void 0, consent, category, value);
152
+ _chunkBOGMJ4Z4cjs.saveConsent.call(void 0, newConsent);
151
153
  setConsent(newConsent);
152
154
  },
153
155
  [consent]
154
156
  );
155
157
  const resetConsentHandler = _react.useCallback.call(void 0, () => {
156
- _chunkACWD5NRIcjs.clearConsent.call(void 0, );
158
+ _chunkBOGMJ4Z4cjs.clearConsent.call(void 0, );
157
159
  setConsent(null);
158
160
  setHasResponded(false);
159
161
  }, []);
@@ -172,4 +174,4 @@ function useConsent(options = {}) {
172
174
 
173
175
 
174
176
 
175
- exports.AnalyticsProvider = AnalyticsProvider; exports.initAnalytics = _chunkACWD5NRIcjs.initAnalytics; exports.useAnalytics = useAnalytics; exports.useConsent = useConsent;
177
+ exports.AnalyticsProvider = AnalyticsProvider; exports.initAnalytics = _chunkBOGMJ4Z4cjs.initAnalytics; exports.useAnalytics = useAnalytics; exports.useConsent = useConsent;
package/dist/react.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
  import { AnalyticsConfig, ConsentState, ConsentCategory, UseConsentOptions, UseConsentReturn } from './index.cjs';
4
- export { h as initAnalytics } from './analytics-BxUQktfB.cjs';
4
+ export { h as initAnalytics } from './analytics-BGm5JlCM.cjs';
5
5
 
6
6
  type AnalyticsContextValue = {
7
7
  acceptAll: () => void;
package/dist/react.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
  import { AnalyticsConfig, ConsentState, ConsentCategory, UseConsentOptions, UseConsentReturn } from './index.js';
4
- export { h as initAnalytics } from './analytics-BxUQktfB.js';
4
+ export { h as initAnalytics } from './analytics-BGm5JlCM.js';
5
5
 
6
6
  type AnalyticsContextValue = {
7
7
  acceptAll: () => void;
package/dist/react.js CHANGED
@@ -10,8 +10,9 @@ import {
10
10
  loadConsent,
11
11
  needsRePrompt,
12
12
  saveConsent,
13
+ setMaxQueuedEvents,
13
14
  updateConsentCategory
14
- } from "./chunk-5COCGKHD.js";
15
+ } from "./chunk-IBYWNCQ4.js";
15
16
 
16
17
  // src/react.tsx
17
18
  import {
@@ -30,6 +31,7 @@ function AnalyticsProvider({
30
31
  consentVersion = CONSENT_VERSION
31
32
  }) {
32
33
  const [consent, setConsent] = useState(() => {
34
+ setMaxQueuedEvents(config.maxQueuedEvents);
33
35
  const stored = loadConsent();
34
36
  if (!stored) return null;
35
37
  if (needsRePrompt(stored, consentVersion)) {
package/docs/API.md CHANGED
@@ -23,7 +23,8 @@ one analytics state, so `initAnalytics` from `./react` and `track` from `.` act
23
23
  The ESM and CommonJS builds each have their own copy, so mixing `import` and `require` in one
24
24
  process gives two instances.
25
25
 
26
- Peer dependency: `react` `^18.0.0 || ^19.0.0` (used by `./react` only).
26
+ Peer dependency: `react` `^18.0.0 || ^19.0.0` (used by `./react` only). TypeScript users need
27
+ `@types/react` 18.2.6 or later: the `./react` declarations use `React.JSX.Element`.
27
28
 
28
29
  All browser APIs are guarded, so importing on the server is safe. On the server `track`,
29
30
  `trackPage`, `identify` and `resetAnalytics` return early, `loadConsent` returns `null`, and
@@ -44,7 +45,8 @@ instance exists. It does not start, and blocks tracking, when Do Not Track is on
44
45
  they are never flushed later. With no stored consent it starts, so call it only after the user
45
46
  accepts if you need opt-in (`AnalyticsProvider` does this for you). Once tracking is blocked (by a
46
47
  blocked init or by `disableAnalytics`), calling `initAnalytics` again does not unblock it; only
47
- `enableAnalytics` does.
48
+ `enableAnalytics` does. It applies `config.maxQueuedEvents` first, so only the first
49
+ `maxQueuedEvents` queued events are kept.
48
50
 
49
51
  ```ts
50
52
  import { initAnalytics } from "@vllnt/analytics";
@@ -57,7 +59,9 @@ initAnalytics({ app: "my-app", version: 1, debug: true });
57
59
  Signature: `track(name: string, properties?: Record<string, unknown>): void`
58
60
 
59
61
  Records a custom event. Before `initAnalytics` the event is queued; while blocked it is dropped.
60
- An empty or non-string `name` is ignored.
62
+ An empty or non-string `name` is ignored. The queue keeps the first `maxQueuedEvents` calls to
63
+ `track` and `trackPage` together (default `DEFAULT_MAX_QUEUED_EVENTS`, 100) and drops later
64
+ calls. Events after init are not limited.
61
65
 
62
66
  ```ts
63
67
  import { track } from "@vllnt/analytics";
@@ -69,7 +73,8 @@ track("button_click", { id: "cta-hero" });
69
73
 
70
74
  Signature: `trackPage(properties?: Record<string, unknown>): void`
71
75
 
72
- Records a page view, queued before init like `track`.
76
+ Records a page view, queued before init like `track`. Page views and custom events share one
77
+ queue limit.
73
78
 
74
79
  ```ts
75
80
  import { trackPage } from "@vllnt/analytics";
@@ -157,6 +162,22 @@ import { getAnalyticsState } from "@vllnt/analytics";
157
162
  console.log(getAnalyticsState()?.userId);
158
163
  ```
159
164
 
165
+ ### `DEFAULT_MAX_QUEUED_EVENTS`
166
+
167
+ Value: `100`
168
+
169
+ The default for `AnalyticsConfig.maxQueuedEvents`: how many `track` and `trackPage` calls are
170
+ queued before init. A `maxQueuedEvents` that is not a non-negative safe integer (for example
171
+ `-1`, `1.5` or `NaN`) means this default. `0` queues nothing. `AnalyticsProvider` applies
172
+ `config.maxQueuedEvents` on mount, before `initAnalytics` runs. Without the provider, the default
173
+ applies until `initAnalytics(config)` runs.
174
+
175
+ ```ts
176
+ import { DEFAULT_MAX_QUEUED_EVENTS, initAnalytics } from "@vllnt/analytics";
177
+
178
+ initAnalytics({ app: "my-app", maxQueuedEvents: DEFAULT_MAX_QUEUED_EVENTS * 2 });
179
+ ```
180
+
160
181
  ### Tutorial helpers
161
182
 
162
183
  Typed wrappers around `track` with fixed event names (`TutorialEventName`). Every helper
@@ -197,7 +218,9 @@ Consent is stored as JSON in `localStorage` under `CONSENT_STORAGE_KEY` and mirr
197
218
 
198
219
  Signature: `loadConsent(): ConsentState | null`
199
220
 
200
- Reads and validates stored consent. `null` when none, invalid, or storage is unavailable.
221
+ Reads and validates stored consent. `null` when none is stored, the value is invalid, there is no
222
+ `window`, or reading `localStorage` throws. It reads without a write probe, so a stored choice is
223
+ found even when the storage quota is full.
201
224
 
202
225
  ```ts
203
226
  import { loadConsent } from "@vllnt/analytics";
@@ -210,8 +233,10 @@ console.log(consent?.analytics);
210
233
 
211
234
  Signature: `saveConsent(state: ConsentState): void`
212
235
 
213
- Writes consent to `localStorage` and the cookie. Does nothing when storage is unavailable. Logs
214
- `Failed to save consent:` with `console.warn` when the write throws.
236
+ Writes consent to `localStorage` and the cookie. Does nothing, without a warning, when
237
+ `isStorageAvailable()` is `false`, which includes a completely full quota. Logs
238
+ `Failed to save consent:` with `console.warn` when that probe succeeds but writing the consent
239
+ value or the cookie throws.
215
240
 
216
241
  ```ts
217
242
  import { createAcceptAllConsent, saveConsent } from "@vllnt/analytics";
@@ -319,7 +344,9 @@ console.log(showBanner);
319
344
 
320
345
  Signature: `isStorageAvailable(): boolean`
321
346
 
322
- `true` when `localStorage` can be written. `false` on the server or when storage throws.
347
+ `true` when a test key can be written to and removed from `localStorage`. `false` on the server
348
+ or when that probe throws, for example when storage is blocked or the quota is full. `loadConsent`
349
+ does not depend on it, so a stored choice can still be read when it is `false`.
323
350
 
324
351
  ```ts
325
352
  import { isStorageAvailable } from "@vllnt/analytics";
@@ -360,7 +387,9 @@ Signature: `AnalyticsProvider(props: { children: ReactNode; config: AnalyticsCon
360
387
  stored decline `track()` calls are dropped, not queued. `acceptAll` and `declineAnalytics` save
361
388
  consent with `consentVersion`; `updateConsent` copies the current consent, so it keeps the stored
362
389
  version. The actions call `enableAnalytics` or `disableAnalytics`. Before the user responds (no
363
- stored consent), events are queued in memory and flushed if the user accepts; after
390
+ stored consent), events are queued in memory and flushed if the user accepts; the provider applies
391
+ `config.maxQueuedEvents` during its first render, so the queue keeps the first `maxQueuedEvents`
392
+ events (default 100), including events from child effects on mount. After
364
393
  `resetConsent()`, tracking is blocked and events are dropped until the user responds again. Pass a stable
365
394
  `config` (for example a module constant), because the init effect depends on it.
366
395
 
@@ -439,7 +468,12 @@ In `AnalyticsProvider` and `useConsent`, `acceptAll` and `declineAnalytics` save
439
468
  Exported from `@vllnt/analytics` as types only.
440
469
 
441
470
  ```ts
442
- type AnalyticsConfig = { app: string; debug?: boolean; version?: number };
471
+ type AnalyticsConfig = {
472
+ app: string;
473
+ debug?: boolean;
474
+ maxQueuedEvents?: number; // events queued before init; default 100, 0 queues nothing
475
+ version?: number;
476
+ };
443
477
 
444
478
  type AnalyticsEvent = {
445
479
  name: string;
package/llms.txt CHANGED
@@ -32,7 +32,10 @@ before writing code.
32
32
  ## Behaviour
33
33
 
34
34
  - Events tracked before `initAnalytics()` are queued and flushed on the first unblocked init;
35
- a blocked init drops them. The queue has no size limit.
35
+ a blocked init drops them. The queue keeps the first `maxQueuedEvents` `track()` and
36
+ `trackPage()` calls (default `DEFAULT_MAX_QUEUED_EVENTS`, 100; `0` queues nothing) and drops
37
+ later ones. `AnalyticsProvider` applies the option on mount; without it, the default applies
38
+ until `initAnalytics()` runs.
36
39
  - `initAnalytics()` blocks tracking when Do Not Track is on (`"1"` or `"yes"`) or stored consent
37
40
  has `analytics: false`. With no stored consent it starts tracking. `AnalyticsProvider` calls it
38
41
  while consent has `analytics: true` and calls `disableAnalytics()` after a stored decline, so a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vllnt/analytics",
3
- "version": "0.2.0-canary.d796133",
3
+ "version": "0.2.0",
4
4
  "description": "Cookie consent state and consent-gated event tracking for React and TypeScript, with Do Not Track and an SSR consent cookie.",
5
5
  "type": "module",
6
6
  "packageManager": "pnpm@12.22.0",
@@ -77,6 +77,7 @@
77
77
  "test": "vitest",
78
78
  "test:once": "vitest run",
79
79
  "test:coverage": "vitest run --coverage",
80
+ "test:package": "bash scripts/test-package.sh",
80
81
  "typecheck": "tsc --noEmit --incremental --tsBuildInfoFile node_modules/.cache/tsc/typecheck.tsbuildinfo",
81
82
  "typecheck:ci": "tsc --noEmit --incremental --tsBuildInfoFile node_modules/.cache/tsc/typecheck-ci.tsbuildinfo"
82
83
  },
@@ -84,14 +85,13 @@
84
85
  "react": "^18.0.0 || ^19.0.0"
85
86
  },
86
87
  "devDependencies": {
87
- "@testing-library/jest-dom": "^8.0.0",
88
88
  "@testing-library/react": "^16.3.3",
89
89
  "@types/node": "^24.19.2",
90
90
  "@types/react": "^19.3.0",
91
91
  "@vitest/coverage-v8": "^5.1.1",
92
- "@vllnt/eslint-config": "^2.1.0",
93
- "@vllnt/typescript": "^3.0.0",
94
- "eslint": "^9.39.5",
92
+ "@vllnt/eslint-config": "^2.2.0",
93
+ "@vllnt/typescript": "^3.0.1",
94
+ "eslint": "^10.15.0",
95
95
  "jsdom": "^31.0.1",
96
96
  "react": "^19.3.1",
97
97
  "tsup": "^9.0.0",
package/src/analytics.ts CHANGED
@@ -17,8 +17,15 @@ type AnalyticsState = {
17
17
 
18
18
  let analyticsState: AnalyticsState | undefined;
19
19
 
20
+ /**
21
+ * Default `maxQueuedEvents`: how many `track` and `trackPage` calls are kept
22
+ * in memory before `initAnalytics` runs.
23
+ */
24
+ export const DEFAULT_MAX_QUEUED_EVENTS = 100;
25
+
20
26
  // Queue for events before initialization
21
27
  let eventQueue: AnalyticsEvent[] = [];
28
+ let maxQueuedEvents = DEFAULT_MAX_QUEUED_EVENTS;
22
29
 
23
30
  // Track initialization state
24
31
  let isInitialized = false;
@@ -31,10 +38,31 @@ let isBlocked = false;
31
38
  export function _resetAnalyticsState(): void {
32
39
  analyticsState = undefined;
33
40
  eventQueue = [];
41
+ maxQueuedEvents = DEFAULT_MAX_QUEUED_EVENTS;
34
42
  isInitialized = false;
35
43
  isBlocked = false;
36
44
  }
37
45
 
46
+ /**
47
+ * Set the pre-init queue limit and keep only the first `limit` queued events.
48
+ * A value that is not a non-negative safe integer means the default.
49
+ * @internal
50
+ */
51
+ export function setMaxQueuedEvents(limit: number | undefined): void {
52
+ maxQueuedEvents =
53
+ typeof limit === "number" && Number.isSafeInteger(limit) && limit >= 0
54
+ ? limit
55
+ : DEFAULT_MAX_QUEUED_EVENTS;
56
+ eventQueue = eventQueue.slice(0, maxQueuedEvents);
57
+ }
58
+
59
+ /**
60
+ * Queue an event before init; calls past the limit are dropped.
61
+ */
62
+ function enqueue(event: AnalyticsEvent): void {
63
+ if (eventQueue.length < maxQueuedEvents) eventQueue.push(event);
64
+ }
65
+
38
66
  /**
39
67
  * Block tracking and drop queued events, so nothing recorded before the
40
68
  * decision is flushed later.
@@ -70,6 +98,8 @@ function sendEvent(name: string, properties?: Record<string, unknown>): void {
70
98
  export function initAnalytics(config: AnalyticsConfig): void {
71
99
  if (analyticsState) return;
72
100
 
101
+ setMaxQueuedEvents(config.maxQueuedEvents);
102
+
73
103
  // Check Do Not Track
74
104
  if (isDoNotTrackEnabled()) {
75
105
  block();
@@ -120,6 +150,8 @@ function processQueue(): void {
120
150
 
121
151
  /**
122
152
  * Track a custom event. Events with an empty or non-string name are ignored.
153
+ * Before init, only the first `maxQueuedEvents` calls (shared with
154
+ * `trackPage`) are queued.
123
155
  */
124
156
  export function track(
125
157
  name: string,
@@ -137,7 +169,7 @@ export function track(
137
169
  };
138
170
 
139
171
  if (!isInitialized) {
140
- eventQueue.push(event);
172
+ enqueue(event);
141
173
  return;
142
174
  }
143
175
 
@@ -145,14 +177,15 @@ export function track(
145
177
  }
146
178
 
147
179
  /**
148
- * Track a page view
180
+ * Track a page view. Before init, it shares the `maxQueuedEvents` limit with
181
+ * `track`.
149
182
  */
150
183
  export function trackPage(properties?: Record<string, unknown>): void {
151
184
  if (typeof window === "undefined") return;
152
185
  if (isBlocked) return;
153
186
 
154
187
  if (!isInitialized) {
155
- eventQueue.push({
188
+ enqueue({
156
189
  name: "__page__",
157
190
  properties,
158
191
  timestamp: new Date().toISOString(),
package/src/consent.ts CHANGED
@@ -42,10 +42,12 @@ export function isStorageAvailable(): boolean {
42
42
  }
43
43
 
44
44
  /**
45
- * Load consent state from localStorage
45
+ * Load consent state from localStorage.
46
+ * Reads directly (no write probe), so a stored choice is still found when the
47
+ * storage quota is full.
46
48
  */
47
49
  export function loadConsent(): ConsentState | null {
48
- if (!isStorageAvailable()) return null;
50
+ if (typeof window === "undefined") return null;
49
51
 
50
52
  try {
51
53
  const raw = localStorage.getItem(CONSENT_STORAGE_KEY);
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  // Core analytics
2
2
  export {
3
+ DEFAULT_MAX_QUEUED_EVENTS,
3
4
  disableAnalytics,
4
5
  enableAnalytics,
5
6
  getAnalyticsState,
package/src/react.tsx CHANGED
@@ -10,7 +10,12 @@ import {
10
10
  useState,
11
11
  } from "react";
12
12
 
13
- import { disableAnalytics, enableAnalytics, initAnalytics } from "./analytics";
13
+ import {
14
+ disableAnalytics,
15
+ enableAnalytics,
16
+ initAnalytics,
17
+ setMaxQueuedEvents,
18
+ } from "./analytics";
14
19
  import {
15
20
  clearConsent,
16
21
  CONSENT_VERSION,
@@ -56,6 +61,9 @@ export function AnalyticsProvider({
56
61
  consentVersion?: number;
57
62
  }) {
58
63
  const [consent, setConsent] = useState<ConsentState | null>(() => {
64
+ // Runs once, during the first render: the limit is set before any child
65
+ // effect can queue an event and before the consent decision.
66
+ setMaxQueuedEvents(config.maxQueuedEvents);
59
67
  const stored = loadConsent();
60
68
  if (!stored) return null;
61
69
  if (needsRePrompt(stored, consentVersion)) {
package/src/types.ts CHANGED
@@ -69,6 +69,14 @@ export type AnalyticsConfig = {
69
69
  app: string;
70
70
  /** Enable debug mode */
71
71
  debug?: boolean;
72
+ /**
73
+ * How many `track` and `trackPage` calls are queued before `initAnalytics`
74
+ * runs; later calls are dropped. `0` queues nothing. Defaults to
75
+ * `DEFAULT_MAX_QUEUED_EVENTS` (100); any value that is not a non-negative
76
+ * safe integer means the default. `AnalyticsProvider` applies it on mount;
77
+ * without the provider, the default applies until `initAnalytics` runs.
78
+ */
79
+ maxQueuedEvents?: number;
72
80
  /** Application version */
73
81
  version?: number;
74
82
  };