@vllnt/analytics 0.1.1 → 0.2.0-canary.c351189
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/README.md +57 -53
- package/dist/analytics-DdAxcZwX.d.cts +166 -0
- package/dist/analytics-DdAxcZwX.d.ts +166 -0
- package/dist/chunk-6RHY2BTB.js +256 -0
- package/dist/chunk-MVOBIOKZ.cjs +256 -0
- package/dist/index.cjs +62 -0
- package/dist/index.d.cts +55 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +62 -0
- package/dist/react.cjs +166 -0
- package/dist/react.d.cts +33 -0
- package/dist/react.d.ts +33 -0
- package/{src/react.tsx → dist/react.js} +41 -96
- package/package.json +61 -35
- package/src/analytics.ts +0 -305
- package/src/consent.ts +0 -175
- package/src/index.ts +0 -48
- package/src/types.ts +0 -102
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-6RHY2BTB.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,166 @@
|
|
|
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";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var _chunkMVOBIOKZcjs = require('./chunk-MVOBIOKZ.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 = _chunkMVOBIOKZcjs.CONSENT_VERSION
|
|
31
|
+
}) {
|
|
32
|
+
const [consent, setConsent] = _react.useState.call(void 0, () => {
|
|
33
|
+
const stored = _chunkMVOBIOKZcjs.loadConsent.call(void 0, );
|
|
34
|
+
if (!stored) return null;
|
|
35
|
+
if (_chunkMVOBIOKZcjs.needsRePrompt.call(void 0, stored, consentVersion)) {
|
|
36
|
+
_chunkMVOBIOKZcjs.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 (_optionalChain([consent, 'optionalAccess', _ => _.analytics])) {
|
|
44
|
+
_chunkMVOBIOKZcjs.initAnalytics.call(void 0, config);
|
|
45
|
+
}
|
|
46
|
+
}, [consent, config]);
|
|
47
|
+
const acceptAll = _react.useCallback.call(void 0, () => {
|
|
48
|
+
const newConsent = _chunkMVOBIOKZcjs.createAcceptAllConsent.call(void 0, );
|
|
49
|
+
_chunkMVOBIOKZcjs.saveConsent.call(void 0, newConsent);
|
|
50
|
+
setConsent(newConsent);
|
|
51
|
+
setHasResponded(true);
|
|
52
|
+
_chunkMVOBIOKZcjs.enableAnalytics.call(void 0, config);
|
|
53
|
+
}, [config]);
|
|
54
|
+
const declineAnalytics = _react.useCallback.call(void 0, () => {
|
|
55
|
+
const newConsent = _chunkMVOBIOKZcjs.createDeclineAnalyticsConsent.call(void 0, );
|
|
56
|
+
_chunkMVOBIOKZcjs.saveConsent.call(void 0, newConsent);
|
|
57
|
+
setConsent(newConsent);
|
|
58
|
+
setHasResponded(true);
|
|
59
|
+
_chunkMVOBIOKZcjs.disableAnalytics.call(void 0, );
|
|
60
|
+
}, []);
|
|
61
|
+
const updateConsentHandler = _react.useCallback.call(void 0,
|
|
62
|
+
(category, value2) => {
|
|
63
|
+
if (!consent) return;
|
|
64
|
+
const newConsent = _chunkMVOBIOKZcjs.updateConsentCategory.call(void 0, consent, category, value2);
|
|
65
|
+
_chunkMVOBIOKZcjs.saveConsent.call(void 0, newConsent);
|
|
66
|
+
setConsent(newConsent);
|
|
67
|
+
if (category === "analytics") {
|
|
68
|
+
if (value2) {
|
|
69
|
+
_chunkMVOBIOKZcjs.enableAnalytics.call(void 0, config);
|
|
70
|
+
} else {
|
|
71
|
+
_chunkMVOBIOKZcjs.disableAnalytics.call(void 0, );
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
[consent, config]
|
|
76
|
+
);
|
|
77
|
+
const resetConsentHandler = _react.useCallback.call(void 0, () => {
|
|
78
|
+
_chunkMVOBIOKZcjs.clearConsent.call(void 0, );
|
|
79
|
+
setConsent(null);
|
|
80
|
+
setHasResponded(false);
|
|
81
|
+
_chunkMVOBIOKZcjs.disableAnalytics.call(void 0, );
|
|
82
|
+
}, []);
|
|
83
|
+
const value = _react.useMemo.call(void 0,
|
|
84
|
+
() => ({
|
|
85
|
+
acceptAll,
|
|
86
|
+
config,
|
|
87
|
+
consent,
|
|
88
|
+
declineAnalytics,
|
|
89
|
+
hasResponded,
|
|
90
|
+
isLoading: false,
|
|
91
|
+
resetConsent: resetConsentHandler,
|
|
92
|
+
updateConsent: updateConsentHandler
|
|
93
|
+
}),
|
|
94
|
+
[
|
|
95
|
+
config,
|
|
96
|
+
consent,
|
|
97
|
+
hasResponded,
|
|
98
|
+
acceptAll,
|
|
99
|
+
declineAnalytics,
|
|
100
|
+
updateConsentHandler,
|
|
101
|
+
resetConsentHandler
|
|
102
|
+
]
|
|
103
|
+
);
|
|
104
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AnalyticsContext.Provider, { value, children });
|
|
105
|
+
}
|
|
106
|
+
function useAnalytics() {
|
|
107
|
+
const context = _react.useContext.call(void 0, AnalyticsContext);
|
|
108
|
+
if (!context) {
|
|
109
|
+
throw new Error("useAnalytics must be used within an AnalyticsProvider");
|
|
110
|
+
}
|
|
111
|
+
return context;
|
|
112
|
+
}
|
|
113
|
+
function useConsent(options = {}) {
|
|
114
|
+
const { consentVersion = _chunkMVOBIOKZcjs.CONSENT_VERSION } = options;
|
|
115
|
+
const [consent, setConsent] = _react.useState.call(void 0, () => {
|
|
116
|
+
const stored = _chunkMVOBIOKZcjs.loadConsent.call(void 0, );
|
|
117
|
+
if (!stored) return null;
|
|
118
|
+
if (_chunkMVOBIOKZcjs.needsRePrompt.call(void 0, stored, consentVersion)) {
|
|
119
|
+
_chunkMVOBIOKZcjs.clearConsent.call(void 0, );
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
return stored;
|
|
123
|
+
});
|
|
124
|
+
const [hasResponded, setHasResponded] = _react.useState.call(void 0, () => consent !== null);
|
|
125
|
+
const acceptAll = _react.useCallback.call(void 0, () => {
|
|
126
|
+
const newConsent = _chunkMVOBIOKZcjs.createAcceptAllConsent.call(void 0, );
|
|
127
|
+
_chunkMVOBIOKZcjs.saveConsent.call(void 0, newConsent);
|
|
128
|
+
setConsent(newConsent);
|
|
129
|
+
setHasResponded(true);
|
|
130
|
+
}, []);
|
|
131
|
+
const declineAnalytics = _react.useCallback.call(void 0, () => {
|
|
132
|
+
const newConsent = _chunkMVOBIOKZcjs.createDeclineAnalyticsConsent.call(void 0, );
|
|
133
|
+
_chunkMVOBIOKZcjs.saveConsent.call(void 0, newConsent);
|
|
134
|
+
setConsent(newConsent);
|
|
135
|
+
setHasResponded(true);
|
|
136
|
+
}, []);
|
|
137
|
+
const updateConsentHandler = _react.useCallback.call(void 0,
|
|
138
|
+
(category, value) => {
|
|
139
|
+
if (!consent) return;
|
|
140
|
+
const newConsent = _chunkMVOBIOKZcjs.updateConsentCategory.call(void 0, consent, category, value);
|
|
141
|
+
_chunkMVOBIOKZcjs.saveConsent.call(void 0, newConsent);
|
|
142
|
+
setConsent(newConsent);
|
|
143
|
+
},
|
|
144
|
+
[consent]
|
|
145
|
+
);
|
|
146
|
+
const resetConsentHandler = _react.useCallback.call(void 0, () => {
|
|
147
|
+
_chunkMVOBIOKZcjs.clearConsent.call(void 0, );
|
|
148
|
+
setConsent(null);
|
|
149
|
+
setHasResponded(false);
|
|
150
|
+
}, []);
|
|
151
|
+
return {
|
|
152
|
+
acceptAll,
|
|
153
|
+
consent,
|
|
154
|
+
declineAnalytics,
|
|
155
|
+
hasResponded,
|
|
156
|
+
isLoading: false,
|
|
157
|
+
resetConsent: resetConsentHandler,
|
|
158
|
+
updateConsent: updateConsentHandler
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
exports.AnalyticsProvider = AnalyticsProvider; exports.initAnalytics = _chunkMVOBIOKZcjs.initAnalytics; exports.useAnalytics = useAnalytics; exports.useConsent = useConsent;
|
package/dist/react.d.cts
ADDED
|
@@ -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-DdAxcZwX.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 };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { AnalyticsConfig, ConsentState, ConsentCategory, UseConsentOptions, UseConsentReturn } from './index.js';
|
|
4
|
+
export { h as initAnalytics } from './analytics-DdAxcZwX.js';
|
|
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 };
|
|
@@ -1,61 +1,35 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
createContext,
|
|
5
|
-
type ReactNode,
|
|
6
|
-
useCallback,
|
|
7
|
-
useContext,
|
|
8
|
-
useEffect,
|
|
9
|
-
useMemo,
|
|
10
|
-
useState,
|
|
11
|
-
} from "react";
|
|
12
|
-
|
|
13
|
-
import { disableAnalytics, enableAnalytics, initAnalytics } from "./analytics";
|
|
14
2
|
import {
|
|
15
|
-
clearConsent,
|
|
16
3
|
CONSENT_VERSION,
|
|
4
|
+
clearConsent,
|
|
17
5
|
createAcceptAllConsent,
|
|
18
6
|
createDeclineAnalyticsConsent,
|
|
7
|
+
disableAnalytics,
|
|
8
|
+
enableAnalytics,
|
|
9
|
+
initAnalytics,
|
|
19
10
|
loadConsent,
|
|
20
11
|
needsRePrompt,
|
|
21
12
|
saveConsent,
|
|
22
|
-
updateConsentCategory
|
|
23
|
-
} from "./
|
|
24
|
-
import type {
|
|
25
|
-
AnalyticsConfig,
|
|
26
|
-
ConsentCategory,
|
|
27
|
-
ConsentState,
|
|
28
|
-
UseConsentOptions,
|
|
29
|
-
UseConsentReturn,
|
|
30
|
-
} from "./types";
|
|
13
|
+
updateConsentCategory
|
|
14
|
+
} from "./chunk-6RHY2BTB.js";
|
|
31
15
|
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const AnalyticsContext = createContext<AnalyticsContextValue | null>(null);
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Analytics provider component
|
|
48
|
-
*/
|
|
49
|
-
export function AnalyticsProvider({
|
|
16
|
+
// src/react.tsx
|
|
17
|
+
import {
|
|
18
|
+
createContext,
|
|
19
|
+
useCallback,
|
|
20
|
+
useContext,
|
|
21
|
+
useEffect,
|
|
22
|
+
useMemo,
|
|
23
|
+
useState
|
|
24
|
+
} from "react";
|
|
25
|
+
import { jsx } from "react/jsx-runtime";
|
|
26
|
+
var AnalyticsContext = createContext(null);
|
|
27
|
+
function AnalyticsProvider({
|
|
50
28
|
children,
|
|
51
29
|
config,
|
|
52
|
-
consentVersion = CONSENT_VERSION
|
|
53
|
-
}: {
|
|
54
|
-
children: ReactNode;
|
|
55
|
-
config: AnalyticsConfig;
|
|
56
|
-
consentVersion?: number;
|
|
30
|
+
consentVersion = CONSENT_VERSION
|
|
57
31
|
}) {
|
|
58
|
-
const [consent, setConsent] = useState
|
|
32
|
+
const [consent, setConsent] = useState(() => {
|
|
59
33
|
const stored = loadConsent();
|
|
60
34
|
if (!stored) return null;
|
|
61
35
|
if (needsRePrompt(stored, consentVersion)) {
|
|
@@ -64,16 +38,12 @@ export function AnalyticsProvider({
|
|
|
64
38
|
}
|
|
65
39
|
return stored;
|
|
66
40
|
});
|
|
67
|
-
|
|
68
41
|
const [hasResponded, setHasResponded] = useState(() => consent !== null);
|
|
69
|
-
|
|
70
|
-
// Initialize analytics if stored consent allows
|
|
71
42
|
useEffect(() => {
|
|
72
43
|
if (consent?.analytics) {
|
|
73
44
|
initAnalytics(config);
|
|
74
45
|
}
|
|
75
46
|
}, [consent, config]);
|
|
76
|
-
|
|
77
47
|
const acceptAll = useCallback(() => {
|
|
78
48
|
const newConsent = createAcceptAllConsent();
|
|
79
49
|
saveConsent(newConsent);
|
|
@@ -81,7 +51,6 @@ export function AnalyticsProvider({
|
|
|
81
51
|
setHasResponded(true);
|
|
82
52
|
enableAnalytics(config);
|
|
83
53
|
}, [config]);
|
|
84
|
-
|
|
85
54
|
const declineAnalytics = useCallback(() => {
|
|
86
55
|
const newConsent = createDeclineAnalyticsConsent();
|
|
87
56
|
saveConsent(newConsent);
|
|
@@ -89,35 +58,29 @@ export function AnalyticsProvider({
|
|
|
89
58
|
setHasResponded(true);
|
|
90
59
|
disableAnalytics();
|
|
91
60
|
}, []);
|
|
92
|
-
|
|
93
61
|
const updateConsentHandler = useCallback(
|
|
94
|
-
(category
|
|
62
|
+
(category, value2) => {
|
|
95
63
|
if (!consent) return;
|
|
96
|
-
|
|
97
|
-
const newConsent = updateConsentCategory(consent, category, value);
|
|
64
|
+
const newConsent = updateConsentCategory(consent, category, value2);
|
|
98
65
|
saveConsent(newConsent);
|
|
99
66
|
setConsent(newConsent);
|
|
100
|
-
|
|
101
|
-
// Update analytics state
|
|
102
67
|
if (category === "analytics") {
|
|
103
|
-
if (
|
|
68
|
+
if (value2) {
|
|
104
69
|
enableAnalytics(config);
|
|
105
70
|
} else {
|
|
106
71
|
disableAnalytics();
|
|
107
72
|
}
|
|
108
73
|
}
|
|
109
74
|
},
|
|
110
|
-
[consent, config]
|
|
75
|
+
[consent, config]
|
|
111
76
|
);
|
|
112
|
-
|
|
113
77
|
const resetConsentHandler = useCallback(() => {
|
|
114
78
|
clearConsent();
|
|
115
79
|
setConsent(null);
|
|
116
80
|
setHasResponded(false);
|
|
117
81
|
disableAnalytics();
|
|
118
82
|
}, []);
|
|
119
|
-
|
|
120
|
-
const value = useMemo<AnalyticsContextValue>(
|
|
83
|
+
const value = useMemo(
|
|
121
84
|
() => ({
|
|
122
85
|
acceptAll,
|
|
123
86
|
config,
|
|
@@ -126,7 +89,7 @@ export function AnalyticsProvider({
|
|
|
126
89
|
hasResponded,
|
|
127
90
|
isLoading: false,
|
|
128
91
|
resetConsent: resetConsentHandler,
|
|
129
|
-
updateConsent: updateConsentHandler
|
|
92
|
+
updateConsent: updateConsentHandler
|
|
130
93
|
}),
|
|
131
94
|
[
|
|
132
95
|
config,
|
|
@@ -135,35 +98,21 @@ export function AnalyticsProvider({
|
|
|
135
98
|
acceptAll,
|
|
136
99
|
declineAnalytics,
|
|
137
100
|
updateConsentHandler,
|
|
138
|
-
resetConsentHandler
|
|
139
|
-
]
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
return (
|
|
143
|
-
<AnalyticsContext.Provider value={value}>
|
|
144
|
-
{children}
|
|
145
|
-
</AnalyticsContext.Provider>
|
|
101
|
+
resetConsentHandler
|
|
102
|
+
]
|
|
146
103
|
);
|
|
104
|
+
return /* @__PURE__ */ jsx(AnalyticsContext.Provider, { value, children });
|
|
147
105
|
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Hook to access analytics context
|
|
151
|
-
*/
|
|
152
|
-
export function useAnalytics() {
|
|
106
|
+
function useAnalytics() {
|
|
153
107
|
const context = useContext(AnalyticsContext);
|
|
154
108
|
if (!context) {
|
|
155
109
|
throw new Error("useAnalytics must be used within an AnalyticsProvider");
|
|
156
110
|
}
|
|
157
111
|
return context;
|
|
158
112
|
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Hook to manage consent state
|
|
162
|
-
*/
|
|
163
|
-
export function useConsent(options: UseConsentOptions = {}): UseConsentReturn {
|
|
113
|
+
function useConsent(options = {}) {
|
|
164
114
|
const { consentVersion = CONSENT_VERSION } = options;
|
|
165
|
-
|
|
166
|
-
const [consent, setConsent] = useState<ConsentState | null>(() => {
|
|
115
|
+
const [consent, setConsent] = useState(() => {
|
|
167
116
|
const stored = loadConsent();
|
|
168
117
|
if (!stored) return null;
|
|
169
118
|
if (needsRePrompt(stored, consentVersion)) {
|
|
@@ -172,40 +121,33 @@ export function useConsent(options: UseConsentOptions = {}): UseConsentReturn {
|
|
|
172
121
|
}
|
|
173
122
|
return stored;
|
|
174
123
|
});
|
|
175
|
-
|
|
176
124
|
const [hasResponded, setHasResponded] = useState(() => consent !== null);
|
|
177
|
-
|
|
178
125
|
const acceptAll = useCallback(() => {
|
|
179
126
|
const newConsent = createAcceptAllConsent();
|
|
180
127
|
saveConsent(newConsent);
|
|
181
128
|
setConsent(newConsent);
|
|
182
129
|
setHasResponded(true);
|
|
183
130
|
}, []);
|
|
184
|
-
|
|
185
131
|
const declineAnalytics = useCallback(() => {
|
|
186
132
|
const newConsent = createDeclineAnalyticsConsent();
|
|
187
133
|
saveConsent(newConsent);
|
|
188
134
|
setConsent(newConsent);
|
|
189
135
|
setHasResponded(true);
|
|
190
136
|
}, []);
|
|
191
|
-
|
|
192
137
|
const updateConsentHandler = useCallback(
|
|
193
|
-
(category
|
|
138
|
+
(category, value) => {
|
|
194
139
|
if (!consent) return;
|
|
195
|
-
|
|
196
140
|
const newConsent = updateConsentCategory(consent, category, value);
|
|
197
141
|
saveConsent(newConsent);
|
|
198
142
|
setConsent(newConsent);
|
|
199
143
|
},
|
|
200
|
-
[consent]
|
|
144
|
+
[consent]
|
|
201
145
|
);
|
|
202
|
-
|
|
203
146
|
const resetConsentHandler = useCallback(() => {
|
|
204
147
|
clearConsent();
|
|
205
148
|
setConsent(null);
|
|
206
149
|
setHasResponded(false);
|
|
207
150
|
}, []);
|
|
208
|
-
|
|
209
151
|
return {
|
|
210
152
|
acceptAll,
|
|
211
153
|
consent,
|
|
@@ -213,9 +155,12 @@ export function useConsent(options: UseConsentOptions = {}): UseConsentReturn {
|
|
|
213
155
|
hasResponded,
|
|
214
156
|
isLoading: false,
|
|
215
157
|
resetConsent: resetConsentHandler,
|
|
216
|
-
updateConsent: updateConsentHandler
|
|
158
|
+
updateConsent: updateConsentHandler
|
|
217
159
|
};
|
|
218
160
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
161
|
+
export {
|
|
162
|
+
AnalyticsProvider,
|
|
163
|
+
initAnalytics,
|
|
164
|
+
useAnalytics,
|
|
165
|
+
useConsent
|
|
166
|
+
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vllnt/analytics",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-canary.c351189",
|
|
4
4
|
"description": "Lightweight, privacy-first analytics with consent management and React integration",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"packageManager": "pnpm@10.34.8",
|
|
6
7
|
"license": "MIT",
|
|
7
8
|
"repository": {
|
|
8
9
|
"type": "git",
|
|
@@ -18,49 +19,74 @@
|
|
|
18
19
|
],
|
|
19
20
|
"sideEffects": false,
|
|
20
21
|
"files": [
|
|
21
|
-
"
|
|
22
|
-
"!src/__tests__",
|
|
23
|
-
"README.md",
|
|
24
|
-
"LICENSE"
|
|
22
|
+
"dist"
|
|
25
23
|
],
|
|
26
|
-
"main": "./
|
|
27
|
-
"module": "./
|
|
28
|
-
"types": "./
|
|
24
|
+
"main": "./dist/index.cjs",
|
|
25
|
+
"module": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
29
27
|
"exports": {
|
|
30
28
|
".": {
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
"import": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"require": {
|
|
34
|
+
"types": "./dist/index.d.cts",
|
|
35
|
+
"default": "./dist/index.cjs"
|
|
36
|
+
}
|
|
34
37
|
},
|
|
35
38
|
"./react": {
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
"import": {
|
|
40
|
+
"types": "./dist/react.d.ts",
|
|
41
|
+
"default": "./dist/react.js"
|
|
42
|
+
},
|
|
43
|
+
"require": {
|
|
44
|
+
"types": "./dist/react.d.cts",
|
|
45
|
+
"default": "./dist/react.cjs"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"./package.json": "./package.json"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsup",
|
|
52
|
+
"clean": "rm -rf node_modules dist",
|
|
53
|
+
"lint": "eslint --cache --cache-location node_modules/.cache/eslint/ .",
|
|
54
|
+
"lint:fix": "eslint --cache --cache-location node_modules/.cache/eslint/ . --fix",
|
|
55
|
+
"test": "vitest",
|
|
56
|
+
"test:once": "vitest run",
|
|
57
|
+
"test:coverage": "vitest run --coverage",
|
|
58
|
+
"typecheck": "tsc --noEmit --incremental --tsBuildInfoFile node_modules/.cache/tsc/typecheck.tsbuildinfo",
|
|
59
|
+
"typecheck:ci": "tsc --noEmit --incremental --tsBuildInfoFile node_modules/.cache/tsc/typecheck-ci.tsbuildinfo"
|
|
40
60
|
},
|
|
41
61
|
"peerDependencies": {
|
|
42
62
|
"react": "^18.0.0 || ^19.0.0"
|
|
43
63
|
},
|
|
44
64
|
"devDependencies": {
|
|
45
|
-
"
|
|
46
|
-
"@testing-library/
|
|
47
|
-
"@
|
|
48
|
-
"@types/
|
|
49
|
-
"@
|
|
50
|
-
"@
|
|
51
|
-
"@vllnt/
|
|
52
|
-
"
|
|
53
|
-
"jsdom": "^
|
|
54
|
-
"react": "^19.
|
|
55
|
-
"
|
|
56
|
-
"
|
|
65
|
+
"@testing-library/jest-dom": "^7.0.1",
|
|
66
|
+
"@testing-library/react": "^16.3.3",
|
|
67
|
+
"@types/node": "^24.19.2",
|
|
68
|
+
"@types/react": "^19.3.0",
|
|
69
|
+
"@vitest/coverage-v8": "^5.1.0",
|
|
70
|
+
"@vllnt/eslint-config": "^2.1.0",
|
|
71
|
+
"@vllnt/typescript": "^2.0.0",
|
|
72
|
+
"eslint": "^9.39.5",
|
|
73
|
+
"jsdom": "^30.1.3",
|
|
74
|
+
"react": "^19.3.1",
|
|
75
|
+
"tsup": "^9.0.0",
|
|
76
|
+
"typescript": "^6.0.3",
|
|
77
|
+
"vitest": "^5.1.0"
|
|
57
78
|
},
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"
|
|
64
|
-
|
|
79
|
+
"pnpm": {
|
|
80
|
+
"minimumReleaseAge": 10080,
|
|
81
|
+
"minimumReleaseAgeExclude": [
|
|
82
|
+
"@vllnt/*"
|
|
83
|
+
],
|
|
84
|
+
"overrides": {
|
|
85
|
+
"deepmerge-ts@<8.0.0": "8.0.0",
|
|
86
|
+
"handlebars@<4.7.10": "4.7.10"
|
|
87
|
+
},
|
|
88
|
+
"ignoredBuiltDependencies": [
|
|
89
|
+
"esbuild"
|
|
90
|
+
]
|
|
65
91
|
}
|
|
66
|
-
}
|
|
92
|
+
}
|