@metamask/connect-multichain 0.14.0 → 0.15.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 (40) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/README.md +20 -19
  3. package/dist/browser/es/connect-multichain.d.mts +17 -5
  4. package/dist/browser/es/connect-multichain.mjs +145 -108
  5. package/dist/browser/es/connect-multichain.mjs.map +1 -1
  6. package/dist/browser/es/metafile-esm.json +1 -1
  7. package/dist/browser/iife/connect-multichain.d.ts +17 -5
  8. package/dist/browser/iife/connect-multichain.js +163 -108
  9. package/dist/browser/iife/connect-multichain.js.map +1 -1
  10. package/dist/browser/iife/metafile-iife.json +1 -1
  11. package/dist/browser/umd/connect-multichain.d.ts +17 -5
  12. package/dist/browser/umd/connect-multichain.js +145 -108
  13. package/dist/browser/umd/connect-multichain.js.map +1 -1
  14. package/dist/browser/umd/metafile-cjs.json +1 -1
  15. package/dist/node/cjs/connect-multichain.d.ts +17 -5
  16. package/dist/node/cjs/connect-multichain.js +145 -108
  17. package/dist/node/cjs/connect-multichain.js.map +1 -1
  18. package/dist/node/cjs/metafile-cjs.json +1 -1
  19. package/dist/node/es/connect-multichain.d.mts +17 -5
  20. package/dist/node/es/connect-multichain.mjs +145 -108
  21. package/dist/node/es/connect-multichain.mjs.map +1 -1
  22. package/dist/node/es/metafile-esm.json +1 -1
  23. package/dist/react-native/es/connect-multichain.d.mts +17 -5
  24. package/dist/react-native/es/connect-multichain.mjs +145 -108
  25. package/dist/react-native/es/connect-multichain.mjs.map +1 -1
  26. package/dist/react-native/es/metafile-esm.json +1 -1
  27. package/dist/src/domain/multichain/index.d.ts +1 -1
  28. package/dist/src/domain/multichain/index.d.ts.map +1 -1
  29. package/dist/src/domain/multichain/index.js +7 -3
  30. package/dist/src/domain/multichain/index.js.map +1 -1
  31. package/dist/src/domain/multichain/types.d.ts +15 -3
  32. package/dist/src/domain/multichain/types.d.ts.map +1 -1
  33. package/dist/src/multichain/index.d.ts.map +1 -1
  34. package/dist/src/multichain/index.js +108 -62
  35. package/dist/src/multichain/index.js.map +1 -1
  36. package/dist/src/multichain/rpc/requestRouter.d.ts.map +1 -1
  37. package/dist/src/multichain/rpc/requestRouter.js +23 -5
  38. package/dist/src/multichain/rpc/requestRouter.js.map +1 -1
  39. package/dist/types/connect-multichain.d.ts +17 -5
  40. package/package.json +2 -2
