@faststats/react 0.2.14 → 0.3.1
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.d.ts +10 -10
- package/dist/index.js +15 -36
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { ConsentMode, FeatureFlagEvaluation, IdentifyOptions, WebAnalyticsOptions, reportError } from "@faststats/web";
|
|
1
|
+
import { ConsentMode, FeatureFlagEvaluation, FeatureFlagEvaluation as FeatureFlagEvaluation$1, IdentifyOptions, WebAnalyticsOptions, WebAnalyticsOptions as WebAnalyticsOptions$1, getInstance, identify, identify as identify$1, logout, logout as logout$1, optIn, optIn as optIn$1, optOut, optOut as optOut$1, reportError, setConsentMode, setConsentMode as setConsentMode$1, trackEvent, trackEvent as trackEvent$1 } from "@faststats/web";
|
|
2
2
|
|
|
3
3
|
//#region src/analytics.d.ts
|
|
4
|
-
type AnalyticsProps = WebAnalyticsOptions;
|
|
4
|
+
type AnalyticsProps = WebAnalyticsOptions$1;
|
|
5
5
|
declare function Analytics(props: AnalyticsProps): null;
|
|
6
6
|
//#endregion
|
|
7
7
|
//#region src/hooks.d.ts
|
|
8
|
-
declare function useTrack():
|
|
8
|
+
declare function useTrack(): typeof trackEvent$1;
|
|
9
9
|
declare function useEvent(name: string, extra?: Record<string, unknown>): () => void;
|
|
10
|
-
declare function useIdentify():
|
|
11
|
-
declare function useLogout():
|
|
12
|
-
declare function useConsentMode():
|
|
13
|
-
declare function useOptIn():
|
|
14
|
-
declare function useOptOut():
|
|
10
|
+
declare function useIdentify(): typeof identify$1;
|
|
11
|
+
declare function useLogout(): typeof logout$1;
|
|
12
|
+
declare function useConsentMode(): typeof setConsentMode$1;
|
|
13
|
+
declare function useOptIn(): typeof optIn$1;
|
|
14
|
+
declare function useOptOut(): typeof optOut$1;
|
|
15
15
|
//#endregion
|
|
16
16
|
//#region src/use-flag.d.ts
|
|
17
17
|
type UseFlagOptions = {
|
|
@@ -19,11 +19,11 @@ type UseFlagOptions = {
|
|
|
19
19
|
externalId?: string;
|
|
20
20
|
skip?: boolean;
|
|
21
21
|
};
|
|
22
|
-
type UseFlagResult = FeatureFlagEvaluation & {
|
|
22
|
+
type UseFlagResult = FeatureFlagEvaluation$1 & {
|
|
23
23
|
isLoading: boolean;
|
|
24
24
|
error: Error | null;
|
|
25
25
|
refetch: () => void;
|
|
26
26
|
};
|
|
27
27
|
declare function useFlag(flagKey: string, options?: UseFlagOptions): UseFlagResult;
|
|
28
28
|
//#endregion
|
|
29
|
-
export { Analytics, type UseFlagOptions, type UseFlagResult, reportError, useConsentMode, useEvent, useFlag, useIdentify, useLogout, useOptIn, useOptOut, useTrack };
|
|
29
|
+
export { Analytics, type AnalyticsProps, type ConsentMode, type FeatureFlagEvaluation, type IdentifyOptions, type UseFlagOptions, type UseFlagResult, type WebAnalyticsOptions, getInstance, identify, logout, optIn, optOut, reportError, setConsentMode, trackEvent, useConsentMode, useEvent, useFlag, useIdentify, useLogout, useOptIn, useOptOut, useTrack };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { WebAnalytics, getInstance, reportError } from "@faststats/web";
|
|
2
|
+
import { WebAnalytics, getInstance, getInstance as getInstance$1, identify, identify as identify$1, logout, logout as logout$1, optIn, optIn as optIn$1, optOut, optOut as optOut$1, reportError, setConsentMode, setConsentMode as setConsentMode$1, trackEvent, trackEvent as trackEvent$1 } from "@faststats/web";
|
|
3
3
|
import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
4
4
|
//#region src/instance.ts
|
|
5
5
|
let instance = null;
|
|
@@ -18,11 +18,9 @@ function setInstance(wa) {
|
|
|
18
18
|
for (const l of listeners) l();
|
|
19
19
|
}
|
|
20
20
|
//#endregion
|
|
21
|
-
//#region src/sdk.ts
|
|
22
|
-
const SDK_NAME = "@faststats/react";
|
|
23
|
-
const SDK_VERSION = "0.2.14";
|
|
24
|
-
//#endregion
|
|
25
21
|
//#region src/analytics.tsx
|
|
22
|
+
const SDK_NAME = "@faststats/react";
|
|
23
|
+
const SDK_VERSION = "0.3.1";
|
|
26
24
|
function Analytics(props) {
|
|
27
25
|
const ownedRef = useRef(null);
|
|
28
26
|
const propsRef = useRef(props);
|
|
@@ -30,18 +28,15 @@ function Analytics(props) {
|
|
|
30
28
|
useEffect(() => {
|
|
31
29
|
if (typeof window === "undefined") return;
|
|
32
30
|
if (ownedRef.current) return;
|
|
33
|
-
|
|
34
|
-
if (existing) existing.destroy();
|
|
31
|
+
getInstance$1()?.destroy();
|
|
35
32
|
const wa = new WebAnalytics({
|
|
36
33
|
...propsRef.current,
|
|
37
34
|
sdkName: SDK_NAME,
|
|
38
35
|
sdkVersion: SDK_VERSION
|
|
39
36
|
});
|
|
40
|
-
const consentMode = propsRef.current.consent?.mode;
|
|
41
|
-
if (consentMode !== void 0) wa.setConsentMode(consentMode);
|
|
42
37
|
ownedRef.current = wa;
|
|
43
38
|
setInstance(wa);
|
|
44
|
-
window.__faststats = { getInstance };
|
|
39
|
+
window.__faststats = { getInstance: getInstance$1 };
|
|
45
40
|
return () => {
|
|
46
41
|
if (ownedRef.current === wa) {
|
|
47
42
|
wa.destroy();
|
|
@@ -60,44 +55,28 @@ function Analytics(props) {
|
|
|
60
55
|
}
|
|
61
56
|
//#endregion
|
|
62
57
|
//#region src/hooks.ts
|
|
63
|
-
function getActiveInstance() {
|
|
64
|
-
if (instance) return instance;
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
58
|
function useTrack() {
|
|
68
|
-
return
|
|
69
|
-
getActiveInstance()?.track(name, extra ?? {});
|
|
70
|
-
};
|
|
59
|
+
return trackEvent$1;
|
|
71
60
|
}
|
|
72
61
|
function useEvent(name, extra) {
|
|
73
|
-
return () => {
|
|
74
|
-
|
|
75
|
-
};
|
|
62
|
+
return useCallback(() => {
|
|
63
|
+
trackEvent$1(name, extra ?? {});
|
|
64
|
+
}, [name, extra]);
|
|
76
65
|
}
|
|
77
66
|
function useIdentify() {
|
|
78
|
-
return
|
|
79
|
-
return getActiveInstance()?.identify(externalId, email, options) ?? Promise.resolve(false);
|
|
80
|
-
};
|
|
67
|
+
return identify$1;
|
|
81
68
|
}
|
|
82
69
|
function useLogout() {
|
|
83
|
-
return
|
|
84
|
-
getActiveInstance()?.logout(resetAnonymousIdentity);
|
|
85
|
-
};
|
|
70
|
+
return logout$1;
|
|
86
71
|
}
|
|
87
72
|
function useConsentMode() {
|
|
88
|
-
return
|
|
89
|
-
getActiveInstance()?.setConsentMode(mode);
|
|
90
|
-
};
|
|
73
|
+
return setConsentMode$1;
|
|
91
74
|
}
|
|
92
75
|
function useOptIn() {
|
|
93
|
-
return
|
|
94
|
-
getActiveInstance()?.optIn();
|
|
95
|
-
};
|
|
76
|
+
return optIn$1;
|
|
96
77
|
}
|
|
97
78
|
function useOptOut() {
|
|
98
|
-
return
|
|
99
|
-
getActiveInstance()?.optOut();
|
|
100
|
-
};
|
|
79
|
+
return optOut$1;
|
|
101
80
|
}
|
|
102
81
|
//#endregion
|
|
103
82
|
//#region src/use-flag.ts
|
|
@@ -171,4 +150,4 @@ function useFlag(flagKey, options) {
|
|
|
171
150
|
};
|
|
172
151
|
}
|
|
173
152
|
//#endregion
|
|
174
|
-
export { Analytics, reportError, useConsentMode, useEvent, useFlag, useIdentify, useLogout, useOptIn, useOptOut, useTrack };
|
|
153
|
+
export { Analytics, getInstance, identify, logout, optIn, optOut, reportError, setConsentMode, trackEvent, useConsentMode, useEvent, useFlag, useIdentify, useLogout, useOptIn, useOptOut, useTrack };
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"type": "git",
|
|
5
5
|
"url": "https://github.com/faststats-dev/faststats-javascript.git"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.3.1",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "./dist/index.js",
|
|
10
10
|
"module": "./dist/index.js",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"react": ">=18"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@faststats/web": "^0.
|
|
34
|
+
"@faststats/web": "^0.3.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/react": "^19.0.0",
|