Maintainer need help with sponsor!
| Han Lin Yap 🚧 | 
// Simply replace `react-ga` with `react-ga4` and remove `ReactGA.pageview()`
// import ReactGA from "react-ga";
import ReactGA from "react-ga4";npm i react-ga4import ReactGA from "react-ga4";
ReactGA.initialize("your GA measurement id");More example can be found in test suite
// Multiple products (previously known as trackers)
ReactGA.initialize([
  {
    trackingId: "your GA measurement id",
    gaOptions: {...}, // optional
    gtagOptions: {...}, // optional
  },
  {
    trackingId: "your second GA measurement id",
  },
]);
// Send pageview with a custom path
ReactGA.send({ hitType: "pageview", page: "/my-path", title: "Custom Title" });
// Send a custom event
ReactGA.event({
  category: "your category",
  action: "your action",
  label: "your label", // optional
  value: 99, // optional, must be a number
  nonInteraction: true, // optional, true/false
  transport: "xhr", // optional, beacon/xhr/image
});| Parameter | Notes | 
|---|---|
| GA_MEASUREMENT_ID | stringRequired | 
| options.nonce | stringOptional Used for Content Security Policy (CSP) more | 
| options.testMode | booleanDefault false | 
| options.gtagUrl | stringDefaulthttps://www.googletagmanager.com/gtag/js | 
| options.gaOptions | objectOptional Reference | 
| options.gtagOptions | objectOptional | 
| Parameter | Notes | 
|---|---|
| fieldsObject | objectRequired | 
This method signature are NOT for UA-XXX
| Parameter | Notes | 
|---|---|
| name | stringRequired A recommended event or a custom event | 
| params | objectOptional | 
| Parameter | Notes | 
|---|---|
| options | objectRequired | 
| options.action | stringRequired | 
| options.category | stringRequired | 
| options.label | stringOptional | 
| options.value | numberOptional | 
| options.nonInteraction | booleanOptional | 
| options.transport | 'beacon'|'xhr'|'image'Optional | 
| Parameter | Notes | 
|---|---|
| fieldsObject | objectRequired | 
import { ReactGAImplementation } from "react-ga4";
class MyCustomOverriddenClass extends ReactGAImplementation {}
export default new MyCustomOverriddenClass();Use Google Analytics Debugger Chrome Extension to see logs
MIT