Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
validateAndConfirmPointer,
WalletAddressFormatError,
} from '@shared/utils/index'
import { useTrackEvent } from '~/lib/analytics'

const htmlEncodePointer = (pointer: string): string => {
return pointer
Expand All @@ -24,6 +25,7 @@ export const LinkTagGenerator = () => {
const [error, setError] = useState('')
const [showCodeBox, setShowCodeBox] = useState(false)
const [isCopied, setIsCopied] = useState(false)
const trackEvent = useTrackEvent()

const handleSubmit = useCallback(
async (e: React.FormEvent) => {
Expand All @@ -36,6 +38,7 @@ export const LinkTagGenerator = () => {
const validatedPointer = await validateAndConfirmPointer(pointerInput)
setParsedLinkTag(htmlEncodePointer(validatedPointer))
setShowCodeBox(true)
trackEvent('generated_tag', { tag_type: 'link_tag' })
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we use the same save /submit event here from other tools and pass tool: "link_tag" with it?

} catch (err) {
const message =
err instanceof WalletAddressFormatError
Expand All @@ -47,7 +50,7 @@ export const LinkTagGenerator = () => {
setIsLoading(false)
}
},
[pointerInput],
[pointerInput, trackEvent],
)

const handleOnChange = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,21 @@ export const ToolsWalletAddress = ({
const walletAddressInfo = await getWalletAddress(walletAddressUrl)
walletActions.setWalletAddressId(walletAddressInfo.id)
await connect()
trackEvent('wallet_connected')
trackEvent('wallet_connected', {
wallet_provider: new URL(walletAddressInfo.id).hostname,
})
} catch (error) {
setError({ walletAddress: [(error as Error).message] })
} finally {
setIsLoading(false)
}
}

const handleDisconnect = () => {
trackEvent('wallet_disconnected')
disconnect()
}

const handleWalletAddressChange = (
e: React.ChangeEvent<HTMLInputElement>,
) => {
Expand Down Expand Up @@ -160,7 +167,7 @@ export const ToolsWalletAddress = ({
</div>
{snap.isWalletConnected && (
<button
onClick={disconnect}
onClick={handleDisconnect}
className="flex items-center justify-center w-12 h-12 p-2 rounded-lg shrink-0 hover:bg-gray-50 active:bg-gray-100 transition-colors"
aria-label="Disconnect wallet"
>
Expand Down
14 changes: 12 additions & 2 deletions frontend/app/hooks/useSaveProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '@/components'
import { TOOL_BANNER, TOOL_OFFERWALL, TOOL_WIDGET } from '@shared/types'
import { useDialog } from '~/hooks/useDialog'
import { useTrackEvent } from '~/lib/analytics'
import { ApiError } from '~/lib/helpers'
import { actions as bannerActions } from '~/stores/banner-store'
import { actions as offerwallActions } from '~/stores/offerwall-store'
Expand All @@ -28,6 +29,7 @@ function getToolActions() {

export const useSaveProfile = (wallet: WalletStore) => {
const [openDialog, closeDialog] = useDialog()
const trackEvent = useTrackEvent()

const save = useCallback(
async (action: 'save-success' | 'script'): Promise<void> => {
Expand All @@ -48,10 +50,18 @@ export const useSaveProfile = (wallet: WalletStore) => {

if (result.success) {
actions.commitProfile()

trackEvent('settings_changed', {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's remove this event for now - this one here is fired even if settings aren't changed.

tool: toolState.currentToolType,
})
if (action === 'script') {
trackEvent('script_generated', {
tool: toolState.currentToolType,
})
openDialog(<ScriptDialog wallet={wallet} />)
} else {
trackEvent('profile_saved', {
Comment on lines +57 to +62
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need two separate events for this? What if we pass an action in event data to tell whether it was save or script?

tool: toolState.currentToolType,
})
openDialog(<StatusDialog onDone={closeDialog} />)
}
}
Expand All @@ -69,7 +79,7 @@ export const useSaveProfile = (wallet: WalletStore) => {
)
}
},
[openDialog, closeDialog],
[openDialog, closeDialog, trackEvent],
)

const saveLastAction = useCallback(async (): Promise<void> => {
Expand Down
11 changes: 11 additions & 0 deletions frontend/app/lib/analytics-events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Tool } from '@shared/types'

export type ToolsEventMap = {
Comment thread
kjmitchelljr marked this conversation as resolved.
click_card_tool: { link: string }
wallet_connected: { wallet_provider: string }
wallet_disconnected: undefined
profile_saved: { tool: Tool }
script_generated: { tool: Tool }
settings_changed: { tool: Tool }
generated_tag: { tag_type: 'link_tag' | 'revshare' }
}
17 changes: 10 additions & 7 deletions frontend/app/lib/analytics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { createContext, useCallback, useContext } from 'react'
import type { ReactNode } from 'react'
import { useLocation } from 'react-router'
import { TOOLS } from '@shared/types'
import type { ToolsEventMap } from '~/lib/analytics-events'

type TrackFn = (
eventName: string,
eventData?: Record<string, string | number | boolean | null>,
export type TrackFn = <E extends keyof ToolsEventMap>(
...args: ToolsEventMap[E] extends undefined
? [eventName: E]
: [eventName: E, data: ToolsEventMap[E]]
) => void

const TrackContext = createContext<TrackFn>(() => {})
Expand All @@ -14,12 +16,13 @@ export function TelemetryProvider({ children }: { children: ReactNode }) {
const { pathname } = useLocation()
const tool = TOOLS.find((t) => pathname.startsWith(`/${t}`))

const track = useCallback<TrackFn>(
(eventName, eventData) => {
window.umami?.track(eventName, tool ? { tool, ...eventData } : eventData)
},
const track = useCallback(
((eventName, eventData) => {
window.umami?.track(eventName, { ...(tool && { tool }), ...eventData })
}) as TrackFn,
[tool],
)

return <TrackContext.Provider value={track}>{children}</TrackContext.Provider>
}

Expand Down
Loading