@formo/analytics 1.17.1 → 1.17.2
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/.env.example +1 -0
- package/.github/workflows/ci.yml +50 -0
- package/.github/workflows/release.yml +54 -0
- package/.husky/post-commit +7 -0
- package/.husky/pre-commit +11 -0
- package/.releaserc.js +34 -0
- package/CONTRIBUTING.md +83 -0
- package/package.json +1 -4
- package/scripts/generate-sri.sh +52 -0
- package/src/FormoAnalytics.ts +1031 -0
- package/src/FormoAnalyticsProvider.tsx +84 -0
- package/src/constants/base.ts +6 -0
- package/src/constants/config.ts +660 -0
- package/src/constants/events.ts +21 -0
- package/src/constants/index.ts +3 -0
- package/src/global.d.ts +12 -0
- package/src/index.ts +3 -0
- package/src/lib/event/EventFactory.ts +519 -0
- package/src/lib/event/EventManager.ts +39 -0
- package/src/lib/event/constants.ts +4 -0
- package/src/lib/event/index.ts +3 -0
- package/src/lib/event/type.ts +9 -0
- package/src/lib/event/utils.ts +33 -0
- package/src/lib/fetch.ts +3 -0
- package/src/lib/index.ts +5 -0
- package/src/lib/logger/Logger.ts +115 -0
- package/src/lib/logger/index.ts +2 -0
- package/src/lib/logger/type.ts +14 -0
- package/src/lib/queue/EventQueue.ts +306 -0
- package/src/lib/queue/index.ts +2 -0
- package/src/lib/queue/type.ts +6 -0
- package/src/lib/ramda/internal/_curry1.ts +19 -0
- package/src/lib/ramda/internal/_curry2.ts +37 -0
- package/src/lib/ramda/internal/_curry3.ts +68 -0
- package/src/lib/ramda/internal/_has.ts +3 -0
- package/src/lib/ramda/internal/_isObject.ts +3 -0
- package/src/lib/ramda/internal/_isPlaceholder.ts +5 -0
- package/src/lib/ramda/mergeDeepRight.ts +13 -0
- package/src/lib/ramda/mergeDeepWithKey.ts +22 -0
- package/src/lib/ramda/mergeWithKey.ts +28 -0
- package/src/lib/storage/StorageManager.ts +51 -0
- package/src/lib/storage/built-in/blueprint.ts +17 -0
- package/src/lib/storage/built-in/cookie.ts +60 -0
- package/src/lib/storage/built-in/memory.ts +23 -0
- package/src/lib/storage/built-in/web.ts +57 -0
- package/src/lib/storage/constant.ts +2 -0
- package/src/lib/storage/index.ts +25 -0
- package/src/lib/storage/type.ts +21 -0
- package/src/lib/version.ts +2 -0
- package/src/types/base.ts +120 -0
- package/src/types/events.ts +126 -0
- package/src/types/index.ts +3 -0
- package/src/types/provider.ts +17 -0
- package/src/utils/address.ts +43 -0
- package/src/utils/base.ts +3 -0
- package/src/utils/converter.ts +44 -0
- package/src/utils/generate.ts +16 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/timestamp.ts +9 -0
- package/src/validators/address.ts +69 -0
- package/src/validators/agent.ts +4 -0
- package/src/validators/checks.ts +160 -0
- package/src/validators/index.ts +7 -0
- package/src/validators/network.ts +34 -0
- package/src/validators/object.ts +4 -0
- package/src/validators/string.ts +4 -0
- package/src/validators/uint8array.ts +17 -0
- package/test/lib/events.spec.ts +12 -0
- package/test/utils/address.spec.ts +14 -0
- package/test/utils/converter.spec.ts +31 -0
- package/test/validators/address.spec.ts +15 -0
- package/tsconfig.json +28 -0
- package/webpack.config.ts +23 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { createContext, useContext, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { FormoAnalytics } from "./FormoAnalytics";
|
|
3
|
+
import { initStorageManager, logger } from "./lib";
|
|
4
|
+
import { FormoAnalyticsProviderProps, IFormoAnalytics } from "./types";
|
|
5
|
+
|
|
6
|
+
const defaultContext: IFormoAnalytics = {
|
|
7
|
+
chain: () => Promise.resolve(),
|
|
8
|
+
page: () => Promise.resolve(),
|
|
9
|
+
reset: () => Promise.resolve(),
|
|
10
|
+
detect: () => Promise.resolve(),
|
|
11
|
+
connect: () => Promise.resolve(),
|
|
12
|
+
disconnect: () => Promise.resolve(),
|
|
13
|
+
signature: () => Promise.resolve(),
|
|
14
|
+
transaction: () => Promise.resolve(),
|
|
15
|
+
identify: () => Promise.resolve(),
|
|
16
|
+
track: () => Promise.resolve(),
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const FormoAnalyticsContext =
|
|
20
|
+
createContext<IFormoAnalytics>(defaultContext);
|
|
21
|
+
|
|
22
|
+
export const FormoAnalyticsProvider = (props: FormoAnalyticsProviderProps) => {
|
|
23
|
+
const { writeKey, disabled = false, children } = props;
|
|
24
|
+
|
|
25
|
+
// Keep the app running without analytics if no Write Key is provided or disabled
|
|
26
|
+
if (!writeKey) {
|
|
27
|
+
console.error("FormoAnalyticsProvider: No Write Key provided");
|
|
28
|
+
return children;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (disabled) {
|
|
32
|
+
console.warn("FormoAnalytics is disabled");
|
|
33
|
+
return children;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return <InitializedAnalytics {...props} />;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const InitializedAnalytics = ({
|
|
40
|
+
writeKey,
|
|
41
|
+
options,
|
|
42
|
+
children,
|
|
43
|
+
}: FormoAnalyticsProviderProps) => {
|
|
44
|
+
const [sdk, setSdk] = useState<IFormoAnalytics>(defaultContext);
|
|
45
|
+
const initializedStartedRef = useRef(false);
|
|
46
|
+
initStorageManager(writeKey);
|
|
47
|
+
|
|
48
|
+
const initializeFormoAnalytics = async (writeKey: string, options: any) => {
|
|
49
|
+
try {
|
|
50
|
+
const sdkInstance = await FormoAnalytics.init(writeKey, options);
|
|
51
|
+
setSdk(sdkInstance);
|
|
52
|
+
console.log("FormoAnalytics SDK initialized successfully");
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error("Failed to initialize FormoAnalytics SDK", error);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
const initialize = async () => {
|
|
60
|
+
if (initializedStartedRef.current) return;
|
|
61
|
+
initializedStartedRef.current = true;
|
|
62
|
+
|
|
63
|
+
await initializeFormoAnalytics(writeKey!, options);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
initialize();
|
|
67
|
+
}, [writeKey, options]);
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<FormoAnalyticsContext.Provider value={sdk}>
|
|
71
|
+
{children}
|
|
72
|
+
</FormoAnalyticsContext.Provider>
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const useFormo = () => {
|
|
77
|
+
const context = useContext(FormoAnalyticsContext);
|
|
78
|
+
|
|
79
|
+
if (!context) {
|
|
80
|
+
logger.warn("useFormo called without a valid context");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return context; // Return undefined if SDK is not initialized, handle accordingly in consumer
|
|
84
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const SESSION_TRAFFIC_SOURCE_KEY = "traffic-source";
|
|
2
|
+
export const SESSION_WALLET_DETECTED_KEY = "wallet-detected";
|
|
3
|
+
export const SESSION_CURRENT_URL_KEY = "analytics-current-url";
|
|
4
|
+
export const SESSION_USER_ID_KEY = "user-id";
|
|
5
|
+
|
|
6
|
+
export const LOCAL_ANONYMOUS_ID_KEY = "anonymous-id";
|