@vllnt/analytics 0.2.0-canary.8bb6613 → 0.2.0-canary.9bbc838

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 ADDED
@@ -0,0 +1,57 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
6
+ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.2.0] - 2026-11-27
9
+
10
+ ### Added
11
+
12
+ - The package ships version-matched docs for coding agents and other readers: `docs/API.md`
13
+ (every public export with its signature and an example), `llms.txt` and `CHANGELOG.md`.
14
+ `llms.txt` links to these files and to the TypeScript sources in `src/`, which still ship.
15
+
16
+ ### Changed
17
+
18
+ - The package entry points now resolve to compiled output in `dist` (ESM, CommonJS and type
19
+ declarations) instead of raw TypeScript sources, so it works without transpiling
20
+ `node_modules`. The `.` and `./react` export subpaths and the `react` peer range are
21
+ unchanged. `./package.json` is now exported too. Both builds of `./react` start with
22
+ `"use client"`.
23
+ - **Breaking:** `track()` ignores events whose name is empty or not a string, and `identify()`
24
+ ignores an empty or non-string user id, instead of recording them.
25
+ - **Breaking:** after a stored decline, `AnalyticsProvider` now blocks tracking with
26
+ `disableAnalytics()`, so `track()` calls are dropped. Before, they were queued in memory without
27
+ limit and sent if the user accepted later.
28
+ - **Breaking:** when `initAnalytics()` is blocked by Do Not Track or a stored decline, it drops the
29
+ events queued before it, as `disableAnalytics()` does. Before, they were kept and sent by a
30
+ later successful `enableAnalytics()` (after the user accepted, or Do Not Track was turned off).
31
+
32
+ ### Fixed
33
+
34
+ - `getConsentFromCookie()` no longer matches look-alike cookie names that merely end with
35
+ `vllnt-consent` (for example `evil-vllnt-consent=1`).
36
+ - `AnalyticsProvider` and `useConsent` save each choice with their `consentVersion`. Before, they
37
+ always saved version `1`, so a `consentVersion` above `1` asked the user again on every visit.
38
+
39
+ ### Security
40
+
41
+ - `@latest` is now published only from a `vX.Y.Z` tag on `main` that matches `package.json` and
42
+ this changelog. Before, a manual workflow run bumped the version in CI. Publishing still uses
43
+ npm trusted publishing (OIDC) with provenance, as in 0.1.1.
44
+
45
+ ## [0.1.1] - 2026-03-10
46
+
47
+ ### Added
48
+
49
+ - CI and publish workflows.
50
+
51
+ ## [0.1.0] - 2026-03-05
52
+
53
+ ### Added
54
+
55
+ - Initial release: event tracking with a pre-initialization queue, two-category consent management
56
+ (localStorage and SSR cookie), versioned consent re-prompts, Do Not Track support, tutorial
57
+ tracking helpers, and React integration (`AnalyticsProvider`, `useAnalytics`, `useConsent`).
package/README.md CHANGED
@@ -21,16 +21,27 @@ Peer dependency: `react ^18.0.0 || ^19.0.0`
21
21
 
22
22
  Ships ESM and CommonJS builds with type declarations; no bundler transpilation of `node_modules` is needed.
23
23
 
24
+ ## For coding agents
25
+
26
+ The docs are bundled in the package at `node_modules/@vllnt/analytics/docs/` ([`docs/API.md`](docs/API.md)), together with
27
+ [`llms.txt`](llms.txt), `CHANGELOG.md` and the TypeScript sources in `src/`. They match the installed
28
+ version. Read them before writing code.
29
+
24
30
  ## Usage
25
31
 
26
32
  ### React Provider
27
33
 
