@formo/analytics 1.13.3-alpha.1 → 1.13.3-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.map +1 -1
- package/dist/cjs/src/FormoAnalytics.js +6 -5
- package/dist/cjs/src/FormoAnalytics.js.map +1 -1
- package/dist/cjs/src/lib/utils.d.ts +2 -0
- package/dist/cjs/src/lib/utils.d.ts.map +1 -0
- package/dist/cjs/src/lib/utils.js +29 -0
- package/dist/cjs/src/lib/utils.js.map +1 -0
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/src/FormoAnalytics.d.ts.map +1 -1
- package/dist/esm/src/FormoAnalytics.js +6 -5
- package/dist/esm/src/FormoAnalytics.js.map +1 -1
- package/dist/esm/src/lib/utils.d.ts +2 -0
- package/dist/esm/src/lib/utils.d.ts.map +1 -0
- package/dist/esm/src/lib/utils.js +26 -0
- package/dist/esm/src/lib/utils.js.map +1 -0
- 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 +7 -6
- package/src/lib/utils.ts +24 -0
package/package.json
CHANGED
package/src/FormoAnalytics.ts
CHANGED
|
@@ -18,6 +18,7 @@ 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;
|
|
@@ -135,8 +136,8 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
135
136
|
this.currentConnectedAddress = address;
|
|
136
137
|
|
|
137
138
|
await this.trackEvent(Event.CONNECT, {
|
|
138
|
-
|
|
139
|
-
address
|
|
139
|
+
chainId,
|
|
140
|
+
address,
|
|
140
141
|
});
|
|
141
142
|
}
|
|
142
143
|
|
|
@@ -188,7 +189,7 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
188
189
|
this.currentChainId = chainId;
|
|
189
190
|
|
|
190
191
|
await this.trackEvent(Event.CHAIN_CHANGED, {
|
|
191
|
-
|
|
192
|
+
chainId,
|
|
192
193
|
address: address || this.currentConnectedAddress,
|
|
193
194
|
});
|
|
194
195
|
}
|
|
@@ -217,7 +218,7 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
217
218
|
}): Promise<void> {
|
|
218
219
|
await this.trackEvent(Event.SIGNATURE, {
|
|
219
220
|
status,
|
|
220
|
-
|
|
221
|
+
chainId,
|
|
221
222
|
address,
|
|
222
223
|
message,
|
|
223
224
|
...(signatureHash && { signatureHash }),
|
|
@@ -254,7 +255,7 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
254
255
|
}): Promise<void> {
|
|
255
256
|
await this.trackEvent(Event.TRANSACTION, {
|
|
256
257
|
status,
|
|
257
|
-
|
|
258
|
+
chainId,
|
|
258
259
|
address,
|
|
259
260
|
data,
|
|
260
261
|
to,
|
|
@@ -597,7 +598,7 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
597
598
|
timestamp: new Date().toISOString(),
|
|
598
599
|
action,
|
|
599
600
|
version: "1",
|
|
600
|
-
payload: await this.buildEventPayload(payload),
|
|
601
|
+
payload: await this.buildEventPayload(toSnakeCase(payload)),
|
|
601
602
|
};
|
|
602
603
|
|
|
603
604
|
try {
|
package/src/lib/utils.ts
ADDED
|
@@ -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
|
+
}
|