@formo/analytics 2.0.0-alpha.4 → 2.0.0-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.
- package/dist/cjs/src/FormoAnalytics.d.ts +36 -3
- package/dist/cjs/src/FormoAnalytics.d.ts.map +1 -1
- package/dist/cjs/src/FormoAnalytics.js +4 -12
- package/dist/cjs/src/FormoAnalytics.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/src/FormoAnalytics.d.ts +36 -3
- package/dist/esm/src/FormoAnalytics.d.ts.map +1 -1
- package/dist/esm/src/FormoAnalytics.js +4 -12
- package/dist/esm/src/FormoAnalytics.js.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 +37 -18
package/package.json
CHANGED
package/src/FormoAnalytics.ts
CHANGED
|
@@ -10,10 +10,40 @@ import { H } from 'highlight.run';
|
|
|
10
10
|
import { ChainID, EIP1193Provider, RequestArguments } from './types';
|
|
11
11
|
|
|
12
12
|
interface IFormoAnalytics {
|
|
13
|
+
/**
|
|
14
|
+
* Initializes the FormoAnalytics instance with the provided API key and project ID.
|
|
15
|
+
*/
|
|
13
16
|
init(apiKey: string, projectId: string): Promise<FormoAnalytics>;
|
|
14
|
-
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Identifies the user with the provided user data.
|
|
20
|
+
*/
|
|
21
|
+
identify(userData: Record<string, any>): void;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Tracks page visit events.
|
|
25
|
+
*/
|
|
15
26
|
page(): void;
|
|
16
|
-
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Tracks a specific event with a name and associated data.
|
|
30
|
+
*/
|
|
31
|
+
track(eventName: string, eventData: Record<string, any>): void;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Connects to a wallet with the specified chain ID and address.
|
|
35
|
+
*/
|
|
36
|
+
connect(params: { chainId: ChainID; address: string }): Promise<void>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Disconnects the current wallet and clears the session information.
|
|
40
|
+
*/
|
|
41
|
+
disconnect(attributes?: { account?: string; chainId?: ChainID }): void;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Switches the blockchain chain context and optionally logs additional attributes.
|
|
45
|
+
*/
|
|
46
|
+
chain(attributes: { chainId: ChainID; account?: string }): void;
|
|
17
47
|
}
|
|
18
48
|
export class FormoAnalytics implements IFormoAnalytics {
|
|
19
49
|
private _provider?: EIP1193Provider;
|
|
@@ -40,7 +70,6 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
40
70
|
|
|
41
71
|
const provider = window?.ethereum || window.web3?.currentProvider;
|
|
42
72
|
if (provider) {
|
|
43
|
-
console.log('FormoAnalytics: Provider is set');
|
|
44
73
|
this.trackProvider(provider);
|
|
45
74
|
}
|
|
46
75
|
}
|
|
@@ -111,8 +140,6 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
111
140
|
const apiUrl = this.buildApiUrl();
|
|
112
141
|
const address = await this.getCurrentWallet();
|
|
113
142
|
|
|
114
|
-
console.log('address: ', address);
|
|
115
|
-
|
|
116
143
|
const requestData = {
|
|
117
144
|
project_id: this.projectId,
|
|
118
145
|
address: address,
|
|
@@ -265,10 +292,7 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
265
292
|
}
|
|
266
293
|
|
|
267
294
|
private trackProvider(provider: EIP1193Provider) {
|
|
268
|
-
console.log('Provider: ', provider);
|
|
269
|
-
console.log('this._provider: ', this._provider);
|
|
270
295
|
if (provider === this._provider) {
|
|
271
|
-
console.log('provider === this._provider');
|
|
272
296
|
return;
|
|
273
297
|
}
|
|
274
298
|
|
|
@@ -305,7 +329,6 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
305
329
|
}
|
|
306
330
|
|
|
307
331
|
private registerChainChangedListener() {
|
|
308
|
-
console.log('registerChainChangedListener is emitted');
|
|
309
332
|
const listener = (...args: unknown[]) =>
|
|
310
333
|
this.onChainChanged(args[0] as string);
|
|
311
334
|
this.provider?.on('chainChanged', listener);
|
|
@@ -383,7 +406,6 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
383
406
|
}
|
|
384
407
|
|
|
385
408
|
private registerAccountsChangedListener() {
|
|
386
|
-
console.log('registerAccountsChangedListener is emitted');
|
|
387
409
|
const listener = (...args: unknown[]) =>
|
|
388
410
|
this.onAccountsChanged(args[0] as string[]);
|
|
389
411
|
|
|
@@ -404,8 +426,6 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
404
426
|
return false;
|
|
405
427
|
}
|
|
406
428
|
|
|
407
|
-
console.log('trackSigning is emitted');
|
|
408
|
-
|
|
409
429
|
if (
|
|
410
430
|
Object.getOwnPropertyDescriptor(this.provider, 'request')?.writable ===
|
|
411
431
|
false
|
|
@@ -480,7 +500,6 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
480
500
|
const accounts = await this.provider.request<string[]>({
|
|
481
501
|
method: 'eth_accounts',
|
|
482
502
|
});
|
|
483
|
-
|
|
484
503
|
if (accounts && accounts.length > 0 && accounts[0]) {
|
|
485
504
|
this.handleAccountConnected(accounts[0]);
|
|
486
505
|
return accounts && accounts.length > 0 && accounts[0];
|
|
@@ -511,18 +530,18 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
511
530
|
return 'Error: No token provided';
|
|
512
531
|
}
|
|
513
532
|
|
|
514
|
-
connect({ chainId, address }: { chainId: ChainID; address: string })
|
|
533
|
+
connect({ chainId, address }: { chainId: ChainID; address: string }) {
|
|
515
534
|
if (!chainId) {
|
|
516
|
-
throw new Error('FormoAnalytics::
|
|
535
|
+
throw new Error('FormoAnalytics::connect: chainId cannot be empty');
|
|
517
536
|
}
|
|
518
537
|
if (!address) {
|
|
519
|
-
throw new Error('FormoAnalytics::
|
|
538
|
+
throw new Error('FormoAnalytics::connect: account cannot be empty');
|
|
520
539
|
}
|
|
521
540
|
|
|
522
541
|
this.currentChainId = chainId.toString();
|
|
523
542
|
this.currentConnectedAccount = address;
|
|
524
543
|
|
|
525
|
-
this.trackEvent(Event.CONNECT, {
|
|
544
|
+
return this.trackEvent(Event.CONNECT, {
|
|
526
545
|
chainId,
|
|
527
546
|
address,
|
|
528
547
|
});
|
|
@@ -555,7 +574,7 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
555
574
|
|
|
556
575
|
if (!account && !this.currentConnectedAccount) {
|
|
557
576
|
throw new Error(
|
|
558
|
-
'FormoAnalytics::chain: account was empty and no previous account has been recorded. You can either pass an account or call
|
|
577
|
+
'FormoAnalytics::chain: account was empty and no previous account has been recorded. You can either pass an account or call connect() first'
|
|
559
578
|
);
|
|
560
579
|
}
|
|
561
580
|
|