Skip to content

Commit

Permalink
Merge pull request #305 from liam-hq/feat/custom-log
Browse files Browse the repository at this point in the history
📈 : add GTM utility functions and types for click logging
  • Loading branch information
junkisai authored Dec 18, 2024
2 parents 421037d + 4c090ee commit ad526f8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions frontend/.changeset/ninety-stingrays-unite.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 CopyLinkButton
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { clickLogEvent } from '@/features/gtm/utils'
import {
Button,
TooltipContent,
Expand Down Expand Up @@ -27,6 +28,10 @@ export const CopyLinkButton: FC = () => {
status: 'error',
})
})

clickLogEvent({
element: 'copyLinkButton',
})
}, [toast])

return (
Expand Down
12 changes: 12 additions & 0 deletions frontend/packages/erd-core/src/features/gtm/utils/clickLogEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { pushToDataLayer } from './pushToDataLayer'

type ClickLogEvent = {
element: string
}

export const clickLogEvent = ({ element }: ClickLogEvent) => {
pushToDataLayer({
event: 'click',
element,
})
}
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
@@ -0,0 +1 @@
export * from './clickLogEvent'
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type WindowWithDataLayer = Window & {
dataLayer: Record<string, unknown>[]
}

declare const window: WindowWithDataLayer

export const pushToDataLayer = (obj: Record<string, unknown>) => {
window.dataLayer = window.dataLayer || []
window.dataLayer.push(obj)
}

0 comments on commit ad526f8

Please sign in to comment.