react-ga4 icon indicating copy to clipboard operation
react-ga4 copied to clipboard

Next.js V15

Open m7eng opened this issue 1 year ago • 2 comments

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?

m7eng avatar Oct 31 '24 11:10 m7eng

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

kleinaber avatar Dec 06 '24 12:12 kleinaber

Next.js has native support for Google Analytics: https://nextjs.org/docs/app/building-your-application/optimizing/third-party-libraries#google-analytics

andreynovikov avatar Dec 11 '24 09:12 andreynovikov