Back to Next Js

React-GA4 example

examples/with-react-ga4/README.md

16.2.51.4 KB
Original Source

React-GA4 example

As of May 2023, react-ga uses Universal Analytics which will stop processing new data starting July 2023. Until this is fixed, this example has been updated to use react-ga4 instead.

This example shows the most basic way to use react-ga4 using a custom App component with Next.js. Modify Tracking ID in utils/analytics.js file for testing this example.

Deploy your own

How to use

Execute create-next-app with npm, Yarn, or pnpm to bootstrap the example:

bash
npx create-next-app --example with-react-ga4 with-react-ga-app
bash
yarn create next-app --example with-react-ga4 with-react-ga-app
bash
pnpm create next-app --example with-react-ga4 with-react-ga-app

Deploy it to the cloud with Vercel (Documentation).