Skip to content

Commit fa5ec4c

Browse files
authored
Track scroll button clicks (#49764)
1 parent 7241404 commit fa5ec4c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/events/components/events.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,17 @@ function initLinkEvent() {
378378
link_container: container?.dataset.container,
379379
})
380380
})
381+
382+
// Add tracking for scroll to top button
383+
document.documentElement.addEventListener('click', (evt) => {
384+
const target = evt.target as HTMLElement
385+
if (!target.closest('.ghd-scroll-to-top')) return
386+
const url = window.location.href.split('#')[0] // Remove hash
387+
sendEvent({
388+
type: EventType.link,
389+
link_url: `${url}#scroll-to-top`,
390+
})
391+
})
381392
}
382393

383394
function initHoverEvent() {

src/frame/components/ui/ScrollButton/ScrollButton.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export const ScrollButton = ({ className, ariaLabel }: ScrollButtonPropsT) => {
4343
<button
4444
onClick={onClick}
4545
className={cx(
46+
'ghd-scroll-to-top', // for data tracking, see events.ts
4647
'tooltipped tooltipped-n tooltipped-no-delay color-bg-accent-emphasis color-fg-on-emphasis circle border-0',
4748
'd-flex flex-items-center flex-justify-center',
4849
)}

0 commit comments

Comments
 (0)