@formo/analytics 1.13.4-alpha.5 → 1.13.4-alpha.6

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.
Files changed (41) hide show
  1. package/dist/cjs/src/FormoAnalytics.d.ts +1 -1
  2. package/dist/cjs/src/FormoAnalytics.d.ts.map +1 -1
  3. package/dist/cjs/src/FormoAnalytics.js +24 -13
  4. package/dist/cjs/src/FormoAnalytics.js.map +1 -1
  5. package/dist/cjs/src/FormoAnalyticsProvider.d.ts +2 -3
  6. package/dist/cjs/src/FormoAnalyticsProvider.d.ts.map +1 -1
  7. package/dist/cjs/src/FormoAnalyticsProvider.js.map +1 -1
  8. package/dist/cjs/src/lib/utils.d.ts +1 -0
  9. package/dist/cjs/src/lib/utils.d.ts.map +1 -1
  10. package/dist/cjs/src/lib/utils.js +5 -0
  11. package/dist/cjs/src/lib/utils.js.map +1 -1
  12. package/dist/cjs/src/types/base.d.ts +5 -3
  13. package/dist/cjs/src/types/base.d.ts.map +1 -1
  14. package/dist/cjs/src/types/provider.d.ts +1 -6
  15. package/dist/cjs/src/types/provider.d.ts.map +1 -1
  16. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  17. package/dist/esm/src/FormoAnalytics.d.ts +1 -1
  18. package/dist/esm/src/FormoAnalytics.d.ts.map +1 -1
  19. package/dist/esm/src/FormoAnalytics.js +25 -14
  20. package/dist/esm/src/FormoAnalytics.js.map +1 -1
  21. package/dist/esm/src/FormoAnalyticsProvider.d.ts +2 -3
  22. package/dist/esm/src/FormoAnalyticsProvider.d.ts.map +1 -1
  23. package/dist/esm/src/FormoAnalyticsProvider.js +1 -1
  24. package/dist/esm/src/FormoAnalyticsProvider.js.map +1 -1
  25. package/dist/esm/src/lib/utils.d.ts +1 -0
  26. package/dist/esm/src/lib/utils.d.ts.map +1 -1
  27. package/dist/esm/src/lib/utils.js +3 -0
  28. package/dist/esm/src/lib/utils.js.map +1 -1
  29. package/dist/esm/src/types/base.d.ts +5 -3
  30. package/dist/esm/src/types/base.d.ts.map +1 -1
  31. package/dist/esm/src/types/provider.d.ts +1 -6
  32. package/dist/esm/src/types/provider.d.ts.map +1 -1
  33. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  34. package/dist/index.umd.min.js +1 -1
  35. package/dist/index.umd.min.js.map +1 -1
  36. package/package.json +1 -1
  37. package/src/FormoAnalytics.ts +18 -13
  38. package/src/FormoAnalyticsProvider.tsx +1 -7
  39. package/src/lib/utils.ts +5 -0
  40. package/src/types/base.ts +5 -3
  41. package/src/types/provider.ts +7 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formo/analytics",
3
- "version": "1.13.4-alpha.5",
3
+ "version": "1.13.4-alpha.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/getformo/sdk.git"
@@ -17,7 +17,7 @@ import {
17
17
  SignatureStatus,
18
18
  TransactionStatus,
19
19
  } from "./types";
20
- import { toSnakeCase } from "./lib/utils";
20
+ import { isLocalhost, toSnakeCase } from "./lib/utils";
21
21
 
