@formo/analytics 1.17.9 → 1.18.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.
Files changed (52) hide show
  1. package/README.md +0 -1
  2. package/dist/cjs/src/FormoAnalytics.d.ts +16 -12
  3. package/dist/cjs/src/FormoAnalytics.d.ts.map +1 -1
  4. package/dist/cjs/src/FormoAnalytics.js +208 -153
  5. package/dist/cjs/src/FormoAnalytics.js.map +1 -1
  6. package/dist/cjs/src/lib/event/EventFactory.d.ts +1 -0
  7. package/dist/cjs/src/lib/event/EventFactory.d.ts.map +1 -1
  8. package/dist/cjs/src/lib/event/EventFactory.js +15 -3
  9. package/dist/cjs/src/lib/event/EventFactory.js.map +1 -1
  10. package/dist/cjs/src/types/base.d.ts +15 -8
  11. package/dist/cjs/src/types/base.d.ts.map +1 -1
  12. package/dist/cjs/src/types/events.d.ts +1 -0
  13. package/dist/cjs/src/types/events.d.ts.map +1 -1
  14. package/dist/cjs/src/types/events.js.map +1 -1
  15. package/dist/cjs/src/types/provider.d.ts +3 -0
  16. package/dist/cjs/src/types/provider.d.ts.map +1 -1
  17. package/dist/cjs/src/utils/chain.d.ts +7 -0
  18. package/dist/cjs/src/utils/chain.d.ts.map +1 -0
  19. package/dist/cjs/src/utils/chain.js +17 -0
  20. package/dist/cjs/src/utils/chain.js.map +1 -0
  21. package/dist/cjs/src/validators/address.d.ts +2 -2
  22. package/dist/cjs/src/validators/address.d.ts.map +1 -1
  23. package/dist/cjs/src/validators/address.js +6 -6
  24. package/dist/cjs/src/validators/address.js.map +1 -1
  25. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  26. package/dist/esm/src/FormoAnalytics.d.ts +16 -12
  27. package/dist/esm/src/FormoAnalytics.d.ts.map +1 -1
  28. package/dist/esm/src/FormoAnalytics.js +208 -153
  29. package/dist/esm/src/FormoAnalytics.js.map +1 -1
  30. package/dist/esm/src/lib/event/EventFactory.d.ts +1 -0
  31. package/dist/esm/src/lib/event/EventFactory.d.ts.map +1 -1
  32. package/dist/esm/src/lib/event/EventFactory.js +15 -3
  33. package/dist/esm/src/lib/event/EventFactory.js.map +1 -1
  34. package/dist/esm/src/types/base.d.ts +15 -8
  35. package/dist/esm/src/types/base.d.ts.map +1 -1
  36. package/dist/esm/src/types/events.d.ts +1 -0
  37. package/dist/esm/src/types/events.d.ts.map +1 -1
  38. package/dist/esm/src/types/events.js.map +1 -1
  39. package/dist/esm/src/types/provider.d.ts +3 -0
  40. package/dist/esm/src/types/provider.d.ts.map +1 -1
  41. package/dist/esm/src/utils/chain.d.ts +7 -0
  42. package/dist/esm/src/utils/chain.d.ts.map +1 -0
  43. package/dist/esm/src/utils/chain.js +14 -0
  44. package/dist/esm/src/utils/chain.js.map +1 -0
  45. package/dist/esm/src/validators/address.d.ts +2 -2
  46. package/dist/esm/src/validators/address.d.ts.map +1 -1
  47. package/dist/esm/src/validators/address.js +4 -4
  48. package/dist/esm/src/validators/address.js.map +1 -1
  49. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  50. package/dist/index.umd.min.js +1 -1
  51. package/dist/index.umd.min.js.map +1 -1
  52. package/package.json +1 -1
