fix: track user on page load

This commit is contained in:
Christel Westerberg
2024-07-15 09:13:20 +02:00
parent edb6005a72
commit c96008fb78
18 changed files with 247 additions and 122 deletions

View File

@@ -3,6 +3,8 @@ import NextLink from "next/link"
import { usePathname } from "next/navigation"
import { useEffect } from "react"
import { trackClick } from "@/utils/tracking"
import { linkVariants } from "./variants"
import type { LinkProps } from "./link"
@@ -36,11 +38,13 @@ export default function Link({
useEffect(() => {
if (trackingId) {
document.getElementById(trackingId)?.addEventListener("click", () => {})
document
.getElementById(trackingId)
?.addEventListener("click", () => trackClick(trackingId))
return () => {
document
.getElementById(trackingId)
?.removeEventListener("click", () => {})
?.removeEventListener("click", () => trackClick(trackingId))
}
}
}, [trackingId])
@@ -51,6 +55,7 @@ export default function Link({
prefetch={prefetch}
className={classNames}
href={href}
id={trackingId}
{...props}
/>
)