@vllnt/analytics 0.1.1 → 0.2.0-canary.6a57f79

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,259 @@
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; }// 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 (e) {
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 (e2) {
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 (e3) {
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 eventQueue = [];
99
+ var isInitialized = false;
100
+ var isBlocked = false;
101
+ function block() {
102
+ isBlocked = true;
103
+ eventQueue = [];
104
+ }
105
+ function debugLog(type, data) {
106
+ if (_optionalChain([analyticsState, 'optionalAccess', _ => _.debug])) {
107
+ console.log(`[analytics:${type}]`, data);
108
+ }
109
+ }
110
+ function sendEvent(name, properties) {
111
+ debugLog("track", { name, properties });
112
+ }
113
+ function initAnalytics(config) {
114
+ if (analyticsState) return;
115
+ if (isDoNotTrackEnabled()) {
116
+ block();
117
+ debugLog("init", "Do Not Track enabled, analytics blocked");
118
+ return;
119
+ }
120
+ const consent = loadConsent();
121
+ if (consent && !consent.analytics) {
122
+ block();
123
+ debugLog("init", "Analytics consent declined");
124
+ return;
125
+ }
126
+ analyticsState = {
127
+ app: config.app,
128
+ debug: config.debug,
129
+ version: config.version
130
+ };
131
+ isInitialized = true;
132
+ debugLog("init", { app: config.app, version: config.version });
133
+ processQueue();
134
+ }
135
+ function processQueue() {
136
+ if (!analyticsState || isBlocked) return;
137
+ const queue = [...eventQueue];
138
+ eventQueue = [];
139
+ for (const event of queue) {
140
+ if (event.name === "__page__") {
141
+ debugLog("page", event.properties);
142
+ } else {
143
+ sendEvent(event.name, event.properties);
144
+ }
145
+ }
146
+ }
147
+ function track(name, properties) {
148
+ if (typeof window === "undefined") return;
149
+ if (typeof name !== "string" || name === "") return;
150
+ if (isBlocked) return;
151
+ const event = {
152
+ name,
153
+ properties,
154
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
155
+ };
156
+ if (!isInitialized) {
157
+ eventQueue.push(event);
158
+ return;
159
+ }
160
+ sendEvent(name, properties);
161
+ }
162
+ function trackPage(properties) {
163
+ if (typeof window === "undefined") return;
164
+ if (isBlocked) return;
165
+ if (!isInitialized) {
166
+ eventQueue.push({
167
+ name: "__page__",
168
+ properties,
169
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
170
+ });
171
+ return;
172
+ }
173
+ debugLog("page", properties);
174
+ }
175
+ function identify(userId, traits) {
176
+ if (typeof window === "undefined") return;
177
+ if (typeof userId !== "string" || userId === "") return;
178
+ if (isBlocked) return;
179
+ if (!isInitialized || !analyticsState) {
180
+ return;
181
+ }
182
+ analyticsState.userId = userId;
183
+ analyticsState.traits = traits;
184
+ debugLog("identify", { traits, userId });
185
+ }
186
+ function resetAnalytics() {
187
+ if (typeof window === "undefined") return;
188
+ if (analyticsState) {
189
+ analyticsState.userId = void 0;
190
+ analyticsState.traits = void 0;
191
+ }
192
+ debugLog("reset", void 0);
193
+ }
194
+ function enableAnalytics(config) {
195
+ if (isBlocked && !isDoNotTrackEnabled()) {
196
+ isBlocked = false;
197
+ analyticsState = void 0;
198
+ initAnalytics(config);
199
+ }
200
+ }
201
+ function disableAnalytics() {
202
+ block();
203
+ }
204
+ function isAnalyticsEnabled() {
205
+ return isInitialized && !isBlocked;
206
+ }
207
+ function getAnalyticsState() {
208
+ return analyticsState;
209
+ }
210
+ function trackTutorialStart(properties) {
211
+ track("tutorial_start", properties);
212
+ }
213
+ function trackSectionView(properties) {
214
+ track("tutorial_section_view", properties);
215
+ }
216
+ function trackSectionComplete(properties) {
217
+ track("tutorial_section_complete", properties);
218
+ }
219
+ function trackTutorialComplete(properties) {
220
+ track("tutorial_complete", properties);
221
+ }
222
+ function trackTutorialNavigation(properties) {
223
+ track("tutorial_navigation", properties);
224
+ }
225
+ function trackTimeSpent(properties) {
226
+ track("tutorial_time_spent", properties);
227
+ }
228
+
229
+
230
+
231
+
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+
256
+
257
+
258
+
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;
package/dist/index.cjs ADDED
@@ -0,0 +1,62 @@
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
+ var _chunkACWD5NRIcjs = require('./chunk-ACWD5NRI.cjs');
32
+
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
+ 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;
@@ -0,0 +1,55 @@
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';
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-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';
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,62 @@
1
+ import {
2
+ CONSENT_COOKIE_NAME,
3
+ CONSENT_STORAGE_KEY,
4
+ CONSENT_VERSION,
5
+ clearConsent,
6
+ createAcceptAllConsent,
7
+ createDeclineAnalyticsConsent,
8
+ disableAnalytics,
9
+ enableAnalytics,
10
+ getAnalyticsState,
11
+ getConsentFromCookie,
12
+ identify,
13
+ initAnalytics,
14
+ isAnalyticsEnabled,
15
+ isDoNotTrackEnabled,
16
+ isStorageAvailable,
17
+ isValidConsentState,
18
+ loadConsent,
19
+ needsRePrompt,
20
+ resetAnalytics,
21
+ saveConsent,
22
+ track,
23
+ trackPage,
24
+ trackSectionComplete,
25
+ trackSectionView,
26
+ trackTimeSpent,
27
+ trackTutorialComplete,
28
+ trackTutorialNavigation,
29
+ trackTutorialStart,
30
+ updateConsentCategory
31
+ } from "./chunk-5COCGKHD.js";
32
+ export {
33
+ CONSENT_COOKIE_NAME,
34
+ CONSENT_STORAGE_KEY,
35
+ CONSENT_VERSION,
36
+ clearConsent,
37
+ createAcceptAllConsent,
38
+ createDeclineAnalyticsConsent,
39
+ disableAnalytics,
40
+ enableAnalytics,
41
+ getAnalyticsState,
42
+ getConsentFromCookie,
43
+ identify,
44
+ initAnalytics,
45
+ isAnalyticsEnabled,
46
+ isDoNotTrackEnabled,
47
+ isStorageAvailable,
48
+ isValidConsentState,
49
+ loadConsent,
50
+ needsRePrompt,
51
+ resetAnalytics,
52
+ saveConsent,
53
+ track,
54
+ trackPage,
55
+ trackSectionComplete,
56
+ trackSectionView,
57
+ trackTimeSpent,
58
+ trackTutorialComplete,
59
+ trackTutorialNavigation,
60
+ trackTutorialStart,
61
+ updateConsentCategory
62
+ };
package/dist/react.cjs ADDED
@@ -0,0 +1,175 @@
1
+ "use client";"use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+ var _chunkACWD5NRIcjs = require('./chunk-ACWD5NRI.cjs');
15
+
16
+ // src/react.tsx
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+ var _react = require('react');
25
+ var _jsxruntime = require('react/jsx-runtime');
26
+ var AnalyticsContext = _react.createContext.call(void 0, null);
27
+ function AnalyticsProvider({
28
+ children,
29
+ config,
30
+ consentVersion = _chunkACWD5NRIcjs.CONSENT_VERSION
31
+ }) {
32
+ const [consent, setConsent] = _react.useState.call(void 0, () => {
33
+ const stored = _chunkACWD5NRIcjs.loadConsent.call(void 0, );
34
+ if (!stored) return null;
35
+ if (_chunkACWD5NRIcjs.needsRePrompt.call(void 0, stored, consentVersion)) {
36
+ _chunkACWD5NRIcjs.clearConsent.call(void 0, );
37
+ return null;
38
+ }
39
+ return stored;
40
+ });
41
+ const [hasResponded, setHasResponded] = _react.useState.call(void 0, () => consent !== null);
42
+ _react.useEffect.call(void 0, () => {
43
+ if (!consent) return;
44
+ if (consent.analytics) {
45
+ _chunkACWD5NRIcjs.initAnalytics.call(void 0, config);
46
+ } else {
47
+ _chunkACWD5NRIcjs.disableAnalytics.call(void 0, );
48
+ }
49
+ }, [consent, config]);
50
+ 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
+ setConsent(newConsent);
54
+ setHasResponded(true);
55
+ _chunkACWD5NRIcjs.enableAnalytics.call(void 0, config);
56
+ }, [config, consentVersion]);
57
+ const declineAnalytics = _react.useCallback.call(void 0, () => {
58
+ const newConsent = {
59
+ ..._chunkACWD5NRIcjs.createDeclineAnalyticsConsent.call(void 0, ),
60
+ version: consentVersion
61
+ };
62
+ _chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
63
+ setConsent(newConsent);
64
+ setHasResponded(true);
65
+ _chunkACWD5NRIcjs.disableAnalytics.call(void 0, );
66
+ }, [consentVersion]);
67
+ const updateConsentHandler = _react.useCallback.call(void 0,
68
+ (category, value2) => {
69
+ if (!consent) return;
70
+ const newConsent = _chunkACWD5NRIcjs.updateConsentCategory.call(void 0, consent, category, value2);
71
+ _chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
72
+ setConsent(newConsent);
73
+ if (category === "analytics") {
74
+ if (value2) {
75
+ _chunkACWD5NRIcjs.enableAnalytics.call(void 0, config);
76
+ } else {
77
+ _chunkACWD5NRIcjs.disableAnalytics.call(void 0, );
78
+ }
79
+ }
80
+ },
81
+ [consent, config]
82
+ );
83
+ const resetConsentHandler = _react.useCallback.call(void 0, () => {
84
+ _chunkACWD5NRIcjs.clearConsent.call(void 0, );
85
+ setConsent(null);
86
+ setHasResponded(false);
87
+ _chunkACWD5NRIcjs.disableAnalytics.call(void 0, );
88
+ }, []);
89
+ const value = _react.useMemo.call(void 0,
90
+ () => ({
91
+ acceptAll,
92
+ config,
93
+ consent,
94
+ declineAnalytics,
95
+ hasResponded,
96
+ isLoading: false,
97
+ resetConsent: resetConsentHandler,
98
+ updateConsent: updateConsentHandler
99
+ }),
100
+ [
101
+ config,
102
+ consent,
103
+ hasResponded,
104
+ acceptAll,
105
+ declineAnalytics,
106
+ updateConsentHandler,
107
+ resetConsentHandler
108
+ ]
109
+ );
110
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AnalyticsContext.Provider, { value, children });
111
+ }
112
+ function useAnalytics() {
113
+ const context = _react.useContext.call(void 0, AnalyticsContext);
114
+ if (!context) {
115
+ throw new Error("useAnalytics must be used within an AnalyticsProvider");
116
+ }
117
+ return context;
118
+ }
119
+ function useConsent(options = {}) {
120
+ const { consentVersion = _chunkACWD5NRIcjs.CONSENT_VERSION } = options;
121
+ const [consent, setConsent] = _react.useState.call(void 0, () => {
122
+ const stored = _chunkACWD5NRIcjs.loadConsent.call(void 0, );
123
+ if (!stored) return null;
124
+ if (_chunkACWD5NRIcjs.needsRePrompt.call(void 0, stored, consentVersion)) {
125
+ _chunkACWD5NRIcjs.clearConsent.call(void 0, );
126
+ return null;
127
+ }
128
+ return stored;
129
+ });
130
+ const [hasResponded, setHasResponded] = _react.useState.call(void 0, () => consent !== null);
131
+ 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
+ setConsent(newConsent);
135
+ setHasResponded(true);
136
+ }, [consentVersion]);
137
+ const declineAnalytics = _react.useCallback.call(void 0, () => {
138
+ const newConsent = {
139
+ ..._chunkACWD5NRIcjs.createDeclineAnalyticsConsent.call(void 0, ),
140
+ version: consentVersion
141
+ };
142
+ _chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
143
+ setConsent(newConsent);
144
+ setHasResponded(true);
145
+ }, [consentVersion]);
146
+ const updateConsentHandler = _react.useCallback.call(void 0,
147
+ (category, value) => {
148
+ if (!consent) return;
149
+ const newConsent = _chunkACWD5NRIcjs.updateConsentCategory.call(void 0, consent, category, value);
150
+ _chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
151
+ setConsent(newConsent);
152
+ },
153
+ [consent]
154
+ );
155
+ const resetConsentHandler = _react.useCallback.call(void 0, () => {
156
+ _chunkACWD5NRIcjs.clearConsent.call(void 0, );
157
+ setConsent(null);
158
+ setHasResponded(false);
159
+ }, []);
160
+ return {
161
+ acceptAll,
162
+ consent,
163
+ declineAnalytics,
164
+ hasResponded,
165
+ isLoading: false,
166
+ resetConsent: resetConsentHandler,
167
+ updateConsent: updateConsentHandler
168
+ };
169
+ }
170
+
171
+
172
+
173
+
174
+
175
+ exports.AnalyticsProvider = AnalyticsProvider; exports.initAnalytics = _chunkACWD5NRIcjs.initAnalytics; exports.useAnalytics = useAnalytics; exports.useConsent = useConsent;
@@ -0,0 +1,33 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { AnalyticsConfig, ConsentState, ConsentCategory, UseConsentOptions, UseConsentReturn } from './index.cjs';
4
+ export { h as initAnalytics } from './analytics-BxUQktfB.cjs';
5
+
6
+ type AnalyticsContextValue = {
7
+ acceptAll: () => void;
8
+ config: AnalyticsConfig;
9
+ consent: ConsentState | null;
10
+ declineAnalytics: () => void;
11
+ hasResponded: boolean;
12
+ isLoading: boolean;
13
+ resetConsent: () => void;
14
+ updateConsent: (category: ConsentCategory, value: boolean) => void;
15
+ };
16
+ /**
17
+ * Analytics provider component
18
+ */
19
+ declare function AnalyticsProvider({ children, config, consentVersion, }: {
20
+ children: ReactNode;
21
+ config: AnalyticsConfig;
22
+ consentVersion?: number;
23
+ }): react.JSX.Element;
24
+ /**
25
+ * Hook to access analytics context
26
+ */
27
+ declare function useAnalytics(): AnalyticsContextValue;
28
+ /**
29
+ * Hook to manage consent state
30
+ */
31
+ declare function useConsent(options?: UseConsentOptions): UseConsentReturn;
32
+
33
+ export { AnalyticsProvider, useAnalytics, useConsent };