Skip to content

Commit

Permalink
📈 Add click logging for toolbar actions and include show mode in even…
Browse files Browse the repository at this point in the history
…t data
  • Loading branch information
FunamaYukina committed Dec 20, 2024
1 parent 2a981ec commit 582ac0e
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 4 deletions.
6 changes: 6 additions & 0 deletions frontend/.changeset/six-rocks-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@liam-hq/erd-core": patch
"@liam-hq/cli": patch
---

📈 Add click logging for toolbar actions and include show mode in event data
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { toolbarActionLogEvent } from '@/features/gtm/utils'
import { useUserEditingStore } from '@/stores'
import { IconButton, Scan } from '@liam-hq/ui'
import { ToolbarButton } from '@radix-ui/react-toolbar'
import { useReactFlow } from '@xyflow/react'
import { type FC, useCallback } from 'react'

export const FitviewButton: FC = () => {
const { fitView } = useReactFlow()
const { showMode } = useUserEditingStore()

const handleClick = useCallback(() => {
toolbarActionLogEvent({
element: 'fitview',
showMode: showMode,
})
fitView()
}, [fitView])
}, [fitView, showMode])

return (
<ToolbarButton asChild onClick={handleClick}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { toolbarActionLogEvent } from '@/features/gtm/utils'
import { type ShowMode, showModeSchema } from '@/schemas/showMode'
import { updateShowMode, useUserEditingStore } from '@/stores'
import {
Expand Down Expand Up @@ -28,6 +29,11 @@ export const ShowModeMenu: FC = () => {

if (parsed.success) {
updateShowMode(parsed.output)

toolbarActionLogEvent({
element: 'changeShowMode',
showMode: value,
})
}
}, [])

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { toolbarActionLogEvent } from '@/features/gtm/utils'
import { useUserEditingStore } from '@/stores'
import { IconButton, TidyUpIcon } from '@liam-hq/ui'
import { ToolbarButton } from '@radix-ui/react-toolbar'
import { type FC, useCallback } from 'react'
import { useAutoLayout } from '../../useAutoLayout'

export const TidyUpButton: FC = () => {
const { handleLayout } = useAutoLayout()
const { showMode } = useUserEditingStore()
const handleClick = useCallback(() => {
toolbarActionLogEvent({
element: 'tidyUp',
showMode: showMode,
})
handleLayout()
}, [handleLayout])
}, [handleLayout, showMode])

return (
<ToolbarButton asChild>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { toolbarActionLogEvent } from '@/features/gtm/utils'
import { useUserEditingStore } from '@/stores'
import { IconButton, Minus, Plus } from '@liam-hq/ui'
import { ToolbarButton } from '@radix-ui/react-toolbar'
import { useReactFlow, useStore } from '@xyflow/react'
Expand All @@ -7,14 +9,25 @@ import styles from './ZoomControls.module.css'
export const ZoomControls: FC = () => {
const zoomLevel = useStore((store) => store.transform[2])
const { zoomIn, zoomOut } = useReactFlow()
const { showMode } = useUserEditingStore()

const handleClickZoomOut = useCallback(() => {
toolbarActionLogEvent({
element: 'zoom',
zoomLevel: zoomLevel.toFixed(2),
showMode: showMode,
})
zoomOut()
}, [zoomOut])
}, [zoomOut, zoomLevel, showMode])

const handleClickZoomIn = useCallback(() => {
toolbarActionLogEvent({
element: 'zoom',
zoomLevel: zoomLevel.toFixed(2),
showMode: showMode,
})
zoomIn()
}, [zoomIn])
}, [zoomIn, zoomLevel, showMode])

return (
<div className={styles.wrapper}>
Expand Down
1 change: 1 addition & 0 deletions frontend/packages/erd-core/src/features/gtm/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './clickLogEvent'
export * from './toolbarActionLogEvent'
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { pushToDataLayer } from './pushToDataLayer'

type ToolbarActionLogEvent = {
element: string
zoomLevel?: string
showMode?: string
}

export const toolbarActionLogEvent = ({
element,
zoomLevel,
showMode,
}: ToolbarActionLogEvent) => {
pushToDataLayer({
event: 'click',
element,
zoomLevel,
showMode,
})
}

0 comments on commit 582ac0e

Please sign in to comment.