@vllnt/analytics 0.2.0-canary.8bb6613 → 0.2.0-canary.bfdedaa

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/react.cjs CHANGED
@@ -1,4 +1,4 @@
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";
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 _chunkMVOBIOKZcjs = require('./chunk-MVOBIOKZ.cjs');
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 = _chunkMVOBIOKZcjs.CONSENT_VERSION
30
+ consentVersion = _chunkACWD5NRIcjs.CONSENT_VERSION
31
31
  }) {
32
32
  const [consent, setConsent] = _react.useState.call(void 0, () => {
33
- const stored = _chunkMVOBIOKZcjs.loadConsent.call(void 0, );
33
+ const stored = _chunkACWD5NRIcjs.loadConsent.call(void 0, );
34
34
  if (!stored) return null;
35
- if (_chunkMVOBIOKZcjs.needsRePrompt.call(void 0, stored, consentVersion)) {
36
- _chunkMVOBIOKZcjs.clearConsent.call(void 0, );
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 (_optionalChain([consent, 'optionalAccess', _ => _.analytics])) {
44
- _chunkMVOBIOKZcjs.initAnalytics.call(void 0, config);
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 = _chunkMVOBIOKZcjs.createAcceptAllConsent.call(void 0, );
49
- _chunkMVOBIOKZcjs.saveConsent.call(void 0, newConsent);
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
- _chunkMVOBIOKZcjs.enableAnalytics.call(void 0, config);
53
- }, [config]);
55
+ _chunkACWD5NRIcjs.enableAnalytics.call(void 0, config);
56
+ }, [config, consentVersion]);
54
57
  const declineAnalytics = _react.useCallback.call(void 0, () => {
55
- const newConsent = _chunkMVOBIOKZcjs.createDeclineAnalyticsConsent.call(void 0, );
56
- _chunkMVOBIOKZcjs.saveConsent.call(void 0, newConsent);
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
- _chunkMVOBIOKZcjs.disableAnalytics.call(void 0, );
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 = _chunkMVOBIOKZcjs.updateConsentCategory.call(void 0, consent, category, value2);
65
- _chunkMVOBIOKZcjs.saveConsent.call(void 0, newConsent);
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
- _chunkMVOBIOKZcjs.enableAnalytics.call(void 0, config);
75
+ _chunkACWD5NRIcjs.enableAnalytics.call(void 0, config);
70
76
  } else {
71
- _chunkMVOBIOKZcjs.disableAnalytics.call(void 0, );
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
- _chunkMVOBIOKZcjs.clearConsent.call(void 0, );
84
+ _chunkACWD5NRIcjs.clearConsent.call(void 0, );
79
85
  setConsent(null);
80
86
  setHasResponded(false);
81
- _chunkMVOBIOKZcjs.disableAnalytics.call(void 0, );
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 = _chunkMVOBIOKZcjs.CONSENT_VERSION } = options;
120
+ const { consentVersion = _chunkACWD5NRIcjs.CONSENT_VERSION } = options;
115
121
  const [consent, setConsent] = _react.useState.call(void 0, () => {
116
- const stored = _chunkMVOBIOKZcjs.loadConsent.call(void 0, );
122
+ const stored = _chunkACWD5NRIcjs.loadConsent.call(void 0, );
117
123
  if (!stored) return null;
118
- if (_chunkMVOBIOKZcjs.needsRePrompt.call(void 0, stored, consentVersion)) {
119
- _chunkMVOBIOKZcjs.clearConsent.call(void 0, );
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 = _chunkMVOBIOKZcjs.createAcceptAllConsent.call(void 0, );
127
- _chunkMVOBIOKZcjs.saveConsent.call(void 0, newConsent);
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 = _chunkMVOBIOKZcjs.createDeclineAnalyticsConsent.call(void 0, );
133
- _chunkMVOBIOKZcjs.saveConsent.call(void 0, newConsent);
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 = _chunkMVOBIOKZcjs.updateConsentCategory.call(void 0, consent, category, value);
141
- _chunkMVOBIOKZcjs.saveConsent.call(void 0, newConsent);
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
- _chunkMVOBIOKZcjs.clearConsent.call(void 0, );
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 = _chunkMVOBIOKZcjs.initAnalytics; exports.useAnalytics = useAnalytics; exports.useConsent = useConsent;
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-DdAxcZwX.cjs';
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-DdAxcZwX.js';
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-6RHY2BTB.js";
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?.analytics) {
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 = createDeclineAnalyticsConsent();
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 = createDeclineAnalyticsConsent();
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;