From c135a7e9797792a889b23c63a62a27627b19c3e8 Mon Sep 17 00:00:00 2001 From: tomiir Date: Tue, 19 Nov 2024 12:18:40 +0100 Subject: [PATCH 1/4] feat: add INITIALIZE event to track configuration options --- packages/appkit/src/client.ts | 15 ++++++++++ .../core/src/controllers/EventsController.ts | 13 ++++++++- packages/core/src/utils/TypeUtil.ts | 29 +++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/packages/appkit/src/client.ts b/packages/appkit/src/client.ts index f80556acec..b2c2b941a6 100644 --- a/packages/appkit/src/client.ts +++ b/packages/appkit/src/client.ts @@ -211,6 +211,21 @@ export class AppKit { await this.initOrContinue() await this.syncExistingConnection() this.version = options.sdkVersion + + const { ...optionsCopy } = options + delete optionsCopy.adapters + + EventsController.sendEvent({ + type: 'track', + event: 'INITIALIZE', + properties: { + ...optionsCopy, + networks: options.networks.map(n => n.id), + siweConfig: { + options: options.siweConfig?.options || {} + } + } + }) } // -- Public ------------------------------------------------------------------- diff --git a/packages/core/src/controllers/EventsController.ts b/packages/core/src/controllers/EventsController.ts index c81b5051e1..dd3291bb98 100644 --- a/packages/core/src/controllers/EventsController.ts +++ b/packages/core/src/controllers/EventsController.ts @@ -45,8 +45,17 @@ export const EventsController = { async _sendAnalyticsEvent(payload: EventsControllerState) { try { if (excluded.includes(payload.data.event) || typeof window === 'undefined') { + console.log( + '>> Analytics early return', + payload, + excluded.includes(payload.data.event), + typeof window === 'undefined' + ) + return } + + console.log('>> Final analytics event', payload) await api.post({ path: '/e', headers: EventsController._getApiHeaders(), @@ -58,14 +67,16 @@ export const EventsController = { props: payload.data } }) - } catch { + } catch (e) { // Catch silently + console.log('>> Analytics error', e) } }, sendEvent(data: EventsControllerState['data']) { state.timestamp = Date.now() state.data = data + console.log('>> Sending analytics event', OptionsController.state.features?.analytics, state) if (OptionsController.state.features?.analytics) { EventsController._sendAnalyticsEvent(state) } diff --git a/packages/core/src/utils/TypeUtil.ts b/packages/core/src/utils/TypeUtil.ts index 4fec7b8f7a..6f7d9a63b7 100644 --- a/packages/core/src/utils/TypeUtil.ts +++ b/packages/core/src/utils/TypeUtil.ts @@ -18,6 +18,30 @@ import type { ConstantsUtil } from './ConstantsUtil.js' import type { ReownName } from '../controllers/EnsController.js' import type UniversalProvider from '@walletconnect/universal-provider' +type AppKitConfigs = { + showWallets?: boolean + siweConfig?: { + options: { + enabled?: boolean + nonceRefetchIntervalMs?: number + sessionRefetchIntervalMs?: number + signOutOnDisconnect?: boolean + signOutOnAccountChange?: boolean + signOutOnNetworkChange?: boolean + } + } + themeMode?: 'dark' | 'light' + + themeVariables?: ThemeVariables + allowUnsupportedChain?: boolean + networks: (string | number)[] + defaultNetwork?: AppKitNetwork + chainImages?: Record + connectorImages?: Record + coinbasePreference?: 'all' | 'smartWalletOnly' | 'eoaOnly' + metadata?: Metadata +} + export type CaipNetworkCoinbaseNetwork = | 'Ethereum' | 'Arbitrum One' @@ -747,6 +771,11 @@ export type Event = search: string } } + | { + type: 'track' + event: 'INITIALIZE' + properties: AppKitConfigs + } // Onramp Types export type DestinationWallet = { address: string From 161868ba37255290b8a6ba2aef5d769f86db88eb Mon Sep 17 00:00:00 2001 From: tomiir Date: Tue, 19 Nov 2024 12:20:07 +0100 Subject: [PATCH 2/4] chore: add test --- packages/appkit/src/tests/appkit.test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/appkit/src/tests/appkit.test.ts b/packages/appkit/src/tests/appkit.test.ts index 16c72584b3..eafa5f9fd0 100644 --- a/packages/appkit/src/tests/appkit.test.ts +++ b/packages/appkit/src/tests/appkit.test.ts @@ -54,6 +54,11 @@ describe('Base', () => { expect(OptionsController.setSdkVersion).toHaveBeenCalledWith(mockOptions.sdkVersion) expect(OptionsController.setProjectId).toHaveBeenCalledWith(mockOptions.projectId) expect(OptionsController.setMetadata).toHaveBeenCalledWith(mockOptions.metadata) + + const copyMockOptions = { ...mockOptions } + delete copyMockOptions.adapters + + expect(EventsController.sendEvent).toHaveBeenCalledWith(mockOptions) }) it('should initialize adapters in ChainController', () => { From beb532538fdae647bcd1372a368b1f1fa495f66e Mon Sep 17 00:00:00 2001 From: tomiir Date: Thu, 5 Dec 2024 12:19:59 -0600 Subject: [PATCH 3/4] chore: remove logs --- packages/core/src/controllers/EventsController.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/packages/core/src/controllers/EventsController.ts b/packages/core/src/controllers/EventsController.ts index dd3291bb98..032984562e 100644 --- a/packages/core/src/controllers/EventsController.ts +++ b/packages/core/src/controllers/EventsController.ts @@ -45,17 +45,9 @@ export const EventsController = { async _sendAnalyticsEvent(payload: EventsControllerState) { try { if (excluded.includes(payload.data.event) || typeof window === 'undefined') { - console.log( - '>> Analytics early return', - payload, - excluded.includes(payload.data.event), - typeof window === 'undefined' - ) - return } - console.log('>> Final analytics event', payload) await api.post({ path: '/e', headers: EventsController._getApiHeaders(), @@ -69,14 +61,12 @@ export const EventsController = { }) } catch (e) { // Catch silently - console.log('>> Analytics error', e) } }, sendEvent(data: EventsControllerState['data']) { state.timestamp = Date.now() state.data = data - console.log('>> Sending analytics event', OptionsController.state.features?.analytics, state) if (OptionsController.state.features?.analytics) { EventsController._sendAnalyticsEvent(state) } From 9c7addee612cba8c6df862b41bdfd4d2c20f2623 Mon Sep 17 00:00:00 2001 From: tomiir Date: Thu, 5 Dec 2024 12:22:34 -0600 Subject: [PATCH 4/4] chore: rename types --- packages/core/src/controllers/EventsController.ts | 2 +- packages/core/src/utils/TypeUtil.ts | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/core/src/controllers/EventsController.ts b/packages/core/src/controllers/EventsController.ts index 032984562e..4c1a40177a 100644 --- a/packages/core/src/controllers/EventsController.ts +++ b/packages/core/src/controllers/EventsController.ts @@ -59,7 +59,7 @@ export const EventsController = { props: payload.data } }) - } catch (e) { + } catch { // Catch silently } }, diff --git a/packages/core/src/utils/TypeUtil.ts b/packages/core/src/utils/TypeUtil.ts index 413a9f402d..97676d74a0 100644 --- a/packages/core/src/utils/TypeUtil.ts +++ b/packages/core/src/utils/TypeUtil.ts @@ -18,7 +18,7 @@ import type { ConstantsUtil } from './ConstantsUtil.js' import type { ReownName } from '../controllers/EnsController.js' import type UniversalProvider from '@walletconnect/universal-provider' -type AppKitConfigs = { +type InitializeAppKitConfigs = { showWallets?: boolean siweConfig?: { options: { @@ -31,7 +31,6 @@ type AppKitConfigs = { } } themeMode?: 'dark' | 'light' - themeVariables?: ThemeVariables allowUnsupportedChain?: boolean networks: (string | number)[] @@ -791,7 +790,7 @@ export type Event = | { type: 'track' event: 'INITIALIZE' - properties: AppKitConfigs + properties: InitializeAppKitConfigs } // Onramp Types export type DestinationWallet = {