22
22
  interface IFormoAnalytics {
23
23
  page(): void;
@@ -73,7 +73,8 @@ export class FormoAnalytics implements IFormoAnalytics {
73
73
  public options: Options = {}
74
74
  ) {
75
75
  this.config = {
76
- apiKey: apiKey,
76
+ apiKey,
77
+ trackLocalhost: options.trackLocalhost,
77
78
  };
78
79
 
79
80
  try {
@@ -283,7 +284,7 @@ export class FormoAnalytics implements IFormoAnalytics {
283
284
  providerName,
284
285
  rdns,
285
286
  }: {
286
- address: Address;
287
+ address: Address | null;
287
288
  providerName?: string;
288
289
  rdns?: string;
289
290
  }): Promise<void> {
@@ -587,6 +588,12 @@ export class FormoAnalytics implements IFormoAnalytics {
587
588
  const href = window.location.href;
588
589
  const hash = window.location.hash;
589
590
 
591
+ if (!this.config.trackLocalhost && isLocalhost()) {
592
+ return console.warn(
593
+ "[Formo] Ignoring event because website is running locally"
594
+ );
595
+ }
596
+
590
597
  setTimeout(async () => {
591
598
  this.trackEvent(Event.PAGE, {
592
599
  pathname,
@@ -654,11 +661,10 @@ export class FormoAnalytics implements IFormoAnalytics {
654
661
  }
655
662
 
656
663
  private async identifyAll(providers: EIP6963ProviderDetail[]): Promise<void> {
657
- console.log("identifying all => providers", providers);
658
664
  for (const { provider, info } of providers) {
659
665
  try {
660
666
  const accounts = await this.getAccounts(provider);
661
- console.log("identifying all => accounts", accounts);
667
+ // Identify with accounts
662
668
  if (accounts && accounts.length > 0) {
663
669
  for (const address of accounts) {
664
670
  await this.identify({
@@ -667,6 +673,13 @@ export class FormoAnalytics implements IFormoAnalytics {
667
673
  rdns: info.rdns,
668
674
  });
669
675
  }
676
+ } else {
677
+ // Identify without accounts
678
+ await this.identify({
679
+ address: null,
680
+ providerName: info.name,
681
+ rdns: info.rdns,
682
+ });
670
683
  }
671
684
  } catch (err) {
672
685
  console.log("identifying all => err", err);
@@ -701,21 +714,13 @@ export class FormoAnalytics implements IFormoAnalytics {
701
714
  provider?: EIP1193Provider
702
715
  ): Promise<Address[] | null> {
703
716
  const p = provider || this.provider;
704
- console.log(
705
- "getAccounts => p, provider, this.provider",
706
- p,
707
- provider,
708
- this.provider
709
- );
710
717
  try {
711
718
  const res: string[] | null | undefined = await p?.request({
712
719
  method: "eth_accounts",
713
720
  });
714
- console.log("getAccounts => res", res);
715
721
  if (!res || res.length === 0) return null;
716
722
  return res;
717
723
  } catch (err) {
718
- console.log("getAccounts => err", err);
719
724
  if ((err as any).code !== 4001) {
720
725
  console.log(
721
726
  "FormoAnalytics::getAccounts: eth_accounts threw an error",
@@ -1,10 +1,4 @@
1
- import React, {
2
- createContext,
3
- useContext,
4
- useEffect,
5
- useState,
6
- useRef,
7
- } from "react";
1
+ import { createContext, useContext, useEffect, useState, useRef } from "react";
8
2
  import { FormoAnalytics } from "./FormoAnalytics";
9
3
  import { FormoAnalyticsProviderProps } from "./types";
10
4
 
package/src/lib/utils.ts CHANGED
@@ -24,3 +24,8 @@ export function toSnakeCase(obj: any, omitKeys: string[] = []) {
24
24
 
25
25
  return convert(obj);
26
26
  }
27
+
28
+ export const isLocalhost = () =>
29
+ /^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*:)*?:?0*1$/.test(
30
+ window.location.hostname
31
+ ) || window.location.protocol === "file:";
package/src/types/base.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { EIP1193Provider, EIP6369Provider } from "./provider";
1
+ import { EIP1193Provider } from "./provider";
2
2
 
3
3
  // Decimal chain ID
4
4
  export type ChainID = number;
@@ -7,11 +7,12 @@ export type ChainID = number;
7
7
  export type Address = string;
8
8
 
9
9
  export interface Options {
10
- provider?: EIP6369Provider;
10
+ provider?: EIP1193Provider;
11
+ trackLocalhost?: boolean;
11
12
  }
12
13
 
13
14
  export interface FormoAnalyticsProviderProps {
14
- apiKey?: string;
15
+ apiKey: string;
15
16
  options?: Options;
16
17
  disabled?: boolean;
17
18
  children: React.ReactNode;
@@ -19,4 +20,5 @@ export interface FormoAnalyticsProviderProps {
19
20
 
20
21
  export interface Config {
21
22
  apiKey: string;
23
+ trackLocalhost?: boolean;
22
24
  }
@@ -1,29 +1,17 @@
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(
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;
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
24
12
  }
25
13
 
26
14
  export interface RPCError extends Error {
27
15
  code: number;
28
16
  data?: unknown;
29
- }
17
+ }