@vllnt/analytics 0.1.1 → 0.2.0-canary.7824f2c

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/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;
@@ -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 };
@@ -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 };
package/dist/react.js ADDED
@@ -0,0 +1,166 @@
1
+ "use client";
2
+ import {
3
+ CONSENT_VERSION,
4
+ clearConsent,
5
+ createAcceptAllConsent,
6
+ createDeclineAnalyticsConsent,
7
+ disableAnalytics,
8
+ enableAnalytics,
9
+ initAnalytics,
10
+ loadConsent,
11
+ needsRePrompt,
12
+ saveConsent,
13
+ updateConsentCategory
14
+ } from "./chunk-6RHY2BTB.js";
15
+
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({
28
+ children,
29
+ config,
30
+ consentVersion = CONSENT_VERSION
31
+ }) {
32
+ const [consent, setConsent] = useState(() => {
33
+ const stored = loadConsent();
34
+ if (!stored) return null;
35
+ if (needsRePrompt(stored, consentVersion)) {
36
+ clearConsent();
37
+ return null;
38
+ }
39
+ return stored;
40
+ });
41
+ const [hasResponded, setHasResponded] = useState(() => consent !== null);
42
+ useEffect(() => {
43
+ if (consent?.analytics) {
44
+ initAnalytics(config);
45
+ }
46
+ }, [consent, config]);
47
+ const acceptAll = useCallback(() => {
48
+ const newConsent = createAcceptAllConsent();
49
+ saveConsent(newConsent);
50
+ setConsent(newConsent);
51
+ setHasResponded(true);
52
+ enableAnalytics(config);
53
+ }, [config]);
54
+ const declineAnalytics = useCallback(() => {
55
+ const newConsent = createDeclineAnalyticsConsent();
56
+ saveConsent(newConsent);
57
+ setConsent(newConsent);
58
+ setHasResponded(true);
59
+ disableAnalytics();
60
+ }, []);
61
+ const updateConsentHandler = useCallback(
62
+ (category, value2) => {
63
+ if (!consent) return;
64
+ const newConsent = updateConsentCategory(consent, category, value2);
65
+ saveConsent(newConsent);
66
+ setConsent(newConsent);
67
+ if (category === "analytics") {
68
+ if (value2) {
69
+ enableAnalytics(config);
70
+ } else {
71
+ disableAnalytics();
72
+ }
73
+ }
74
+ },
75
+ [consent, config]
76
+ );
77
+ const resetConsentHandler = useCallback(() => {
78
+ clearConsent();
79
+ setConsent(null);
80
+ setHasResponded(false);
81
+ disableAnalytics();
82
+ }, []);
83
+ const value = useMemo(
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__ */ jsx(AnalyticsContext.Provider, { value, children });
105
+ }
106
+ function useAnalytics() {
107
+ const context = useContext(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 = CONSENT_VERSION } = options;
115
+ const [consent, setConsent] = useState(() => {
116
+ const stored = loadConsent();
117
+ if (!stored) return null;
118
+ if (needsRePrompt(stored, consentVersion)) {
119
+ clearConsent();
120
+ return null;
121
+ }
122
+ return stored;
123
+ });
124
+ const [hasResponded, setHasResponded] = useState(() => consent !== null);
125
+ const acceptAll = useCallback(() => {
126
+ const newConsent = createAcceptAllConsent();
127
+ saveConsent(newConsent);
128
+ setConsent(newConsent);
129
+ setHasResponded(true);
130
+ }, []);
131
+ const declineAnalytics = useCallback(() => {
132
+ const newConsent = createDeclineAnalyticsConsent();
133
+ saveConsent(newConsent);
134
+ setConsent(newConsent);
135
+ setHasResponded(true);
136
+ }, []);
137
+ const updateConsentHandler = useCallback(
138
+ (category, value) => {
139
+ if (!consent) return;
140
+ const newConsent = updateConsentCategory(consent, category, value);
141
+ saveConsent(newConsent);
142
+ setConsent(newConsent);
143
+ },
144
+ [consent]
145
+ );
146
+ const resetConsentHandler = useCallback(() => {
147
+ clearConsent();
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
+ export {
162
+ AnalyticsProvider,
163
+ initAnalytics,
164
+ useAnalytics,
165
+ useConsent
166
+ };