Track redirects in Next.js 14? #2477
deadcoder0904
started this conversation in
General
Replies: 1 comment
-
this is a much better solution but lmk if you guys have a better one: "use client"
import { notFound, redirect, useParams } from "next/navigation"
import Script from "next/script"
import React from "react"
const Guide = () => {
const { guide } = useParams()
const [umamiLoaded, setUmamiLoaded] = React.useState(false)
const guides = [
{
source: "/google",
destination:
"https://google.com/",
},
]
const result = guides.find((g) => {
const param = g.source.split("/")[1]
if (guide === param) {
return g
}
})
if (!result) {
return notFound()
}
if (!umamiLoaded) {
return (
<>
<p className="m-2">Wait, redirecting...</p>
<Script
async
src="https://umami.example.com/script.js"
data-website-id="whateverisyourid"
onLoad={() => {
setUmamiLoaded(true)
}}
/>
</>
)
}
redirect(result.destination)
}
export default Guide |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Describe the Bug
i want to track redirects in my url.
i have a filepath named
src/app/[guide]/page.tsx
in next.js 14 that looks like:if anyone visits
https://example.com/google
, then it should redirect togoogle.com
but doesn't get tracked.i tested it by adding a bit of timeout & it gets tracked. i've tested it & only from 1.5 seconds, it starts working. but i've made the delay to be
2
because i think it depends on loading the script & that depends on network a particular user is using. idk if i can track it like url shorteners do but that's what i want.current solution that works:
is there a way to track redirects in umami directly without adding timeout?
maybe like https://www.zachgollwitzer.com/posts/fathom-analytics-nextjs13-app-directory
Database
PostgreSQL
Relevant log output
No response
Which browser are you using? (if relevant)
Edge
How are you deploying your application? (if relevant)
Coolify
Beta Was this translation helpful? Give feedback.
All reactions