From b77ac5537dd7ceacb545af3a6a151da54f0405c1 Mon Sep 17 00:00:00 2001 From: tomiir Date: Wed, 28 Feb 2024 22:26:31 -0400 Subject: [PATCH] feat: unify connection events (#1929) --- packages/core/src/utils/TypeUtil.ts | 12 +++--------- .../src/partials/w3m-connecting-wc-browser/index.ts | 2 +- .../src/views/w3m-connecting-external-view/index.ts | 12 ++++-------- .../src/views/w3m-connecting-wc-view/index.ts | 3 ++- .../src/views/w3m-email-verify-otp-view/index.ts | 2 +- 5 files changed, 11 insertions(+), 20 deletions(-) diff --git a/packages/core/src/utils/TypeUtil.ts b/packages/core/src/utils/TypeUtil.ts index 7255294580..8299f95093 100644 --- a/packages/core/src/utils/TypeUtil.ts +++ b/packages/core/src/utils/TypeUtil.ts @@ -27,14 +27,7 @@ export interface LinkingRecord { export type ProjectId = string -export type Platform = - | 'mobile' - | 'desktop' - | 'browser' - | 'web' - | 'qrcode' - | 'unsupported' - | 'external' +export type Platform = 'mobile' | 'desktop' | 'browser' | 'web' | 'qrcode' | 'unsupported' export type ConnectorType = 'EXTERNAL' | 'WALLET_CONNECT' | 'INJECTED' | 'ANNOUNCED' | 'EMAIL' @@ -216,7 +209,8 @@ export type Event = type: 'track' event: 'CONNECT_SUCCESS' properties: { - method: 'qrcode' | 'mobile' | 'external' | 'browser' | 'email' + method: 'qrcode' | 'mobile' | 'browser' | 'email' + name: string } } | { diff --git a/packages/scaffold/src/partials/w3m-connecting-wc-browser/index.ts b/packages/scaffold/src/partials/w3m-connecting-wc-browser/index.ts index 790b15a9ca..0b4f47013b 100644 --- a/packages/scaffold/src/partials/w3m-connecting-wc-browser/index.ts +++ b/packages/scaffold/src/partials/w3m-connecting-wc-browser/index.ts @@ -43,7 +43,7 @@ export class W3mConnectingWcBrowser extends W3mConnectingWidget { EventsController.sendEvent({ type: 'track', event: 'CONNECT_SUCCESS', - properties: { method: 'browser' } + properties: { method: 'browser', name: this.wallet?.name || 'Unknown' } }) } catch (error) { EventsController.sendEvent({ diff --git a/packages/scaffold/src/views/w3m-connecting-external-view/index.ts b/packages/scaffold/src/views/w3m-connecting-external-view/index.ts index c7eeb1019d..b4bf8d3673 100644 --- a/packages/scaffold/src/views/w3m-connecting-external-view/index.ts +++ b/packages/scaffold/src/views/w3m-connecting-external-view/index.ts @@ -1,4 +1,4 @@ -import type { BaseError, ConnectorType, Platform } from '@web3modal/core' +import type { BaseError } from '@web3modal/core' import { ConnectionController, EventsController, @@ -10,11 +10,6 @@ import { import { customElement } from '@web3modal/ui' import { W3mConnectingWidget } from '../../utils/w3m-connecting-widget/index.js' -const platformMap = { - INJECTED: 'browser', - ANNOUNCED: 'browser' -} as Record - @customElement('w3m-connecting-external-view') export class W3mConnectingExternalView extends W3mConnectingWidget { public constructor() { @@ -22,12 +17,13 @@ export class W3mConnectingExternalView extends W3mConnectingWidget { if (!this.connector) { throw new Error('w3m-connecting-view: No connector provided') } + EventsController.sendEvent({ type: 'track', event: 'SELECT_WALLET', properties: { name: this.connector.name ?? 'Unknown', - platform: platformMap[this.connector.type] ?? 'external' + platform: 'browser' } }) this.onConnect = this.onConnectProxy.bind(this) @@ -54,7 +50,7 @@ export class W3mConnectingExternalView extends W3mConnectingWidget { EventsController.sendEvent({ type: 'track', event: 'CONNECT_SUCCESS', - properties: { method: 'external' } + properties: { method: 'browser', name: this.connector.name || 'Unknown' } }) } } catch (error) { diff --git a/packages/scaffold/src/views/w3m-connecting-wc-view/index.ts b/packages/scaffold/src/views/w3m-connecting-wc-view/index.ts index 1dd8a8e31a..fd6c3ad01e 100644 --- a/packages/scaffold/src/views/w3m-connecting-wc-view/index.ts +++ b/packages/scaffold/src/views/w3m-connecting-wc-view/index.ts @@ -111,7 +111,8 @@ export class W3mConnectingWcView extends LitElement { type: 'track', event: 'CONNECT_SUCCESS', properties: { - method: wcLinking ? 'mobile' : 'qrcode' + method: wcLinking ? 'mobile' : 'qrcode', + name: this.wallet?.name || 'Unknown' } }) } diff --git a/packages/scaffold/src/views/w3m-email-verify-otp-view/index.ts b/packages/scaffold/src/views/w3m-email-verify-otp-view/index.ts index 26d58c38c9..e6060a09bb 100644 --- a/packages/scaffold/src/views/w3m-email-verify-otp-view/index.ts +++ b/packages/scaffold/src/views/w3m-email-verify-otp-view/index.ts @@ -20,7 +20,7 @@ export class W3mEmailVerifyOtpView extends W3mEmailOtpWidget { EventsController.sendEvent({ type: 'track', event: 'CONNECT_SUCCESS', - properties: { method: 'email' } + properties: { method: 'email', name: this.emailConnector.name || 'Unknown' } }) } } catch (error) {