@@ -406,6 +406,19 @@ type ConnectionRequest = {
406
406
  type ConnectVersions = {
407
407
  'connect-multichain': string;
408
408
  } & Partial<Record<'connect-evm' | 'connect-solana', string>>;
409
+ type AnalyticsOptions = {
410
+ /**
411
+ * Whether to enable analytics tracking. Defaults to `true` when omitted.
412
+ * Set to `false` to disable all analytics event collection.
413
+ */
414
+ enabled?: boolean;
415
+ /**
416
+ * Identifies the integration surface that instantiated the SDK (e.g. `'direct'`,
417
+ * `'wagmi'`). Recorded as the `integration_types` global analytics property.
418
+ * Defaults to `'direct'` when omitted or empty.
419
+ */
420
+ integrationType?: string;
421
+ };
409
422
  /**
410
423
  * Constructor options for creating a Multichain SDK instance.
411
424
  *
@@ -422,9 +435,7 @@ type MultichainOptions = {
422
435
  supportedNetworks: RpcUrlsMap;
423
436
  };
424
437
  /** Analytics configuration */
425
- analytics?: {
426
- integrationType: string;
427
- };
438
+ analytics?: AnalyticsOptions;
428
439
  /** Storage client for persisting SDK data */
429
440
  storage: StoreClient;
430
441
  /** UI configuration options */
@@ -464,6 +475,7 @@ type MultiChainFNOptions = Omit<MultichainOptions, 'storage' | 'ui'> & {
464
475
  * with an existing singleton.
465
476
  */
466
477
  type MergeableMultichainOptions = Omit<MultichainOptions, 'dapp' | 'analytics' | 'storage' | 'api' | 'ui' | 'transport' | 'versions'> & {
478
+ analytics?: AnalyticsOptions;
467
479
  api?: MultichainOptions['api'];
468
480
  ui?: Pick<MultichainOptions['ui'], 'headless' | 'preferExtension' | 'showInstallModal'>;
469
481
  transport?: Pick<NonNullable<MultichainOptions['transport']>, 'extensionId'>;
@@ -553,7 +565,7 @@ declare abstract class MultichainCore extends EventEmitter<SDKEvents> {
553
565
  constructor(options: MultichainOptions);
554
566
  /**
555
567
  * Merges the given options into the current instance options.
556
- * Only the mergeable keys are updated (api.supportedNetworks, versions, ui.*, mobile.*, transport.extensionId, debug).
568
+ * Only the mergeable keys are updated (api.supportedNetworks, analytics, versions, ui.*, mobile.*, transport.extensionId, debug).
557
569
  * The main thing to note is that the value for `dapp` is not merged as it does not make sense for
558
570
  * subsequent calls to `createMultichainClient` to have a different `dapp` value.
559
571
  * Used when createMultichainClient is called with an existing singleton.
@@ -757,4 +769,4 @@ declare function getVersion(): string;
757
769
 
758
770
  declare const createMultichainClient: CreateMultichainFN;
759
771
 
760
- export { type ConnectVersions, type ConnectionRequest, type ConnectionStatus, type CreateMultichainFN, type DappSettings, type DataType, type DomainErrorCodes, type Enumerate, type ErrorCodeRange, type ErrorCodes, EventEmitter, type EventTypes, type ExtendedTransport, type FailureReason, type InstallWidgetProps, type InvokeMethodOptions, type LoggerNameSpaces, type MergeableMultichainOptions, Modal, type ModalFactoryConnectOptions, type ModalFactoryOptions, MultichainCore, type MultichainOptions, type NotificationCallback, type OTPCode, type OTPCodeWidgetProps, PlatformType, type QRLink, type RPCAPI, type RPCErrorCodes, RPCHttpErr, RPCInvokeMethodErr, RPCReadonlyRequestErr, RPCReadonlyResponseErr, type RPCResponse, RPC_HANDLED_METHODS, type RpcMethod, type RpcUrlsMap, type SDKEvents, SDK_HANDLED_METHODS, type Scope, type StorageErrorCodes, StoreAdapter, StoreClient, type StoreOptions, TransportType, classifyFailureReason, createLogger, createMultichainClient, enableDebug, getInfuraRpcUrls, getPlatformType, getTransportType, getVersion, getWalletActionAnalyticsProperties, hasExtension, infuraRpcUrls, isEnabled, isMetamaskExtensionInstalled, isRejectionError, isSecure };
772
+ export { type AnalyticsOptions, type ConnectVersions, type ConnectionRequest, type ConnectionStatus, type CreateMultichainFN, type DappSettings, type DataType, type DomainErrorCodes, type Enumerate, type ErrorCodeRange, type ErrorCodes, EventEmitter, type EventTypes, type ExtendedTransport, type FailureReason, type InstallWidgetProps, type InvokeMethodOptions, type LoggerNameSpaces, type MergeableMultichainOptions, Modal, type ModalFactoryConnectOptions, type ModalFactoryOptions, MultichainCore, type MultichainOptions, type NotificationCallback, type OTPCode, type OTPCodeWidgetProps, PlatformType, type QRLink, type RPCAPI, type RPCErrorCodes, RPCHttpErr, RPCInvokeMethodErr, RPCReadonlyRequestErr, RPCReadonlyResponseErr, type RPCResponse, RPC_HANDLED_METHODS, type RpcMethod, type RpcUrlsMap, type SDKEvents, SDK_HANDLED_METHODS, type Scope, type StorageErrorCodes, StoreAdapter, StoreClient, type StoreOptions, TransportType, classifyFailureReason, createLogger, createMultichainClient, enableDebug, getInfuraRpcUrls, getPlatformType, getTransportType, getVersion, getWalletActionAnalyticsProperties, hasExtension, infuraRpcUrls, isEnabled, isMetamaskExtensionInstalled, isRejectionError, isSecure };
@@ -493,7 +493,7 @@ var init_multichain = __esm({
493
493
  }
494
494
  /**
495
495
  * Merges the given options into the current instance options.
496
- * Only the mergeable keys are updated (api.supportedNetworks, versions, ui.*, mobile.*, transport.extensionId, debug).
496
+ * Only the mergeable keys are updated (api.supportedNetworks, analytics, versions, ui.*, mobile.*, transport.extensionId, debug).
497
497
  * The main thing to note is that the value for `dapp` is not merged as it does not make sense for
498
498
  * subsequent calls to `createMultichainClient` to have a different `dapp` value.
499
499
  * Used when createMultichainClient is called with an existing singleton.
@@ -501,23 +501,28 @@ var init_multichain = __esm({
501
501
  * @param partial - Options to merge/overwrite onto the current instance
502
502
  */
503
503
  mergeOptions(partial) {
504
- var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
504
+ var _a3, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
505
505
  const opts = this.options;
506
+ const analytics3 = __spreadValues(__spreadValues({}, opts.analytics), (_a3 = partial.analytics) != null ? _a3 : {});
507
+ if (((_b = opts.analytics) == null ? void 0 : _b.enabled) === false) {
508
+ analytics3.enabled = false;
509
+ }
506
510
  this.options = __spreadProps(__spreadValues({}, opts), {
507
511
  api: __spreadProps(__spreadValues({}, opts.api), {
508
- supportedNetworks: __spreadValues(__spreadValues({}, opts.api.supportedNetworks), (_b = (_a3 = partial.api) == null ? void 0 : _a3.supportedNetworks) != null ? _b : {})
512
+ supportedNetworks: __spreadValues(__spreadValues({}, opts.api.supportedNetworks), (_d = (_c = partial.api) == null ? void 0 : _c.supportedNetworks) != null ? _d : {})
509
513
  }),
510
- versions: __spreadValues(__spreadValues({}, opts.versions), (_c = partial.versions) != null ? _c : {}),
514
+ versions: __spreadValues(__spreadValues({}, opts.versions), (_e = partial.versions) != null ? _e : {}),
515
+ analytics: __spreadValues({}, analytics3),
511
516
  ui: __spreadProps(__spreadValues({}, opts.ui), {
512
- headless: (_e = (_d = partial.ui) == null ? void 0 : _d.headless) != null ? _e : opts.ui.headless,
513
- preferExtension: (_g = (_f = partial.ui) == null ? void 0 : _f.preferExtension) != null ? _g : opts.ui.preferExtension,
514
- showInstallModal: (_i = (_h = partial.ui) == null ? void 0 : _h.showInstallModal) != null ? _i : opts.ui.showInstallModal
517
+ headless: (_g = (_f = partial.ui) == null ? void 0 : _f.headless) != null ? _g : opts.ui.headless,
518
+ preferExtension: (_i = (_h = partial.ui) == null ? void 0 : _h.preferExtension) != null ? _i : opts.ui.preferExtension,
519
+ showInstallModal: (_k = (_j = partial.ui) == null ? void 0 : _j.showInstallModal) != null ? _k : opts.ui.showInstallModal
515
520
  }),
516
- mobile: __spreadValues(__spreadValues({}, opts.mobile), (_j = partial.mobile) != null ? _j : {}),
517
- transport: __spreadProps(__spreadValues({}, (_k = opts.transport) != null ? _k : {}), {
518
- extensionId: (_n = (_l = partial.transport) == null ? void 0 : _l.extensionId) != null ? _n : (_m = opts.transport) == null ? void 0 : _m.extensionId
521
+ mobile: __spreadValues(__spreadValues({}, opts.mobile), (_l = partial.mobile) != null ? _l : {}),
522
+ transport: __spreadProps(__spreadValues({}, (_m = opts.transport) != null ? _m : {}), {
523
+ extensionId: (_p = (_n = partial.transport) == null ? void 0 : _n.extensionId) != null ? _p : (_o = opts.transport) == null ? void 0 : _o.extensionId
519
524
  }),
520
- debug: (_o = partial.debug) != null ? _o : opts.debug
525
+ debug: (_q = partial.debug) != null ? _q : opts.debug
521
526
  });
522
527
  }
523
528
  };
@@ -2345,6 +2350,17 @@ var import_analytics2 = require("@metamask/analytics");
2345
2350
  init_domain();
2346
2351
  init_utils2();
2347
2352
  init_analytics();
2353
+ function toRPCInvokeMethodErr(error) {
2354
+ var _a3;
2355
+ if (error instanceof RPCInvokeMethodErr) {
2356
+ return error;
2357
+ }
2358
+ const castError = error;
2359
+ return new RPCInvokeMethodErr(
2360
+ (_a3 = castError.message) != null ? _a3 : "Unknown error",
2361
+ castError.code
2362
+ );
2363
+ }
2348
2364
  var _RequestRouter_instances, withAnalyticsTracking_fn, trackWalletActionRequested_fn, trackWalletActionSucceeded_fn, trackWalletActionFailed_fn, trackWalletActionRejected_fn;
2349
2365
  var RequestRouter = class {
2350
2366
  constructor(transport, rpcClient, config, transportType) {
@@ -2451,6 +2467,13 @@ _RequestRouter_instances = new WeakSet();
2451
2467
  withAnalyticsTracking_fn = function(options, execute) {
2452
2468
  return __async(this, null, function* () {
2453
2469
  var _a3;
2470
+ if (((_a3 = this.config.analytics) == null ? void 0 : _a3.enabled) === false) {
2471
+ try {
2472
+ return yield execute();
2473
+ } catch (error) {
2474
+ throw toRPCInvokeMethodErr(error);
2475
+ }
2476
+ }
2454
2477
  yield __privateMethod(this, _RequestRouter_instances, trackWalletActionRequested_fn).call(this, options);
2455
2478
  try {
2456
2479
  const result = yield execute();
@@ -2463,14 +2486,7 @@ withAnalyticsTracking_fn = function(options, execute) {
2463
2486
  } else {
2464
2487
  yield __privateMethod(this, _RequestRouter_instances, trackWalletActionFailed_fn).call(this, options, error);
2465
2488
  }
2466
- if (error instanceof RPCInvokeMethodErr) {
2467
- throw error;
2468
- }
2469
- const castError = error;
2470
- throw new RPCInvokeMethodErr(
2471
- (_a3 = castError.message) != null ? _a3 : "Unknown error",
2472
- castError.code
2473
- );
2489
+ throw toRPCInvokeMethodErr(error);
2474
2490
  }
2475
2491
  });
2476
2492
  };
@@ -2929,26 +2945,65 @@ walletInvokeMethod_fn = function(request) {
2929
2945
  init_utils2();
2930
2946
  var logger2 = createLogger("metamask-sdk:core");
2931
2947
  var SINGLETON_KEY = "__METAMASK_CONNECT_MULTICHAIN_SINGLETON__";
2948
+ function normalizeAnalyticsOptions(analyticsOptions) {
2949
+ var _a3;
2950
+ return __spreadProps(__spreadValues({}, analyticsOptions != null ? analyticsOptions : {}), {
2951
+ enabled: (_a3 = analyticsOptions == null ? void 0 : analyticsOptions.enabled) != null ? _a3 : true,
2952
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
2953
+ integrationType: (analyticsOptions == null ? void 0 : analyticsOptions.integrationType) || "direct"
2954
+ });
2955
+ }
2956
+ function isAnalyticsEnabled(options) {
2957
+ var _a3;
2958
+ return ((_a3 = options.analytics) == null ? void 0 : _a3.enabled) !== false;
2959
+ }
2960
+ function setupAnalyticsGlobals(options, storage, setAnonId) {
2961
+ return __async(this, null, function* () {
2962
+ var _a3, _b;
2963
+ if (!isAnalyticsEnabled(options)) {
2964
+ setAnonId == null ? void 0 : setAnonId(void 0);
2965
+ import_analytics4.analytics.disable();
2966
+ return;
2967
+ }
2968
+ const platform = getPlatformType();
2969
+ const isBrowser = platform === "in-app-browser" /* MetaMaskMobileWebview */ || platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */;
2970
+ const isReactNative2 = platform === "react-native" /* ReactNative */;
2971
+ if (!isBrowser && !isReactNative2) {
2972
+ return;
2973
+ }
2974
+ const dappId = getDappId(options.dapp);
2975
+ const anonId = yield storage.getAnonId();
2976
+ setAnonId == null ? void 0 : setAnonId(anonId);
2977
+ const { integrationType } = (_a3 = options.analytics) != null ? _a3 : {
2978
+ integrationType: ""
2979
+ };
2980
+ import_analytics4.analytics.setGlobalProperty("mmconnect_versions", (_b = options.versions) != null ? _b : {});
2981
+ import_analytics4.analytics.setGlobalProperty("dapp_id", dappId);
2982
+ import_analytics4.analytics.setGlobalProperty("anon_id", anonId);
2983
+ import_analytics4.analytics.setGlobalProperty("platform", platform);
2984
+ if (integrationType) {
2985
+ import_analytics4.analytics.setGlobalProperty("integration_types", [integrationType]);
2986
+ }
2987
+ import_analytics4.analytics.enable();
2988
+ });
2989
+ }
2932
2990
  var _a2, _provider, _providerTransportWrapper, _transport2, _dappClient, _beforeUnloadListener, _transportType, _listener, _anonId, _sdkInfo, _MetaMaskConnectMultichain_instances, setupAnalytics_fn, onTransportNotification_fn, getStoredTransport_fn, setupTransport_fn, buildConnectionMetadata_fn, init_fn2, createDappClient_fn, setupMWP_fn, onBeforeUnload_fn, createBeforeUnloadListener_fn, renderInstallModalAsync_fn, showInstallModal_fn, headlessConnect_fn, setupDefaultTransport_fn, deeplinkConnect_fn, handleConnection_fn, getCaipSession_fn, openConnectDeeplinkIfNeeded_fn;
2933
2991
  var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends MultichainCore {
2934
2992
  constructor(options) {
2935
- var _a3, _b, _c, _d, _e, _f;
2993
+ var _a3, _b, _c, _d;
2936
2994
  const withDappMetadata = setupDappMetadata(options);
2937
- const integrationType = ((_a3 = options.analytics) == null ? void 0 : _a3.integrationType) || "direct";
2938
2995
  const allOptions = __spreadProps(__spreadValues({}, withDappMetadata), {
2939
2996
  ui: __spreadProps(__spreadValues({}, withDappMetadata.ui), {
2940
- preferExtension: (_b = withDappMetadata.ui.preferExtension) != null ? _b : true,
2941
- showInstallModal: (_c = withDappMetadata.ui.showInstallModal) != null ? _c : false,
2942
- headless: (_d = withDappMetadata.ui.headless) != null ? _d : false
2943
- }),
2944
- analytics: __spreadProps(__spreadValues({}, (_e = options.analytics) != null ? _e : {}), {
2945
- integrationType
2997
+ preferExtension: (_a3 = withDappMetadata.ui.preferExtension) != null ? _a3 : true,
2998
+ showInstallModal: (_b = withDappMetadata.ui.showInstallModal) != null ? _b : false,
2999
+ headless: (_c = withDappMetadata.ui.headless) != null ? _c : false
2946
3000
  }),
3001
+ analytics: normalizeAnalyticsOptions(options.analytics),
2947
3002
  versions: __spreadValues({
2948
3003
  // typeof guard needed: Metro (React Native) bundles TS source directly,
2949
3004
  // bypassing the tsup build that substitutes __PACKAGE_VERSION__.
2950
- "connect-multichain": false ? "unknown" : "0.14.0"
2951
- }, (_f = options.versions) != null ? _f : {})
3005
+ "connect-multichain": false ? "unknown" : "0.15.0"
3006
+ }, (_d = options.versions) != null ? _d : {})
2952
3007
  });
2953
3008
  super(allOptions);
2954
3009
  __privateAdd(this, _MetaMaskConnectMultichain_instances);
@@ -3004,25 +3059,22 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
3004
3059
  // Creates a singleton instance of MetaMaskConnectMultichain.
3005
3060
  // If the singleton already exists, it merges the incoming options with the
3006
3061
  // existing singleton options for the following keys: `api.supportedNetworks`,
3007
- // `versions`, `ui.*`, `mobile.*`, `transport.extensionId`, `debug`. Take note
3008
- // that the value for `dapp` is not merged as it does not make sense for
3009
- // subsequent calls to `createMultichainClient` to have a different `dapp` value.
3062
+ // `analytics`, `versions`, `ui.*`, `mobile.*`, `transport.extensionId`,
3063
+ // `debug`. Take note that the value for `dapp` is not merged as it does not
3064
+ // make sense for subsequent calls to `createMultichainClient` to have a
3065
+ // different `dapp` value.
3010
3066
  static create(options) {
3011
3067
  return __async(this, null, function* () {
3012
- var _a3, _b;
3068
+ var _a3;
3013
3069
  const globalObject = getGlobalObject();
3014
3070
  const existing = globalObject[SINGLETON_KEY];
3015
3071
  if (existing) {
3016
3072
  const instance = yield existing;
3017
3073
  instance.mergeOptions(options);
3018
- import_analytics4.analytics.setGlobalProperty(
3019
- "mmconnect_versions",
3020
- (_a3 = instance.options.versions) != null ? _a3 : {}
3021
- );
3022
- if ((_b = options.analytics) == null ? void 0 : _b.integrationType) {
3023
- import_analytics4.analytics.setGlobalProperty("integration_types", [
3024
- options.analytics.integrationType
3025
- ]);
3074
+ if (instance instanceof _MetaMaskConnectMultichain) {
3075
+ yield __privateMethod(_a3 = instance, _MetaMaskConnectMultichain_instances, setupAnalytics_fn).call(_a3);
3076
+ } else {
3077
+ yield setupAnalyticsGlobals(instance.options, instance.storage);
3026
3078
  }
3027
3079
  if (options.debug) {
3028
3080
  enableDebug("metamask-sdk:*");
@@ -3072,21 +3124,23 @@ var _MetaMaskConnectMultichain = class _MetaMaskConnectMultichain extends Multic
3072
3124
  } else {
3073
3125
  transportType = "mwp" /* MWP */;
3074
3126
  }
3075
- try {
3076
- const baseProps = yield getBaseAnalyticsProperties(
3077
- this.options,
3078
- this.storage
3079
- );
3080
- const dappConfiguredChains = Object.keys(
3081
- this.options.api.supportedNetworks
3082
- );
3083
- import_analytics4.analytics.track("mmconnect_connection_initiated", __spreadProps(__spreadValues({}, baseProps), {
3084
- transport_type: transportType,
3085
- dapp_configured_chains: dappConfiguredChains,
3086
- dapp_requested_chains: scopes
3087
- }));
3088
- } catch (error) {
3089
- logger2("Error tracking connection_initiated event", error);
3127
+ if (isAnalyticsEnabled(this.options)) {
3128
+ try {
3129
+ const baseProps = yield getBaseAnalyticsProperties(
3130
+ this.options,
3131
+ this.storage
3132
+ );
3133
+ const dappConfiguredChains = Object.keys(
3134
+ this.options.api.supportedNetworks
3135
+ );
3136
+ import_analytics4.analytics.track("mmconnect_connection_initiated", __spreadProps(__spreadValues({}, baseProps), {
3137
+ transport_type: transportType,
3138
+ dapp_configured_chains: dappConfiguredChains,
3139
+ dapp_requested_chains: scopes
3140
+ }));
3141
+ } catch (error) {
3142
+ logger2("Error tracking connection_initiated event", error);
3143
+ }
3090
3144
  }
3091
3145
  const sessionData = yield __privateMethod(this, _MetaMaskConnectMultichain_instances, getCaipSession_fn).call(this);
3092
3146
  const { mergedScopes, mergedCaipAccountIds, mergedSessionProperties } = mergeRequestedSessionWithExisting(
@@ -3229,30 +3283,9 @@ _sdkInfo = new WeakMap();
3229
3283
  _MetaMaskConnectMultichain_instances = new WeakSet();
3230
3284
  setupAnalytics_fn = function() {
3231
3285
  return __async(this, null, function* () {
3232
- var _a3, _b;
3233
- const platform = getPlatformType();
3234
- const isBrowser = platform === "in-app-browser" /* MetaMaskMobileWebview */ || platform === "web-desktop" /* DesktopWeb */ || platform === "web-mobile" /* MobileWeb */;
3235
- const isReactNative2 = platform === "react-native" /* ReactNative */;
3236
- if (!isBrowser && !isReactNative2) {
3237
- return;
3238
- }
3239
- const dappId = getDappId(this.options.dapp);
3240
- const anonId = yield this.storage.getAnonId();
3241
- __privateSet(this, _anonId, anonId);
3242
- const { integrationType } = (_a3 = this.options.analytics) != null ? _a3 : {
3243
- integrationType: ""
3244
- };
3245
- import_analytics4.analytics.setGlobalProperty(
3246
- "mmconnect_versions",
3247
- (_b = this.options.versions) != null ? _b : {}
3248
- );
3249
- import_analytics4.analytics.setGlobalProperty("dapp_id", dappId);
3250
- import_analytics4.analytics.setGlobalProperty("anon_id", anonId);
3251
- import_analytics4.analytics.setGlobalProperty("platform", platform);
3252
- if (integrationType) {
3253
- import_analytics4.analytics.setGlobalProperty("integration_types", [integrationType]);
3254
- }
3255
- import_analytics4.analytics.enable();
3286
+ yield setupAnalyticsGlobals(this.options, this.storage, (anonId) => {
3287
+ __privateSet(this, _anonId, anonId);
3288
+ });
3256
3289
  });
3257
3290
  };
3258
3291
  onTransportNotification_fn = function(payload) {
@@ -3341,7 +3374,7 @@ buildConnectionMetadata_fn = function() {
3341
3374
  dapp: this.options.dapp,
3342
3375
  sdk: { version: getVersion(), platform: getPlatformType() }
3343
3376
  };
3344
- if (__privateGet(this, _anonId)) {
3377
+ if (isAnalyticsEnabled(this.options) && __privateGet(this, _anonId)) {
3345
3378
  metadata.analytics = { remote_session_id: __privateGet(this, _anonId) };
3346
3379
  }
3347
3380
  return metadata;
@@ -3623,38 +3656,42 @@ handleConnection_fn = function(promise, scopes, transportType) {
3623
3656
  this.status = "connecting";
3624
3657
  return promise.then(() => __async(this, null, function* () {
3625
3658
  this.status = "connected";
3626
- try {
3627
- const baseProps = yield getBaseAnalyticsProperties(
3628
- this.options,
3629
- this.storage
3630
- );
3631
- import_analytics4.analytics.track("mmconnect_connection_established", __spreadProps(__spreadValues({}, baseProps), {
3632
- transport_type: transportType,
3633
- user_permissioned_chains: scopes
3634
- }));
3635
- } catch (error) {
3636
- logger2("Error tracking connection_established event", error);
3659
+ if (isAnalyticsEnabled(this.options)) {
3660
+ try {
3661
+ const baseProps = yield getBaseAnalyticsProperties(
3662
+ this.options,
3663
+ this.storage
3664
+ );
3665
+ import_analytics4.analytics.track("mmconnect_connection_established", __spreadProps(__spreadValues({}, baseProps), {
3666
+ transport_type: transportType,
3667
+ user_permissioned_chains: scopes
3668
+ }));
3669
+ } catch (error) {
3670
+ logger2("Error tracking connection_established event", error);
3671
+ }
3637
3672
  }
3638
3673
  return void 0;
3639
3674
  })).catch((error) => __async(this, null, function* () {
3640
3675
  this.status = "disconnected";
3641
- try {
3642
- const baseProps = yield getBaseAnalyticsProperties(
3643
- this.options,
3644
- this.storage
3645
- );
3646
- const isRejection = isRejectionError(error);
3647
- if (isRejection) {
3648
- import_analytics4.analytics.track("mmconnect_connection_rejected", __spreadProps(__spreadValues({}, baseProps), {
3649
- transport_type: transportType
3650
- }));
3651
- } else {
3652
- import_analytics4.analytics.track("mmconnect_connection_failed", __spreadValues(__spreadProps(__spreadValues({}, baseProps), {
3653
- transport_type: transportType
3654
- }), extractErrorDiagnostics(error)));
3676
+ if (isAnalyticsEnabled(this.options)) {
3677
+ try {
3678
+ const baseProps = yield getBaseAnalyticsProperties(
3679
+ this.options,
3680
+ this.storage
3681
+ );
3682
+ const isRejection = isRejectionError(error);
3683
+ if (isRejection) {
3684
+ import_analytics4.analytics.track("mmconnect_connection_rejected", __spreadProps(__spreadValues({}, baseProps), {
3685
+ transport_type: transportType
3686
+ }));
3687
+ } else {
3688
+ import_analytics4.analytics.track("mmconnect_connection_failed", __spreadValues(__spreadProps(__spreadValues({}, baseProps), {
3689
+ transport_type: transportType
3690
+ }), extractErrorDiagnostics(error)));
3691
+ }
3692
+ } catch (e) {
3693
+ logger2("Error tracking connection failed/rejected event", error);
3655
3694
  }
3656
- } catch (e) {
3657
- logger2("Error tracking connection failed/rejected event", error);
3658
3695
  }
3659
3696
  throw error;
3660
3697
  }));