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 19, 2024
1 parent 2a981ec commit f6b3faf
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 5 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 { clickLogEvent } 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(() => {
clickLogEvent({
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 { clickLogEvent } 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)

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { clickLogEvent } 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(() => {
clickLogEvent({
element: 'fitview',
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 { clickLogEvent } 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(() => {
clickLogEvent({
element: 'zoom',
zoomLevel: zoomLevel.toFixed(2),
showMode: showMode,
})
zoomOut()
}, [zoomOut])
}, [zoomOut, zoomLevel, showMode])

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

return (
<div className={styles.wrapper}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ import { pushToDataLayer } from './pushToDataLayer'

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

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

0 comments on commit f6b3faf

Please sign in to comment.