@formo/analytics 1.11.5-alpha.3 → 1.11.5-alpha.4
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/cjs/src/FormoAnalyticsProvider.d.ts +1 -1
- package/dist/cjs/src/FormoAnalyticsProvider.d.ts.map +1 -1
- package/dist/cjs/src/FormoAnalyticsProvider.js +100 -29
- package/dist/cjs/src/FormoAnalyticsProvider.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/src/FormoAnalyticsProvider.d.ts +1 -1
- package/dist/esm/src/FormoAnalyticsProvider.d.ts.map +1 -1
- package/dist/esm/src/FormoAnalyticsProvider.js +100 -29
- package/dist/esm/src/FormoAnalyticsProvider.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/src/FormoAnalyticsProvider.tsx +52 -31
package/package.json
CHANGED
|
@@ -23,42 +23,65 @@ export const FormoAnalyticsProvider = ({
|
|
|
23
23
|
children,
|
|
24
24
|
}: FormoAnalyticsProviderProps) => {
|
|
25
25
|
const [sdk, setSdk] = useState<FormoAnalytics | undefined>();
|
|
26
|
+
const [isInitialized, setIsInitialized] = useState(false);
|
|
26
27
|
const initializedStartedRef = useRef(false);
|
|
27
28
|
|
|
28
|
-
console.log(HIGHLIGHT_PROJECT_ID);
|
|
29
|
-
|
|
30
29
|
useEffect(() => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
const initialize = async () => {
|
|
31
|
+
if (!apiKey) {
|
|
32
|
+
console.error('FormoAnalyticsProvider: No API key provided');
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (disabled) {
|
|
37
|
+
console.warn('FormoAnalytics is disabled');
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
34
40
|
|
|
35
|
-
|
|
41
|
+
if (initializedStartedRef.current) return;
|
|
42
|
+
initializedStartedRef.current = true;
|
|
36
43
|
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
// Initialize Highlight.run if project ID is available
|
|
45
|
+
if (HIGHLIGHT_PROJECT_ID) {
|
|
46
|
+
try {
|
|
47
|
+
H.init(HIGHLIGHT_PROJECT_ID, {
|
|
48
|
+
serviceName: 'formo-analytics-sdk',
|
|
49
|
+
tracingOrigins: true,
|
|
50
|
+
networkRecording: {
|
|
51
|
+
enabled: true,
|
|
52
|
+
recordHeadersAndBody: true,
|
|
53
|
+
urlBlocklist: [
|
|
54
|
+
'https://www.googleapis.com/identitytoolkit',
|
|
55
|
+
'https://securetoken.googleapis.com',
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
console.log('Highlight.run initialized successfully');
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.error('Failed to initialize Highlight.run', error);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
39
64
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
'https://securetoken.googleapis.com',
|
|
52
|
-
],
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
}
|
|
65
|
+
// Initialize FormoAnalytics
|
|
66
|
+
try {
|
|
67
|
+
const sdkInstance = await FormoAnalytics.init(apiKey, projectId);
|
|
68
|
+
setSdk(sdkInstance);
|
|
69
|
+
console.log('FormoAnalytics SDK initialized successfully');
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error('Failed to initialize FormoAnalytics SDK', error);
|
|
72
|
+
} finally {
|
|
73
|
+
setIsInitialized(true); // Ensure UI renders even after failure
|
|
74
|
+
}
|
|
75
|
+
};
|
|
56
76
|
|
|
57
|
-
|
|
58
|
-
setSdk(sdkInstance)
|
|
59
|
-
);
|
|
77
|
+
initialize();
|
|
60
78
|
}, [apiKey, disabled, projectId]);
|
|
61
79
|
|
|
80
|
+
if (!isInitialized) {
|
|
81
|
+
// Optionally show a loading state until initialization attempt finishes
|
|
82
|
+
return <div>Loading analytics...</div>;
|
|
83
|
+
}
|
|
84
|
+
|
|
62
85
|
return (
|
|
63
86
|
<ErrorBoundary onError={(error, info) => H?.consumeError(error, info)}>
|
|
64
87
|
<FormoAnalyticsContext.Provider value={sdk}>
|
|
@@ -72,10 +95,8 @@ export const useFormoAnalytics = () => {
|
|
|
72
95
|
const context = useContext(FormoAnalyticsContext);
|
|
73
96
|
|
|
74
97
|
if (!context) {
|
|
75
|
-
|
|
76
|
-
'useFormoAnalytics must be used within a FormoAnalyticsProvider'
|
|
77
|
-
);
|
|
98
|
+
console.warn('useFormoAnalytics called without a valid context');
|
|
78
99
|
}
|
|
79
100
|
|
|
80
|
-
return context;
|
|
101
|
+
return context; // Return undefined if SDK is not initialized, handle accordingly in consumer
|
|
81
102
|
};
|