fix: support for tracking link clicks
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"use client"
|
||||
import NextLink from "next/link"
|
||||
import { usePathname } from "next/navigation"
|
||||
import { useEffect } from "react"
|
||||
|
||||
import { linkVariants } from "./variants"
|
||||
|
||||
@@ -16,6 +17,7 @@ export default function Link({
|
||||
scroll = true,
|
||||
prefetch,
|
||||
variant,
|
||||
trackingId,
|
||||
...props
|
||||
}: LinkProps) {
|
||||
const currentPageSlug = usePathname()
|
||||
@@ -31,6 +33,18 @@ export default function Link({
|
||||
size,
|
||||
variant,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (trackingId) {
|
||||
document.getElementById(trackingId)?.addEventListener("click", () => {})
|
||||
return () => {
|
||||
document
|
||||
.getElementById(trackingId)
|
||||
?.removeEventListener("click", () => {})
|
||||
}
|
||||
}
|
||||
}, [trackingId])
|
||||
|
||||
return (
|
||||
<NextLink
|
||||
scroll={scroll}
|
||||
|
||||
Reference in New Issue
Block a user