react-ga4
react-ga4 copied to clipboard
Next.js V15
Hello, how do I used react-ga4 in NextJS V15 especially with the App Router? Is it sufficient to put
import ReactGA from 'react-ga4'; (...) const TRACKING_ID = "G-R85LV3LZ4X"; ReactGA.initialize(TRACKING_ID);
into the page.tsx and it will track all other routes as well?
Haven't tested this with v15 yet but at least in this post it's said to work right out of the box: https://medium.com/@vergil333/google-analytics-4-in-react-a250005c2455
Next.js has native support for Google Analytics: https://nextjs.org/docs/app/building-your-application/optimizing/third-party-libraries#google-analytics