@vllnt/analytics 0.2.0-canary.e4bb20a → 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 +74 -0
- package/README.md +252 -137
- package/dist/{analytics-DdAxcZwX.d.cts → analytics-BGm5JlCM.d.cts} +21 -3
- package/dist/{analytics-DdAxcZwX.d.ts → analytics-BGm5JlCM.d.ts} +21 -3
- package/dist/{chunk-MVOBIOKZ.cjs → chunk-BOGMJ4Z4.cjs} +23 -8
- package/dist/{chunk-6RHY2BTB.js → chunk-IBYWNCQ4.js} +22 -7
- package/dist/index.cjs +4 -2
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3 -1
- package/dist/react.cjs +47 -36
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +21 -10
- package/docs/API.md +524 -0
- package/llms.txt +77 -0
- package/package.json +36 -27
- package/src/analytics.ts +322 -0
- package/src/consent.ts +181 -0
- package/src/index.ts +49 -0
- package/src/react.tsx +239 -0
- package/src/types.ts +110 -0
|
@@ -19,7 +19,7 @@ function isStorageAvailable() {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
function loadConsent() {
|
|
22
|
-
if (
|
|
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,22 @@ 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
|
+
}
|
|
110
|
+
function block() {
|
|
111
|
+
isBlocked = true;
|
|
112
|
+
eventQueue = [];
|
|
113
|
+
}
|
|
101
114
|
function debugLog(type, data) {
|
|
102
115
|
if (_optionalChain([analyticsState, 'optionalAccess', _ => _.debug])) {
|
|
103
116
|
console.log(`[analytics:${type}]`, data);
|
|
@@ -108,14 +121,15 @@ function sendEvent(name, properties) {
|
|
|
108
121
|
}
|
|
109
122
|
function initAnalytics(config) {
|
|
110
123
|
if (analyticsState) return;
|
|
124
|
+
setMaxQueuedEvents(config.maxQueuedEvents);
|
|
111
125
|
if (isDoNotTrackEnabled()) {
|
|
112
|
-
|
|
126
|
+
block();
|
|
113
127
|
debugLog("init", "Do Not Track enabled, analytics blocked");
|
|
114
128
|
return;
|
|
115
129
|
}
|
|
116
130
|
const consent = loadConsent();
|
|
117
131
|
if (consent && !consent.analytics) {
|
|
118
|
-
|
|
132
|
+
block();
|
|
119
133
|
debugLog("init", "Analytics consent declined");
|
|
120
134
|
return;
|
|
121
135
|
}
|
|
@@ -150,7 +164,7 @@ function track(name, properties) {
|
|
|
150
164
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
151
165
|
};
|
|
152
166
|
if (!isInitialized) {
|
|
153
|
-
|
|
167
|
+
enqueue(event);
|
|
154
168
|
return;
|
|
155
169
|
}
|
|
156
170
|
sendEvent(name, properties);
|
|
@@ -159,7 +173,7 @@ function trackPage(properties) {
|
|
|
159
173
|
if (typeof window === "undefined") return;
|
|
160
174
|
if (isBlocked) return;
|
|
161
175
|
if (!isInitialized) {
|
|
162
|
-
|
|
176
|
+
enqueue({
|
|
163
177
|
name: "__page__",
|
|
164
178
|
properties,
|
|
165
179
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -195,8 +209,7 @@ function enableAnalytics(config) {
|
|
|
195
209
|
}
|
|
196
210
|
}
|
|
197
211
|
function disableAnalytics() {
|
|
198
|
-
|
|
199
|
-
eventQueue.length = 0;
|
|
212
|
+
block();
|
|
200
213
|
}
|
|
201
214
|
function isAnalyticsEnabled() {
|
|
202
215
|
return isInitialized && !isBlocked;
|
|
@@ -253,4 +266,6 @@ function trackTimeSpent(properties) {
|
|
|
253
266
|
|
|
254
267
|
|
|
255
268
|
|
|
256
|
-
|
|
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 (
|
|
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,22 @@ 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
|
+
}
|
|
110
|
+
function block() {
|
|
111
|
+
isBlocked = true;
|
|
112
|
+
eventQueue = [];
|
|
113
|
+
}
|
|
101
114
|
function debugLog(type, data) {
|
|
102
115
|
if (analyticsState?.debug) {
|
|
103
116
|
console.log(`[analytics:${type}]`, data);
|
|
@@ -108,14 +121,15 @@ function sendEvent(name, properties) {
|
|
|
108
121
|
}
|
|
109
122
|
function initAnalytics(config) {
|
|
110
123
|
if (analyticsState) return;
|
|
124
|
+
setMaxQueuedEvents(config.maxQueuedEvents);
|
|
111
125
|
if (isDoNotTrackEnabled()) {
|
|
112
|
-
|
|
126
|
+
block();
|
|
113
127
|
debugLog("init", "Do Not Track enabled, analytics blocked");
|
|
114
128
|
return;
|
|
115
129
|
}
|
|
116
130
|
const consent = loadConsent();
|
|
117
131
|
if (consent && !consent.analytics) {
|
|
118
|
-
|
|
132
|
+
block();
|
|
119
133
|
debugLog("init", "Analytics consent declined");
|
|
120
134
|
return;
|
|
121
135
|
}
|
|
@@ -150,7 +164,7 @@ function track(name, properties) {
|
|
|
150
164
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
151
165
|
};
|
|
152
166
|
if (!isInitialized) {
|
|
153
|
-
|
|
167
|
+
enqueue(event);
|
|
154
168
|
return;
|
|
155
169
|
}
|
|
156
170
|
sendEvent(name, properties);
|
|
@@ -159,7 +173,7 @@ function trackPage(properties) {
|
|
|
159
173
|
if (typeof window === "undefined") return;
|
|
160
174
|
if (isBlocked) return;
|
|
161
175
|
if (!isInitialized) {
|
|
162
|
-
|
|
176
|
+
enqueue({
|
|
163
177
|
name: "__page__",
|
|
164
178
|
properties,
|
|
165
179
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -195,8 +209,7 @@ function enableAnalytics(config) {
|
|
|
195
209
|
}
|
|
196
210
|
}
|
|
197
211
|
function disableAnalytics() {
|
|
198
|
-
|
|
199
|
-
eventQueue.length = 0;
|
|
212
|
+
block();
|
|
200
213
|
}
|
|
201
214
|
function isAnalyticsEnabled() {
|
|
202
215
|
return isInitialized && !isBlocked;
|
|
@@ -238,6 +251,8 @@ export {
|
|
|
238
251
|
needsRePrompt,
|
|
239
252
|
isDoNotTrackEnabled,
|
|
240
253
|
getConsentFromCookie,
|
|
254
|
+
DEFAULT_MAX_QUEUED_EVENTS,
|
|
255
|
+
setMaxQueuedEvents,
|
|
241
256
|
initAnalytics,
|
|
242
257
|
track,
|
|
243
258
|
trackPage,
|
package/dist/index.cjs
CHANGED
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
var _chunkMVOBIOKZcjs = require('./chunk-MVOBIOKZ.cjs');
|
|
32
31
|
|
|
32
|
+
var _chunkBOGMJ4Z4cjs = require('./chunk-BOGMJ4Z4.cjs');
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
|
|
@@ -59,4 +59,6 @@ var _chunkMVOBIOKZcjs = require('./chunk-MVOBIOKZ.cjs');
|
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
|
|
62
|
-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
var _chunkBOGMJ4Z4cjs = require('./chunk-BOGMJ4Z4.cjs');
|
|
15
16
|
|
|
16
17
|
// src/react.tsx
|
|
17
18
|
|
|
@@ -27,58 +28,65 @@ var AnalyticsContext = _react.createContext.call(void 0, null);
|
|
|
27
28
|
function AnalyticsProvider({
|
|
28
29
|
children,
|
|
29
30
|
config,
|
|
30
|
-
consentVersion =
|
|
31
|
+
consentVersion = _chunkBOGMJ4Z4cjs.CONSENT_VERSION
|
|
31
32
|
}) {
|
|
32
33
|
const [consent, setConsent] = _react.useState.call(void 0, () => {
|
|
33
|
-
|
|
34
|
+
_chunkBOGMJ4Z4cjs.setMaxQueuedEvents.call(void 0, config.maxQueuedEvents);
|
|
35
|
+
const stored = _chunkBOGMJ4Z4cjs.loadConsent.call(void 0, );
|
|
34
36
|
if (!stored) return null;
|
|
35
|
-
if (
|
|
36
|
-
|
|
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;
|
|
40
42
|
});
|
|
41
43
|
const [hasResponded, setHasResponded] = _react.useState.call(void 0, () => consent !== null);
|
|
42
44
|
_react.useEffect.call(void 0, () => {
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
+
if (!consent) return;
|
|
46
|
+
if (consent.analytics) {
|
|
47
|
+
_chunkBOGMJ4Z4cjs.initAnalytics.call(void 0, config);
|
|
48
|
+
} else {
|
|
49
|
+
_chunkBOGMJ4Z4cjs.disableAnalytics.call(void 0, );
|
|
45
50
|
}
|
|
46
51
|
}, [consent, config]);
|
|
47
52
|
const acceptAll = _react.useCallback.call(void 0, () => {
|
|
48
|
-
const newConsent =
|
|
49
|
-
|
|
53
|
+
const newConsent = { ..._chunkBOGMJ4Z4cjs.createAcceptAllConsent.call(void 0, ), version: consentVersion };
|
|
54
|
+
_chunkBOGMJ4Z4cjs.saveConsent.call(void 0, newConsent);
|
|
50
55
|
setConsent(newConsent);
|
|
51
56
|
setHasResponded(true);
|
|
52
|
-
|
|
53
|
-
}, [config]);
|
|
57
|
+
_chunkBOGMJ4Z4cjs.enableAnalytics.call(void 0, config);
|
|
58
|
+
}, [config, consentVersion]);
|
|
54
59
|
const declineAnalytics = _react.useCallback.call(void 0, () => {
|
|
55
|
-
const newConsent =
|
|
56
|
-
|
|
60
|
+
const newConsent = {
|
|
61
|
+
..._chunkBOGMJ4Z4cjs.createDeclineAnalyticsConsent.call(void 0, ),
|
|
62
|
+
version: consentVersion
|
|
63
|
+
};
|
|
64
|
+
_chunkBOGMJ4Z4cjs.saveConsent.call(void 0, newConsent);
|
|
57
65
|
setConsent(newConsent);
|
|
58
66
|
setHasResponded(true);
|
|
59
|
-
|
|
60
|
-
}, []);
|
|
67
|
+
_chunkBOGMJ4Z4cjs.disableAnalytics.call(void 0, );
|
|
68
|
+
}, [consentVersion]);
|
|
61
69
|
const updateConsentHandler = _react.useCallback.call(void 0,
|
|
62
70
|
(category, value2) => {
|
|
63
71
|
if (!consent) return;
|
|
64
|
-
const newConsent =
|
|
65
|
-
|
|
72
|
+
const newConsent = _chunkBOGMJ4Z4cjs.updateConsentCategory.call(void 0, consent, category, value2);
|
|
73
|
+
_chunkBOGMJ4Z4cjs.saveConsent.call(void 0, newConsent);
|
|
66
74
|
setConsent(newConsent);
|
|
67
75
|
if (category === "analytics") {
|
|
68
76
|
if (value2) {
|
|
69
|
-
|
|
77
|
+
_chunkBOGMJ4Z4cjs.enableAnalytics.call(void 0, config);
|
|
70
78
|
} else {
|
|
71
|
-
|
|
79
|
+
_chunkBOGMJ4Z4cjs.disableAnalytics.call(void 0, );
|
|
72
80
|
}
|
|
73
81
|
}
|
|
74
82
|
},
|
|
75
83
|
[consent, config]
|
|
76
84
|
);
|
|
77
85
|
const resetConsentHandler = _react.useCallback.call(void 0, () => {
|
|
78
|
-
|
|
86
|
+
_chunkBOGMJ4Z4cjs.clearConsent.call(void 0, );
|
|
79
87
|
setConsent(null);
|
|
80
88
|
setHasResponded(false);
|
|
81
|
-
|
|
89
|
+
_chunkBOGMJ4Z4cjs.disableAnalytics.call(void 0, );
|
|
82
90
|
}, []);
|
|
83
91
|
const value = _react.useMemo.call(void 0,
|
|
84
92
|
() => ({
|
|
@@ -111,40 +119,43 @@ function useAnalytics() {
|
|
|
111
119
|
return context;
|
|
112
120
|
}
|
|
113
121
|
function useConsent(options = {}) {
|
|
114
|
-
const { consentVersion =
|
|
122
|
+
const { consentVersion = _chunkBOGMJ4Z4cjs.CONSENT_VERSION } = options;
|
|
115
123
|
const [consent, setConsent] = _react.useState.call(void 0, () => {
|
|
116
|
-
const stored =
|
|
124
|
+
const stored = _chunkBOGMJ4Z4cjs.loadConsent.call(void 0, );
|
|
117
125
|
if (!stored) return null;
|
|
118
|
-
if (
|
|
119
|
-
|
|
126
|
+
if (_chunkBOGMJ4Z4cjs.needsRePrompt.call(void 0, stored, consentVersion)) {
|
|
127
|
+
_chunkBOGMJ4Z4cjs.clearConsent.call(void 0, );
|
|
120
128
|
return null;
|
|
121
129
|
}
|
|
122
130
|
return stored;
|
|
123
131
|
});
|
|
124
132
|
const [hasResponded, setHasResponded] = _react.useState.call(void 0, () => consent !== null);
|
|
125
133
|
const acceptAll = _react.useCallback.call(void 0, () => {
|
|
126
|
-
const newConsent =
|
|
127
|
-
|
|
134
|
+
const newConsent = { ..._chunkBOGMJ4Z4cjs.createAcceptAllConsent.call(void 0, ), version: consentVersion };
|
|
135
|
+
_chunkBOGMJ4Z4cjs.saveConsent.call(void 0, newConsent);
|
|
128
136
|
setConsent(newConsent);
|
|
129
137
|
setHasResponded(true);
|
|
130
|
-
}, []);
|
|
138
|
+
}, [consentVersion]);
|
|
131
139
|
const declineAnalytics = _react.useCallback.call(void 0, () => {
|
|
132
|
-
const newConsent =
|
|
133
|
-
|
|
140
|
+
const newConsent = {
|
|
141
|
+
..._chunkBOGMJ4Z4cjs.createDeclineAnalyticsConsent.call(void 0, ),
|
|
142
|
+
version: consentVersion
|
|
143
|
+
};
|
|
144
|
+
_chunkBOGMJ4Z4cjs.saveConsent.call(void 0, newConsent);
|
|
134
145
|
setConsent(newConsent);
|
|
135
146
|
setHasResponded(true);
|
|
136
|
-
}, []);
|
|
147
|
+
}, [consentVersion]);
|
|
137
148
|
const updateConsentHandler = _react.useCallback.call(void 0,
|
|
138
149
|
(category, value) => {
|
|
139
150
|
if (!consent) return;
|
|
140
|
-
const newConsent =
|
|
141
|
-
|
|
151
|
+
const newConsent = _chunkBOGMJ4Z4cjs.updateConsentCategory.call(void 0, consent, category, value);
|
|
152
|
+
_chunkBOGMJ4Z4cjs.saveConsent.call(void 0, newConsent);
|
|
142
153
|
setConsent(newConsent);
|
|
143
154
|
},
|
|
144
155
|
[consent]
|
|
145
156
|
);
|
|
146
157
|
const resetConsentHandler = _react.useCallback.call(void 0, () => {
|
|
147
|
-
|
|
158
|
+
_chunkBOGMJ4Z4cjs.clearConsent.call(void 0, );
|
|
148
159
|
setConsent(null);
|
|
149
160
|
setHasResponded(false);
|
|
150
161
|
}, []);
|
|
@@ -163,4 +174,4 @@ function useConsent(options = {}) {
|
|
|
163
174
|
|
|
164
175
|
|
|
165
176
|
|
|
166
|
-
exports.AnalyticsProvider = AnalyticsProvider; exports.initAnalytics =
|
|
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-
|
|
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-
|
|
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-
|
|
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)) {
|
|
@@ -40,24 +42,30 @@ function AnalyticsProvider({
|
|
|
40
42
|
});
|
|
41
43
|
const [hasResponded, setHasResponded] = useState(() => consent !== null);
|
|
42
44
|
useEffect(() => {
|
|
43
|
-
if (consent
|
|
45
|
+
if (!consent) return;
|
|
46
|
+
if (consent.analytics) {
|
|
44
47
|
initAnalytics(config);
|
|
48
|
+
} else {
|
|
49
|
+
disableAnalytics();
|
|
45
50
|
}
|
|
46
51
|
}, [consent, config]);
|
|
47
52
|
const acceptAll = useCallback(() => {
|
|
48
|
-
const newConsent = createAcceptAllConsent();
|
|
53
|
+
const newConsent = { ...createAcceptAllConsent(), version: consentVersion };
|
|
49
54
|
saveConsent(newConsent);
|
|
50
55
|
setConsent(newConsent);
|
|
51
56
|
setHasResponded(true);
|
|
52
57
|
enableAnalytics(config);
|
|
53
|
-
}, [config]);
|
|
58
|
+
}, [config, consentVersion]);
|
|
54
59
|
const declineAnalytics = useCallback(() => {
|
|
55
|
-
const newConsent =
|
|
60
|
+
const newConsent = {
|
|
61
|
+
...createDeclineAnalyticsConsent(),
|
|
62
|
+
version: consentVersion
|
|
63
|
+
};
|
|
56
64
|
saveConsent(newConsent);
|
|
57
65
|
setConsent(newConsent);
|
|
58
66
|
setHasResponded(true);
|
|
59
67
|
disableAnalytics();
|
|
60
|
-
}, []);
|
|
68
|
+
}, [consentVersion]);
|
|
61
69
|
const updateConsentHandler = useCallback(
|
|
62
70
|
(category, value2) => {
|
|
63
71
|
if (!consent) return;
|
|
@@ -123,17 +131,20 @@ function useConsent(options = {}) {
|
|
|
123
131
|
});
|
|
124
132
|
const [hasResponded, setHasResponded] = useState(() => consent !== null);
|
|
125
133
|
const acceptAll = useCallback(() => {
|
|
126
|
-
const newConsent = createAcceptAllConsent();
|
|
134
|
+
const newConsent = { ...createAcceptAllConsent(), version: consentVersion };
|
|
127
135
|
saveConsent(newConsent);
|
|
128
136
|
setConsent(newConsent);
|
|
129
137
|
setHasResponded(true);
|
|
130
|
-
}, []);
|
|
138
|
+
}, [consentVersion]);
|
|
131
139
|
const declineAnalytics = useCallback(() => {
|
|
132
|
-
const newConsent =
|
|
140
|
+
const newConsent = {
|
|
141
|
+
...createDeclineAnalyticsConsent(),
|
|
142
|
+
version: consentVersion
|
|
143
|
+
};
|
|
133
144
|
saveConsent(newConsent);
|
|
134
145
|
setConsent(newConsent);
|
|
135
146
|
setHasResponded(true);
|
|
136
|
-
}, []);
|
|
147
|
+
}, [consentVersion]);
|
|
137
148
|
const updateConsentHandler = useCallback(
|
|
138
149
|
(category, value) => {
|
|
139
150
|
if (!consent) return;
|