Maintainer need help with sponsor!
Han Lin Yap 🚧 |
// Simply replace `react-ga` with `react-ga4` and remove `ReactGA.pageview()`// import ReactGA from "react-ga";importReactGAfrom"react-ga4";npm i react-ga4importReactGAfrom"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: {...},// optionalgtagOptions: {...},// optional},{trackingId: "your second GA measurement id",},]);// Send pageview with a custom pathReactGA.send({hitType: "pageview",page: "/my-path",title: "Custom Title"});// Send a custom eventReactGA.event({category: "your category",action: "your action",label: "your label",// optionalvalue: 99,// optional, must be a numbernonInteraction: true,// optional, true/falsetransport: "xhr",// optional, beacon/xhr/image});| Parameter | Notes |
|---|---|
| GA_MEASUREMENT_ID | string Required |
| options.nonce | string Optional Used for Content Security Policy (CSP) more |
| options.testMode | boolean Default false |
| options.gtagUrl | string Default https://www.googletagmanager.com/gtag/js |
| options.gaOptions | object Optional Reference |
| options.gtagOptions | object Optional |
| Parameter | Notes |
|---|---|
| fieldsObject | object Required |
This method signature are NOT for UA-XXX
| Parameter | Notes |
|---|---|
| name | string Required A recommended event or a custom event |
| params | object Optional |
| Parameter | Notes |
|---|---|
| options | object Required |
| options.action | string Required |
| options.category | string Required |
| options.label | string Optional |
| options.value | number Optional |
| options.nonInteraction | boolean Optional |
| options.transport | 'beacon'|'xhr'|'image' Optional |
| Parameter | Notes |
|---|---|
| fieldsObject | object Required |
import{ReactGAImplementation}from"react-ga4";classMyCustomOverriddenClassextendsReactGAImplementation{}exportdefaultnewMyCustomOverriddenClass();Use Google Analytics Debugger Chrome Extension to see logs
MIT