@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formo/analytics",
3
- "version": "1.13.4-alpha.2",
3
+ "version": "1.13.4-alpha.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/getformo/sdk.git"
@@ -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 a identify event with current wallet address.
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,
@@ -55,7 +55,7 @@ const InitializedAnalytics = ({
55
55
  if (initializedStartedRef.current) return;
56
56
  initializedStartedRef.current = true;
57
57
 
58
- await initializeFormoAnalytics(apiKey, options);
58
+ await initializeFormoAnalytics(apiKey!, options);
59
59
  };
60
60
 
61
61
  initialize();
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?: EIP1193Provider;
10
+ provider?: EIP6369Provider;
11
11
  }
12
12
 
13
13
  export interface FormoAnalyticsProviderProps {
14
- apiKey: string;
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
+ }
@@ -1,17 +1,29 @@
1
- import EventEmitter from 'events'
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(eventName: string | symbol, listener: (...args: unknown[]) => void): this
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
+ }