@@ -50,6 +50,7 @@ import { EVENTS_API_URL, EventType, LOCAL_ANONYMOUS_ID_KEY, SESSION_CURRENT_URL_
50
50
  import { cookie, EventManager, EventQueue, initStorageManager, logger, Logger, } from "./lib";
51
51
  import { SignatureStatus, TransactionStatus, } from "./types";
52
52
  import { isAddress, isLocalhost } from "./validators";
53
+ import { parseChainId } from "./utils/chain";
53
54
  var FormoAnalytics = /** @class */ (function () {
54
55
  function FormoAnalytics(writeKey, options) {
55
56
  if (options === void 0) { options = {}; }
@@ -62,8 +63,8 @@ var FormoAnalytics = /** @class */ (function () {
62
63
  this.currentUserId = "";
63
64
  this.config = {
64
65
  writeKey: writeKey,
65
- trackLocalhost: options.trackLocalhost || false,
66
66
  };
67
+ this.options = options;
67
68
  this.session = new FormoAnalyticsSession();
68
69
  this.currentUserId =
69
70
  cookie().get(SESSION_USER_ID_KEY) || undefined;
@@ -92,7 +93,7 @@ var FormoAnalytics = /** @class */ (function () {
92
93
  if (provider) {
93
94
  this.trackProvider(provider);
94
95
  }
95
- this.trackFirstPageHit();
96
+ this.trackPageHit();
96
97
  this.trackPageHits();
97
98
  }
98
99
  FormoAnalytics.init = function (writeKey, options) {
@@ -126,13 +127,14 @@ var FormoAnalytics = /** @class */ (function () {
126
127
  * @param {string} name - The name of the page
127
128
  * @param {Record<string, any>} properties - Additional properties to include
128
129
  * @param {Record<string, any>} context - Additional context to include
130
+ * @param {(...args: unknown[]) => void} callback - Optional callback function
129
131
  * @returns {Promise<void>}
130
132
  */
131
- FormoAnalytics.prototype.page = function (category, name, properties, context) {
133
+ FormoAnalytics.prototype.page = function (category, name, properties, context, callback) {
132
134
  return __awaiter(this, void 0, void 0, function () {
133
135
  return __generator(this, function (_a) {
134
136
  switch (_a.label) {
135
- case 0: return [4 /*yield*/, this.trackPageHit(category, name, properties, context)];
137
+ case 0: return [4 /*yield*/, this.trackPageHit(category, name, properties, context, callback)];
136
138
  case 1:
137
139
  _a.sent();
138
140
  return [2 /*return*/];
@@ -185,9 +187,9 @@ var FormoAnalytics = /** @class */ (function () {
185
187
  });
186
188
  };
187
189
  /**
188
- * Emits a wallet disconnect event.
189
- * @param {ChainID} params.chainId
190
- * @param {Address} params.address
190
+ * Emits a disconnect wallet event.
191
+ * @param {ChainID} [params.chainId]
192
+ * @param {Address} [params.address]
191
193
  * @param {IFormoEventProperties} properties
192
194
  * @param {IFormoEventContext} context
193
195
  * @param {(...args: unknown[]) => void} callback
@@ -195,15 +197,21 @@ var FormoAnalytics = /** @class */ (function () {
195
197
  */
196
198
  FormoAnalytics.prototype.disconnect = function (params, properties, context, callback) {
197
199
  return __awaiter(this, void 0, void 0, function () {
198
- var address, chainId;
200
+ var chainId, address;
199
201
  return __generator(this, function (_a) {
200
202
  switch (_a.label) {
201
203
  case 0:
202
- address = (params === null || params === void 0 ? void 0 : params.address) || this.currentAddress;
203
204
  chainId = (params === null || params === void 0 ? void 0 : params.chainId) || this.currentChainId;
204
- return [4 /*yield*/, this.handleDisconnect(chainId, address, properties, context, callback)];
205
+ address = (params === null || params === void 0 ? void 0 : params.address) || this.currentAddress;
206
+ return [4 /*yield*/, this.trackEvent(EventType.DISCONNECT, {
207
+ chainId: chainId,
208
+ address: address,
209
+ }, properties, context, callback)];
205
210
  case 1:
206
211
  _a.sent();
212
+ this.currentAddress = undefined;
213
+ this.currentChainId = undefined;
214
+ logger.info("Wallet disconnected: Cleared currentAddress and currentChainId");
207
215
  return [2 /*return*/];
208
216
  }
209
217
  });
@@ -357,7 +365,7 @@ var FormoAnalytics = /** @class */ (function () {
357
365
  case 8: return [2 /*return*/];
358
366
  case 9:
359
367
  userId = params.userId, address = params.address, providerName = params.providerName, rdns = params.rdns;
360
- logger.debug("Identify", address, userId, providerName, rdns);
368
+ logger.info("Identify", address, userId, providerName, rdns);
361
369
  if (address)
362
370
  this.currentAddress = address;
363
371
  if (userId) {
@@ -435,6 +443,7 @@ var FormoAnalytics = /** @class */ (function () {
435
443
  SDK tracking and event listener functions
436
444
  */
437
445
  FormoAnalytics.prototype.trackProvider = function (provider) {
446
+ logger.info("trackProvider", provider);
438
447
  try {
439
448
  if (provider === this._provider) {
440
449
  logger.warn("TrackProvider: Provider already tracked.");
@@ -452,33 +461,65 @@ var FormoAnalytics = /** @class */ (function () {
452
461
  }
453
462
  this._provider = provider;
454
463
  // Register listeners for web3 provider events
455
- this.registerAddressChangedListener();
464
+ this.registerAccountsChangedListener();
456
465
  this.registerChainChangedListener();
466
+ this.registerConnectListener();
457
467
  this.registerRequestListeners();
458
468
  }
459
469
  catch (error) {
460
470
  logger.error("Error tracking provider:", error);
461
471
  }
462
472
  };
463
- FormoAnalytics.prototype.registerAddressChangedListener = function () {
473
+ FormoAnalytics.prototype.registerAccountsChangedListener = function () {
464
474
  var _this = this;
465
- var _a, _b;
475
+ var _a;
476
+ logger.info("registerAccountsChangedListener");
466
477
  var listener = function () {
467
478
  var args = [];
468
479
  for (var _i = 0; _i < arguments.length; _i++) {
469
480
  args[_i] = arguments[_i];
470
481
  }
471
- return _this.onAddressChanged(args[0]);
482
+ return _this.onAccountsChanged(args[0]);
472
483
  };
473
484
  (_a = this._provider) === null || _a === void 0 ? void 0 : _a.on("accountsChanged", listener);
474
485
  this._providerListeners["accountsChanged"] = listener;
475
- var onAddressDisconnected = this.onAddressDisconnected.bind(this);
476
- (_b = this._provider) === null || _b === void 0 ? void 0 : _b.on("disconnect", onAddressDisconnected);
477
- this._providerListeners["disconnect"] = onAddressDisconnected;
486
+ };
487
+ FormoAnalytics.prototype.onAccountsChanged = function (accounts) {
488
+ return __awaiter(this, void 0, void 0, function () {
489
+ var address, _a;
490
+ return __generator(this, function (_b) {
491
+ switch (_b.label) {
492
+ case 0:
493
+ logger.info("onAccountsChanged", accounts);
494
+ if (!(accounts.length === 0)) return [3 /*break*/, 2];
495
+ // Handle wallet disconnect
496
+ return [4 /*yield*/, this.disconnect()];
497
+ case 1:
498
+ // Handle wallet disconnect
499
+ _b.sent();
500
+ return [2 /*return*/];
501
+ case 2:
502
+ address = accounts[0];
503
+ if (address === this.currentAddress) {
504
+ // We have already reported this address
505
+ return [2 /*return*/];
506
+ }
507
+ // Handle wallet connect
508
+ this.currentAddress = address;
509
+ _a = this;
510
+ return [4 /*yield*/, this.getCurrentChainId()];
511
+ case 3:
512
+ _a.currentChainId = _b.sent();
513
+ this.connect({ chainId: this.currentChainId, address: address });
514
+ return [2 /*return*/];
515
+ }
516
+ });
517
+ });
478
518
  };
479
519
  FormoAnalytics.prototype.registerChainChangedListener = function () {
480
520
  var _this = this;
481
521
  var _a;
522
+ logger.info("registerChainChangedListener");
482
523
  var listener = function () {
483
524
  var args = [];
484
525
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -489,10 +530,92 @@ var FormoAnalytics = /** @class */ (function () {
489
530
  (_a = this.provider) === null || _a === void 0 ? void 0 : _a.on("chainChanged", listener);
490
531
  this._providerListeners["chainChanged"] = listener;
491
532
  };
533
+ FormoAnalytics.prototype.onChainChanged = function (chainIdHex) {
534
+ return __awaiter(this, void 0, void 0, function () {
535
+ var address;
536
+ return __generator(this, function (_a) {
537
+ switch (_a.label) {
538
+ case 0:
539
+ logger.info("onChainChanged", chainIdHex);
540
+ this.currentChainId = parseChainId(chainIdHex);
541
+ if (!!this.currentAddress) return [3 /*break*/, 2];
542
+ if (!this.provider) {
543
+ logger.info("OnChainChanged: Provider not found. CHAIN_CHANGED not reported");
544
+ return [2 /*return*/, Promise.resolve()];
545
+ }
546
+ return [4 /*yield*/, this.getAddress()];
547
+ case 1:
548
+ address = _a.sent();
549
+ if (!address) {
550
+ logger.info("OnChainChanged: Unable to fetch or store connected address");
551
+ return [2 /*return*/, Promise.resolve()];
552
+ }
553
+ this.currentAddress = address;
554
+ _a.label = 2;
555
+ case 2:
556
+ // Proceed only if the address exists
557
+ if (this.currentAddress) {
558
+ return [2 /*return*/, this.chain({
559
+ chainId: this.currentChainId,
560
+ address: this.currentAddress,
561
+ })];
562
+ }
563
+ else {
564
+ logger.info("OnChainChanged: Current connected address is null despite fetch attempt");
565
+ }
566
+ return [2 /*return*/];
567
+ }
568
+ });
569
+ });
570
+ };
571
+ FormoAnalytics.prototype.registerConnectListener = function () {
572
+ var _this = this;
573
+ var _a;
574
+ logger.info("registerConnectListener");
575
+ var listener = function () {
576
+ var args = [];
577
+ for (var _i = 0; _i < arguments.length; _i++) {
578
+ args[_i] = arguments[_i];
579
+ }
580
+ var connection = args[0];
581
+ _this.onConnected(connection);
582
+ };
583
+ (_a = this._provider) === null || _a === void 0 ? void 0 : _a.on("connect", listener);
584
+ this._providerListeners["connect"] = listener;
585
+ };
586
+ FormoAnalytics.prototype.onConnected = function (connection) {
587
+ return __awaiter(this, void 0, void 0, function () {
588
+ var chainId, address, e_2;
589
+ return __generator(this, function (_a) {
590
+ switch (_a.label) {
591
+ case 0:
592
+ logger.info("onConnected", connection);
593
+ _a.label = 1;
594
+ case 1:
595
+ _a.trys.push([1, 3, , 4]);
596
+ if (!connection || typeof connection.chainId !== 'string')
597
+ return [2 /*return*/];
598
+ chainId = parseChainId(connection.chainId);
599
+ return [4 /*yield*/, this.getAddress()];
600
+ case 2:
601
+ address = _a.sent();
602
+ if (chainId !== null && chainId !== undefined && address) {
603
+ this.connect({ chainId: chainId, address: address });
604
+ }
605
+ return [3 /*break*/, 4];
606
+ case 3:
607
+ e_2 = _a.sent();
608
+ logger.error("Error handling connect event", e_2);
609
+ return [3 /*break*/, 4];
610
+ case 4: return [2 /*return*/];
611
+ }
612
+ });
613
+ });
614
+ };
492
615
  FormoAnalytics.prototype.registerRequestListeners = function () {
493
616
  var _this = this;
494
617
  var _a;
495
- logger.debug("registerRequestListeners");
618
+ logger.info("registerRequestListeners");
496
619
  if (!this.provider) {
497
620
  logger.error("Provider not found for request (signature, transaction) tracking");
498
621
  return;
@@ -567,7 +690,7 @@ var FormoAnalytics = /** @class */ (function () {
567
690
  method === "eth_sendTransaction" &&
568
691
  params[0])) return [3 /*break*/, 8];
569
692
  (function () { return __awaiter(_this, void 0, void 0, function () {
570
- var payload, e_2;
693
+ var payload, e_3;
571
694
  return __generator(this, function (_a) {
572
695
  switch (_a.label) {
573
696
  case 0:
@@ -578,8 +701,8 @@ var FormoAnalytics = /** @class */ (function () {
578
701
  this.transaction(__assign({ status: TransactionStatus.STARTED }, payload));
579
702
  return [3 /*break*/, 3];
580
703
  case 2:
581
- e_2 = _a.sent();
582
- logger.error("Formo: Failed to track transaction start", e_2);
704
+ e_3 = _a.sent();
705
+ logger.error("Formo: Failed to track transaction start", e_3);
583
706
  return [3 /*break*/, 3];
584
707
  case 3: return [2 /*return*/];
585
708
  }
@@ -595,7 +718,7 @@ var FormoAnalytics = /** @class */ (function () {
595
718
  case 6:
596
719
  transactionHash_1 = (_c.sent());
597
720
  (function () { return __awaiter(_this, void 0, void 0, function () {
598
- var payload, e_3;
721
+ var payload, e_4;
599
722
  return __generator(this, function (_a) {
600
723
  switch (_a.label) {
601
724
  case 0:
@@ -608,8 +731,8 @@ var FormoAnalytics = /** @class */ (function () {
608
731
  this.pollTransactionReceipt(transactionHash_1, payload);
609
732
  return [3 /*break*/, 3];
610
733
  case 2:
611
- e_3 = _a.sent();
612
- logger.error("Formo: Failed to track transaction broadcast", e_3);
734
+ e_4 = _a.sent();
735
+ logger.error("Formo: Failed to track transaction broadcast", e_4);
613
736
  return [3 /*break*/, 3];
614
737
  case 3: return [2 /*return*/];
615
738
  }
@@ -619,7 +742,7 @@ var FormoAnalytics = /** @class */ (function () {
619
742
  case 7:
620
743
  error_2 = _c.sent();
621
744
  (function () { return __awaiter(_this, void 0, void 0, function () {
622
- var rpcError, payload, e_4;
745
+ var rpcError, payload, e_5;
623
746
  return __generator(this, function (_a) {
624
747
  switch (_a.label) {
625
748
  case 0:
@@ -633,8 +756,8 @@ var FormoAnalytics = /** @class */ (function () {
633
756
  _a.label = 2;
634
757
  case 2: return [3 /*break*/, 4];
635
758
  case 3:
636
- e_4 = _a.sent();
637
- logger.error("Formo: Failed to track transaction rejection", e_4);
759
+ e_5 = _a.sent();
760
+ logger.error("Formo: Failed to track transaction rejection", e_5);
638
761
  return [3 /*break*/, 4];
639
762
  case 4: return [2 /*return*/];
640
763
  }
@@ -646,116 +769,16 @@ var FormoAnalytics = /** @class */ (function () {
646
769
  });
647
770
  }); };
648
771
  };
649
- FormoAnalytics.prototype.onAddressChanged = function (addresses) {
650
- return __awaiter(this, void 0, void 0, function () {
651
- return __generator(this, function (_a) {
652
- if (addresses.length > 0) {
653
- this.onAddressConnected(addresses[0]);
654
- }
655
- else {
656
- this.onAddressDisconnected();
657
- }
658
- return [2 /*return*/];
659
- });
660
- });
661
- };
662
- FormoAnalytics.prototype.onAddressConnected = function (address) {
663
- return __awaiter(this, void 0, void 0, function () {
664
- var _a;
665
- return __generator(this, function (_b) {
666
- switch (_b.label) {
667
- case 0:
668
- if (address === this.currentAddress)
669
- // We have already reported this address
670
- return [2 /*return*/];
671
- this.currentAddress = address;
672
- _a = this;
673
- return [4 /*yield*/, this.getCurrentChainId()];
674
- case 1:
675
- _a.currentChainId = _b.sent();
676
- this.connect({ chainId: this.currentChainId, address: address });
677
- return [2 /*return*/];
678
- }
679
- });
680
- });
681
- };
682
- FormoAnalytics.prototype.handleDisconnect = function (chainId, address, properties, context, callback) {
683
- return __awaiter(this, void 0, void 0, function () {
684
- var payload;
685
- return __generator(this, function (_a) {
686
- switch (_a.label) {
687
- case 0:
688
- payload = {
689
- chainId: chainId || this.currentChainId,
690
- address: address || this.currentAddress,
691
- };
692
- this.currentChainId = undefined;
693
- this.currentAddress = undefined;
694
- cookie().remove(SESSION_USER_ID_KEY);
695
- return [4 /*yield*/, this.trackEvent(EventType.DISCONNECT, payload, properties, context, callback)];
696
- case 1:
697
- _a.sent();
698
- return [2 /*return*/];
699
- }
700
- });
701
- });
702
- };
703
- FormoAnalytics.prototype.onAddressDisconnected = function () {
704
- return __awaiter(this, void 0, void 0, function () {
705
- return __generator(this, function (_a) {
706
- switch (_a.label) {
707
- case 0: return [4 /*yield*/, this.handleDisconnect(this.currentChainId, this.currentAddress)];
708
- case 1:
709
- _a.sent();
710
- return [2 /*return*/];
711
- }
712
- });
713
- });
714
- };
715
- FormoAnalytics.prototype.onChainChanged = function (chainIdHex) {
716
- return __awaiter(this, void 0, void 0, function () {
717
- var address;
718
- return __generator(this, function (_a) {
719
- switch (_a.label) {
720
- case 0:
721
- this.currentChainId = parseInt(chainIdHex);
722
- if (!!this.currentAddress) return [3 /*break*/, 2];
723
- if (!this.provider) {
724
- logger.info("OnChainChanged: Provider not found. CHAIN_CHANGED not reported");
725
- return [2 /*return*/, Promise.resolve()];
726
- }
727
- return [4 /*yield*/, this.getAddress()];
728
- case 1:
729
- address = _a.sent();
730
- if (!address) {
731
- logger.info("OnChainChanged: Unable to fetch or store connected address");
732
- return [2 /*return*/, Promise.resolve()];
733
- }
734
- this.currentAddress = address;
735
- _a.label = 2;
736
- case 2:
737
- // Proceed only if the address exists
738
- if (this.currentAddress) {
739
- return [2 /*return*/, this.chain({
740
- chainId: this.currentChainId,
741
- address: this.currentAddress,
742
- })];
743
- }
744
- else {
745
- logger.info("OnChainChanged: Current connected address is null despite fetch attempt");
746
- }
747
- return [2 /*return*/];
748
- }
749
- });
750
- });
751
- };
752
- FormoAnalytics.prototype.trackFirstPageHit = function () {
772
+ FormoAnalytics.prototype.onLocationChange = function () {
753
773
  return __awaiter(this, void 0, void 0, function () {
774
+ var currentUrl;
754
775
  return __generator(this, function (_a) {
755
- if (cookie().get(SESSION_CURRENT_URL_KEY) === null) {
776
+ currentUrl = cookie().get(SESSION_CURRENT_URL_KEY);
777
+ if (currentUrl !== window.location.href) {
756
778
  cookie().set(SESSION_CURRENT_URL_KEY, window.location.href);
779
+ this.trackPageHit();
757
780
  }
758
- return [2 /*return*/, this.trackPageHit()];
781
+ return [2 /*return*/];
759
782
  });
760
783
  });
761
784
  };
@@ -790,25 +813,13 @@ var FormoAnalytics = /** @class */ (function () {
790
813
  });
791
814
  });
792
815
  };
793
- FormoAnalytics.prototype.onLocationChange = function () {
794
- return __awaiter(this, void 0, void 0, function () {
795
- var currentUrl;
796
- return __generator(this, function (_a) {
797
- currentUrl = cookie().get(SESSION_CURRENT_URL_KEY);
798
- if (currentUrl !== window.location.href) {
799
- cookie().set(SESSION_CURRENT_URL_KEY, window.location.href);
800
- this.trackPageHit();
801
- }
802
- return [2 /*return*/];
803
- });
804
- });
805
- };
806
816
  FormoAnalytics.prototype.trackPageHit = function (category, name, properties, context, callback) {
807
817
  return __awaiter(this, void 0, void 0, function () {
808
818
  var _this = this;
809
819
  return __generator(this, function (_a) {
810
- if (!this.config.trackLocalhost && isLocalhost()) {
811
- return [2 /*return*/, logger.warn("Track page hit: Ignoring event because website is running locally")];
820
+ if (!this.shouldTrack()) {
821
+ logger.info("Track page hit: Skipping event due to tracking configuration");
822
+ return [2 /*return*/];
812
823
  }
813
824
  setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
814
825
  return __generator(this, function (_a) {
@@ -827,6 +838,10 @@ var FormoAnalytics = /** @class */ (function () {
827
838
  return __awaiter(this, void 0, void 0, function () {
828
839
  return __generator(this, function (_a) {
829
840
  try {
841
+ if (!this.shouldTrack()) {
842
+ logger.info("Skipping ".concat(type, " event due to tracking configuration"));
843
+ return [2 /*return*/];
844
+ }
830
845
  this.eventManager.addEvent(__assign(__assign({ type: type }, payload), { properties: properties, context: context, callback: callback }), this.currentAddress, this.currentUserId);
831
846
  }
832
847
  catch (error) {
@@ -836,6 +851,46 @@ var FormoAnalytics = /** @class */ (function () {
836
851
  });
837
852
  });
838
853
  };
854
+ /**
855
+ * Determines if tracking should be enabled based on configuration
856
+ * @returns {boolean} True if tracking should be enabled
857
+ */
858
+ FormoAnalytics.prototype.shouldTrack = function () {
859
+ // Check if tracking is explicitly provided as a boolean
860
+ if (typeof this.options.tracking === 'boolean') {
861
+ return this.options.tracking;
862
+ }
863
+ // Handle object configuration with exclusion rules
864
+ if (this.options.tracking !== null &&
865
+ typeof this.options.tracking === 'object' &&
866
+ !Array.isArray(this.options.tracking)) {
867
+ 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;
868
+ // Check hostname exclusions - use exact matching
869
+ if (excludeHosts.length > 0 && typeof window !== 'undefined') {
870
+ var hostname = window.location.hostname;
871
+ if (excludeHosts.includes(hostname)) {
872
+ return false;
873
+ }
874
+ }
875
+ // Check path exclusions - use exact matching
876
+ if (excludePaths.length > 0 && typeof window !== 'undefined') {
877
+ var pathname = window.location.pathname;
878
+ if (excludePaths.includes(pathname)) {
879
+ return false;
880
+ }
881
+ }
882
+ // Check chainId exclusions
883
+ if (excludeChains.length > 0 &&
884
+ this.currentChainId &&
885
+ excludeChains.includes(this.currentChainId)) {
886
+ return false;
887
+ }
888
+ // If nothing is excluded, tracking is enabled
889
+ return true;
890
+ }
891
+ // Default behavior: track everywhere except localhost
892
+ return !isLocalhost();
893
+ };
839
894
  /*
840
895
  Utility functions
841
896
  */
@@ -991,7 +1046,7 @@ var FormoAnalytics = /** @class */ (function () {
991
1046
  logger.info("Chain id not found");
992
1047
  return [2 /*return*/, 0];
993
1048
  }
994
- return [2 /*return*/, parseInt(chainIdHex, 16)];
1049
+ return [2 /*return*/, parseChainId(chainIdHex)];
995
1050
  case 3:
996
1051
  err_5 = _b.sent();
997
1052
  logger.error("eth_chainId threw an error:", err_5);
@@ -1054,7 +1109,7 @@ var FormoAnalytics = /** @class */ (function () {
1054
1109
  if (!provider)
1055
1110
  return [2 /*return*/];
1056
1111
  poll = function () { return __awaiter(_this, void 0, void 0, function () {
1057
- var receipt, e_5;
1112
+ var receipt, e_6;
1058
1113
  return __generator(this, function (_a) {
1059
1114
  switch (_a.label) {
1060
1115
  case 0:
@@ -1078,8 +1133,8 @@ var FormoAnalytics = /** @class */ (function () {
1078
1133
  }
1079
1134
  return [3 /*break*/, 3];
1080
1135
  case 2:
1081
- e_5 = _a.sent();
1082
- logger.error("Error polling transaction receipt", e_5);
1136
+ e_6 = _a.sent();
1137
+ logger.error("Error polling transaction receipt", e_6);
1083
1138
  return [3 /*break*/, 3];
1084
1139
  case 3:
1085
1140
  attempts++;