@vllnt/analytics 0.2.0-canary.c351189 → 0.2.0-canary.d796133
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 +58 -0
- package/README.md +242 -137
- package/dist/{analytics-DdAxcZwX.d.cts → analytics-BxUQktfB.d.cts} +3 -1
- package/dist/{analytics-DdAxcZwX.d.ts → analytics-BxUQktfB.d.ts} +3 -1
- package/dist/{chunk-6RHY2BTB.js → chunk-5COCGKHD.js} +7 -4
- package/dist/{chunk-MVOBIOKZ.cjs → chunk-ACWD5NRI.cjs} +7 -4
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/react.cjs +45 -36
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +19 -10
- package/docs/API.md +490 -0
- package/llms.txt +74 -0
- package/package.json +34 -25
- package/src/analytics.ts +289 -0
- package/src/consent.ts +179 -0
- package/src/index.ts +48 -0
- package/src/react.tsx +231 -0
- package/src/types.ts +102 -0
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,7 @@
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _chunkACWD5NRIcjs = require('./chunk-ACWD5NRI.cjs');
|
|
15
15
|
|
|
16
16
|
// src/react.tsx
|
|
17
17
|
|
|
@@ -27,58 +27,64 @@ var AnalyticsContext = _react.createContext.call(void 0, null);
|
|
|
27
27
|
function AnalyticsProvider({
|
|
28
28
|
children,
|
|
29
29
|
config,
|
|
30
|
-
consentVersion =
|
|
30
|
+
consentVersion = _chunkACWD5NRIcjs.CONSENT_VERSION
|
|
31
31
|
}) {
|
|
32
32
|
const [consent, setConsent] = _react.useState.call(void 0, () => {
|
|
33
|
-
const stored =
|
|
33
|
+
const stored = _chunkACWD5NRIcjs.loadConsent.call(void 0, );
|
|
34
34
|
if (!stored) return null;
|
|
35
|
-
if (
|
|
36
|
-
|
|
35
|
+
if (_chunkACWD5NRIcjs.needsRePrompt.call(void 0, stored, consentVersion)) {
|
|
36
|
+
_chunkACWD5NRIcjs.clearConsent.call(void 0, );
|
|
37
37
|
return null;
|
|
38
38
|
}
|
|
39
39
|
return stored;
|
|
40
40
|
});
|
|
41
41
|
const [hasResponded, setHasResponded] = _react.useState.call(void 0, () => consent !== null);
|
|
42
42
|
_react.useEffect.call(void 0, () => {
|
|
43
|
-
if (
|
|
44
|
-
|
|
43
|
+
if (!consent) return;
|
|
44
|
+
if (consent.analytics) {
|
|
45
|
+
_chunkACWD5NRIcjs.initAnalytics.call(void 0, config);
|
|
46
|
+
} else {
|
|
47
|
+
_chunkACWD5NRIcjs.disableAnalytics.call(void 0, );
|
|
45
48
|
}
|
|
46
49
|
}, [consent, config]);
|
|
47
50
|
const acceptAll = _react.useCallback.call(void 0, () => {
|
|
48
|
-
const newConsent =
|
|
49
|
-
|
|
51
|
+
const newConsent = { ..._chunkACWD5NRIcjs.createAcceptAllConsent.call(void 0, ), version: consentVersion };
|
|
52
|
+
_chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
|
|
50
53
|
setConsent(newConsent);
|
|
51
54
|
setHasResponded(true);
|
|
52
|
-
|
|
53
|
-
}, [config]);
|
|
55
|
+
_chunkACWD5NRIcjs.enableAnalytics.call(void 0, config);
|
|
56
|
+
}, [config, consentVersion]);
|
|
54
57
|
const declineAnalytics = _react.useCallback.call(void 0, () => {
|
|
55
|
-
const newConsent =
|
|
56
|
-
|
|
58
|
+
const newConsent = {
|
|
59
|
+
..._chunkACWD5NRIcjs.createDeclineAnalyticsConsent.call(void 0, ),
|
|
60
|
+
version: consentVersion
|
|
61
|
+
};
|
|
62
|
+
_chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
|
|
57
63
|
setConsent(newConsent);
|
|
58
64
|
setHasResponded(true);
|
|
59
|
-
|
|
60
|
-
}, []);
|
|
65
|
+
_chunkACWD5NRIcjs.disableAnalytics.call(void 0, );
|
|
66
|
+
}, [consentVersion]);
|
|
61
67
|
const updateConsentHandler = _react.useCallback.call(void 0,
|
|
62
68
|
(category, value2) => {
|
|
63
69
|
if (!consent) return;
|
|
64
|
-
const newConsent =
|
|
65
|
-
|
|
70
|
+
const newConsent = _chunkACWD5NRIcjs.updateConsentCategory.call(void 0, consent, category, value2);
|
|
71
|
+
_chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
|
|
66
72
|
setConsent(newConsent);
|
|
67
73
|
if (category === "analytics") {
|
|
68
74
|
if (value2) {
|
|
69
|
-
|
|
75
|
+
_chunkACWD5NRIcjs.enableAnalytics.call(void 0, config);
|
|
70
76
|
} else {
|
|
71
|
-
|
|
77
|
+
_chunkACWD5NRIcjs.disableAnalytics.call(void 0, );
|
|
72
78
|
}
|
|
73
79
|
}
|
|
74
80
|
},
|
|
75
81
|
[consent, config]
|
|
76
82
|
);
|
|
77
83
|
const resetConsentHandler = _react.useCallback.call(void 0, () => {
|
|
78
|
-
|
|
84
|
+
_chunkACWD5NRIcjs.clearConsent.call(void 0, );
|
|
79
85
|
setConsent(null);
|
|
80
86
|
setHasResponded(false);
|
|
81
|
-
|
|
87
|
+
_chunkACWD5NRIcjs.disableAnalytics.call(void 0, );
|
|
82
88
|
}, []);
|
|
83
89
|
const value = _react.useMemo.call(void 0,
|
|
84
90
|
() => ({
|
|
@@ -111,40 +117,43 @@ function useAnalytics() {
|
|
|
111
117
|
return context;
|
|
112
118
|
}
|
|
113
119
|
function useConsent(options = {}) {
|
|
114
|
-
const { consentVersion =
|
|
120
|
+
const { consentVersion = _chunkACWD5NRIcjs.CONSENT_VERSION } = options;
|
|
115
121
|
const [consent, setConsent] = _react.useState.call(void 0, () => {
|
|
116
|
-
const stored =
|
|
122
|
+
const stored = _chunkACWD5NRIcjs.loadConsent.call(void 0, );
|
|
117
123
|
if (!stored) return null;
|
|
118
|
-
if (
|
|
119
|
-
|
|
124
|
+
if (_chunkACWD5NRIcjs.needsRePrompt.call(void 0, stored, consentVersion)) {
|
|
125
|
+
_chunkACWD5NRIcjs.clearConsent.call(void 0, );
|
|
120
126
|
return null;
|
|
121
127
|
}
|
|
122
128
|
return stored;
|
|
123
129
|
});
|
|
124
130
|
const [hasResponded, setHasResponded] = _react.useState.call(void 0, () => consent !== null);
|
|
125
131
|
const acceptAll = _react.useCallback.call(void 0, () => {
|
|
126
|
-
const newConsent =
|
|
127
|
-
|
|
132
|
+
const newConsent = { ..._chunkACWD5NRIcjs.createAcceptAllConsent.call(void 0, ), version: consentVersion };
|
|
133
|
+
_chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
|
|
128
134
|
setConsent(newConsent);
|
|
129
135
|
setHasResponded(true);
|
|
130
|
-
}, []);
|
|
136
|
+
}, [consentVersion]);
|
|
131
137
|
const declineAnalytics = _react.useCallback.call(void 0, () => {
|
|
132
|
-
const newConsent =
|
|
133
|
-
|
|
138
|
+
const newConsent = {
|
|
139
|
+
..._chunkACWD5NRIcjs.createDeclineAnalyticsConsent.call(void 0, ),
|
|
140
|
+
version: consentVersion
|
|
141
|
+
};
|
|
142
|
+
_chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
|
|
134
143
|
setConsent(newConsent);
|
|
135
144
|
setHasResponded(true);
|
|
136
|
-
}, []);
|
|
145
|
+
}, [consentVersion]);
|
|
137
146
|
const updateConsentHandler = _react.useCallback.call(void 0,
|
|
138
147
|
(category, value) => {
|
|
139
148
|
if (!consent) return;
|
|
140
|
-
const newConsent =
|
|
141
|
-
|
|
149
|
+
const newConsent = _chunkACWD5NRIcjs.updateConsentCategory.call(void 0, consent, category, value);
|
|
150
|
+
_chunkACWD5NRIcjs.saveConsent.call(void 0, newConsent);
|
|
142
151
|
setConsent(newConsent);
|
|
143
152
|
},
|
|
144
153
|
[consent]
|
|
145
154
|
);
|
|
146
155
|
const resetConsentHandler = _react.useCallback.call(void 0, () => {
|
|
147
|
-
|
|
156
|
+
_chunkACWD5NRIcjs.clearConsent.call(void 0, );
|
|
148
157
|
setConsent(null);
|
|
149
158
|
setHasResponded(false);
|
|
150
159
|
}, []);
|
|
@@ -163,4 +172,4 @@ function useConsent(options = {}) {
|
|
|
163
172
|
|
|
164
173
|
|
|
165
174
|
|
|
166
|
-
exports.AnalyticsProvider = AnalyticsProvider; exports.initAnalytics =
|
|
175
|
+
exports.AnalyticsProvider = AnalyticsProvider; exports.initAnalytics = _chunkACWD5NRIcjs.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-BxUQktfB.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-BxUQktfB.js';
|
|
5
5
|
|
|
6
6
|
type AnalyticsContextValue = {
|
|
7
7
|
acceptAll: () => void;
|
package/dist/react.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
needsRePrompt,
|
|
12
12
|
saveConsent,
|
|
13
13
|
updateConsentCategory
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-5COCGKHD.js";
|
|
15
15
|
|
|
16
16
|
// src/react.tsx
|
|
17
17
|
import {
|
|
@@ -40,24 +40,30 @@ function AnalyticsProvider({
|
|
|
40
40
|
});
|
|
41
41
|
const [hasResponded, setHasResponded] = useState(() => consent !== null);
|
|
42
42
|
useEffect(() => {
|
|
43
|
-
if (consent
|
|
43
|
+
if (!consent) return;
|
|
44
|
+
if (consent.analytics) {
|
|
44
45
|
initAnalytics(config);
|
|
46
|
+
} else {
|
|
47
|
+
disableAnalytics();
|
|
45
48
|
}
|
|
46
49
|
}, [consent, config]);
|
|
47
50
|
const acceptAll = useCallback(() => {
|
|
48
|
-
const newConsent = createAcceptAllConsent();
|
|
51
|
+
const newConsent = { ...createAcceptAllConsent(), version: consentVersion };
|
|
49
52
|
saveConsent(newConsent);
|
|
50
53
|
setConsent(newConsent);
|
|
51
54
|
setHasResponded(true);
|
|
52
55
|
enableAnalytics(config);
|
|
53
|
-
}, [config]);
|
|
56
|
+
}, [config, consentVersion]);
|
|
54
57
|
const declineAnalytics = useCallback(() => {
|
|
55
|
-
const newConsent =
|
|
58
|
+
const newConsent = {
|
|
59
|
+
...createDeclineAnalyticsConsent(),
|
|
60
|
+
version: consentVersion
|
|
61
|
+
};
|
|
56
62
|
saveConsent(newConsent);
|
|
57
63
|
setConsent(newConsent);
|
|
58
64
|
setHasResponded(true);
|
|
59
65
|
disableAnalytics();
|
|
60
|
-
}, []);
|
|
66
|
+
}, [consentVersion]);
|
|
61
67
|
const updateConsentHandler = useCallback(
|
|
62
68
|
(category, value2) => {
|
|
63
69
|
if (!consent) return;
|
|
@@ -123,17 +129,20 @@ function useConsent(options = {}) {
|
|
|
123
129
|
});
|
|
124
130
|
const [hasResponded, setHasResponded] = useState(() => consent !== null);
|
|
125
131
|
const acceptAll = useCallback(() => {
|
|
126
|
-
const newConsent = createAcceptAllConsent();
|
|
132
|
+
const newConsent = { ...createAcceptAllConsent(), version: consentVersion };
|
|
127
133
|
saveConsent(newConsent);
|
|
128
134
|
setConsent(newConsent);
|
|
129
135
|
setHasResponded(true);
|
|
130
|
-
}, []);
|
|
136
|
+
}, [consentVersion]);
|
|
131
137
|
const declineAnalytics = useCallback(() => {
|
|
132
|
-
const newConsent =
|
|
138
|
+
const newConsent = {
|
|
139
|
+
...createDeclineAnalyticsConsent(),
|
|
140
|
+
version: consentVersion
|
|
141
|
+
};
|
|
133
142
|
saveConsent(newConsent);
|
|
134
143
|
setConsent(newConsent);
|
|
135
144
|
setHasResponded(true);
|
|
136
|
-
}, []);
|
|
145
|
+
}, [consentVersion]);
|
|
137
146
|
const updateConsentHandler = useCallback(
|
|
138
147
|
(category, value) => {
|
|
139
148
|
if (!consent) return;
|