@formo/analytics 1.13.4-alpha.2 → 1.13.4-alpha.3
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/FormoAnalytics.d.ts +3 -1
- package/dist/cjs/src/FormoAnalytics.d.ts.map +1 -1
- package/dist/cjs/src/FormoAnalytics.js +16 -3
- package/dist/cjs/src/FormoAnalytics.js.map +1 -1
- package/dist/cjs/src/FormoAnalyticsProvider.js.map +1 -1
- package/dist/cjs/src/types/base.d.ts +3 -3
- package/dist/cjs/src/types/base.d.ts.map +1 -1
- package/dist/cjs/src/types/provider.d.ts +6 -1
- package/dist/cjs/src/types/provider.d.ts.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/src/FormoAnalytics.d.ts +3 -1
- package/dist/esm/src/FormoAnalytics.d.ts.map +1 -1
- package/dist/esm/src/FormoAnalytics.js +16 -3
- package/dist/esm/src/FormoAnalytics.js.map +1 -1
- package/dist/esm/src/FormoAnalyticsProvider.js.map +1 -1
- package/dist/esm/src/types/base.d.ts +3 -3
- package/dist/esm/src/types/base.d.ts.map +1 -1
- package/dist/esm/src/types/provider.d.ts +6 -1
- package/dist/esm/src/types/provider.d.ts.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/FormoAnalytics.ts +21 -3
- package/src/FormoAnalyticsProvider.tsx +1 -1
- package/src/types/base.ts +6 -6
- package/src/types/provider.ts +19 -7
package/package.json
CHANGED
package/src/FormoAnalytics.ts
CHANGED
|
@@ -61,6 +61,8 @@ interface IFormoAnalytics {
|
|
|
61
61
|
export class FormoAnalytics implements IFormoAnalytics {
|
|
62
62
|
private _provider?: EIP1193Provider;
|
|
63
63
|
private _providerListeners: Record<string, (...args: unknown[]) => void> = {};
|
|
64
|
+
private identifySent?: boolean;
|
|
65
|
+
readonly identifySentKey = "identifySent";
|
|
64
66
|
|
|
65
67
|
config: Config;
|
|
66
68
|
currentChainId?: ChainID;
|
|
@@ -74,6 +76,15 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
74
76
|
apiKey: apiKey,
|
|
75
77
|
};
|
|
76
78
|
|
|
79
|
+
try {
|
|
80
|
+
const isWalletIdentified = JSON.parse(
|
|
81
|
+
sessionStorage.getItem(this.identifySentKey) || "false"
|
|
82
|
+
);
|
|
83
|
+
this.identifySent = isWalletIdentified;
|
|
84
|
+
} catch {
|
|
85
|
+
this.identifySent = false;
|
|
86
|
+
}
|
|
87
|
+
|
|
77
88
|
// TODO: replace with eip6963
|
|
78
89
|
const provider = options.provider || window?.ethereum;
|
|
79
90
|
if (provider) {
|
|
@@ -263,7 +274,7 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
263
274
|
}
|
|
264
275
|
|
|
265
276
|
/**
|
|
266
|
-
* Emits
|
|
277
|
+
* Emits an identify event with current wallet address.
|
|
267
278
|
* @param {Address} params.address
|
|
268
279
|
* @returns {Promise<void>}
|
|
269
280
|
*/
|
|
@@ -276,7 +287,9 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
276
287
|
providerName?: string;
|
|
277
288
|
rdns?: string;
|
|
278
289
|
}): Promise<void> {
|
|
279
|
-
if (address) {
|
|
290
|
+
if (address && this.identifySent === false) {
|
|
291
|
+
this.identifySent = true;
|
|
292
|
+
sessionStorage.setItem(this.identifySentKey, "true");
|
|
280
293
|
await this.trackEvent(Event.IDENTIFY, {
|
|
281
294
|
address,
|
|
282
295
|
providerName,
|
|
@@ -641,9 +654,11 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
641
654
|
}
|
|
642
655
|
|
|
643
656
|
private async identifyAll(providers: EIP6963ProviderDetail[]): Promise<void> {
|
|
657
|
+
console.log("identifying all => providers", providers);
|
|
644
658
|
for (const { provider, info } of providers) {
|
|
645
659
|
try {
|
|
646
660
|
const accounts = await this.getAccounts(provider);
|
|
661
|
+
console.log("identifying all => accounts", accounts);
|
|
647
662
|
if (accounts && accounts.length > 0) {
|
|
648
663
|
for (const address of accounts) {
|
|
649
664
|
await this.identify({
|
|
@@ -653,7 +668,9 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
653
668
|
});
|
|
654
669
|
}
|
|
655
670
|
}
|
|
656
|
-
} catch (err) {
|
|
671
|
+
} catch (err) {
|
|
672
|
+
console.log("identifying all => err", err);
|
|
673
|
+
}
|
|
657
674
|
}
|
|
658
675
|
}
|
|
659
676
|
|
|
@@ -763,6 +780,7 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
763
780
|
// common browser properties
|
|
764
781
|
return {
|
|
765
782
|
"user-agent": window.navigator.userAgent,
|
|
783
|
+
origin: url.origin,
|
|
766
784
|
locale: language,
|
|
767
785
|
location,
|
|
768
786
|
referrer: document.referrer,
|
package/src/types/base.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { EIP1193Provider } from "./provider";
|
|
1
|
+
import { EIP1193Provider, EIP6369Provider } from "./provider";
|
|
2
2
|
|
|
3
3
|
// Decimal chain ID
|
|
4
|
-
export type ChainID = number
|
|
4
|
+
export type ChainID = number;
|
|
5
5
|
|
|
6
6
|
// Address (EVM, Solana, etc.)
|
|
7
|
-
export type Address = string
|
|
7
|
+
export type Address = string;
|
|
8
8
|
|
|
9
9
|
export interface Options {
|
|
10
|
-
provider?:
|
|
10
|
+
provider?: EIP6369Provider;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export interface FormoAnalyticsProviderProps {
|
|
14
|
-
apiKey
|
|
14
|
+
apiKey?: string;
|
|
15
15
|
options?: Options;
|
|
16
16
|
disabled?: boolean;
|
|
17
17
|
children: React.ReactNode;
|
|
@@ -19,4 +19,4 @@ export interface FormoAnalyticsProviderProps {
|
|
|
19
19
|
|
|
20
20
|
export interface Config {
|
|
21
21
|
apiKey: string;
|
|
22
|
-
}
|
|
22
|
+
}
|
package/src/types/provider.ts
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
|
-
import EventEmitter from
|
|
1
|
+
import EventEmitter from "events";
|
|
2
2
|
|
|
3
3
|
export interface RequestArguments {
|
|
4
|
-
method: string
|
|
5
|
-
params?: unknown[] | Record<string, unknown
|
|
4
|
+
method: string;
|
|
5
|
+
params?: unknown[] | Record<string, unknown>;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export interface EIP1193Provider extends EventEmitter {
|
|
9
|
-
request<T>(args: RequestArguments): Promise<T | null | undefined
|
|
10
|
-
on(eventName: string | symbol, listener: (...args: unknown[]) => void): this
|
|
11
|
-
removeListener(
|
|
9
|
+
request<T>(args: RequestArguments): Promise<T | null | undefined>;
|
|
10
|
+
on(eventName: string | symbol, listener: (...args: unknown[]) => void): this;
|
|
11
|
+
removeListener(
|
|
12
|
+
eventName: string | symbol,
|
|
13
|
+
listener: (...args: unknown[]) => void
|
|
14
|
+
): this;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface EIP6369Provider extends EventEmitter {
|
|
18
|
+
request<T>(args: RequestArguments): Promise<T | null | undefined>;
|
|
19
|
+
on(eventName: string | symbol, listener: (...args: unknown[]) => void): this;
|
|
20
|
+
removeListener(
|
|
21
|
+
eventName: string | symbol,
|
|
22
|
+
listener: (...args: unknown[]) => void
|
|
23
|
+
): this;
|
|
12
24
|
}
|
|
13
25
|
|
|
14
26
|
export interface RPCError extends Error {
|
|
15
27
|
code: number;
|
|
16
28
|
data?: unknown;
|
|
17
|
-
}
|
|
29
|
+
}
|