@formo/analytics 1.29.0 → 1.29.1
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 +32 -0
- package/dist/cjs/src/FormoAnalytics.js +161 -43
- package/dist/cjs/src/constants/base.d.ts +9 -0
- package/dist/cjs/src/constants/base.js +10 -1
- package/dist/cjs/src/constants/config.d.ts +3 -58
- package/dist/cjs/src/constants/config.js +3 -73
- package/dist/cjs/src/event/EventFactory.js +9 -3
- package/dist/cjs/src/version.d.ts +1 -1
- package/dist/cjs/src/version.js +1 -1
- package/dist/esm/src/FormoAnalytics.d.ts +32 -0
- package/dist/esm/src/FormoAnalytics.js +162 -44
- package/dist/esm/src/constants/base.d.ts +9 -0
- package/dist/esm/src/constants/base.js +9 -0
- package/dist/esm/src/constants/config.d.ts +3 -58
- package/dist/esm/src/constants/config.js +3 -73
- package/dist/esm/src/event/EventFactory.js +9 -3
- package/dist/esm/src/version.d.ts +1 -1
- package/dist/esm/src/version.js +1 -1
- package/dist/index.umd.min.js +1 -1
- package/package.json +9 -8
|
@@ -192,7 +192,7 @@ exports.COUNTRY_LIST = {
|
|
|
192
192
|
"America/Panama": "PA",
|
|
193
193
|
"America/Pangnirtung": "CA",
|
|
194
194
|
"America/Paramaribo": "SR",
|
|
195
|
-
"America/Phoenix": "US
|
|
195
|
+
"America/Phoenix": "US",
|
|
196
196
|
"America/Port-au-Prince": "HT",
|
|
197
197
|
"America/Port_of_Spain": "TT",
|
|
198
198
|
"America/Porto_Acre": "BR",
|
|
@@ -298,6 +298,7 @@ exports.COUNTRY_LIST = {
|
|
|
298
298
|
"Asia/Katmandu": "NP",
|
|
299
299
|
"Asia/Khandyga": "RU",
|
|
300
300
|
"Asia/Kolkata": "IN",
|
|
301
|
+
"Asia/Kostanay": "KZ",
|
|
301
302
|
"Asia/Krasnoyarsk": "RU",
|
|
302
303
|
"Asia/Kuala_Lumpur": "MY",
|
|
303
304
|
"Asia/Kuching": "MY",
|
|
@@ -399,59 +400,15 @@ exports.COUNTRY_LIST = {
|
|
|
399
400
|
"Canada/Pacific": "CA",
|
|
400
401
|
"Canada/Saskatchewan": "CA",
|
|
401
402
|
"Canada/Yukon": "CA",
|
|
402
|
-
// CET
|
|
403
|
-
CET: "CET",
|
|
404
403
|
// Chile
|
|
405
404
|
"Chile/Continental": "CL",
|
|
406
405
|
"Chile/EasterIsland": "CL",
|
|
407
|
-
// CST6CDT
|
|
408
|
-
CST6CDT: "CST6CDT",
|
|
409
406
|
// Cuba
|
|
410
407
|
Cuba: "CU",
|
|
411
|
-
// EET
|
|
412
|
-
EET: "EET",
|
|
413
408
|
// Egypt
|
|
414
409
|
Egypt: "EG",
|
|
415
410
|
// Eire
|
|
416
411
|
Eire: "IE",
|
|
417
|
-
// EST
|
|
418
|
-
EST: "EST",
|
|
419
|
-
EST5EDT: "EST5EDT",
|
|
420
|
-
"Etc/GMT": "Etc/GMT",
|
|
421
|
-
"Etc/GMT+0": "Etc/GMT+0",
|
|
422
|
-
"Etc/GMT+1": "Etc/GMT+1",
|
|
423
|
-
"Etc/GMT+10": "Etc/GMT+10",
|
|
424
|
-
"Etc/GMT+11": "Etc/GMT+11",
|
|
425
|
-
"Etc/GMT+12": "Etc/GMT+12",
|
|
426
|
-
"Etc/GMT+2": "Etc/GMT+2",
|
|
427
|
-
"Etc/GMT+3": "Etc/GMT+3",
|
|
428
|
-
"Etc/GMT+4": "Etc/GMT+4",
|
|
429
|
-
"Etc/GMT+5": "Etc/GMT+5",
|
|
430
|
-
"Etc/GMT+6": "Etc/GMT+6",
|
|
431
|
-
"Etc/GMT+7": "Etc/GMT+7",
|
|
432
|
-
"Etc/GMT+8": "Etc/GMT+8",
|
|
433
|
-
"Etc/GMT+9": "Etc/GMT+9",
|
|
434
|
-
"Etc/GMT-0": "Etc/GMT-0",
|
|
435
|
-
"Etc/GMT-1": "Etc/GMT-1",
|
|
436
|
-
"Etc/GMT-10": "Etc/GMT-10",
|
|
437
|
-
"Etc/GMT-11": "Etc/GMT-11",
|
|
438
|
-
"Etc/GMT-12": "Etc/GMT-12",
|
|
439
|
-
"Etc/GMT-13": "Etc/GMT-13",
|
|
440
|
-
"Etc/GMT-14": "Etc/GMT-14",
|
|
441
|
-
"Etc/GMT-2": "Etc/GMT-2",
|
|
442
|
-
"Etc/GMT-3": "Etc/GMT-3",
|
|
443
|
-
"Etc/GMT-4": "Etc/GMT-4",
|
|
444
|
-
"Etc/GMT-5": "Etc/GMT-5",
|
|
445
|
-
"Etc/GMT-6": "Etc/GMT-6",
|
|
446
|
-
"Etc/GMT-7": "Etc/GMT-7",
|
|
447
|
-
"Etc/GMT-8": "Etc/GMT-8",
|
|
448
|
-
"Etc/GMT-9": "Etc/GMT-9",
|
|
449
|
-
"Etc/GMT0": "Etc/GMT0",
|
|
450
|
-
"Etc/Greenwich": "Etc/Greenwich",
|
|
451
|
-
"Etc/UCT": "Etc/UCT",
|
|
452
|
-
"Etc/UTC": "Etc/UTC",
|
|
453
|
-
"Etc/Universal": "Etc/Universal",
|
|
454
|
-
"Etc/Zulu": "Etc/Zulu",
|
|
455
412
|
// Europe
|
|
456
413
|
"Europe/Amsterdam": "NL",
|
|
457
414
|
"Europe/Andorra": "AD",
|
|
@@ -517,21 +474,11 @@ exports.COUNTRY_LIST = {
|
|
|
517
474
|
"Europe/Zagreb": "HR",
|
|
518
475
|
"Europe/Zaporozhye": "UA",
|
|
519
476
|
"Europe/Zurich": "CH",
|
|
520
|
-
// Factory
|
|
521
|
-
Factory: "Factory",
|
|
522
477
|
// GB
|
|
523
478
|
GB: "GB",
|
|
524
479
|
"GB-Eire": "GB",
|
|
525
|
-
// GMT
|
|
526
|
-
GMT: "GMT",
|
|
527
|
-
"GMT+0": "GMT+0",
|
|
528
|
-
"GMT-0": "GMT-0",
|
|
529
|
-
GMT0: "GMT0",
|
|
530
|
-
Greenwich: "Greenwich",
|
|
531
480
|
// HK
|
|
532
481
|
Hongkong: "HK",
|
|
533
|
-
// HST
|
|
534
|
-
HST: "HST",
|
|
535
482
|
// Iceland
|
|
536
483
|
Iceland: "IS",
|
|
537
484
|
// Indian
|
|
@@ -558,15 +505,10 @@ exports.COUNTRY_LIST = {
|
|
|
558
505
|
Kwajalein: "MH",
|
|
559
506
|
// Libya
|
|
560
507
|
Libya: "LY",
|
|
561
|
-
// MET
|
|
562
|
-
MET: "MET",
|
|
563
508
|
// Mexico
|
|
564
509
|
"Mexico/BajaNorte": "MX",
|
|
565
510
|
"Mexico/BajaSur": "MX",
|
|
566
511
|
"Mexico/General": "MX",
|
|
567
|
-
// MST
|
|
568
|
-
MST: "MST",
|
|
569
|
-
MST7MDT: "MST7MDT",
|
|
570
512
|
// Navajo
|
|
571
513
|
Navajo: "US",
|
|
572
514
|
// NZ
|
|
@@ -587,7 +529,7 @@ exports.COUNTRY_LIST = {
|
|
|
587
529
|
"Pacific/Galapagos": "EC",
|
|
588
530
|
"Pacific/Gambier": "PF",
|
|
589
531
|
"Pacific/Guadalcanal": "SB",
|
|
590
|
-
"Pacific/Guam": "GU
|
|
532
|
+
"Pacific/Guam": "GU",
|
|
591
533
|
"Pacific/Honolulu": "US",
|
|
592
534
|
"Pacific/Johnston": "UM",
|
|
593
535
|
"Pacific/Kanton": "KI",
|
|
@@ -623,8 +565,6 @@ exports.COUNTRY_LIST = {
|
|
|
623
565
|
Portugal: "PT",
|
|
624
566
|
// PRC
|
|
625
567
|
PRC: "CN",
|
|
626
|
-
// PST8PDT
|
|
627
|
-
PST8PDT: "PST8PDT",
|
|
628
568
|
// ROC
|
|
629
569
|
ROC: "TW",
|
|
630
570
|
// ROK
|
|
@@ -633,10 +573,6 @@ exports.COUNTRY_LIST = {
|
|
|
633
573
|
Singapore: "SG",
|
|
634
574
|
// Turkey
|
|
635
575
|
Turkey: "TR",
|
|
636
|
-
// UCT
|
|
637
|
-
UCT: "UCT",
|
|
638
|
-
// Universal
|
|
639
|
-
Universal: "Universal",
|
|
640
576
|
// US
|
|
641
577
|
"US/Alaska": "US",
|
|
642
578
|
"US/Aleutian": "US",
|
|
@@ -650,13 +586,7 @@ exports.COUNTRY_LIST = {
|
|
|
650
586
|
"US/Mountain": "US",
|
|
651
587
|
"US/Pacific": "US",
|
|
652
588
|
"US/Samoa": "AS",
|
|
653
|
-
// UTC
|
|
654
|
-
UTC: "UTC",
|
|
655
589
|
// W-SU
|
|
656
590
|
"W-SU": "RU",
|
|
657
|
-
// WET
|
|
658
|
-
WET: "WET",
|
|
659
|
-
// Zulu
|
|
660
|
-
Zulu: "Zulu",
|
|
661
591
|
};
|
|
662
592
|
//# sourceMappingURL=config.js.map
|
|
@@ -63,6 +63,7 @@ var version_1 = require("../version");
|
|
|
63
63
|
var constants_2 = require("./constants");
|
|
64
64
|
var utils_2 = require("./utils");
|
|
65
65
|
var browsers_1 = require("../browser/browsers");
|
|
66
|
+
var ISO_3166_ALPHA_2_REGEX = /^[A-Z]{2}$/;
|
|
66
67
|
var EventFactory = /** @class */ (function () {
|
|
67
68
|
function EventFactory(options) {
|
|
68
69
|
var _this = this;
|
|
@@ -230,9 +231,14 @@ var EventFactory = /** @class */ (function () {
|
|
|
230
231
|
EventFactory.prototype.getLocation = function () {
|
|
231
232
|
try {
|
|
232
233
|
var timezone = this.getTimezone();
|
|
233
|
-
if (timezone
|
|
234
|
-
return
|
|
235
|
-
|
|
234
|
+
if (!timezone)
|
|
235
|
+
return "";
|
|
236
|
+
var mapped = constants_1.COUNTRY_LIST[timezone];
|
|
237
|
+
// Only emit ISO-3166 alpha-2. Anything else (including the raw
|
|
238
|
+
// timezone string) is treated as unknown.
|
|
239
|
+
return typeof mapped === "string" && ISO_3166_ALPHA_2_REGEX.test(mapped)
|
|
240
|
+
? mapped
|
|
241
|
+
: "";
|
|
236
242
|
}
|
|
237
243
|
catch (error) {
|
|
238
244
|
logger_1.logger.error("Error resolving location:", error);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "1.29.
|
|
1
|
+
export declare const version = "1.29.1";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/cjs/src/version.js
CHANGED
|
@@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.version = void 0;
|
|
4
4
|
// This file is auto-generated by scripts/update-version.js during npm version
|
|
5
5
|
// Do not edit manually - it will be overwritten
|
|
6
|
-
exports.version = '1.29.
|
|
6
|
+
exports.version = '1.29.1';
|
|
7
7
|
//# sourceMappingURL=version.js.map
|
|
@@ -54,6 +54,10 @@ export declare class FormoAnalytics implements IFormoAnalytics {
|
|
|
54
54
|
private crossSubdomainCookies;
|
|
55
55
|
/** In-memory URL used to deduplicate SPA pageview events. */
|
|
56
56
|
private _currentUrl;
|
|
57
|
+
/** Page-hit hooks installed in trackPageHits() so cleanup() can undo them. */
|
|
58
|
+
private _onPopStateListener?;
|
|
59
|
+
private _onLocationChangeListener?;
|
|
60
|
+
private _pageHooksDisposed;
|
|
57
61
|
config: Config;
|
|
58
62
|
currentChainId?: ChainID;
|
|
59
63
|
currentAddress?: Address;
|
|
@@ -272,6 +276,12 @@ export declare class FormoAnalytics implements IFormoAnalytics {
|
|
|
272
276
|
private registerRequestListeners;
|
|
273
277
|
private onLocationChange;
|
|
274
278
|
private trackPageHits;
|
|
279
|
+
/**
|
|
280
|
+
* Wrap history.pushState / replaceState exactly once per `history` object,
|
|
281
|
+
* regardless of how many SDK instances are constructed. Uses a Symbol
|
|
282
|
+
* marker so we recognize our own wrapper across module reloads in HMR.
|
|
283
|
+
*/
|
|
284
|
+
private static installHistoryHooksOnce;
|
|
275
285
|
private trackPageHit;
|
|
276
286
|
private trackEvent;
|
|
277
287
|
/**
|
|
@@ -312,6 +322,15 @@ export declare class FormoAnalytics implements IFormoAnalytics {
|
|
|
312
322
|
private getCurrentChainId;
|
|
313
323
|
private buildSignatureEventPayload;
|
|
314
324
|
private buildTransactionEventPayload;
|
|
325
|
+
/**
|
|
326
|
+
* Persist an EVM address discovered through autocapture (signature / transaction)
|
|
327
|
+
* as the current EVM address when none is currently set. This lets subsequent
|
|
328
|
+
* track()/page() calls carry the address even when the underlying wallet never
|
|
329
|
+
* fires an EIP-1193 `accountsChanged` event (embedded wallets, smart accounts,
|
|
330
|
+
* social-login wrappers). If `accountsChanged` later fires it overwrites this
|
|
331
|
+
* value in the normal way; existing connections are never clobbered.
|
|
332
|
+
*/
|
|
333
|
+
private backfillActiveWallet;
|
|
315
334
|
/**
|
|
316
335
|
* Polls for transaction receipt and emits tx.status = CONFIRMED or REVERTED.
|
|
317
336
|
*/
|
|
@@ -367,6 +386,19 @@ export declare class FormoAnalytics implements IFormoAnalytics {
|
|
|
367
386
|
* Last-connected-chain-wins: _activeNamespace takes precedence.
|
|
368
387
|
*/
|
|
369
388
|
private syncDerivedState;
|
|
389
|
+
/**
|
|
390
|
+
* Persist (or clear) the current wallet snapshot in a cookie so that the
|
|
391
|
+
* SDK can repopulate `currentAddress`/`currentChainId` at init on the next
|
|
392
|
+
* page load — closing the gap between page-show and wagmi/EIP-1193
|
|
393
|
+
* reconnection during which track()/page() events would otherwise ship
|
|
394
|
+
* with an empty address.
|
|
395
|
+
*/
|
|
396
|
+
private persistActiveWallet;
|
|
397
|
+
/**
|
|
398
|
+
* Seed `currentAddress`/`currentChainId` from the persisted snapshot, if
|
|
399
|
+
* any. Called once during construction before the first page hit fires.
|
|
400
|
+
*/
|
|
401
|
+
private loadActiveWallet;
|
|
370
402
|
/**
|
|
371
403
|
* Helper method to clear the active provider state
|
|
372
404
|
* Centralizes provider clearing logic for consistency
|
|
@@ -55,7 +55,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
55
55
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
56
56
|
};
|
|
57
57
|
import { createStore } from "mipd";
|
|
58
|
-
import { EVENTS_API_HOST, EventType, LOCAL_ANONYMOUS_ID_KEY, SESSION_USER_ID_KEY, CONSENT_OPT_OUT_KEY, } from "./constants";
|
|
58
|
+
import { EVENTS_API_HOST, EventType, LOCAL_ANONYMOUS_ID_KEY, SESSION_USER_ID_KEY, ACTIVE_WALLET_KEY, ACTIVE_WALLET_TTL_MS, CONSENT_OPT_OUT_KEY, } from "./constants";
|
|
59
59
|
import { cookie, initStorageManager } from "./storage";
|
|
60
60
|
import { getIdentityCookieDomain } from "./storage/cookiePolicy";
|
|
61
61
|
import { EventManager } from "./event";
|
|
@@ -121,6 +121,7 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
121
121
|
this.isEvmDisabled = false;
|
|
122
122
|
/** In-memory URL used to deduplicate SPA pageview events. */
|
|
123
123
|
this._currentUrl = "";
|
|
124
|
+
this._pageHooksDisposed = false;
|
|
124
125
|
this.currentUserId = "";
|
|
125
126
|
this.config = {
|
|
126
127
|
writeKey: writeKey,
|
|
@@ -188,6 +189,10 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
188
189
|
this.solanaManager = new SolanaManager(this, options.solana);
|
|
189
190
|
}
|
|
190
191
|
this._currentUrl = window.location.href;
|
|
192
|
+
// Seed currentAddress/currentChainId from the persisted snapshot before
|
|
193
|
+
// the first page hit queues so reload-time track()/page() carry the
|
|
194
|
+
// wallet even before wagmi/EIP-1193 reconnection completes.
|
|
195
|
+
this.loadActiveWallet();
|
|
191
196
|
this.trackPageHit();
|
|
192
197
|
this.trackPageHits();
|
|
193
198
|
}
|
|
@@ -293,6 +298,7 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
293
298
|
cookie().remove(SESSION_USER_ID_KEY);
|
|
294
299
|
cookie().remove(SESSION_WALLET_DETECTED_KEY);
|
|
295
300
|
cookie().remove(SESSION_WALLET_IDENTIFIED_KEY);
|
|
301
|
+
cookie().remove(ACTIVE_WALLET_KEY);
|
|
296
302
|
};
|
|
297
303
|
/**
|
|
298
304
|
* Clean up resources and event listeners
|
|
@@ -318,6 +324,21 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
318
324
|
this.untrackProvider(provider);
|
|
319
325
|
}
|
|
320
326
|
}
|
|
327
|
+
// Tear down page-hit hooks: remove window listeners and silence the
|
|
328
|
+
// history.pushState/replaceState wrappers so an orphaned instance (e.g.
|
|
329
|
+
// from a re-mount in React Strict Mode / HMR) stops emitting page events
|
|
330
|
+
// with stale state.
|
|
331
|
+
this._pageHooksDisposed = true;
|
|
332
|
+
if (typeof window !== "undefined") {
|
|
333
|
+
if (this._onPopStateListener) {
|
|
334
|
+
window.removeEventListener("popstate", this._onPopStateListener);
|
|
335
|
+
this._onPopStateListener = undefined;
|
|
336
|
+
}
|
|
337
|
+
if (this._onLocationChangeListener) {
|
|
338
|
+
window.removeEventListener("locationchange", this._onLocationChangeListener);
|
|
339
|
+
this._onLocationChangeListener = undefined;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
321
342
|
logger.debug("FormoAnalytics: Cleanup complete");
|
|
322
343
|
};
|
|
323
344
|
/**
|
|
@@ -597,6 +618,7 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
597
618
|
validAddress = validateAddress(address);
|
|
598
619
|
if (validAddress) {
|
|
599
620
|
this.currentAddress = validAddress;
|
|
621
|
+
this.persistActiveWallet();
|
|
600
622
|
}
|
|
601
623
|
else {
|
|
602
624
|
(_c = logger.warn) === null || _c === void 0 ? void 0 : _c.call(logger, "Invalid address provided to identify:", address);
|
|
@@ -1450,35 +1472,52 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
1450
1472
|
});
|
|
1451
1473
|
};
|
|
1452
1474
|
FormoAnalytics.prototype.trackPageHits = function () {
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1475
|
+
var _this = this;
|
|
1476
|
+
// Install a single, instance-agnostic wrapper around history.pushState /
|
|
1477
|
+
// replaceState so concurrent SDK instances (React Strict Mode, HMR) don't
|
|
1478
|
+
// each stack their own wrapper — which would dispatch N synthetic events
|
|
1479
|
+
// per navigation and produce O(N^2) onLocationChange calls. The wrapper
|
|
1480
|
+
// dispatches once; per-instance bookkeeping is done by per-instance
|
|
1481
|
+
// listeners that each register/unregister themselves.
|
|
1482
|
+
FormoAnalytics.installHistoryHooksOnce();
|
|
1483
|
+
this._onPopStateListener = function () { return _this.onLocationChange(); };
|
|
1484
|
+
this._onLocationChangeListener = function () { return _this.onLocationChange(); };
|
|
1485
|
+
window.addEventListener("popstate", this._onPopStateListener);
|
|
1486
|
+
window.addEventListener("locationchange", this._onLocationChangeListener);
|
|
1487
|
+
};
|
|
1488
|
+
/**
|
|
1489
|
+
* Wrap history.pushState / replaceState exactly once per `history` object,
|
|
1490
|
+
* regardless of how many SDK instances are constructed. Uses a Symbol
|
|
1491
|
+
* marker so we recognize our own wrapper across module reloads in HMR.
|
|
1492
|
+
*/
|
|
1493
|
+
FormoAnalytics.installHistoryHooksOnce = function () {
|
|
1494
|
+
if (typeof history === "undefined" || typeof window === "undefined")
|
|
1495
|
+
return;
|
|
1496
|
+
var marker = Symbol.for("formo.historyWrapped");
|
|
1497
|
+
if (history[marker])
|
|
1498
|
+
return;
|
|
1499
|
+
history[marker] = true;
|
|
1500
|
+
var dispatch = function () { return window.dispatchEvent(new window.Event("locationchange")); };
|
|
1501
|
+
var oldPushState = history.pushState;
|
|
1502
|
+
history.pushState = function pushState() {
|
|
1503
|
+
var args = [];
|
|
1504
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1505
|
+
args[_i] = arguments[_i];
|
|
1506
|
+
}
|
|
1507
|
+
var ret = oldPushState.apply(this, args);
|
|
1508
|
+
dispatch();
|
|
1509
|
+
return ret;
|
|
1510
|
+
};
|
|
1511
|
+
var oldReplaceState = history.replaceState;
|
|
1512
|
+
history.replaceState = function replaceState() {
|
|
1513
|
+
var args = [];
|
|
1514
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
1515
|
+
args[_i] = arguments[_i];
|
|
1516
|
+
}
|
|
1517
|
+
var ret = oldReplaceState.apply(this, args);
|
|
1518
|
+
dispatch();
|
|
1519
|
+
return ret;
|
|
1520
|
+
};
|
|
1482
1521
|
};
|
|
1483
1522
|
FormoAnalytics.prototype.trackPageHit = function (category, name, properties, context, callback) {
|
|
1484
1523
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -1489,6 +1528,12 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
1489
1528
|
return [2 /*return*/];
|
|
1490
1529
|
}
|
|
1491
1530
|
setTimeout(function () {
|
|
1531
|
+
// Drop in-flight page hits from an SDK instance that was torn down
|
|
1532
|
+
// between scheduling and firing (e.g. provider remount in React Strict
|
|
1533
|
+
// Mode / HMR). Otherwise the orphan instance would queue a page event
|
|
1534
|
+
// here with its stale, never-populated `currentAddress`.
|
|
1535
|
+
if (_this._pageHooksDisposed)
|
|
1536
|
+
return;
|
|
1492
1537
|
(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1493
1538
|
var e_7;
|
|
1494
1539
|
return __generator(this, function (_a) {
|
|
@@ -1905,8 +1950,10 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
1905
1950
|
if (!validAddress) {
|
|
1906
1951
|
throw new Error("Invalid address in signature payload: ".concat(rawAddress));
|
|
1907
1952
|
}
|
|
1953
|
+
var effectiveChainId = (_a = chainId !== null && chainId !== void 0 ? chainId : this._evmChainId) !== null && _a !== void 0 ? _a : undefined;
|
|
1954
|
+
this.backfillActiveWallet(validAddress, effectiveChainId);
|
|
1908
1955
|
var basePayload = {
|
|
1909
|
-
chainId:
|
|
1956
|
+
chainId: effectiveChainId,
|
|
1910
1957
|
address: validAddress,
|
|
1911
1958
|
};
|
|
1912
1959
|
if (method === "personal_sign") {
|
|
@@ -1917,33 +1964,48 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
1917
1964
|
};
|
|
1918
1965
|
FormoAnalytics.prototype.buildTransactionEventPayload = function (params, provider) {
|
|
1919
1966
|
return __awaiter(this, void 0, void 0, function () {
|
|
1920
|
-
var _a, data, from, to, value, validAddress, _b;
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
switch (_d.label) {
|
|
1967
|
+
var _a, data, from, to, value, validAddress, chainId, _b;
|
|
1968
|
+
return __generator(this, function (_c) {
|
|
1969
|
+
switch (_c.label) {
|
|
1924
1970
|
case 0:
|
|
1925
1971
|
_a = params[0], data = _a.data, from = _a.from, to = _a.to, value = _a.value;
|
|
1926
1972
|
validAddress = validateAndChecksumAddress(from);
|
|
1927
1973
|
if (!validAddress) {
|
|
1928
1974
|
throw new Error("Invalid address in transaction payload: ".concat(from));
|
|
1929
1975
|
}
|
|
1930
|
-
_c = {};
|
|
1931
1976
|
_b = this._evmChainId;
|
|
1932
1977
|
if (_b) return [3 /*break*/, 2];
|
|
1933
1978
|
return [4 /*yield*/, this.getCurrentChainId(provider)];
|
|
1934
1979
|
case 1:
|
|
1935
|
-
_b = (
|
|
1936
|
-
|
|
1937
|
-
case 2:
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1980
|
+
_b = (_c.sent());
|
|
1981
|
+
_c.label = 2;
|
|
1982
|
+
case 2:
|
|
1983
|
+
chainId = _b;
|
|
1984
|
+
this.backfillActiveWallet(validAddress, chainId);
|
|
1985
|
+
return [2 /*return*/, {
|
|
1986
|
+
chainId: chainId,
|
|
1987
|
+
data: data,
|
|
1988
|
+
address: validAddress,
|
|
1989
|
+
to: to,
|
|
1990
|
+
value: value,
|
|
1991
|
+
}];
|
|
1943
1992
|
}
|
|
1944
1993
|
});
|
|
1945
1994
|
});
|
|
1946
1995
|
};
|
|
1996
|
+
/**
|
|
1997
|
+
* Persist an EVM address discovered through autocapture (signature / transaction)
|
|
1998
|
+
* as the current EVM address when none is currently set. This lets subsequent
|
|
1999
|
+
* track()/page() calls carry the address even when the underlying wallet never
|
|
2000
|
+
* fires an EIP-1193 `accountsChanged` event (embedded wallets, smart accounts,
|
|
2001
|
+
* social-login wrappers). If `accountsChanged` later fires it overwrites this
|
|
2002
|
+
* value in the normal way; existing connections are never clobbered.
|
|
2003
|
+
*/
|
|
2004
|
+
FormoAnalytics.prototype.backfillActiveWallet = function (address, chainId) {
|
|
2005
|
+
if (this._evmAddress)
|
|
2006
|
+
return;
|
|
2007
|
+
this.setChainState('evm', { address: address, chainId: chainId });
|
|
2008
|
+
};
|
|
1947
2009
|
/**
|
|
1948
2010
|
* Polls for transaction receipt and emits tx.status = CONFIRMED or REVERTED.
|
|
1949
2011
|
*/
|
|
@@ -2143,6 +2205,7 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
2143
2205
|
if (state.address || state.chainId) {
|
|
2144
2206
|
this.currentAddress = state.address;
|
|
2145
2207
|
this.currentChainId = state.chainId;
|
|
2208
|
+
this.persistActiveWallet();
|
|
2146
2209
|
return;
|
|
2147
2210
|
}
|
|
2148
2211
|
}
|
|
@@ -2153,10 +2216,65 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
2153
2216
|
this.currentAddress = otherState.address;
|
|
2154
2217
|
this.currentChainId = otherState.chainId;
|
|
2155
2218
|
this._activeNamespace = other;
|
|
2219
|
+
this.persistActiveWallet();
|
|
2156
2220
|
return;
|
|
2157
2221
|
}
|
|
2158
2222
|
this.currentAddress = undefined;
|
|
2159
2223
|
this.currentChainId = undefined;
|
|
2224
|
+
this.persistActiveWallet();
|
|
2225
|
+
};
|
|
2226
|
+
/**
|
|
2227
|
+
* Persist (or clear) the current wallet snapshot in a cookie so that the
|
|
2228
|
+
* SDK can repopulate `currentAddress`/`currentChainId` at init on the next
|
|
2229
|
+
* page load — closing the gap between page-show and wagmi/EIP-1193
|
|
2230
|
+
* reconnection during which track()/page() events would otherwise ship
|
|
2231
|
+
* with an empty address.
|
|
2232
|
+
*/
|
|
2233
|
+
FormoAnalytics.prototype.persistActiveWallet = function () {
|
|
2234
|
+
try {
|
|
2235
|
+
if (this.currentAddress) {
|
|
2236
|
+
var value = JSON.stringify(__assign({ address: this.currentAddress }, (this.currentChainId !== undefined && { chainId: this.currentChainId })));
|
|
2237
|
+
var domain = getIdentityCookieDomain(this.crossSubdomainCookies);
|
|
2238
|
+
cookie().set(ACTIVE_WALLET_KEY, value, __assign({ path: "/", expires: new Date(Date.now() + ACTIVE_WALLET_TTL_MS).toUTCString() }, (domain ? { domain: domain } : {})));
|
|
2239
|
+
}
|
|
2240
|
+
else {
|
|
2241
|
+
cookie().remove(ACTIVE_WALLET_KEY);
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
catch (err) {
|
|
2245
|
+
logger.warn("Failed to persist current wallet snapshot", err);
|
|
2246
|
+
}
|
|
2247
|
+
};
|
|
2248
|
+
/**
|
|
2249
|
+
* Seed `currentAddress`/`currentChainId` from the persisted snapshot, if
|
|
2250
|
+
* any. Called once during construction before the first page hit fires.
|
|
2251
|
+
*/
|
|
2252
|
+
FormoAnalytics.prototype.loadActiveWallet = function () {
|
|
2253
|
+
try {
|
|
2254
|
+
var raw = cookie().get(ACTIVE_WALLET_KEY);
|
|
2255
|
+
if (!raw)
|
|
2256
|
+
return;
|
|
2257
|
+
var parsed = JSON.parse(raw);
|
|
2258
|
+
if (!(parsed === null || parsed === void 0 ? void 0 : parsed.address))
|
|
2259
|
+
return;
|
|
2260
|
+
var namespace = isSolanaChainId(parsed.chainId) ? "solana" : "evm";
|
|
2261
|
+
var validated = validateAddress(parsed.address, parsed.chainId);
|
|
2262
|
+
if (!validated) {
|
|
2263
|
+
cookie().remove(ACTIVE_WALLET_KEY);
|
|
2264
|
+
return;
|
|
2265
|
+
}
|
|
2266
|
+
var ns = this._chainState[namespace];
|
|
2267
|
+
ns.address = validated;
|
|
2268
|
+
if (parsed.chainId !== undefined)
|
|
2269
|
+
ns.chainId = parsed.chainId;
|
|
2270
|
+
this._activeNamespace = namespace;
|
|
2271
|
+
this.currentAddress = validated;
|
|
2272
|
+
this.currentChainId = parsed.chainId;
|
|
2273
|
+
}
|
|
2274
|
+
catch (err) {
|
|
2275
|
+
logger.warn("Failed to restore persisted wallet snapshot", err);
|
|
2276
|
+
cookie().remove(ACTIVE_WALLET_KEY);
|
|
2277
|
+
}
|
|
2160
2278
|
};
|
|
2161
2279
|
/**
|
|
2162
2280
|
* Helper method to clear the active provider state
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
export declare const SESSION_TRAFFIC_SOURCE_KEY = "traffic-source";
|
|
2
2
|
export declare const SESSION_USER_ID_KEY = "user-id";
|
|
3
|
+
/**
|
|
4
|
+
* Persisted snapshot of the currently-active EVM/Solana wallet
|
|
5
|
+
* (address + chainId). Lets the SDK seed `currentAddress`/`currentChainId`
|
|
6
|
+
* at init so the first page hit after a reload carries the address, without
|
|
7
|
+
* having to wait for wagmi/EIP-1193 reconnection to fire.
|
|
8
|
+
*/
|
|
9
|
+
export declare const ACTIVE_WALLET_KEY = "active-wallet";
|
|
10
|
+
/** TTL for the persisted active-wallet snapshot cookie. */
|
|
11
|
+
export declare const ACTIVE_WALLET_TTL_MS: number;
|
|
3
12
|
export declare const LOCAL_ANONYMOUS_ID_KEY = "anonymous-id";
|
|
4
13
|
export declare const CONSENT_OPT_OUT_KEY = "opt-out-tracking";
|
|
5
14
|
export declare const DEFAULT_PROVIDER_ICON = "data:image/svg+xml;base64,";
|
|
@@ -2,6 +2,15 @@ export var SESSION_TRAFFIC_SOURCE_KEY = "traffic-source";
|
|
|
2
2
|
// SESSION_WALLET_DETECTED_KEY and SESSION_WALLET_IDENTIFIED_KEY
|
|
3
3
|
// are now defined in src/session/index.ts
|
|
4
4
|
export var SESSION_USER_ID_KEY = "user-id";
|
|
5
|
+
/**
|
|
6
|
+
* Persisted snapshot of the currently-active EVM/Solana wallet
|
|
7
|
+
* (address + chainId). Lets the SDK seed `currentAddress`/`currentChainId`
|
|
8
|
+
* at init so the first page hit after a reload carries the address, without
|
|
9
|
+
* having to wait for wagmi/EIP-1193 reconnection to fire.
|
|
10
|
+
*/
|
|
11
|
+
export var ACTIVE_WALLET_KEY = "active-wallet";
|
|
12
|
+
/** TTL for the persisted active-wallet snapshot cookie. */
|
|
13
|
+
export var ACTIVE_WALLET_TTL_MS = 24 * 60 * 60 * 1000;
|
|
5
14
|
export var LOCAL_ANONYMOUS_ID_KEY = "anonymous-id";
|
|
6
15
|
// Consent management keys
|
|
7
16
|
export var CONSENT_OPT_OUT_KEY = "opt-out-tracking";
|