Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add INITIALIZE event to track configuration options #3267

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/appkit/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 -------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions packages/appkit/src/tests/appkit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,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', () => {
Expand Down
13 changes: 12 additions & 1 deletion packages/core/src/controllers/EventsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,17 @@
async _sendAnalyticsEvent(payload: EventsControllerState) {
try {
if (excluded.includes(payload.data.event) || typeof window === 'undefined') {
console.log(

Check failure on line 48 in packages/core/src/controllers/EventsController.ts

View workflow job for this annotation

GitHub Actions / code_style (lint)

Unexpected console statement
'>> Analytics early return',
payload,
excluded.includes(payload.data.event),
typeof window === 'undefined'
)

return
}

console.log('>> Final analytics event', payload)

Check failure on line 58 in packages/core/src/controllers/EventsController.ts

View workflow job for this annotation

GitHub Actions / code_style (lint)

Unexpected console statement
await api.post({
path: '/e',
headers: EventsController._getApiHeaders(),
Expand All @@ -58,14 +67,16 @@
props: payload.data
}
})
} catch {
} catch (e) {
// Catch silently
console.log('>> Analytics error', e)

Check failure on line 72 in packages/core/src/controllers/EventsController.ts

View workflow job for this annotation

GitHub Actions / code_style (lint)

Unexpected console statement
}
},

sendEvent(data: EventsControllerState['data']) {
state.timestamp = Date.now()
state.data = data
console.log('>> Sending analytics event', OptionsController.state.features?.analytics, state)

Check failure on line 79 in packages/core/src/controllers/EventsController.ts

View workflow job for this annotation

GitHub Actions / code_style (lint)

Unexpected console statement
if (OptionsController.state.features?.analytics) {
EventsController._sendAnalyticsEvent(state)
}
Expand Down
29 changes: 29 additions & 0 deletions packages/core/src/utils/TypeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we give another name specific to event to not confuse with other type definitions? Like InitializeEventAppKitParams

showWallets?: boolean
siweConfig?: {
options: {
enabled?: boolean
nonceRefetchIntervalMs?: number
sessionRefetchIntervalMs?: number
signOutOnDisconnect?: boolean
signOutOnAccountChange?: boolean
signOutOnNetworkChange?: boolean
}
}
themeMode?: 'dark' | 'light'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected empty line maybe?

themeVariables?: ThemeVariables
allowUnsupportedChain?: boolean
networks: (string | number)[]
defaultNetwork?: AppKitNetwork
chainImages?: Record<number | string, string>
connectorImages?: Record<string, string>
coinbasePreference?: 'all' | 'smartWalletOnly' | 'eoaOnly'
metadata?: Metadata
}

export type CaipNetworkCoinbaseNetwork =
| 'Ethereum'
| 'Arbitrum One'
Expand Down Expand Up @@ -747,6 +771,11 @@ export type Event =
search: string
}
}
| {
type: 'track'
event: 'INITIALIZE'
properties: AppKitConfigs
}
// Onramp Types
export type DestinationWallet = {
address: string
Expand Down
Loading