@formo/analytics 1.11.10 → 1.11.11
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 +4 -0
- package/dist/cjs/src/FormoAnalytics.d.ts.map +1 -1
- package/dist/cjs/src/FormoAnalytics.js +90 -49
- package/dist/cjs/src/FormoAnalytics.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/src/FormoAnalytics.d.ts +4 -0
- package/dist/esm/src/FormoAnalytics.d.ts.map +1 -1
- package/dist/esm/src/FormoAnalytics.js +90 -49
- 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 +86 -54
package/package.json
CHANGED
package/src/FormoAnalytics.ts
CHANGED
|
@@ -191,39 +191,76 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
191
191
|
|
|
192
192
|
// Function to track page hits
|
|
193
193
|
private trackPageHit() {
|
|
194
|
-
if (
|
|
195
|
-
|
|
194
|
+
if (this.isAutomationEnvironment()) return;
|
|
195
|
+
|
|
196
|
+
const location = this.getUserLocation();
|
|
197
|
+
const language = this.getUserLanguage();
|
|
198
|
+
|
|
199
|
+
setTimeout(async () => {
|
|
200
|
+
const eventData = await this.buildPageEventData(location, language);
|
|
201
|
+
this.trackEvent(Event.PAGE, eventData);
|
|
202
|
+
}, 300);
|
|
203
|
+
}
|
|
196
204
|
|
|
197
|
-
|
|
198
|
-
|
|
205
|
+
private isAutomationEnvironment(): boolean {
|
|
206
|
+
return (
|
|
207
|
+
window.__nightmare ||
|
|
208
|
+
window.navigator.webdriver ||
|
|
209
|
+
window.Cypress ||
|
|
210
|
+
false
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private getUserLocation(): string | undefined {
|
|
199
215
|
try {
|
|
200
216
|
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
217
|
+
return this.timezoneToCountry[timezone];
|
|
218
|
+
} catch (error) {
|
|
219
|
+
console.error('Error resolving timezone:', error);
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
private getUserLanguage(): string {
|
|
225
|
+
try {
|
|
226
|
+
return (
|
|
227
|
+
(navigator.languages && navigator.languages.length
|
|
204
228
|
? navigator.languages[0]
|
|
205
|
-
: navigator.language || 'en'
|
|
229
|
+
: navigator.language) || 'en'
|
|
230
|
+
);
|
|
206
231
|
} catch (error) {
|
|
207
|
-
console.error('Error resolving
|
|
232
|
+
console.error('Error resolving language:', error);
|
|
233
|
+
return 'en';
|
|
208
234
|
}
|
|
235
|
+
}
|
|
209
236
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
237
|
+
async buildPageEventData(location: string | undefined, language: string): Promise<Record<string, unknown>> {
|
|
238
|
+
const url = new URL(window.location.href);
|
|
239
|
+
const params = new URLSearchParams(url.search);
|
|
240
|
+
|
|
241
|
+
const address = await this.getAndStoreConnectedAddress();
|
|
242
|
+
if (address === null) {
|
|
243
|
+
console.warn('Wallet address could not be retrieved.');
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const eventData: Record<string, unknown> = {
|
|
247
|
+
'user-agent': window.navigator.userAgent,
|
|
248
|
+
locale: language,
|
|
249
|
+
location,
|
|
250
|
+
referrer: document.referrer,
|
|
251
|
+
pathname: window.location.pathname,
|
|
252
|
+
href: window.location.href,
|
|
253
|
+
utm_source: params.get('utm_source'),
|
|
254
|
+
utm_medium: params.get('utm_medium'),
|
|
255
|
+
utm_campaign: params.get('utm_campaign'),
|
|
256
|
+
ref: params.get('ref'),
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
if (address !== null) {
|
|
260
|
+
eventData['address'] = address;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return eventData;
|
|
227
264
|
}
|
|
228
265
|
|
|
229
266
|
private trackProvider(provider: EIP1193Provider) {
|
|
@@ -413,7 +450,7 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
413
450
|
|
|
414
451
|
const payload = {
|
|
415
452
|
chain_id: this.currentChainId,
|
|
416
|
-
address: this.
|
|
453
|
+
address: this.getAndStoreConnectedAddress(),
|
|
417
454
|
};
|
|
418
455
|
this.currentChainId = undefined;
|
|
419
456
|
this.currentConnectedAddress = undefined;
|
|
@@ -433,36 +470,31 @@ export class FormoAnalytics implements IFormoAnalytics {
|
|
|
433
470
|
return;
|
|
434
471
|
}
|
|
435
472
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
return;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
this.currentConnectedAddress = res[0];
|
|
448
|
-
} catch (err) {
|
|
449
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
450
|
-
if ((err as any).code !== 4001) {
|
|
451
|
-
// 4001: The request is rejected by the user , see https://docs.metamask.io/wallet/reference/provider-api/#errors
|
|
452
|
-
console.error(
|
|
453
|
-
'error',
|
|
454
|
-
`FormoAnalytics::onChainChanged: unable to get account. eth_accounts threw an error`,
|
|
455
|
-
err
|
|
456
|
-
);
|
|
457
|
-
return;
|
|
458
|
-
}
|
|
473
|
+
// Attempt to fetch and store the connected address
|
|
474
|
+
const address = await this.getAndStoreConnectedAddress();
|
|
475
|
+
if (!address) {
|
|
476
|
+
console.error(
|
|
477
|
+
'error',
|
|
478
|
+
'FormoAnalytics::onChainChanged: Unable to fetch or store connected address'
|
|
479
|
+
);
|
|
480
|
+
return;
|
|
459
481
|
}
|
|
482
|
+
|
|
483
|
+
this.currentConnectedAddress = address[0];
|
|
460
484
|
}
|
|
461
485
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
486
|
+
// Proceed only if the address exists
|
|
487
|
+
if (this.currentConnectedAddress) {
|
|
488
|
+
return this.chain({
|
|
489
|
+
chainId: this.currentChainId,
|
|
490
|
+
address: this.currentConnectedAddress,
|
|
491
|
+
});
|
|
492
|
+
} else {
|
|
493
|
+
console.error(
|
|
494
|
+
'error',
|
|
495
|
+
'FormoAnalytics::onChainChanged: currentConnectedAddress is null despite fetch attempt'
|
|
496
|
+
);
|
|
497
|
+
}
|
|
466
498
|
}
|
|
467
499
|
|
|
468
500
|
/**
|