@formo/analytics 1.20.0 → 1.21.0
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.js +108 -81
- package/dist/cjs/src/lib/browser/browsers.d.ts +3 -0
- package/dist/cjs/src/lib/browser/browsers.js +132 -0
- package/dist/cjs/src/lib/event/EventFactory.d.ts +10 -10
- package/dist/cjs/src/lib/event/EventFactory.js +272 -140
- package/dist/cjs/src/lib/event/EventManager.d.ts +1 -1
- package/dist/cjs/src/lib/event/EventManager.js +61 -14
- package/dist/cjs/src/lib/event/type.d.ts +2 -2
- package/dist/esm/src/FormoAnalytics.js +108 -81
- package/dist/esm/src/lib/browser/browsers.d.ts +3 -0
- package/dist/esm/src/lib/browser/browsers.js +129 -0
- package/dist/esm/src/lib/event/EventFactory.d.ts +10 -10
- package/dist/esm/src/lib/event/EventFactory.js +272 -140
- package/dist/esm/src/lib/event/EventManager.d.ts +1 -1
- package/dist/esm/src/lib/event/EventManager.js +61 -14
- package/dist/esm/src/lib/event/type.d.ts +2 -2
- package/dist/index.umd.min.js +1 -1
- package/package.json +2 -2
|
@@ -71,7 +71,7 @@ var chain_1 = require("./utils/chain");
|
|
|
71
71
|
var PROVIDER_SWITCH_REASONS = {
|
|
72
72
|
ADDRESS_MISMATCH: "Address mismatch indicates wallet switch",
|
|
73
73
|
NO_ACCOUNTS: "Current provider has no accounts",
|
|
74
|
-
CHECK_FAILED: "Could not check current provider accounts"
|
|
74
|
+
CHECK_FAILED: "Could not check current provider accounts",
|
|
75
75
|
};
|
|
76
76
|
var FormoAnalytics = /** @class */ (function () {
|
|
77
77
|
function FormoAnalytics(writeKey, options) {
|
|
@@ -136,7 +136,7 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
136
136
|
if (optProvider) {
|
|
137
137
|
provider = optProvider;
|
|
138
138
|
}
|
|
139
|
-
else if (typeof window !==
|
|
139
|
+
else if (typeof window !== "undefined" && window.ethereum) {
|
|
140
140
|
provider = window.ethereum;
|
|
141
141
|
}
|
|
142
142
|
if (provider) {
|
|
@@ -163,9 +163,9 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
163
163
|
FormoAnalytics.prototype.isProviderInValidState = function (provider) {
|
|
164
164
|
// Basic validation: ensure provider exists and has required methods
|
|
165
165
|
return (provider &&
|
|
166
|
-
typeof provider.request ===
|
|
167
|
-
typeof provider.on ===
|
|
168
|
-
typeof provider.removeListener ===
|
|
166
|
+
typeof provider.request === "function" &&
|
|
167
|
+
typeof provider.on === "function" &&
|
|
168
|
+
typeof provider.removeListener === "function");
|
|
169
169
|
};
|
|
170
170
|
FormoAnalytics.init = function (writeKey, options) {
|
|
171
171
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -284,16 +284,18 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
284
284
|
case 0:
|
|
285
285
|
chainId = (params === null || params === void 0 ? void 0 : params.chainId) || this.currentChainId;
|
|
286
286
|
address = (params === null || params === void 0 ? void 0 : params.address) || this.currentAddress;
|
|
287
|
-
providerInfo = this._provider
|
|
287
|
+
providerInfo = this._provider
|
|
288
|
+
? this.getProviderInfo(this._provider)
|
|
289
|
+
: null;
|
|
288
290
|
lib_1.logger.info("Disconnect: Emitting disconnect event with:", {
|
|
289
291
|
chainId: chainId,
|
|
290
292
|
address: address,
|
|
291
293
|
providerName: providerInfo === null || providerInfo === void 0 ? void 0 : providerInfo.name,
|
|
292
|
-
rdns: providerInfo === null || providerInfo === void 0 ? void 0 : providerInfo.rdns
|
|
294
|
+
rdns: providerInfo === null || providerInfo === void 0 ? void 0 : providerInfo.rdns,
|
|
293
295
|
});
|
|
294
296
|
disconnectProperties = __assign(__assign({}, (providerInfo && {
|
|
295
297
|
providerName: providerInfo.name,
|
|
296
|
-
rdns: providerInfo.rdns
|
|
298
|
+
rdns: providerInfo.rdns,
|
|
297
299
|
})), properties);
|
|
298
300
|
return [4 /*yield*/, this.trackEvent(constants_1.EventType.DISCONNECT, __assign(__assign({}, (chainId && { chainId: chainId })), (address && { address: address })), disconnectProperties, context, callback)];
|
|
299
301
|
case 1:
|
|
@@ -440,9 +442,12 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
440
442
|
validAddress: validAddress_1,
|
|
441
443
|
rdns: providerDetail.info.rdns,
|
|
442
444
|
providerName: providerDetail.info.name,
|
|
443
|
-
isAlreadyIdentified: validAddress_1
|
|
445
|
+
isAlreadyIdentified: validAddress_1
|
|
446
|
+
? this.session.isWalletIdentified(validAddress_1, providerDetail.info.rdns)
|
|
447
|
+
: false,
|
|
444
448
|
});
|
|
445
|
-
if (!(validAddress_1 &&
|
|
449
|
+
if (!(validAddress_1 &&
|
|
450
|
+
!this.session.isWalletIdentified(validAddress_1, providerDetail.info.rdns))) return [3 /*break*/, 5];
|
|
446
451
|
lib_1.logger.info("Auto-identifying", validAddress_1, providerDetail.info.name, providerDetail.info.rdns);
|
|
447
452
|
// NOTE: do not set this.currentAddress without explicit connect or identify
|
|
448
453
|
return [4 /*yield*/, this.identify({
|
|
@@ -486,23 +491,25 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
486
491
|
this.currentUserId = userId;
|
|
487
492
|
(0, lib_1.cookie)().set(constants_1.SESSION_USER_ID_KEY, userId);
|
|
488
493
|
}
|
|
489
|
-
isAlreadyIdentified = validAddress
|
|
494
|
+
isAlreadyIdentified = validAddress
|
|
495
|
+
? this.session.isWalletIdentified(validAddress, rdns || "")
|
|
496
|
+
: false;
|
|
490
497
|
lib_1.logger.debug("Identify: Checking deduplication", {
|
|
491
498
|
validAddress: validAddress,
|
|
492
499
|
rdns: rdns,
|
|
493
500
|
providerName: providerName,
|
|
494
501
|
hasValidAddress: !!validAddress,
|
|
495
502
|
hasRdns: !!rdns,
|
|
496
|
-
isAlreadyIdentified: isAlreadyIdentified
|
|
503
|
+
isAlreadyIdentified: isAlreadyIdentified,
|
|
497
504
|
});
|
|
498
505
|
if (isAlreadyIdentified) {
|
|
499
|
-
lib_1.logger.info("Identify: Wallet ".concat(providerName ||
|
|
506
|
+
lib_1.logger.info("Identify: Wallet ".concat(providerName || "Unknown", " with address ").concat(validAddress, " already identified in this session (rdns: ").concat(rdns || "empty", ")"));
|
|
500
507
|
return [2 /*return*/];
|
|
501
508
|
}
|
|
502
509
|
// Mark as identified before emitting the event
|
|
503
510
|
// Mark even if rdns is empty to prevent duplicate empty identifies
|
|
504
511
|
if (validAddress) {
|
|
505
|
-
this.session.markWalletIdentified(validAddress, rdns ||
|
|
512
|
+
this.session.markWalletIdentified(validAddress, rdns || "");
|
|
506
513
|
}
|
|
507
514
|
return [4 /*yield*/, this.trackEvent(constants_1.EventType.IDENTIFY, {
|
|
508
515
|
address: validAddress,
|
|
@@ -670,7 +677,7 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
670
677
|
// Prevent concurrent processing of accountsChanged events to avoid race conditions
|
|
671
678
|
if (this._processingAccountsChanged) {
|
|
672
679
|
lib_1.logger.debug("OnAccountsChanged: Already processing accountsChanged, skipping", {
|
|
673
|
-
provider: this.getProviderInfo(provider).name
|
|
680
|
+
provider: this.getProviderInfo(provider).name,
|
|
674
681
|
});
|
|
675
682
|
return [2 /*return*/];
|
|
676
683
|
}
|
|
@@ -711,7 +718,7 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
711
718
|
lib_1.logger.info("OnAccountsChanged: Detecting disconnect, current state:", {
|
|
712
719
|
currentAddress: this.currentAddress,
|
|
713
720
|
currentChainId: this.currentChainId,
|
|
714
|
-
providerMatch: this._provider === provider
|
|
721
|
+
providerMatch: this._provider === provider,
|
|
715
722
|
});
|
|
716
723
|
_a.label = 1;
|
|
717
724
|
case 1:
|
|
@@ -719,7 +726,7 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
719
726
|
// Pass current state explicitly to ensure we have the data for the disconnect event
|
|
720
727
|
return [4 /*yield*/, this.disconnect({
|
|
721
728
|
chainId: this.currentChainId,
|
|
722
|
-
address: this.currentAddress
|
|
729
|
+
address: this.currentAddress,
|
|
723
730
|
})];
|
|
724
731
|
case 2:
|
|
725
732
|
// Pass current state explicitly to ensure we have the data for the disconnect event
|
|
@@ -747,7 +754,7 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
747
754
|
activeProvider: this.getProviderInfo(this._provider).name,
|
|
748
755
|
eventProvider: this.getProviderInfo(provider).name,
|
|
749
756
|
currentStoredAddress: currentStoredAddress,
|
|
750
|
-
newProviderAddress: newProviderAddress
|
|
757
|
+
newProviderAddress: newProviderAddress,
|
|
751
758
|
});
|
|
752
759
|
_a.label = 8;
|
|
753
760
|
case 8:
|
|
@@ -757,22 +764,26 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
757
764
|
activeProviderAccounts = _a.sent();
|
|
758
765
|
lib_1.logger.info("OnAccountsChanged: Checking current provider accounts", {
|
|
759
766
|
activeProvider: this.getProviderInfo(this._provider).name,
|
|
760
|
-
accountsLength: activeProviderAccounts
|
|
761
|
-
|
|
767
|
+
accountsLength: activeProviderAccounts
|
|
768
|
+
? activeProviderAccounts.length
|
|
769
|
+
: 0,
|
|
770
|
+
accounts: activeProviderAccounts,
|
|
762
771
|
});
|
|
763
772
|
if (!(activeProviderAccounts && activeProviderAccounts.length > 0)) return [3 /*break*/, 13];
|
|
764
|
-
if (!(newProviderAddress &&
|
|
773
|
+
if (!(newProviderAddress &&
|
|
774
|
+
currentStoredAddress &&
|
|
775
|
+
newProviderAddress !== currentStoredAddress)) return [3 /*break*/, 11];
|
|
765
776
|
lib_1.logger.info("OnAccountsChanged: Different address detected, switching providers despite current provider having accounts", {
|
|
766
777
|
activeProvider: this.getProviderInfo(this._provider).name,
|
|
767
778
|
eventProvider: this.getProviderInfo(provider).name,
|
|
768
779
|
currentAddress: currentStoredAddress,
|
|
769
780
|
newAddress: newProviderAddress,
|
|
770
|
-
reason: PROVIDER_SWITCH_REASONS.ADDRESS_MISMATCH
|
|
781
|
+
reason: PROVIDER_SWITCH_REASONS.ADDRESS_MISMATCH,
|
|
771
782
|
});
|
|
772
783
|
// Emit disconnect for the old provider
|
|
773
784
|
return [4 /*yield*/, this.disconnect({
|
|
774
785
|
chainId: this.currentChainId,
|
|
775
|
-
address: this.currentAddress
|
|
786
|
+
address: this.currentAddress,
|
|
776
787
|
})];
|
|
777
788
|
case 10:
|
|
778
789
|
// Emit disconnect for the old provider
|
|
@@ -786,7 +797,7 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
786
797
|
eventProvider: this.getProviderInfo(provider).name,
|
|
787
798
|
activeProviderAccountsCount: activeProviderAccounts.length,
|
|
788
799
|
currentAddress: currentStoredAddress,
|
|
789
|
-
newAddress: newProviderAddress
|
|
800
|
+
newAddress: newProviderAddress,
|
|
790
801
|
});
|
|
791
802
|
return [2 /*return*/];
|
|
792
803
|
case 12: return [3 /*break*/, 15];
|
|
@@ -794,12 +805,12 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
794
805
|
lib_1.logger.info("OnAccountsChanged: Current provider has no accounts, switching to new provider", {
|
|
795
806
|
oldProvider: this.getProviderInfo(this._provider).name,
|
|
796
807
|
newProvider: this.getProviderInfo(provider).name,
|
|
797
|
-
reason: PROVIDER_SWITCH_REASONS.NO_ACCOUNTS
|
|
808
|
+
reason: PROVIDER_SWITCH_REASONS.NO_ACCOUNTS,
|
|
798
809
|
});
|
|
799
810
|
// Emit disconnect for the old provider that didn't signal properly
|
|
800
811
|
return [4 /*yield*/, this.disconnect({
|
|
801
812
|
chainId: this.currentChainId,
|
|
802
|
-
address: this.currentAddress
|
|
813
|
+
address: this.currentAddress,
|
|
803
814
|
})];
|
|
804
815
|
case 14:
|
|
805
816
|
// Emit disconnect for the old provider that didn't signal properly
|
|
@@ -813,14 +824,16 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
813
824
|
lib_1.logger.warn("OnAccountsChanged: Could not check current provider accounts, switching to new provider", {
|
|
814
825
|
error: error_2 instanceof Error ? error_2.message : String(error_2),
|
|
815
826
|
errorType: error_2 instanceof Error ? error_2.constructor.name : typeof error_2,
|
|
816
|
-
oldProvider: this._provider
|
|
827
|
+
oldProvider: this._provider
|
|
828
|
+
? this.getProviderInfo(this._provider).name
|
|
829
|
+
: "unknown",
|
|
817
830
|
newProvider: this.getProviderInfo(provider).name,
|
|
818
|
-
reason: PROVIDER_SWITCH_REASONS.CHECK_FAILED
|
|
831
|
+
reason: PROVIDER_SWITCH_REASONS.CHECK_FAILED,
|
|
819
832
|
});
|
|
820
833
|
// If we can't check the current provider, assume it's disconnected
|
|
821
834
|
return [4 /*yield*/, this.disconnect({
|
|
822
835
|
chainId: this.currentChainId,
|
|
823
|
-
address: this.currentAddress
|
|
836
|
+
address: this.currentAddress,
|
|
824
837
|
})];
|
|
825
838
|
case 17:
|
|
826
839
|
// If we can't check the current provider, assume it's disconnected
|
|
@@ -849,7 +862,7 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
849
862
|
wasDisconnected: wasDisconnected,
|
|
850
863
|
providerName: providerInfo.name,
|
|
851
864
|
rdns: providerInfo.rdns,
|
|
852
|
-
hasChainId: !!nextChainId
|
|
865
|
+
hasChainId: !!nextChainId,
|
|
853
866
|
});
|
|
854
867
|
effectiveChainId = nextChainId || 0;
|
|
855
868
|
if (effectiveChainId === 0) {
|
|
@@ -857,10 +870,10 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
857
870
|
}
|
|
858
871
|
this.connect({
|
|
859
872
|
chainId: effectiveChainId,
|
|
860
|
-
address: address
|
|
873
|
+
address: address,
|
|
861
874
|
}, {
|
|
862
875
|
providerName: providerInfo.name,
|
|
863
|
-
rdns: providerInfo.rdns
|
|
876
|
+
rdns: providerInfo.rdns,
|
|
864
877
|
}).catch(function (error) {
|
|
865
878
|
lib_1.logger.error("Failed to track connect event during account change:", error);
|
|
866
879
|
});
|
|
@@ -942,7 +955,7 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
942
955
|
return [2 /*return*/];
|
|
943
956
|
lib_1.logger.info("OnDisconnect: Wallet disconnect event received, current state:", {
|
|
944
957
|
currentAddress: this.currentAddress,
|
|
945
|
-
currentChainId: this.currentChainId
|
|
958
|
+
currentChainId: this.currentChainId,
|
|
946
959
|
});
|
|
947
960
|
_a.label = 1;
|
|
948
961
|
case 1:
|
|
@@ -950,7 +963,7 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
950
963
|
// Pass current state explicitly to ensure we have the data for the disconnect event
|
|
951
964
|
return [4 /*yield*/, this.disconnect({
|
|
952
965
|
chainId: this.currentChainId,
|
|
953
|
-
address: this.currentAddress
|
|
966
|
+
address: this.currentAddress,
|
|
954
967
|
})];
|
|
955
968
|
case 2:
|
|
956
969
|
// Pass current state explicitly to ensure we have the data for the disconnect event
|
|
@@ -977,7 +990,7 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
977
990
|
_a.label = 1;
|
|
978
991
|
case 1:
|
|
979
992
|
_a.trys.push([1, 3, , 4]);
|
|
980
|
-
if (!(connection === null || connection === void 0 ? void 0 : connection.chainId) || typeof connection.chainId !==
|
|
993
|
+
if (!(connection === null || connection === void 0 ? void 0 : connection.chainId) || typeof connection.chainId !== "string")
|
|
981
994
|
return [2 /*return*/];
|
|
982
995
|
chainId = (0, chain_1.parseChainId)(connection.chainId);
|
|
983
996
|
return [4 /*yield*/, this.getAddress(provider)];
|
|
@@ -993,7 +1006,8 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
993
1006
|
// Only update global state (chainId/address) from the active provider
|
|
994
1007
|
if (isActiveProvider) {
|
|
995
1008
|
this.currentChainId = chainId;
|
|
996
|
-
this.currentAddress =
|
|
1009
|
+
this.currentAddress =
|
|
1010
|
+
this.validateAndChecksumAddress(address) || undefined;
|
|
997
1011
|
}
|
|
998
1012
|
if (isActiveProvider && this.currentAddress) {
|
|
999
1013
|
providerInfo = this.getProviderInfo(provider);
|
|
@@ -1003,7 +1017,7 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
1003
1017
|
providerName: providerInfo.name,
|
|
1004
1018
|
rdns: providerInfo.rdns,
|
|
1005
1019
|
hasChainId: !!chainId,
|
|
1006
|
-
isActiveProvider: isActiveProvider
|
|
1020
|
+
isActiveProvider: isActiveProvider,
|
|
1007
1021
|
});
|
|
1008
1022
|
effectiveChainId = chainId || 0;
|
|
1009
1023
|
if (effectiveChainId === 0) {
|
|
@@ -1011,10 +1025,10 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
1011
1025
|
}
|
|
1012
1026
|
this.connect({
|
|
1013
1027
|
chainId: effectiveChainId,
|
|
1014
|
-
address: address
|
|
1028
|
+
address: address,
|
|
1015
1029
|
}, {
|
|
1016
1030
|
providerName: providerInfo.name,
|
|
1017
|
-
rdns: providerInfo.rdns
|
|
1031
|
+
rdns: providerInfo.rdns,
|
|
1018
1032
|
}).catch(function (error) {
|
|
1019
1033
|
lib_1.logger.error("Failed to track connect event during provider connection:", error);
|
|
1020
1034
|
});
|
|
@@ -1026,7 +1040,9 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
1026
1040
|
providerName: providerInfo.name,
|
|
1027
1041
|
rdns: providerInfo.rdns,
|
|
1028
1042
|
isActiveProvider: isActiveProvider,
|
|
1029
|
-
activeProviderInfo: this._provider
|
|
1043
|
+
activeProviderInfo: this._provider
|
|
1044
|
+
? this.getProviderInfo(this._provider)
|
|
1045
|
+
: null,
|
|
1030
1046
|
});
|
|
1031
1047
|
}
|
|
1032
1048
|
}
|
|
@@ -1208,7 +1224,8 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
1208
1224
|
}); };
|
|
1209
1225
|
// Mark the wrapper so we can detect if request is replaced externally and keep a reference on provider
|
|
1210
1226
|
wrappedRequest[types_1.WRAPPED_REQUEST_SYMBOL] = true;
|
|
1211
|
-
provider[types_1.WRAPPED_REQUEST_REF_SYMBOL] =
|
|
1227
|
+
provider[types_1.WRAPPED_REQUEST_REF_SYMBOL] =
|
|
1228
|
+
wrappedRequest;
|
|
1212
1229
|
try {
|
|
1213
1230
|
// Attempt to assign the wrapped request function (rely on try-catch for mutability errors)
|
|
1214
1231
|
provider.request = wrappedRequest;
|
|
@@ -1298,18 +1315,25 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
1298
1315
|
};
|
|
1299
1316
|
FormoAnalytics.prototype.trackEvent = function (type, payload, properties, context, callback) {
|
|
1300
1317
|
return __awaiter(this, void 0, void 0, function () {
|
|
1318
|
+
var error_5;
|
|
1301
1319
|
return __generator(this, function (_a) {
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1320
|
+
switch (_a.label) {
|
|
1321
|
+
case 0:
|
|
1322
|
+
_a.trys.push([0, 2, , 3]);
|
|
1323
|
+
if (!this.shouldTrack()) {
|
|
1324
|
+
lib_1.logger.info("Skipping ".concat(type, " event due to tracking configuration"));
|
|
1325
|
+
return [2 /*return*/];
|
|
1326
|
+
}
|
|
1327
|
+
return [4 /*yield*/, this.eventManager.addEvent(__assign(__assign({ type: type }, payload), { properties: properties, context: context, callback: callback }), this.currentAddress, this.currentUserId)];
|
|
1328
|
+
case 1:
|
|
1329
|
+
_a.sent();
|
|
1330
|
+
return [3 /*break*/, 3];
|
|
1331
|
+
case 2:
|
|
1332
|
+
error_5 = _a.sent();
|
|
1333
|
+
lib_1.logger.error("Error tracking event:", error_5);
|
|
1334
|
+
return [3 /*break*/, 3];
|
|
1335
|
+
case 3: return [2 /*return*/];
|
|
1311
1336
|
}
|
|
1312
|
-
return [2 /*return*/];
|
|
1313
1337
|
});
|
|
1314
1338
|
});
|
|
1315
1339
|
};
|
|
@@ -1323,23 +1347,23 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
1323
1347
|
return false;
|
|
1324
1348
|
}
|
|
1325
1349
|
// Check if tracking is explicitly provided as a boolean
|
|
1326
|
-
if (typeof this.options.tracking ===
|
|
1350
|
+
if (typeof this.options.tracking === "boolean") {
|
|
1327
1351
|
return this.options.tracking;
|
|
1328
1352
|
}
|
|
1329
1353
|
// Handle object configuration with exclusion rules
|
|
1330
1354
|
if (this.options.tracking !== null &&
|
|
1331
|
-
typeof this.options.tracking ===
|
|
1355
|
+
typeof this.options.tracking === "object" &&
|
|
1332
1356
|
!Array.isArray(this.options.tracking)) {
|
|
1333
1357
|
var _a = this.options.tracking, _b = _a.excludeHosts, excludeHosts = _b === void 0 ? [] : _b, _c = _a.excludePaths, excludePaths = _c === void 0 ? [] : _c, _d = _a.excludeChains, excludeChains = _d === void 0 ? [] : _d;
|
|
1334
1358
|
// Check hostname exclusions - use exact matching
|
|
1335
|
-
if (excludeHosts.length > 0 && typeof window !==
|
|
1359
|
+
if (excludeHosts.length > 0 && typeof window !== "undefined") {
|
|
1336
1360
|
var hostname = window.location.hostname;
|
|
1337
1361
|
if (excludeHosts.includes(hostname)) {
|
|
1338
1362
|
return false;
|
|
1339
1363
|
}
|
|
1340
1364
|
}
|
|
1341
1365
|
// Check path exclusions - use exact matching
|
|
1342
|
-
if (excludePaths.length > 0 && typeof window !==
|
|
1366
|
+
if (excludePaths.length > 0 && typeof window !== "undefined") {
|
|
1343
1367
|
var pathname = window.location.pathname;
|
|
1344
1368
|
if (excludePaths.includes(pathname)) {
|
|
1345
1369
|
return false;
|
|
@@ -1371,14 +1395,14 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
1371
1395
|
if (eip6963Provider) {
|
|
1372
1396
|
return {
|
|
1373
1397
|
name: eip6963Provider.info.name,
|
|
1374
|
-
rdns: eip6963Provider.info.rdns
|
|
1398
|
+
rdns: eip6963Provider.info.rdns,
|
|
1375
1399
|
};
|
|
1376
1400
|
}
|
|
1377
1401
|
// Fallback to injected provider detection
|
|
1378
1402
|
var injectedInfo = this.detectInjectedProviderInfo(provider);
|
|
1379
1403
|
return {
|
|
1380
1404
|
name: injectedInfo.name,
|
|
1381
|
-
rdns: injectedInfo.rdns
|
|
1405
|
+
rdns: injectedInfo.rdns,
|
|
1382
1406
|
};
|
|
1383
1407
|
};
|
|
1384
1408
|
/**
|
|
@@ -1388,45 +1412,45 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
1388
1412
|
*/
|
|
1389
1413
|
FormoAnalytics.prototype.detectInjectedProviderInfo = function (provider) {
|
|
1390
1414
|
// Try to detect provider type from common properties
|
|
1391
|
-
var name =
|
|
1392
|
-
var rdns =
|
|
1415
|
+
var name = "Injected Provider";
|
|
1416
|
+
var rdns = "io.injected.provider";
|
|
1393
1417
|
// Use WalletProviderFlags interface for type safety
|
|
1394
1418
|
var flags = provider;
|
|
1395
1419
|
// Check if it's MetaMask
|
|
1396
1420
|
if (flags.isMetaMask) {
|
|
1397
|
-
name =
|
|
1398
|
-
rdns =
|
|
1421
|
+
name = "MetaMask";
|
|
1422
|
+
rdns = "io.metamask";
|
|
1399
1423
|
}
|
|
1400
1424
|
// Check if it's Coinbase Wallet
|
|
1401
1425
|
else if (flags.isCoinbaseWallet) {
|
|
1402
|
-
name =
|
|
1403
|
-
rdns =
|
|
1426
|
+
name = "Coinbase Wallet";
|
|
1427
|
+
rdns = "com.coinbase.wallet";
|
|
1404
1428
|
}
|
|
1405
1429
|
// Check if it's WalletConnect
|
|
1406
1430
|
else if (flags.isWalletConnect) {
|
|
1407
|
-
name =
|
|
1408
|
-
rdns =
|
|
1431
|
+
name = "WalletConnect";
|
|
1432
|
+
rdns = "com.walletconnect";
|
|
1409
1433
|
}
|
|
1410
1434
|
// Check if it's Trust Wallet
|
|
1411
1435
|
else if (flags.isTrust) {
|
|
1412
|
-
name =
|
|
1413
|
-
rdns =
|
|
1436
|
+
name = "Trust Wallet";
|
|
1437
|
+
rdns = "com.trustwallet";
|
|
1414
1438
|
}
|
|
1415
1439
|
// Check if it's Brave Wallet
|
|
1416
1440
|
else if (flags.isBraveWallet) {
|
|
1417
|
-
name =
|
|
1418
|
-
rdns =
|
|
1441
|
+
name = "Brave Wallet";
|
|
1442
|
+
rdns = "com.brave.wallet";
|
|
1419
1443
|
}
|
|
1420
1444
|
// Check if it's Phantom
|
|
1421
1445
|
else if (flags.isPhantom) {
|
|
1422
|
-
name =
|
|
1423
|
-
rdns =
|
|
1446
|
+
name = "Phantom";
|
|
1447
|
+
rdns = "app.phantom";
|
|
1424
1448
|
}
|
|
1425
1449
|
return {
|
|
1426
1450
|
name: name,
|
|
1427
1451
|
rdns: rdns,
|
|
1428
|
-
uuid: "injected-".concat(rdns.replace(/[^a-zA-Z0-9]/g,
|
|
1429
|
-
icon: constants_1.DEFAULT_PROVIDER_ICON
|
|
1452
|
+
uuid: "injected-".concat(rdns.replace(/[^a-zA-Z0-9]/g, "-")),
|
|
1453
|
+
icon: constants_1.DEFAULT_PROVIDER_ICON,
|
|
1430
1454
|
};
|
|
1431
1455
|
};
|
|
1432
1456
|
FormoAnalytics.prototype.getProviders = function () {
|
|
@@ -1480,7 +1504,7 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
1480
1504
|
});
|
|
1481
1505
|
// Fallback to injected provider if no providers are found
|
|
1482
1506
|
if (providers.length === 0) {
|
|
1483
|
-
injected_1 = typeof window !==
|
|
1507
|
+
injected_1 = typeof window !== "undefined" ? window.ethereum : undefined;
|
|
1484
1508
|
if (injected_1) {
|
|
1485
1509
|
// If we have already detected and cached the injected provider, and it's the same instance, return the cached result
|
|
1486
1510
|
if (this._injectedProviderDetail &&
|
|
@@ -1491,7 +1515,9 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
1491
1515
|
}
|
|
1492
1516
|
// Merge with existing providers instead of overwriting
|
|
1493
1517
|
if (!this._providers.some(function (existing) { return existing.provider === injected_1; })) {
|
|
1494
|
-
this._providers = __spreadArray(__spreadArray([], this._providers, true), [
|
|
1518
|
+
this._providers = __spreadArray(__spreadArray([], this._providers, true), [
|
|
1519
|
+
this._injectedProviderDetail,
|
|
1520
|
+
], false);
|
|
1495
1521
|
}
|
|
1496
1522
|
return [2 /*return*/, this._providers];
|
|
1497
1523
|
}
|
|
@@ -1502,7 +1528,7 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
1502
1528
|
injectedProviderInfo = this.detectInjectedProviderInfo(injected_1);
|
|
1503
1529
|
injectedDetail = {
|
|
1504
1530
|
provider: injected_1,
|
|
1505
|
-
info: injectedProviderInfo
|
|
1531
|
+
info: injectedProviderInfo,
|
|
1506
1532
|
};
|
|
1507
1533
|
// Cache the detected injected provider detail
|
|
1508
1534
|
this._injectedProviderDetail = injectedDetail;
|
|
@@ -1841,9 +1867,10 @@ var FormoAnalytics = /** @class */ (function () {
|
|
|
1841
1867
|
*/
|
|
1842
1868
|
FormoAnalytics.prototype.isProviderAlreadyWrapped = function (provider, currentRequest) {
|
|
1843
1869
|
return !!(currentRequest &&
|
|
1844
|
-
typeof currentRequest ===
|
|
1870
|
+
typeof currentRequest === "function" &&
|
|
1845
1871
|
currentRequest[types_1.WRAPPED_REQUEST_SYMBOL] &&
|
|
1846
|
-
provider[types_1.WRAPPED_REQUEST_REF_SYMBOL] ===
|
|
1872
|
+
provider[types_1.WRAPPED_REQUEST_REF_SYMBOL] ===
|
|
1873
|
+
currentRequest);
|
|
1847
1874
|
};
|
|
1848
1875
|
/**
|
|
1849
1876
|
* Handle provider mismatch by switching to the new provider and invalidating old tokens
|
|
@@ -1932,7 +1959,7 @@ var FormoAnalyticsSession = /** @class */ (function () {
|
|
|
1932
1959
|
lib_1.logger.debug("Session: Checking wallet identification", {
|
|
1933
1960
|
identifiedKey: identifiedKey,
|
|
1934
1961
|
isIdentified: isIdentified,
|
|
1935
|
-
hasRdns: !!rdns
|
|
1962
|
+
hasRdns: !!rdns,
|
|
1936
1963
|
});
|
|
1937
1964
|
return isIdentified;
|
|
1938
1965
|
};
|
|
@@ -1950,14 +1977,14 @@ var FormoAnalyticsSession = /** @class */ (function () {
|
|
|
1950
1977
|
});
|
|
1951
1978
|
lib_1.logger.debug("Session: Marked wallet as identified", {
|
|
1952
1979
|
identifiedKey: identifiedKey,
|
|
1953
|
-
hasRdns: !!rdns
|
|
1980
|
+
hasRdns: !!rdns,
|
|
1954
1981
|
});
|
|
1955
1982
|
}
|
|
1956
1983
|
else {
|
|
1957
1984
|
lib_1.logger.info("Session: Wallet already marked as identified", {
|
|
1958
1985
|
identifiedKey: identifiedKey,
|
|
1959
1986
|
existingWallets: identifiedWallets,
|
|
1960
|
-
hasRdns: !!rdns
|
|
1987
|
+
hasRdns: !!rdns,
|
|
1961
1988
|
});
|
|
1962
1989
|
}
|
|
1963
1990
|
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.detectBrowser = detectBrowser;
|
|
40
|
+
var inFlight = null;
|
|
41
|
+
var cached = null;
|
|
42
|
+
function getUA() {
|
|
43
|
+
try {
|
|
44
|
+
return typeof globalThis.navigator !== "undefined"
|
|
45
|
+
? globalThis.navigator.userAgent
|
|
46
|
+
: "";
|
|
47
|
+
}
|
|
48
|
+
catch (_a) {
|
|
49
|
+
return "";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function isBraveHeuristic() {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
54
|
+
var nav, ok, _a, brands;
|
|
55
|
+
var _b, _c;
|
|
56
|
+
return __generator(this, function (_d) {
|
|
57
|
+
switch (_d.label) {
|
|
58
|
+
case 0:
|
|
59
|
+
nav = typeof globalThis.navigator !== "undefined"
|
|
60
|
+
? globalThis.navigator
|
|
61
|
+
: undefined;
|
|
62
|
+
if (!nav)
|
|
63
|
+
return [2 /*return*/, false];
|
|
64
|
+
_d.label = 1;
|
|
65
|
+
case 1:
|
|
66
|
+
_d.trys.push([1, 4, , 5]);
|
|
67
|
+
if (!((_b = nav.brave) === null || _b === void 0 ? void 0 : _b.isBrave)) return [3 /*break*/, 3];
|
|
68
|
+
return [4 /*yield*/, nav.brave.isBrave().catch(function () { return false; })];
|
|
69
|
+
case 2:
|
|
70
|
+
ok = _d.sent();
|
|
71
|
+
if (ok)
|
|
72
|
+
return [2 /*return*/, true];
|
|
73
|
+
_d.label = 3;
|
|
74
|
+
case 3: return [3 /*break*/, 5];
|
|
75
|
+
case 4:
|
|
76
|
+
_a = _d.sent();
|
|
77
|
+
return [3 /*break*/, 5];
|
|
78
|
+
case 5:
|
|
79
|
+
try {
|
|
80
|
+
brands = (_c = nav.userAgentData) === null || _c === void 0 ? void 0 : _c.brands;
|
|
81
|
+
if (brands === null || brands === void 0 ? void 0 : brands.some(function (b) { return /Brave/i.test(b.brand); }))
|
|
82
|
+
return [2 /*return*/, true];
|
|
83
|
+
}
|
|
84
|
+
catch (_e) { }
|
|
85
|
+
try {
|
|
86
|
+
if (/Brave/i.test(nav.userAgent))
|
|
87
|
+
return [2 /*return*/, true];
|
|
88
|
+
}
|
|
89
|
+
catch (_f) { }
|
|
90
|
+
return [2 /*return*/, false];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function classifyNonBrave(ua) {
|
|
96
|
+
if (/Firefox\/\d+/i.test(ua))
|
|
97
|
+
return "firefox";
|
|
98
|
+
if (/Edg\/\d+/i.test(ua))
|
|
99
|
+
return "edge";
|
|
100
|
+
if (/OPR\/\d+/i.test(ua))
|
|
101
|
+
return "opera";
|
|
102
|
+
if (/Safari\/\d+/i.test(ua) && !/Chrome\/\d+/i.test(ua))
|
|
103
|
+
return "safari";
|
|
104
|
+
if (/Chrome\/\d+/i.test(ua))
|
|
105
|
+
return "chrome";
|
|
106
|
+
return "unknown";
|
|
107
|
+
}
|
|
108
|
+
function detectBrowser() {
|
|
109
|
+
var _this = this;
|
|
110
|
+
if (cached)
|
|
111
|
+
return Promise.resolve(cached);
|
|
112
|
+
if (inFlight)
|
|
113
|
+
return inFlight;
|
|
114
|
+
inFlight = (function () { return __awaiter(_this, void 0, void 0, function () {
|
|
115
|
+
var ua, brave;
|
|
116
|
+
return __generator(this, function (_a) {
|
|
117
|
+
switch (_a.label) {
|
|
118
|
+
case 0:
|
|
119
|
+
ua = getUA();
|
|
120
|
+
return [4 /*yield*/, isBraveHeuristic().catch(function () { return false; })];
|
|
121
|
+
case 1:
|
|
122
|
+
brave = _a.sent();
|
|
123
|
+
cached = brave ? "brave" : classifyNonBrave(ua);
|
|
124
|
+
return [2 /*return*/, cached];
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}); })().finally(function () {
|
|
128
|
+
inFlight = null; // subsequent calls hit cache
|
|
129
|
+
});
|
|
130
|
+
return inFlight;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=browsers.js.map
|