@vllnt/analytics 0.1.1-canary.c0d1582 → 0.2.0-canary.0cf6be9

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.
@@ -0,0 +1,271 @@
1
+ // src/consent.ts
2
+ var CONSENT_VERSION = 1;
3
+ var CONSENT_STORAGE_KEY = "vllnt:analytics-consent";
4
+ var CONSENT_COOKIE_NAME = "vllnt-consent";
5
+ function isValidConsentState(value) {
6
+ if (typeof value !== "object" || value === null) return false;
7
+ const state = value;
8
+ return typeof state.analytics === "boolean" && typeof state.functional === "boolean" && typeof state.timestamp === "string" && typeof state.version === "number";
9
+ }
10
+ function isStorageAvailable() {
11
+ if (typeof window === "undefined") return false;
12
+ try {
13
+ const testKey = "__storage_test__";
14
+ localStorage.setItem(testKey, testKey);
15
+ localStorage.removeItem(testKey);
16
+ return true;
17
+ } catch {
18
+ return false;
19
+ }
20
+ }
21
+ function loadConsent() {
22
+ if (!isStorageAvailable()) return null;
23
+ try {
24
+ const raw = localStorage.getItem(CONSENT_STORAGE_KEY);
25
+ if (!raw) return null;
26
+ const parsed = JSON.parse(raw);
27
+ if (!isValidConsentState(parsed)) return null;
28
+ return parsed;
29
+ } catch {
30
+ return null;
31
+ }
32
+ }
33
+ function saveConsent(state) {
34
+ if (!isStorageAvailable()) return;
35
+ try {
36
+ localStorage.setItem(CONSENT_STORAGE_KEY, JSON.stringify(state));
37
+ const expires = /* @__PURE__ */ new Date();
38
+ expires.setFullYear(expires.getFullYear() + 1);
39
+ const cookieValue = state.analytics ? "1" : "0";
40
+ document.cookie = `${CONSENT_COOKIE_NAME}=${cookieValue}; expires=${expires.toUTCString()}; path=/; SameSite=Lax`;
41
+ } catch (error) {
42
+ console.warn("Failed to save consent:", error);
43
+ }
44
+ }
45
+ function clearConsent() {
46
+ if (!isStorageAvailable()) return;
47
+ try {
48
+ localStorage.removeItem(CONSENT_STORAGE_KEY);
49
+ document.cookie = `${CONSENT_COOKIE_NAME}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; SameSite=Lax`;
50
+ } catch {
51
+ }
52
+ }
53
+ function createAcceptAllConsent() {
54
+ return {
55
+ analytics: true,
56
+ functional: true,
57
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
58
+ version: CONSENT_VERSION
59
+ };
60
+ }
61
+ function createDeclineAnalyticsConsent() {
62
+ return {
63
+ analytics: false,
64
+ functional: true,
65
+ // Functional always enabled
66
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
67
+ version: CONSENT_VERSION
68
+ };
69
+ }
70
+ function updateConsentCategory(current, category, value) {
71
+ if (category === "functional" && !value) {
72
+ return current;
73
+ }
74
+ return {
75
+ ...current,
76
+ [category]: value,
77
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
78
+ };
79
+ }
80
+ function needsRePrompt(consent, currentVersion) {
81
+ return consent.version < currentVersion;
82
+ }
83
+ function isDoNotTrackEnabled() {
84
+ if (typeof window === "undefined") return false;
85
+ const dnt = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
86
+ return dnt === "1" || dnt === "yes";
87
+ }
88
+ function getConsentFromCookie(cookieString) {
89
+ const match = new RegExp(`(?:^|;\\s*)${CONSENT_COOKIE_NAME}=([^;]+)`).exec(
90
+ cookieString
91
+ );
92
+ if (!match) return null;
93
+ return match[1] === "1";
94
+ }
95
+
96
+ // src/analytics.ts
97
+ var analyticsState;
98
+ var DEFAULT_MAX_QUEUED_EVENTS = 100;
99
+ var eventQueue = [];
100
+ var maxQueuedEvents = DEFAULT_MAX_QUEUED_EVENTS;
101
+ var isInitialized = false;
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
+ }
110
+ function block() {
111
+ isBlocked = true;
112
+ eventQueue = [];
113
+ }
114
+ function debugLog(type, data) {
115
+ if (analyticsState?.debug) {
116
+ console.log(`[analytics:${type}]`, data);
117
+ }
118
+ }
119
+ function sendEvent(name, properties) {
120
+ debugLog("track", { name, properties });
121
+ }
122
+ function initAnalytics(config) {
123
+ if (analyticsState) return;
124
+ setMaxQueuedEvents(config.maxQueuedEvents);
125
+ if (isDoNotTrackEnabled()) {
126
+ block();
127
+ debugLog("init", "Do Not Track enabled, analytics blocked");
128
+ return;
129
+ }
130
+ const consent = loadConsent();
131
+ if (consent && !consent.analytics) {
132
+ block();
133
+ debugLog("init", "Analytics consent declined");
134
+ return;
135
+ }
136
+ analyticsState = {
137
+ app: config.app,
138
+ debug: config.debug,
139
+ version: config.version
140
+ };
141
+ isInitialized = true;
142
+ debugLog("init", { app: config.app, version: config.version });
143
+ processQueue();
144
+ }
145
+ function processQueue() {
146
+ if (!analyticsState || isBlocked) return;
147
+ const queue = [...eventQueue];
148
+ eventQueue = [];
149
+ for (const event of queue) {
150
+ if (event.name === "__page__") {
151
+ debugLog("page", event.properties);
152
+ } else {
153
+ sendEvent(event.name, event.properties);
154
+ }
155
+ }
156
+ }
157
+ function track(name, properties) {
158
+ if (typeof window === "undefined") return;
159
+ if (typeof name !== "string" || name === "") return;
160
+ if (isBlocked) return;
161
+ const event = {
162
+ name,
163
+ properties,
164
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
165
+ };
166
+ if (!isInitialized) {
167
+ enqueue(event);
168
+ return;
169
+ }
170
+ sendEvent(name, properties);
171
+ }
172
+ function trackPage(properties) {
173
+ if (typeof window === "undefined") return;
174
+ if (isBlocked) return;
175
+ if (!isInitialized) {
176
+ enqueue({
177
+ name: "__page__",
178
+ properties,
179
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
180
+ });
181
+ return;
182
+ }
183
+ debugLog("page", properties);
184
+ }
185
+ function identify(userId, traits) {
186
+ if (typeof window === "undefined") return;
187
+ if (typeof userId !== "string" || userId === "") return;
188
+ if (isBlocked) return;
189
+ if (!isInitialized || !analyticsState) {
190
+ return;
191
+ }
192
+ analyticsState.userId = userId;
193
+ analyticsState.traits = traits;
194
+ debugLog("identify", { traits, userId });
195
+ }
196
+ function resetAnalytics() {
197
+ if (typeof window === "undefined") return;
198
+ if (analyticsState) {
199
+ analyticsState.userId = void 0;
200
+ analyticsState.traits = void 0;
201
+ }
202
+ debugLog("reset", void 0);
203
+ }
204
+ function enableAnalytics(config) {
205
+ if (isBlocked && !isDoNotTrackEnabled()) {
206
+ isBlocked = false;
207
+ analyticsState = void 0;
208
+ initAnalytics(config);
209
+ }
210
+ }
211
+ function disableAnalytics() {
212
+ block();
213
+ }
214
+ function isAnalyticsEnabled() {
215
+ return isInitialized && !isBlocked;
216
+ }
217
+ function getAnalyticsState() {
218
+ return analyticsState;
219
+ }
220
+ function trackTutorialStart(properties) {
221
+ track("tutorial_start", properties);
222
+ }
223
+ function trackSectionView(properties) {
224
+ track("tutorial_section_view", properties);
225
+ }
226
+ function trackSectionComplete(properties) {
227
+ track("tutorial_section_complete", properties);
228
+ }
229
+ function trackTutorialComplete(properties) {
230
+ track("tutorial_complete", properties);
231
+ }
232
+ function trackTutorialNavigation(properties) {
233
+ track("tutorial_navigation", properties);
234
+ }
235
+ function trackTimeSpent(properties) {
236
+ track("tutorial_time_spent", properties);
237
+ }
238
+
239
+ export {
240
+ CONSENT_VERSION,
241
+ CONSENT_STORAGE_KEY,
242
+ CONSENT_COOKIE_NAME,
243
+ isValidConsentState,
244
+ isStorageAvailable,
245
+ loadConsent,
246
+ saveConsent,
247
+ clearConsent,
248
+ createAcceptAllConsent,
249
+ createDeclineAnalyticsConsent,
250
+ updateConsentCategory,
251
+ needsRePrompt,
252
+ isDoNotTrackEnabled,
253
+ getConsentFromCookie,
254
+ DEFAULT_MAX_QUEUED_EVENTS,
255
+ setMaxQueuedEvents,
256
+ initAnalytics,
257
+ track,
258
+ trackPage,
259
+ identify,
260
+ resetAnalytics,
261
+ enableAnalytics,
262
+ disableAnalytics,
263
+ isAnalyticsEnabled,
264
+ getAnalyticsState,
265
+ trackTutorialStart,
266
+ trackSectionView,
267
+ trackSectionComplete,
268
+ trackTutorialComplete,
269
+ trackTutorialNavigation,
270
+ trackTimeSpent
271
+ };
package/dist/index.cjs ADDED
@@ -0,0 +1,64 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+ var _chunkJB5OMGDZcjs = require('./chunk-JB5OMGDZ.cjs');
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+ exports.CONSENT_COOKIE_NAME = _chunkJB5OMGDZcjs.CONSENT_COOKIE_NAME; exports.CONSENT_STORAGE_KEY = _chunkJB5OMGDZcjs.CONSENT_STORAGE_KEY; exports.CONSENT_VERSION = _chunkJB5OMGDZcjs.CONSENT_VERSION; exports.DEFAULT_MAX_QUEUED_EVENTS = _chunkJB5OMGDZcjs.DEFAULT_MAX_QUEUED_EVENTS; exports.clearConsent = _chunkJB5OMGDZcjs.clearConsent; exports.createAcceptAllConsent = _chunkJB5OMGDZcjs.createAcceptAllConsent; exports.createDeclineAnalyticsConsent = _chunkJB5OMGDZcjs.createDeclineAnalyticsConsent; exports.disableAnalytics = _chunkJB5OMGDZcjs.disableAnalytics; exports.enableAnalytics = _chunkJB5OMGDZcjs.enableAnalytics; exports.getAnalyticsState = _chunkJB5OMGDZcjs.getAnalyticsState; exports.getConsentFromCookie = _chunkJB5OMGDZcjs.getConsentFromCookie; exports.identify = _chunkJB5OMGDZcjs.identify; exports.initAnalytics = _chunkJB5OMGDZcjs.initAnalytics; exports.isAnalyticsEnabled = _chunkJB5OMGDZcjs.isAnalyticsEnabled; exports.isDoNotTrackEnabled = _chunkJB5OMGDZcjs.isDoNotTrackEnabled; exports.isStorageAvailable = _chunkJB5OMGDZcjs.isStorageAvailable; exports.isValidConsentState = _chunkJB5OMGDZcjs.isValidConsentState; exports.loadConsent = _chunkJB5OMGDZcjs.loadConsent; exports.needsRePrompt = _chunkJB5OMGDZcjs.needsRePrompt; exports.resetAnalytics = _chunkJB5OMGDZcjs.resetAnalytics; exports.saveConsent = _chunkJB5OMGDZcjs.saveConsent; exports.track = _chunkJB5OMGDZcjs.track; exports.trackPage = _chunkJB5OMGDZcjs.trackPage; exports.trackSectionComplete = _chunkJB5OMGDZcjs.trackSectionComplete; exports.trackSectionView = _chunkJB5OMGDZcjs.trackSectionView; exports.trackTimeSpent = _chunkJB5OMGDZcjs.trackTimeSpent; exports.trackTutorialComplete = _chunkJB5OMGDZcjs.trackTutorialComplete; exports.trackTutorialNavigation = _chunkJB5OMGDZcjs.trackTutorialNavigation; exports.trackTutorialStart = _chunkJB5OMGDZcjs.trackTutorialStart; exports.updateConsentCategory = _chunkJB5OMGDZcjs.updateConsentCategory;
@@ -0,0 +1,55 @@
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
+
4
+ /** Current consent schema version - bump to re-prompt users */
5
+ declare const CONSENT_VERSION = 1;
6
+ /** localStorage key for consent state */
7
+ declare const CONSENT_STORAGE_KEY = "vllnt:analytics-consent";
8
+ /** Cookie name for SSR consent detection */
9
+ declare const CONSENT_COOKIE_NAME = "vllnt-consent";
10
+ /**
11
+ * Type guard to validate consent state from storage
12
+ */
13
+ declare function isValidConsentState(value: unknown): value is ConsentState;
14
+ /**
15
+ * Check if localStorage is available
16
+ */
17
+ declare function isStorageAvailable(): boolean;
18
+ /**
19
+ * Load consent state from localStorage
20
+ */
21
+ declare function loadConsent(): ConsentState | null;
22
+ /**
23
+ * Save consent state to localStorage and cookie
24
+ */
25
+ declare function saveConsent(state: ConsentState): void;
26
+ /**
27
+ * Clear consent state (for re-prompting)
28
+ */
29
+ declare function clearConsent(): void;
30
+ /**
31
+ * Create a new consent state with all categories accepted
32
+ */
33
+ declare function createAcceptAllConsent(): ConsentState;
34
+ /**
35
+ * Create a consent state with analytics declined
36
+ */
37
+ declare function createDeclineAnalyticsConsent(): ConsentState;
38
+ /**
39
+ * Update a specific consent category
40
+ */
41
+ declare function updateConsentCategory(current: ConsentState, category: ConsentCategory, value: boolean): ConsentState;
42
+ /**
43
+ * Check if consent needs to be re-prompted (version mismatch)
44
+ */
45
+ declare function needsRePrompt(consent: ConsentState, currentVersion: number): boolean;
46
+ /**
47
+ * Check Do Not Track browser setting
48
+ */
49
+ declare function isDoNotTrackEnabled(): boolean;
50
+ /**
51
+ * Get consent from cookie (for SSR)
52
+ */
53
+ declare function getConsentFromCookie(cookieString: string): boolean | null;
54
+
55
+ export { CONSENT_COOKIE_NAME, CONSENT_STORAGE_KEY, CONSENT_VERSION, ConsentCategory, ConsentState, clearConsent, createAcceptAllConsent, createDeclineAnalyticsConsent, getConsentFromCookie, isDoNotTrackEnabled, isStorageAvailable, isValidConsentState, loadConsent, needsRePrompt, saveConsent, updateConsentCategory };
@@ -0,0 +1,55 @@
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
+
4
+ /** Current consent schema version - bump to re-prompt users */
5
+ declare const CONSENT_VERSION = 1;
6
+ /** localStorage key for consent state */
7
+ declare const CONSENT_STORAGE_KEY = "vllnt:analytics-consent";
8
+ /** Cookie name for SSR consent detection */
9
+ declare const CONSENT_COOKIE_NAME = "vllnt-consent";
10
+ /**
11
+ * Type guard to validate consent state from storage
12
+ */
13
+ declare function isValidConsentState(value: unknown): value is ConsentState;
14
+ /**
15
+ * Check if localStorage is available
16
+ */
17
+ declare function isStorageAvailable(): boolean;
18
+ /**
19
+ * Load consent state from localStorage
20
+ */
21
+ declare function loadConsent(): ConsentState | null;
22
+ /**
23
+ * Save consent state to localStorage and cookie
24
+ */
25
+ declare function saveConsent(state: ConsentState): void;
26
+ /**
27
+ * Clear consent state (for re-prompting)
28
+ */
29
+ declare function clearConsent(): void;
30
+ /**
31
+ * Create a new consent state with all categories accepted
32
+ */
33
+ declare function createAcceptAllConsent(): ConsentState;
34
+ /**
35
+ * Create a consent state with analytics declined
36
+ */
37
+ declare function createDeclineAnalyticsConsent(): ConsentState;
38
+ /**
39
+ * Update a specific consent category
40
+ */
41
+ declare function updateConsentCategory(current: ConsentState, category: ConsentCategory, value: boolean): ConsentState;
42
+ /**
43
+ * Check if consent needs to be re-prompted (version mismatch)
44
+ */
45
+ declare function needsRePrompt(consent: ConsentState, currentVersion: number): boolean;
46
+ /**
47
+ * Check Do Not Track browser setting
48
+ */
49
+ declare function isDoNotTrackEnabled(): boolean;
50
+ /**
51
+ * Get consent from cookie (for SSR)
52
+ */
53
+ declare function getConsentFromCookie(cookieString: string): boolean | null;
54
+
55
+ export { CONSENT_COOKIE_NAME, CONSENT_STORAGE_KEY, CONSENT_VERSION, ConsentCategory, ConsentState, clearConsent, createAcceptAllConsent, createDeclineAnalyticsConsent, getConsentFromCookie, isDoNotTrackEnabled, isStorageAvailable, isValidConsentState, loadConsent, needsRePrompt, saveConsent, updateConsentCategory };
package/dist/index.js ADDED
@@ -0,0 +1,64 @@
1
+ import {
2
+ CONSENT_COOKIE_NAME,
3
+ CONSENT_STORAGE_KEY,
4
+ CONSENT_VERSION,
5
+ DEFAULT_MAX_QUEUED_EVENTS,
6
+ clearConsent,
7
+ createAcceptAllConsent,
8
+ createDeclineAnalyticsConsent,
9
+ disableAnalytics,
10
+ enableAnalytics,
11
+ getAnalyticsState,
12
+ getConsentFromCookie,
13
+ identify,
14
+ initAnalytics,
15
+ isAnalyticsEnabled,
16
+ isDoNotTrackEnabled,
17
+ isStorageAvailable,
18
+ isValidConsentState,
19
+ loadConsent,
20
+ needsRePrompt,
21
+ resetAnalytics,
22
+ saveConsent,
23
+ track,
24
+ trackPage,
25
+ trackSectionComplete,
26
+ trackSectionView,
27
+ trackTimeSpent,
28
+ trackTutorialComplete,
29
+ trackTutorialNavigation,
30
+ trackTutorialStart,
31
+ updateConsentCategory
32
+ } from "./chunk-UVPDJSPZ.js";
33
+ export {
34
+ CONSENT_COOKIE_NAME,
35
+ CONSENT_STORAGE_KEY,
36
+ CONSENT_VERSION,
37
+ DEFAULT_MAX_QUEUED_EVENTS,
38
+ clearConsent,
39
+ createAcceptAllConsent,
40
+ createDeclineAnalyticsConsent,
41
+ disableAnalytics,
42
+ enableAnalytics,
43
+ getAnalyticsState,
44
+ getConsentFromCookie,
45
+ identify,
46
+ initAnalytics,
47
+ isAnalyticsEnabled,
48
+ isDoNotTrackEnabled,
49
+ isStorageAvailable,
50
+ isValidConsentState,
51
+ loadConsent,
52
+ needsRePrompt,
53
+ resetAnalytics,
54
+ saveConsent,
55
+ track,
56
+ trackPage,
57
+ trackSectionComplete,
58
+ trackSectionView,
59
+ trackTimeSpent,
60
+ trackTutorialComplete,
61
+ trackTutorialNavigation,
62
+ trackTutorialStart,
63
+ updateConsentCategory
64
+ };
package/dist/react.cjs ADDED
@@ -0,0 +1,177 @@
1
+ "use client";"use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+ var _chunkJB5OMGDZcjs = require('./chunk-JB5OMGDZ.cjs');
16
+
17
+ // src/react.tsx
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+ var _react = require('react');
26
+ var _jsxruntime = require('react/jsx-runtime');
27
+ var AnalyticsContext = _react.createContext.call(void 0, null);
28
+ function AnalyticsProvider({
29
+ children,
30
+ config,
31
+ consentVersion = _chunkJB5OMGDZcjs.CONSENT_VERSION
32
+ }) {
33
+ const [consent, setConsent] = _react.useState.call(void 0, () => {
34
+ _chunkJB5OMGDZcjs.setMaxQueuedEvents.call(void 0, config.maxQueuedEvents);
35
+ const stored = _chunkJB5OMGDZcjs.loadConsent.call(void 0, );
36
+ if (!stored) return null;
37
+ if (_chunkJB5OMGDZcjs.needsRePrompt.call(void 0, stored, consentVersion)) {
38
+ _chunkJB5OMGDZcjs.clearConsent.call(void 0, );
39
+ return null;
40
+ }
41
+ return stored;
42
+ });
43
+ const [hasResponded, setHasResponded] = _react.useState.call(void 0, () => consent !== null);
44
+ _react.useEffect.call(void 0, () => {
45
+ if (!consent) return;
46
+ if (consent.analytics) {
47
+ _chunkJB5OMGDZcjs.initAnalytics.call(void 0, config);
48
+ } else {
49
+ _chunkJB5OMGDZcjs.disableAnalytics.call(void 0, );
50
+ }
51
+ }, [consent, config]);
52
+ const acceptAll = _react.useCallback.call(void 0, () => {
53
+ const newConsent = { ..._chunkJB5OMGDZcjs.createAcceptAllConsent.call(void 0, ), version: consentVersion };
54
+ _chunkJB5OMGDZcjs.saveConsent.call(void 0, newConsent);
55
+ setConsent(newConsent);
56
+ setHasResponded(true);
57
+ _chunkJB5OMGDZcjs.enableAnalytics.call(void 0, config);
58
+ }, [config, consentVersion]);
59
+ const declineAnalytics = _react.useCallback.call(void 0, () => {
60
+ const newConsent = {
61
+ ..._chunkJB5OMGDZcjs.createDeclineAnalyticsConsent.call(void 0, ),
62
+ version: consentVersion
63
+ };
64
+ _chunkJB5OMGDZcjs.saveConsent.call(void 0, newConsent);
65
+ setConsent(newConsent);
66
+ setHasResponded(true);
67
+ _chunkJB5OMGDZcjs.disableAnalytics.call(void 0, );
68
+ }, [consentVersion]);
69
+ const updateConsentHandler = _react.useCallback.call(void 0,
70
+ (category, value2) => {
71
+ if (!consent) return;
72
+ const newConsent = _chunkJB5OMGDZcjs.updateConsentCategory.call(void 0, consent, category, value2);
73
+ _chunkJB5OMGDZcjs.saveConsent.call(void 0, newConsent);
74
+ setConsent(newConsent);
75
+ if (category === "analytics") {
76
+ if (value2) {
77
+ _chunkJB5OMGDZcjs.enableAnalytics.call(void 0, config);
78
+ } else {
79
+ _chunkJB5OMGDZcjs.disableAnalytics.call(void 0, );
80
+ }
81
+ }
82
+ },
83
+ [consent, config]
84
+ );
85
+ const resetConsentHandler = _react.useCallback.call(void 0, () => {
86
+ _chunkJB5OMGDZcjs.clearConsent.call(void 0, );
87
+ setConsent(null);
88
+ setHasResponded(false);
89
+ _chunkJB5OMGDZcjs.disableAnalytics.call(void 0, );
90
+ }, []);
91
+ const value = _react.useMemo.call(void 0,
92
+ () => ({
93
+ acceptAll,
94
+ config,
95
+ consent,
96
+ declineAnalytics,
97
+ hasResponded,
98
+ isLoading: false,
99
+ resetConsent: resetConsentHandler,
100
+ updateConsent: updateConsentHandler
101
+ }),
102
+ [
103
+ config,
104
+ consent,
105
+ hasResponded,
106
+ acceptAll,
107
+ declineAnalytics,
108
+ updateConsentHandler,
109
+ resetConsentHandler
110
+ ]
111
+ );
112
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AnalyticsContext.Provider, { value, children });
113
+ }
114
+ function useAnalytics() {
115
+ const context = _react.useContext.call(void 0, AnalyticsContext);
116
+ if (!context) {
117
+ throw new Error("useAnalytics must be used within an AnalyticsProvider");
118
+ }
119
+ return context;
120
+ }
121
+ function useConsent(options = {}) {
122
+ const { consentVersion = _chunkJB5OMGDZcjs.CONSENT_VERSION } = options;
123
+ const [consent, setConsent] = _react.useState.call(void 0, () => {
124
+ const stored = _chunkJB5OMGDZcjs.loadConsent.call(void 0, );
125
+ if (!stored) return null;
126
+ if (_chunkJB5OMGDZcjs.needsRePrompt.call(void 0, stored, consentVersion)) {
127
+ _chunkJB5OMGDZcjs.clearConsent.call(void 0, );
128
+ return null;
129
+ }
130
+ return stored;
131
+ });
132
+ const [hasResponded, setHasResponded] = _react.useState.call(void 0, () => consent !== null);
133
+ const acceptAll = _react.useCallback.call(void 0, () => {
134
+ const newConsent = { ..._chunkJB5OMGDZcjs.createAcceptAllConsent.call(void 0, ), version: consentVersion };
135
+ _chunkJB5OMGDZcjs.saveConsent.call(void 0, newConsent);
136
+ setConsent(newConsent);
137
+ setHasResponded(true);
138
+ }, [consentVersion]);
139
+ const declineAnalytics = _react.useCallback.call(void 0, () => {
140
+ const newConsent = {
141
+ ..._chunkJB5OMGDZcjs.createDeclineAnalyticsConsent.call(void 0, ),
142
+ version: consentVersion
143
+ };
144
+ _chunkJB5OMGDZcjs.saveConsent.call(void 0, newConsent);
145
+ setConsent(newConsent);
146
+ setHasResponded(true);
147
+ }, [consentVersion]);
148
+ const updateConsentHandler = _react.useCallback.call(void 0,
149
+ (category, value) => {
150
+ if (!consent) return;
151
+ const newConsent = _chunkJB5OMGDZcjs.updateConsentCategory.call(void 0, consent, category, value);
152
+ _chunkJB5OMGDZcjs.saveConsent.call(void 0, newConsent);
153
+ setConsent(newConsent);
154
+ },
155
+ [consent]
156
+ );
157
+ const resetConsentHandler = _react.useCallback.call(void 0, () => {
158
+ _chunkJB5OMGDZcjs.clearConsent.call(void 0, );
159
+ setConsent(null);
160
+ setHasResponded(false);
161
+ }, []);
162
+ return {
163
+ acceptAll,
164
+ consent,
165
+ declineAnalytics,
166
+ hasResponded,
167
+ isLoading: false,
168
+ resetConsent: resetConsentHandler,
169
+ updateConsent: updateConsentHandler
170
+ };
171
+ }
172
+
173
+
174
+
175
+
176
+
177
+ exports.AnalyticsProvider = AnalyticsProvider; exports.initAnalytics = _chunkJB5OMGDZcjs.initAnalytics; exports.useAnalytics = useAnalytics; exports.useConsent = useConsent;