@tonconnect/sdk 3.4.0-beta.5 → 3.4.0-beta.7

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/lib/esm/index.mjs CHANGED
@@ -3877,7 +3877,7 @@ class TonConnectTracker {
3877
3877
  }
3878
3878
  }
3879
3879
 
3880
- const tonConnectSdkVersion = "3.4.0-beta.5";
3880
+ const tonConnectSdkVersion = "3.4.0-beta.7";
3881
3881
 
3882
3882
  const bounceableTag = 0x11;
3883
3883
  const noBounceableTag = 0x51;
@@ -4452,7 +4452,7 @@ class AnalyticsManager {
4452
4452
  this.currentBatchTimeoutMs = this.batchTimeoutMs;
4453
4453
  this.maxBatchSize = (_b = options.maxBatchSize) !== null && _b !== void 0 ? _b : 100;
4454
4454
  this.analyticsUrl = (_c = options.analyticsUrl) !== null && _c !== void 0 ? _c : 'https://analytics.ton.org/events';
4455
- this.enabled = (_d = options.enabled) !== null && _d !== void 0 ? _d : true;
4455
+ this.mode = (_d = options.mode) !== null && _d !== void 0 ? _d : 'telemetry';
4456
4456
  this.baseEvent = Object.assign({ subsystem: 'dapp-sdk', version: tonConnectSdkVersion, client_environment: (_f = (_e = options.environment) === null || _e === void 0 ? void 0 : _e.getClientEnvironment) === null || _f === void 0 ? void 0 : _f.call(_e) }, getStaticConnectionMetrics());
4457
4457
  this.addWindowFocusAndBlurSubscriptions();
4458
4458
  }
@@ -4478,16 +4478,17 @@ class AnalyticsManager {
4478
4478
  }
