@formo/analytics 1.13.3-alpha.2 → 1.13.3-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formo/analytics",
3
- "version": "1.13.3-alpha.2",
3
+ "version": "1.13.3-alpha.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/getformo/sdk.git"
@@ -1,5 +1,5 @@
1
1
  import axios from "axios";
2
- import { createStore, EIP6963ProviderDetail, EIP6963ProviderInfo } from "mipd";
2
+ import { createStore, EIP6963ProviderDetail } from "mipd";
3
3
  import {
4
4
  COUNTRY_LIST,
5
5
  CURRENT_URL_KEY,
@@ -18,10 +18,10 @@ import {
18
18
  SignatureStatus,
19
19
  TransactionStatus,
20
20
  } from "./types";
21
+ import { toSnakeCase } from "./lib/utils";
21
22
 
22
23
  interface IFormoAnalytics {
23
24
  page(): void;
24
- // trackPagesChange(): void;
25
25
  connect(params: { chainId: ChainID; address: Address }): Promise<void>;
26
26
  disconnect(params?: { chainId?: ChainID; address?: Address }): Promise<void>;
27
27
  chain(params: { chainId: ChainID; address?: Address }): Promise<void>;
@@ -81,8 +81,8 @@ export class FormoAnalytics implements IFormoAnalytics {
81
81
  this.trackProvider(provider);
82
82
  }
83
83
 
84
- this.trackFirstPageVisit();
85
- this.trackPagesChange();
84
+ this.trackFirstPageHit();
85
+ this.trackPageHits();
86
86
  }
87
87
 
88
88
  static async init(
@@ -534,7 +534,7 @@ export class FormoAnalytics implements IFormoAnalytics {
534
534
  }
535
535
  }
536
536
 
537
- private async trackFirstPageVisit(): Promise<void> {
537
+ private async trackFirstPageHit(): Promise<void> {
538
538
  if (sessionStorage.getItem(CURRENT_URL_KEY) === null) {
539
539
  sessionStorage.setItem(CURRENT_URL_KEY, window.location.href);
540
540
  }
@@ -542,7 +542,7 @@ export class FormoAnalytics implements IFormoAnalytics {
542
542
  return this.trackPageHit();
543
543
  }
544
544
 
545
- private async trackPagesChange(): Promise<void> {
545
+ private async trackPageHits(): Promise<void> {
546
546
  const oldPushState = history.pushState;
547
547
  history.pushState = function pushState(...args) {
548
548
  const ret = oldPushState.apply(this, args);
@@ -558,7 +558,6 @@ export class FormoAnalytics implements IFormoAnalytics {
558
558
  };
559
559
 
560
560
  window.addEventListener("popstate", () => this.onLocationChange());
561
-
562
561
  window.addEventListener("locationchange", () => this.onLocationChange());
563
562
  }
564
563
 
@@ -571,8 +570,6 @@ export class FormoAnalytics implements IFormoAnalytics {
571
570
  }
572
571
  }
573
572
 
574
- // TODO: Add event listener and support for SPA and hash-based navigation
575
- // https://linear.app/getformo/issue/P-800/sdk-support-spa-and-hash-based-routing
576
573
  private trackPageHit(): void {
577
574
  const pathname = window.location.pathname;
578
575
  const href = window.location.href;
@@ -597,7 +594,7 @@ export class FormoAnalytics implements IFormoAnalytics {
597
594
  timestamp: new Date().toISOString(),
598
595
  action,
599
596
  version: "1",
600
- payload: await this.buildEventPayload(this.toSnakeCase(payload)),
597
+ payload: await this.buildEventPayload(toSnakeCase(payload)),
601
598
  };
602
599
 
603
600
  try {
@@ -680,8 +677,6 @@ export class FormoAnalytics implements IFormoAnalytics {
680
677
  const accounts = await this.getAccounts();
681
678
  if (accounts && accounts.length > 0) {
682
679
  return accounts[0];
683
- // TODO: how to handle multiple addresses? Should we emit a connect event here? Since the user has not manually connected
684
- // https://linear.app/getformo/issue/P-691/sdk-detect-multiple-wallets-using-eip6963
685
680
  }
686
681
  } catch (err) {
687
682
  console.log("Failed to fetch accounts from provider:", err);
@@ -837,31 +832,4 @@ export class FormoAnalytics implements IFormoAnalytics {
837
832
  private getActionDescriptor(action: string, payload: any): string {
838
833
  return `${action}${payload.status ? ` ${payload.status}` : ""}`;
839
834
  }
840
-
841
- // Converts object keys to snake_case, omitting keys in the omitKeys array
842
- private toSnakeCase(obj: any, omitKeys: string[] = []) {
843
- const toSnake = (str: string) =>
844
- str
845
- .replace(/([a-z])([A-Z])/g, "$1_$2")
846
- .replace(/[\s-]+/g, "_")
847
- .toLowerCase();
848
-
849
- const convert = (data: any): any => {
850
- if (Array.isArray(data)) {
851
- return data.map(convert);
852
- } else if (data !== null && typeof data === "object") {
853
- return Object.keys(data).reduce((acc: any, key) => {
854
- // If the key is in omitKeys, keep it as it is
855
- const resultKey = omitKeys.includes(key) ? key : toSnake(key);
856
- acc[resultKey] = omitKeys.includes(key)
857
- ? data[key]
858
- : convert(data[key]);
859
- return acc;
860
- }, {});
861
- }
862
- return data;
863
- };
864
-
865
- return convert(obj);
866
- }
867
835
  }
@@ -0,0 +1,24 @@
1
+ const toSnake = (str: string) =>
2
+ str
3
+ .replace(/([a-z])([A-Z])/g, "$1_$2")
4
+ .replace(/[\s-]+/g, "_")
5
+ .toLowerCase();
6
+
7
+ // Converts object keys to snake_case, omitting keys in the omitKeys array
8
+ export function toSnakeCase(obj: any, omitKeys: string[] = []) {
9
+ const convert = (data: any): any => {
10
+ if (Array.isArray(obj)) {
11
+ return obj.map(convert);
12
+ } else if (obj !== null && typeof obj === "object") {
13
+ return Object.keys(obj).reduce((acc: any, key) => {
14
+ // If the key is in omitKeys, keep it as it is
15
+ const resultKey = omitKeys.includes(key) ? key : toSnake(key);
16
+ acc[resultKey] = omitKeys.includes(key) ? obj[key] : convert(obj[key]);
17
+ return acc;
18
+ }, {});
19
+ }
20
+ return data;
21
+ };
22
+
23
+ return convert(obj);
24
+ }