Skip to content

Commit 67b2d42

Browse files
committed
feat(analytics): align Remote Connection Request platform property with sig/txn events
Pairs with [segment-schema#545](Consensys/segment-schema#545), which renames `sdk_platform` → `remote_request_platform` on the Remote Connection Request Received/Failed events and tightens the type to the 5-value `PlatformType` enum shared between SDK v1 and v2. Mobile-side changes: - `SDKConnectV2/services/connection-registry.ts`: rename the property key on the three MWP `trackMwpEvent` call sites (the V2 emitter). - `SDKConnect/ConnectionManagement/connectToChannel.ts`: extend the V1 emitter to populate `remote_request_platform` from `originatorInfo.platform`. V1 previously did not populate this field at all. The value is coerced from an empty string to `undefined` so the property is dropped when `getPlatformType` can't resolve a platform (the remote SDK falls back to `platform: ''` in that case), avoiding an invalid-enum rejection on the Segment side. - Updated tests to assert the new key and the empty-string coercion. Both V1 and V2 derive their platform values from `PlatformType` in `@metamask/sdk-communication-layer`, so no client-side mapping or enum widening is required.
1 parent 70f8823 commit 67b2d42

4 files changed

Lines changed: 34 additions & 4 deletions

File tree

app/core/SDKConnect/ConnectionManagement/connectToChannel.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,34 @@ describe('connectToChannel', () => {
282282
properties: expect.objectContaining({
283283
transport_type: 'socket_relay',
284284
remote_session_id: 'test-anon-id',
285+
sdk_version: '1.0.0',
286+
remote_request_platform: 'web',
285287
}),
286288
}),
287289
);
288290
});
289291

292+
it('should coerce an empty-string originatorInfo.platform to undefined so the property is dropped', async () => {
293+
originatorInfo.anonId = 'test-anon-id';
294+
originatorInfo.platform = '';
295+
(checkPermissions as jest.Mock).mockResolvedValue(true);
296+
297+
await connectToChannel({
298+
instance: mockInstance,
299+
id,
300+
trigger,
301+
otherPublicKey,
302+
origin,
303+
validUntil,
304+
originatorInfo,
305+
initialConnection: true,
306+
});
307+
308+
const trackedProperties = (analytics.trackEvent as jest.Mock).mock
309+
.calls[0][0].properties;
310+
expect(trackedProperties).not.toHaveProperty('remote_request_platform');
311+
});
312+
290313
// wallet_connection_user_approved / wallet_connection_user_rejected are
291314
// intentionally NOT tracked here — they are already covered by the
292315
// MetaMetrics CONNECT_REQUEST_COMPLETED / CONNECT_REQUEST_CANCELLED events

app/core/SDKConnect/ConnectionManagement/connectToChannel.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ async function connectToChannel({
8585
.addProperties({
8686
transport_type: 'socket_relay',
8787
sdk_version: originatorInfo?.apiVersion,
88+
// `originatorInfo.platform` is sourced from `PlatformType` in
89+
// `@metamask/sdk-communication-layer`; aligns with the V2 emitter and
90+
// the `remote_request_platform` enum in schema#545. Coerce empty
91+
// strings (fallback when `getPlatformType` can't resolve) to
92+
// undefined so the property is dropped rather than flagged as an
93+
// invalid enum value.
94+
remote_request_platform: originatorInfo?.platform || undefined,
8895
remote_session_id: anonId,
8996
})
9097
.build(),

app/core/SDKConnectV2/services/connection-registry.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ describe('ConnectionRegistry', () => {
441441
remote_session_id: mockConnectionRequest.sessionRequest.id,
442442
transport_type: TransportType.MWP,
443443
sdk_version: '2.0.0',
444-
sdk_platform: 'JavaScript',
444+
remote_request_platform: 'JavaScript',
445445
}),
446446
);
447447
});

app/core/SDKConnectV2/services/connection-registry.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ export class ConnectionRegistry {
182182
remote_session_id: conn.metadata?.analytics?.remote_session_id ?? id,
183183
transport_type: TransportType.MWP,
184184
sdk_version: conn.metadata?.sdk?.version,
185-
sdk_platform: conn.metadata?.sdk?.platform,
185+
remote_request_platform: conn.metadata?.sdk?.platform,
186186
found_in_store: true,
187187
});
188188
return;
@@ -257,7 +257,7 @@ export class ConnectionRegistry {
257257
connReq.sessionRequest.id,
258258
transport_type: TransportType.MWP,
259259
sdk_version: connReq.metadata.sdk.version,
260-
sdk_platform: connReq.metadata.sdk.platform,
260+
remote_request_platform: connReq.metadata.sdk.platform,
261261
});
262262

263263
// Defense-in-depth: block connections whose self-reported dapp metadata
@@ -304,7 +304,7 @@ export class ConnectionRegistry {
304304
'unknown',
305305
transport_type: TransportType.MWP,
306306
sdk_version: connReq?.metadata?.sdk?.version,
307-
sdk_platform: connReq?.metadata?.sdk?.platform,
307+
remote_request_platform: connReq?.metadata?.sdk?.platform,
308308
failure_reason: error instanceof Error ? error.message : String(error),
309309
});
310310

0 commit comments

Comments
 (0)