rsnext/examples/with-react-ga4
Rodrigo Esteves 9e5116975d
Upgrading react-ga to react-ga4 (#48932)
taken from google analytic's page:

 "_On July 1, 2023, this property will stop processing data. Starting in March 2023, for continued website measurement, migrate your original property settings to a Google Analytics 4 (GA4) property, or they'll be copied for you to an existing GA4 property, reusing existing site tags._"

The package 'react-ga' doesn't support GA4, so i updated the package to 'react-ga4', the example continues primarily the same, the only differences is that specifying 'pageview' is now required instead of just setting the location of the pageview and the expection() function doesn't exist in this package.

required changes are welcomed




Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
2023-05-16 22:06:09 +00:00
..
pages Upgrading react-ga to react-ga4 (#48932) 2023-05-16 22:06:09 +00:00
utils Upgrading react-ga to react-ga4 (#48932) 2023-05-16 22:06:09 +00:00
.gitignore Upgrading react-ga to react-ga4 (#48932) 2023-05-16 22:06:09 +00:00
package.json Upgrading react-ga to react-ga4 (#48932) 2023-05-16 22:06:09 +00:00
README.md Upgrading react-ga to react-ga4 (#48932) 2023-05-16 22:06:09 +00:00

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 custom App component with NextJs. Modify Tracking ID in utils/analytics.js file for testing this example.

Deploy your own

Deploy the example using Vercel:

Deploy with Vercel

How to use

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

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

Deploy it to the cloud with Vercel (Documentation).