4479
4479
  emit(event) {
4480
4480
  var _a;
4481
- if (!this.enabled) {
4481
+ if (this.mode === 'off') {
4482
4482
  return;
4483
4483
  }
4484
4484
  const traceId = (_a = event.trace_id) !== null && _a !== void 0 ? _a : UUIDv7();
4485
4485
  const dynamicMetrics = getDynamicConnectionMetrics();
4486
4486
  const enhancedEvent = Object.assign(Object.assign(Object.assign(Object.assign({}, this.baseEvent), dynamicMetrics), event), { event_id: UUIDv7(), client_timestamp: Math.floor(Date.now() / 1000), trace_id: traceId });
4487
+ const filteredEvent = this.mode === 'telemetry' ? this.filterFullModeFields(enhancedEvent) : enhancedEvent;
4487
4488
  if (isQaModeEnabled()) {
4488
- logDebug(enhancedEvent);
4489
+ logDebug(filteredEvent);
4489
4490
  }
4490
- this.events.push(enhancedEvent);
4491
+ this.events.push(filteredEvent);
4491
4492
  if (this.events.length >= this.maxBatchSize) {
4492
4493
  void this.flush();
4493
4494
  return;
@@ -4629,15 +4630,30 @@ class AnalyticsManager {
4629
4630
  logError('Cannot subscribe to the document.visibilitychange: ', e);
4630
4631
  }
4631
4632
  }
4632
- setEnabled(enabled) {
4633
- this.enabled = enabled;
4634
- }
4635
- isEnabled() {
4636
- return this.enabled;
4633
+ getMode() {
4634
+ return this.mode;
4637
4635
  }
4638
4636
  getPendingEventsCount() {
4639
4637
  return this.events.length;
4640
4638
  }
4639
+ filterFullModeFields(event) {
4640
+ const filtered = Object.assign({}, event);
4641
+ for (const field of AnalyticsManager.FULL_MODE_FIELDS) {
4642
+ delete filtered[field];
4643
+ }
4644
+ // wallet_address is kept for error events, removed for non-error events
4645
+ const eventName = 'event_name' in event ? String(event.event_name) : '';
4646
+ const isErrorEvent = 'error_code' in event ||
4647
+ 'error_message' in event ||
4648
+ eventName.includes('error') ||
4649
+ eventName === 'connection-error' ||
4650
+ eventName === 'transaction-signing-failed' ||
4651
+ eventName === 'sign-data-request-failed';
4652
+ if (!isErrorEvent && 'wallet_address' in filtered) {
4653
+ delete filtered.wallet_address;
4654
+ }
4655
+ return filtered;
4656
+ }
4641
4657
  setWalletListDownloadDuration(duration) {
4642
4658
  this.baseEvent = Object.assign(Object.assign({}, this.baseEvent), { wallet_list_download_duration: duration });
4643
4659
  }
@@ -4649,6 +4665,12 @@ AnalyticsManager.HTTP_STATUS = {
4649
4665
  };
4650
4666
  AnalyticsManager.MAX_BACKOFF_ATTEMPTS = 5;
4651
4667
  AnalyticsManager.BACKOFF_MULTIPLIER = 2;
4668
+ AnalyticsManager.FULL_MODE_FIELDS = [
4669
+ 'user_id',
4670
+ 'tg_id',
4671
+ 'locale',
4672
+ 'tma_is_premium'
4673
+ ];
4652
4674
 
4653
4675
  /**
4654
4676
  * A concrete implementation of EventDispatcher that dispatches events to the browser window.
@@ -5366,7 +5388,7 @@ class TonConnect {
5366
5388
  this.statusChangeSubscriptions.forEach(callback => callback(this._wallet));
5367
5389
  }
5368
5390
  constructor(options) {
5369
- var _a, _b;
5391
+ var _a, _b, _c;
5370
5392
  this._wallet = null;
5371
5393
  this.provider = null;
5372
5394
  this.statusChangeSubscriptions = [];
@@ -5378,8 +5400,6 @@ class TonConnect {
5378
5400
  };
5379
5401
  this.walletsRequiredFeatures = options === null || options === void 0 ? void 0 : options.walletsRequiredFeatures;
5380
5402
  this.environment = (_a = options === null || options === void 0 ? void 0 : options.environment) !== null && _a !== void 0 ? _a : new DefaultEnvironment();
5381
- // TODO: in production ready make flag to enable them?
5382
- this.analytics = new AnalyticsManager({ environment: this.environment });
5383
5403
  this.walletsList = new WalletsListManager({
5384
5404
  walletsListSource: options === null || options === void 0 ? void 0 : options.walletsListSource,
5385
5405
  cacheTTLMs: options === null || options === void 0 ? void 0 : options.walletsListCacheTTLMs,
@@ -5393,16 +5413,8 @@ class TonConnect {
5393
5413
  eventDispatcher,
5394
5414
  tonConnectSdkVersion: tonConnectSdkVersion
5395
5415
  });
5396
- const telegramUser = this.environment.getTelegramUser();
5397
- bindEventsTo(eventDispatcher, this.analytics.scoped({
5398
- locale: this.environment.getLocale(),
5399
- browser: this.environment.getBrowser(),
5400
- platform: this.environment.getPlatform(),
5401
- tg_id: telegramUser === null || telegramUser === void 0 ? void 0 : telegramUser.id,
5402
- tma_is_premium: telegramUser === null || telegramUser === void 0 ? void 0 : telegramUser.isPremium,
5403
- manifest_json_url: manifestUrl,
5404
- origin_url: getOriginWithPath
5405
- }));
5416
+ this.environment = (_c = options === null || options === void 0 ? void 0 : options.environment) !== null && _c !== void 0 ? _c : new DefaultEnvironment();
5417
+ this.initAnalytics(manifestUrl, eventDispatcher, options);
5406
5418
  if (!this.dappSettings.manifestUrl) {
5407
5419
  throw new DappMetadataError('Dapp tonconnect-manifest.json must be specified if window.location.origin is undefined. See more https://github.com/ton-connect/docs/blob/main/requests-responses.md#app-manifest');
5408
5420
  }
@@ -5834,6 +5846,32 @@ class TonConnect {
5834
5846
  logError('Cannot subscribe to the document.visibilitychange: ', e);
5835
5847
  }
5836
5848
  }
5849
+ initAnalytics(manifestUrl, eventDispatcher, options) {
5850
+ var _a;
5851
+ const analyticsSettings = options === null || options === void 0 ? void 0 : options.analytics;
5852
+ const mode = (_a = analyticsSettings === null || analyticsSettings === void 0 ? void 0 : analyticsSettings.mode) !== null && _a !== void 0 ? _a : 'telemetry';
5853
+ if (mode === 'off') {
5854
+ return;
5855
+ }
5856
+ const analytics = new AnalyticsManager({
5857
+ environment: this.environment,
5858
+ mode
5859
+ });
5860
+ this.analytics = analytics;
5861
+ const telegramUser = this.environment.getTelegramUser();
5862
+ const sharedAnalyticsData = {
5863
+ browser: this.environment.getBrowser(),
5864
+ platform: this.environment.getPlatform(),
5865
+ manifest_json_url: manifestUrl,
5866
+ origin_url: getOriginWithPath,
5867
+ locale: this.environment.getLocale()
5868
+ };
5869
+ if (telegramUser) {
5870
+ sharedAnalyticsData.tg_id = telegramUser.id;
5871
+ sharedAnalyticsData.tma_is_premium = telegramUser.isPremium;
5872
+ }
5873
+ bindEventsTo(eventDispatcher, analytics.scoped(sharedAnalyticsData));
5874
+ }
5837
5875
  createProvider(wallet) {
5838
5876
  let provider;
5839
5877
  if (!Array.isArray(wallet) && isWalletConnectionSourceJS(wallet)) {