28
34
  ```tsx
35
+ import type { ReactNode } from "react";
29
36
  import { AnalyticsProvider } from "@vllnt/analytics/react";
30
37
 
31
- function App() {
38
+ // Keep config stable: an inline object re-runs the init effect and re-renders every consumer.
39
+ // Config changes are ignored while analytics is running (initAnalytics returns once started).
40
+ const config = { app: "my-app", version: 1, debug: true };
41
+
42
+ function App({ children }: { children: ReactNode }) {
32
43
  return (
33
- <AnalyticsProvider config={{ app: "my-app", version: 1, debug: true }}>
44
+ <AnalyticsProvider config={config}>
34
45
  {children}
35
46
  </AnalyticsProvider>
36
47
  );
@@ -40,12 +51,17 @@ function App() {
40
51
  ### Consent Banner
41
52
 
42
53
  ```tsx
43
- import { useConsent } from "@vllnt/analytics/react";
54
+ import { useEffect, useState } from "react";
55
+ import { useAnalytics } from "@vllnt/analytics/react";
44
56
 
57
+ // Render inside <AnalyticsProvider> so accepting starts tracking.
45
58
  function CookieBanner() {
46
- const { hasResponded, isLoading, acceptAll, declineAnalytics } = useConsent();
59
+ const { hasResponded, acceptAll, declineAnalytics } = useAnalytics();
60
+ // Stored consent is read in the browser only; wait for mount to avoid a hydration mismatch.
61
+ const [mounted, setMounted] = useState(false);
62
+ useEffect(() => setMounted(true), []);
47
63
 
48
- if (isLoading || hasResponded) return null;
64
+ if (!mounted || hasResponded) return null;
49
65
 
50
66
  return (
51
67
  <div>
@@ -57,6 +73,9 @@ function CookieBanner() {
57
73
  }
58
74
  ```
59
75
 
76
+ `useConsent()` exposes the same consent fields without a provider, but it only reads and writes
77
+ stored consent: it does not start or stop analytics.
78
+
60
79
  ### Track Events
61
80
 
62
81
  ```tsx
@@ -127,7 +146,7 @@ import {
127
146
  } from "@vllnt/analytics";
128
147
 
129
148
  // SSR: read consent from cookie header
130
- const analyticsAllowed = getConsentFromCookie(request.headers.cookie);
149
+ const analyticsAllowed = getConsentFromCookie(request.headers.get("cookie") ?? "");
131
150
 
132
151
  // Check if re-prompt needed after version bump
133
152
  const consent = loadConsent();
@@ -138,6 +157,8 @@ if (consent && needsRePrompt(consent, 2)) {
138
157
 
139
158
  ## API
140
159
 
160
+ Full reference with signatures and examples: [`docs/API.md`](docs/API.md).
161
+
141
162
  ### Core
142
163
 
143
164
  | Function | Description |
@@ -176,19 +197,21 @@ if (consent && needsRePrompt(consent, 2)) {
176
197
  ## How It Works
177
198
 
178
199
  ```
179
- User visits site
200
+ AnalyticsProvider mounts
180
201
  │
181
- ├─ DNT enabled? ──▶ Block all tracking
202
+ ├─ Stored consent outdated? ──▶ Clear it & re-prompt
182
203
  │
183
- ├─ Consent exists?
184
- │ ├─ Version outdated? ──▶ Clear & re-prompt
185
- │ ├─ Analytics declined? ──▶ Block tracking
186
- │ └─ Analytics accepted ──▶ Initialize & flush queue
204
+ ├─ Analytics accepted ──▶ initAnalytics()
205
+ │ ├─ DNT enabled? ──▶ Block tracking
206
+ │ └─ Otherwise ──▶ Start & flush queue
187
207
  │
188
- └─ No consent ──▶ Queue events until user responds
208
+ ├─ Analytics declined ──▶ disableAnalytics(); track() calls are dropped
209
+ │
210
+ └─ No consent yet ──▶ No init; track() calls are queued in memory
189
211
  ```
190
212
 
191
- Events fired before initialization are queued and flushed once consent is granted and analytics initializes.
213
+ Events fired before the user responds are queued and flushed once consent is granted and
214
+ analytics initializes. A decline, or an init blocked by Do Not Track, drops them.
192
215
 
193
216
  ## Scripts
194
217
 
@@ -202,6 +225,19 @@ pnpm typecheck # Type-check
202
225
  pnpm build # Build dist (ESM, CJS, types)
203
226
  ```
204
227
 
228
+ ## Related packages
229
+
230
+ - [`@vllnt/convex-analytics`](https://www.npmjs.com/package/@vllnt/convex-analytics): a Convex
231
+ component that stores events and serves rollups, funnels and retention. Use it as the backend if
232
+ your app runs on Convex; this package does not send events to it for you.
233
+ - [`@vllnt/convex-consent`](https://www.npmjs.com/package/@vllnt/convex-consent): an append-only
234
+ consent ledger stored in Convex. Use it when you need a server-side record of consent per
235
+ subject and purpose; this package only keeps the visitor's choice in the browser.
236
+
205
237
  ## License
206
238
 
207
239
  [MIT](LICENSE)
240
+
241
+ ---
242
+
243
+ Part of vllnt oss: https://oss.vllnt.com
@@ -98,6 +98,10 @@ var analyticsState;
98
98
  var eventQueue = [];
99
99
  var isInitialized = false;
100
100
  var isBlocked = false;
101
+ function block() {
102
+ isBlocked = true;
103
+ eventQueue = [];
104
+ }
101
105
  function debugLog(type, data) {
102
106
  if (analyticsState?.debug) {
103
107
  console.log(`[analytics:${type}]`, data);
@@ -109,13 +113,13 @@ function sendEvent(name, properties) {
109
113
  function initAnalytics(config) {
110
114
  if (analyticsState) return;
111
115
  if (isDoNotTrackEnabled()) {
112
- isBlocked = true;
116
+ block();
113
117
  debugLog("init", "Do Not Track enabled, analytics blocked");
114
118
  return;
115
119
  }
116
120
  const consent = loadConsent();
117
121
  if (consent && !consent.analytics) {
118
- isBlocked = true;
122
+ block();
119
123
  debugLog("init", "Analytics consent declined");
120
124
  return;
121
125
  }
@@ -195,8 +199,7 @@ function enableAnalytics(config) {
195
199
  }
196
200
  }
197
201
  function disableAnalytics() {
198
- isBlocked = true;
199
- eventQueue.length = 0;
202
+ block();
200
203
  }
201
204
  function isAnalyticsEnabled() {
202
205
  return isInitialized && !isBlocked;
@@ -98,6 +98,10 @@ var analyticsState;
98
98
  var eventQueue = [];
99
99
  var isInitialized = false;
100
100
  var isBlocked = false;
101
+ function block() {
102
+ isBlocked = true;
103
+ eventQueue = [];
104
+ }
101
105
  function debugLog(type, data) {
102
106
  if (_optionalChain([analyticsState, 'optionalAccess', _ => _.debug])) {
103
107
  console.log(`[analytics:${type}]`, data);
@@ -109,13 +113,13 @@ function sendEvent(name, properties) {
109
113
  function initAnalytics(config) {
110
114
  if (analyticsState) return;
111
115
  if (isDoNotTrackEnabled()) {
112
- isBlocked = true;
116
+ block();
113
117
  debugLog("init", "Do Not Track enabled, analytics blocked");
114
118
  return;
115
119
  }
116
120
  const consent = loadConsent();
117
121
  if (consent && !consent.analytics) {
118
- isBlocked = true;
122
+ block();
119
123
  debugLog("init", "Analytics consent declined");
120
124
  return;
121
125
  }
@@ -195,8 +199,7 @@ function enableAnalytics(config) {
195
199
  }
196
200
  }
197
201
  function disableAnalytics() {
198
- isBlocked = true;
199
- eventQueue.length = 0;
202
+ block();
200
203
  }
201
204
  function isAnalyticsEnabled() {
202
205
  return isInitialized && !isBlocked;
package/dist/index.cjs CHANGED
@@ -28,7 +28,7 @@
28
28
 
29
29
 
30
30
 
31
- var _chunkMVOBIOKZcjs = require('./chunk-MVOBIOKZ.cjs');
31
+ var _chunkACWD5NRIcjs = require('./chunk-ACWD5NRI.cjs');
32
32
 
33
33
 
34
34
 
@@ -59,4 +59,4 @@ var _chunkMVOBIOKZcjs = require('./chunk-MVOBIOKZ.cjs');
59
59
 
60
60
 
61
61
 
62
- exports.CONSENT_COOKIE_NAME = _chunkMVOBIOKZcjs.CONSENT_COOKIE_NAME; exports.CONSENT_STORAGE_KEY = _chunkMVOBIOKZcjs.CONSENT_STORAGE_KEY; exports.CONSENT_VERSION = _chunkMVOBIOKZcjs.CONSENT_VERSION; exports.clearConsent = _chunkMVOBIOKZcjs.clearConsent; exports.createAcceptAllConsent = _chunkMVOBIOKZcjs.createAcceptAllConsent; exports.createDeclineAnalyticsConsent = _chunkMVOBIOKZcjs.createDeclineAnalyticsConsent; exports.disableAnalytics = _chunkMVOBIOKZcjs.disableAnalytics; exports.enableAnalytics = _chunkMVOBIOKZcjs.enableAnalytics; exports.getAnalyticsState = _chunkMVOBIOKZcjs.getAnalyticsState; exports.getConsentFromCookie = _chunkMVOBIOKZcjs.getConsentFromCookie; exports.identify = _chunkMVOBIOKZcjs.identify; exports.initAnalytics = _chunkMVOBIOKZcjs.initAnalytics; exports.isAnalyticsEnabled = _chunkMVOBIOKZcjs.isAnalyticsEnabled; exports.isDoNotTrackEnabled = _chunkMVOBIOKZcjs.isDoNotTrackEnabled; exports.isStorageAvailable = _chunkMVOBIOKZcjs.isStorageAvailable; exports.isValidConsentState = _chunkMVOBIOKZcjs.isValidConsentState; exports.loadConsent = _chunkMVOBIOKZcjs.loadConsent; exports.needsRePrompt = _chunkMVOBIOKZcjs.needsRePrompt; exports.resetAnalytics = _chunkMVOBIOKZcjs.resetAnalytics; exports.saveConsent = _chunkMVOBIOKZcjs.saveConsent; exports.track = _chunkMVOBIOKZcjs.track; exports.trackPage = _chunkMVOBIOKZcjs.trackPage; exports.trackSectionComplete = _chunkMVOBIOKZcjs.trackSectionComplete; exports.trackSectionView = _chunkMVOBIOKZcjs.trackSectionView; exports.trackTimeSpent = _chunkMVOBIOKZcjs.trackTimeSpent; exports.trackTutorialComplete = _chunkMVOBIOKZcjs.trackTutorialComplete; exports.trackTutorialNavigation = _chunkMVOBIOKZcjs.trackTutorialNavigation; exports.trackTutorialStart = _chunkMVOBIOKZcjs.trackTutorialStart; exports.updateConsentCategory = _chunkMVOBIOKZcjs.updateConsentCategory;
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;
package/dist/index.js CHANGED
@@ -28,7 +28,7 @@ import {
28
28
  trackTutorialNavigation,
29
29
  trackTutorialStart,
30
30
  updateConsentCategory
31
- } from "./chunk-6RHY2BTB.js";
31
+ } from "./chunk-5COCGKHD.js";
32
32
  export {
33
33
  CONSENT_COOKIE_NAME,
34
34
  CONSENT_STORAGE_KEY,
package/dist/react.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";
1
+ "use client";"use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
4
 
@@ -11,7 +11,7 @@
11
11
 
12
12
 
13
13
 
14
- var _chunkMVOBIOKZcjs = require('./chunk-MVOBIOKZ.cjs');
14
+ var _chunkACWD5NRIcjs = require('./chunk-ACWD5NRI.cjs');
15
15
 
16
16
  // src/react.tsx
17
17
 
@@ -27,58 +27,64 @@ var AnalyticsContext = _react.createContext.call(void 0, null);
27
27
  function AnalyticsProvider({
28
28
  children,
29
29
  config,
30
- consentVersion = _chunkMVOBIOKZcjs.CONSENT_VERSION
30
+ consentVersion = _chunkACWD5NRIcjs.CONSENT_VERSION
31
31
  }) {
32
32
  const [consent, setConsent] = _react.useState.call(void 0, () => {
33
- const stored = _chunkMVOBIOKZcjs.loadConsent.call(void 0, );
33
+ const stored = _chunkACWD5NRIcjs.loadConsent.call(void 0, );
34
34
  if (!stored) return null;
35
- if (_chunkMVOBIOKZcjs.needsRePrompt.call(void 0, stored, consentVersion)) {
36
- _chunkMVOBIOKZcjs.clearConsent.call(void 0, );
35
+ if (_chunkACWD5NRIcjs.needsRePrompt.call(void 0, stored, consentVersion)) {
36
+ _chunkACWD5NRIcjs.clearConsent.call(void 0, );
37
37
  return null;
38
38
  }
39
39
  return stored;
40
40
  });
41
41
  const [hasResponded, setHasResponded] = _react.useState.call(void 0, () => consent !== null);
42
42
  _react.useEffect.call(void 0, () => {
43
- if (_optionalChain([consent, 'optionalAccess', _ => _.analytics])) {
44
- _chunkMVOBIOKZcjs.initAnalytics.call(void 0, config);
43
+ if (!consent) return;
44
+ if (consent.analytics) {
45
+ _chunkACWD5NRIcjs.initAnalytics.call(void 0, config);
46
+ } else {
47
+ _chunkACWD5NRIcjs.disableAnalytics.call(void 0, );
45
48
  }
46
49
  }, [consent, config]);
47
50
  const acceptAll = _react.useCallback.call(void 0, () => {
48
- const newConsent = _chunkMVOBIOKZcjs.createAcceptAllConsent.call(void 0, );
49
- _chunkMVOBIOKZcjs.saveConsent.call(void 0, newConsent);
51
+ const newConsent = { ..._chunkACWD5NRIcjs.createAcceptAllConsent.call(void 0, ), version: consentVersion };
52
+ _chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
50
53
  setConsent(newConsent);
51
54
  setHasResponded(true);
52
- _chunkMVOBIOKZcjs.enableAnalytics.call(void 0, config);
53
- }, [config]);
55
+ _chunkACWD5NRIcjs.enableAnalytics.call(void 0, config);
56
+ }, [config, consentVersion]);
54
57
  const declineAnalytics = _react.useCallback.call(void 0, () => {
55
- const newConsent = _chunkMVOBIOKZcjs.createDeclineAnalyticsConsent.call(void 0, );
56
- _chunkMVOBIOKZcjs.saveConsent.call(void 0, newConsent);
58
+ const newConsent = {
59
+ ..._chunkACWD5NRIcjs.createDeclineAnalyticsConsent.call(void 0, ),
60
+ version: consentVersion
61
+ };
62
+ _chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
57
63
  setConsent(newConsent);
58
64
  setHasResponded(true);
59
- _chunkMVOBIOKZcjs.disableAnalytics.call(void 0, );
60
- }, []);
65
+ _chunkACWD5NRIcjs.disableAnalytics.call(void 0, );
66
+ }, [consentVersion]);
61
67
  const updateConsentHandler = _react.useCallback.call(void 0,
62
68
  (category, value2) => {
63
69
  if (!consent) return;
64
- const newConsent = _chunkMVOBIOKZcjs.updateConsentCategory.call(void 0, consent, category, value2);
65
- _chunkMVOBIOKZcjs.saveConsent.call(void 0, newConsent);
70
+ const newConsent = _chunkACWD5NRIcjs.updateConsentCategory.call(void 0, consent, category, value2);
71
+ _chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
66
72
  setConsent(newConsent);
67
73
  if (category === "analytics") {
68
74
  if (value2) {
69
- _chunkMVOBIOKZcjs.enableAnalytics.call(void 0, config);
75
+ _chunkACWD5NRIcjs.enableAnalytics.call(void 0, config);
70
76
  } else {
71
- _chunkMVOBIOKZcjs.disableAnalytics.call(void 0, );
77
+ _chunkACWD5NRIcjs.disableAnalytics.call(void 0, );
72
78
  }
73
79
  }
74
80
  },
75
81
  [consent, config]
76
82
  );
77
83
  const resetConsentHandler = _react.useCallback.call(void 0, () => {
78
- _chunkMVOBIOKZcjs.clearConsent.call(void 0, );
84
+ _chunkACWD5NRIcjs.clearConsent.call(void 0, );
79
85
  setConsent(null);
80
86
  setHasResponded(false);
81
- _chunkMVOBIOKZcjs.disableAnalytics.call(void 0, );
87
+ _chunkACWD5NRIcjs.disableAnalytics.call(void 0, );
82
88
  }, []);
83
89
  const value = _react.useMemo.call(void 0,
84
90
  () => ({
@@ -111,40 +117,43 @@ function useAnalytics() {
111
117
  return context;
112
118
  }
113
119
  function useConsent(options = {}) {
114
- const { consentVersion = _chunkMVOBIOKZcjs.CONSENT_VERSION } = options;
120
+ const { consentVersion = _chunkACWD5NRIcjs.CONSENT_VERSION } = options;
115
121
  const [consent, setConsent] = _react.useState.call(void 0, () => {
116
- const stored = _chunkMVOBIOKZcjs.loadConsent.call(void 0, );
122
+ const stored = _chunkACWD5NRIcjs.loadConsent.call(void 0, );
117
123
  if (!stored) return null;
118
- if (_chunkMVOBIOKZcjs.needsRePrompt.call(void 0, stored, consentVersion)) {
119
- _chunkMVOBIOKZcjs.clearConsent.call(void 0, );
124
+ if (_chunkACWD5NRIcjs.needsRePrompt.call(void 0, stored, consentVersion)) {
125
+ _chunkACWD5NRIcjs.clearConsent.call(void 0, );
120
126
  return null;
121
127
  }
122
128
  return stored;
123
129
  });
124
130
  const [hasResponded, setHasResponded] = _react.useState.call(void 0, () => consent !== null);
125
131
  const acceptAll = _react.useCallback.call(void 0, () => {
126
- const newConsent = _chunkMVOBIOKZcjs.createAcceptAllConsent.call(void 0, );
127
- _chunkMVOBIOKZcjs.saveConsent.call(void 0, newConsent);
132
+ const newConsent = { ..._chunkACWD5NRIcjs.createAcceptAllConsent.call(void 0, ), version: consentVersion };
133
+ _chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
128
134
  setConsent(newConsent);
129
135
  setHasResponded(true);
130
- }, []);
136
+ }, [consentVersion]);
131
137
  const declineAnalytics = _react.useCallback.call(void 0, () => {
132
- const newConsent = _chunkMVOBIOKZcjs.createDeclineAnalyticsConsent.call(void 0, );
133
- _chunkMVOBIOKZcjs.saveConsent.call(void 0, newConsent);
138
+ const newConsent = {
139
+ ..._chunkACWD5NRIcjs.createDeclineAnalyticsConsent.call(void 0, ),
140
+ version: consentVersion
141
+ };
142
+ _chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
134
143
  setConsent(newConsent);
135
144
  setHasResponded(true);
136
- }, []);
145
+ }, [consentVersion]);
137
146
  const updateConsentHandler = _react.useCallback.call(void 0,
138
147
  (category, value) => {
139
148
  if (!consent) return;
140
- const newConsent = _chunkMVOBIOKZcjs.updateConsentCategory.call(void 0, consent, category, value);
141
- _chunkMVOBIOKZcjs.saveConsent.call(void 0, newConsent);
149
+ const newConsent = _chunkACWD5NRIcjs.updateConsentCategory.call(void 0, consent, category, value);
150
+ _chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
142
151
  setConsent(newConsent);
143
152
  },
144
153
  [consent]
145
154
  );
146
155
  const resetConsentHandler = _react.useCallback.call(void 0, () => {
147
- _chunkMVOBIOKZcjs.clearConsent.call(void 0, );
156
+ _chunkACWD5NRIcjs.clearConsent.call(void 0, );
148
157
  setConsent(null);
149
158
  setHasResponded(false);
150
159
  }, []);
@@ -163,4 +172,4 @@ function useConsent(options = {}) {
163
172
 
164
173
 
165
174
 
166
- exports.AnalyticsProvider = AnalyticsProvider; exports.initAnalytics = _chunkMVOBIOKZcjs.initAnalytics; exports.useAnalytics = useAnalytics; exports.useConsent = useConsent;
175
+ exports.AnalyticsProvider = AnalyticsProvider; exports.initAnalytics = _chunkACWD5NRIcjs.initAnalytics; exports.useAnalytics = useAnalytics; exports.useConsent = useConsent;
package/dist/react.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  needsRePrompt,
12
12
  saveConsent,
13
13
  updateConsentCategory
14
- } from "./chunk-6RHY2BTB.js";
14
+ } from "./chunk-5COCGKHD.js";
15
15
 
16
16
  // src/react.tsx
17
17
  import {
@@ -40,24 +40,30 @@ function AnalyticsProvider({
40
40
  });
41
41
  const [hasResponded, setHasResponded] = useState(() => consent !== null);
42
42
  useEffect(() => {
43
- if (consent?.analytics) {
43
+ if (!consent) return;
44
+ if (consent.analytics) {
44
45
  initAnalytics(config);
46
+ } else {
47
+ disableAnalytics();
45
48
  }
46
49
  }, [consent, config]);
47
50
  const acceptAll = useCallback(() => {
48
- const newConsent = createAcceptAllConsent();
51
+ const newConsent = { ...createAcceptAllConsent(), version: consentVersion };
49
52
  saveConsent(newConsent);
50
53
  setConsent(newConsent);
51
54
  setHasResponded(true);
52
55
  enableAnalytics(config);
53
- }, [config]);
56
+ }, [config, consentVersion]);
54
57
  const declineAnalytics = useCallback(() => {
55
- const newConsent = createDeclineAnalyticsConsent();
58
+ const newConsent = {
59
+ ...createDeclineAnalyticsConsent(),
60
+ version: consentVersion
61
+ };
56
62
  saveConsent(newConsent);
57
63
  setConsent(newConsent);
58
64
  setHasResponded(true);
59
65
  disableAnalytics();
60
- }, []);
66
+ }, [consentVersion]);
61
67
  const updateConsentHandler = useCallback(
62
68
  (category, value2) => {
63
69
  if (!consent) return;
@@ -123,17 +129,20 @@ function useConsent(options = {}) {
123
129
  });
124
130
  const [hasResponded, setHasResponded] = useState(() => consent !== null);
125
131
  const acceptAll = useCallback(() => {
126
- const newConsent = createAcceptAllConsent();
132
+ const newConsent = { ...createAcceptAllConsent(), version: consentVersion };
127
133
  saveConsent(newConsent);
128
134
  setConsent(newConsent);
129
135
  setHasResponded(true);
130
- }, []);
136
+ }, [consentVersion]);
131
137
  const declineAnalytics = useCallback(() => {
132
- const newConsent = createDeclineAnalyticsConsent();
138
+ const newConsent = {
139
+ ...createDeclineAnalyticsConsent(),
140
+ version: consentVersion
141
+ };
133
142
  saveConsent(newConsent);
134
143
  setConsent(newConsent);
135
144
  setHasResponded(true);
136
- }, []);
145
+ }, [consentVersion]);
137
146
  const updateConsentHandler = useCallback(
138
147
  (category, value) => {
139
148
  if (!consent) return;