Skip to content

Commit

Permalink
chore: fix pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
omridan159 committed Oct 25, 2023
1 parent cae30bd commit b4db689
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
6 changes: 3 additions & 3 deletions packages/sdk/src/services/Analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface AnalyticsProps {
};
}

const constants = {
export const ANALYTICS_CONSTANTS = {
DEFAULT_ID: 'sdk',
NO_VERSION: 'NONE',
};
Expand Down Expand Up @@ -44,9 +44,9 @@ export class Analytics {

SendAnalytics(
{
id: constants.DEFAULT_ID,
id: ANALYTICS_CONSTANTS.DEFAULT_ID,
event,
commLayerVersion: constants.NO_VERSION,
commLayerVersion: ANALYTICS_CONSTANTS.NO_VERSION,
originationInfo: this.#metadata,
},
this.#serverURL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
import { STORAGE_PROVIDER_TYPE } from '../../../config';
import { MetaMaskSDK } from '../../../sdk';
import { connectWithExtensionProvider } from '../ProviderManager';
import packageJson from '../../../../package.json';
import { ANALYTICS_CONSTANTS } from '../../Analytics';

/**
* Handles automatic and extension-based connections for MetaMask SDK.
Expand Down Expand Up @@ -33,24 +33,37 @@ export async function handleAutoAndExtensionConnections(
);
}

SendAnalytics(
{
id: instance.remoteConnection?.state.connector?.state.channelId ?? '',
event: TrackingEvents.SDK_EXTENSION_UTILIZED,
...instance.remoteConnection?.state.connector?.state.originatorInfo,
commLayer:
instance.remoteConnection?.state.communicationLayerPreference,
sdkVersion:
instance.remoteConnection?.state.connector?.state.sdkVersion,
walletVersion:
instance.remoteConnection?.state.connector?.state.walletInfo?.version,
commLayerVersion: packageJson.version,
},
instance.remoteConnection?.state.connector?.state
.communicationServerUrl as string,
).catch((_err) => {
console.warn(`Can't send the SDK_EXTENSION_UTILIZED analytics event...`);
});
const { remoteConnection } = instance;

if (remoteConnection) {
const {
state: { connector, communicationLayerPreference },
} = remoteConnection;

const channelId = connector?.state.channelId ?? '';
const originatorInfo = connector?.state.originatorInfo ?? {};
const sdkVersion = connector?.state.sdkVersion;
const walletVersion = connector?.state.walletInfo?.version;
const communicationServerUrl = connector?.state.communicationServerUrl;

if (communicationServerUrl) {
const analyticsData = {
id: channelId,
event: TrackingEvents.SDK_EXTENSION_UTILIZED,
...originatorInfo,
commLayer: communicationLayerPreference,
sdkVersion,
walletVersion,
commLayerVersion: ANALYTICS_CONSTANTS.NO_VERSION,
};

SendAnalytics(analyticsData, communicationServerUrl).catch((_err) => {
console.warn(
`Can't send the SDK_EXTENSION_UTILIZED analytics event...`,
);
});
}
}

connectWithExtensionProvider(instance).catch((_err) => {
console.warn(`Can't connect with MetaMask extension...`);
Expand Down

0 comments on commit b4db689

Please sign in to comment.