{"id":13599511,"url":"https://github.com/PriceRunner/react-ga4","last_synced_at":"2025-04-10T12:33:06.241Z","repository":{"id":37262754,"uuid":"371366023","full_name":"PriceRunner/react-ga4","owner":"PriceRunner","description":"React Google Analytics 4","archived":true,"fork":false,"pushed_at":"2023-01-02T23:20:21.000Z","size":789,"stargazers_count":307,"open_issues_count":22,"forks_count":39,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-25T12:01:48.802Z","etag":null,"topics":["analytics","react","reactjs"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/react-ga4","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PriceRunner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-27T12:30:21.000Z","updated_at":"2025-02-14T12:09:37.000Z","dependencies_parsed_at":"2022-07-12T16:14:54.964Z","dependency_job_id":null,"html_url":"https://github.com/PriceRunner/react-ga4","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PriceRunner%2Freact-ga4","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PriceRunner%2Freact-ga4/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PriceRunner%2Freact-ga4/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PriceRunner%2Freact-ga4/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PriceRunner","download_url":"https://codeload.github.com/PriceRunner/react-ga4/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248217145,"owners_count":21066633,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analytics","react","reactjs"],"created_at":"2024-08-01T17:01:05.566Z","updated_at":"2025-04-10T12:33:01.227Z","avatar_url":"https://github.com/PriceRunner.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# React Google Analytics 4\n\n## Migrate from old react-ga\n\n```js\n// Simply replace `react-ga` with `react-ga4`\n// import ReactGA from \"react-ga\";\nimport ReactGA from \"react-ga4\";\n```\n\n## Install\n\n```bash\nnpm i react-ga4\n```\n\n## Usage\n\n```js\nimport ReactGA from \"react-ga4\";\n\nReactGA.initialize(\"your GA measurement id\");\nReactGA.send(\"pageview\");\n```\n\n## Example\n\nMore example can be found in [test suite](src/ga4.test.js)\n\n```js\n// Multiple products (previously known as trackers)\nReactGA.initialize([\n  {\n    trackingId: \"your GA measurement id\",\n    gaOptions: {...}, // optional\n    gtagOptions: {...}, // optional\n  },\n  {\n    trackingId: \"your second GA measurement id\",\n  },\n]);\n\n// Send pageview with a custom path\nReactGA.send({ hitType: \"pageview\", page: \"/my-path\" });\n\n// Send a custom event\nReactGA.event({\n  category: \"your category\",\n  action: \"your action\",\n  label: \"your label\", // optional\n  value: 99, // optional, must be a number\n  nonInteraction: true, // optional, true/false\n  transport: \"xhr\", // optional, beacon/xhr/image\n});\n```\n\n## Reference\n\n#### ReactGA.initialize(GA_MEASUREMENT_ID, options)\n\n| Parameter                     | Notes                                                                                                                   |\n| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------- |\n| GA_MEASUREMENT_ID             | `string` Required                                                                                                       |\n| options.nonce                 | `string` Optional Used for Content Security Policy (CSP) [more](https://developers.google.com/tag-manager/web/csp)      |\n| options.testMode              | `boolean` Default false                                                                                                 |\n| options.gaOptions             | `object` Optional [Reference](https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference) |\n| options.gtagOptions           | `object` Optional                                                                                                       |\n| options.legacyDimensionMetric | `boolean` Default true                                                                                                  |\n\n#### ReactGA.set(fieldsObject)\n\n| Parameter    | Notes             |\n| ------------ | ----------------- |\n| fieldsObject | `object` Required |\n\n#### ReactGA.event(name, params)\n\nThis method signature are NOT for `UA-XXX`\n\n| Parameter | Notes                                                                                                                         |\n| --------- | ----------------------------------------------------------------------------------------------------------------------------- |\n| name      | `string` Required A [recommended event](https://developers.google.com/tag-platform/gtagjs/reference/events) or a custom event |\n| params    | `object` Optional                                                                                                             |\n\n#### ReactGA.event(options)\n\n| Parameter                    | Notes                               |\n| ---------------------------- | ----------------------------------- |\n| options                      | `object` Required                   |\n| options.action               | `string` Required                   |\n| options.category             | `string` Required                   |\n| options.label                | `string` Optional                   |\n| options.value                | `number` Optional                   |\n| options.nonInteraction       | `boolean` Optional                  |\n| options.transport            | `'beacon'\\|'xhr'\\|'image'` Optional |\n| options.dimension`{1...200}` | `any` Optional                      |\n| options.metric`{1...200}`    | `any` Optional                      |\n\n#### ReactGA.send(fieldsObject)\n\n| Parameter    | Notes             |\n| ------------ | ----------------- |\n| fieldsObject | `object` Required |\n\n#### ReactGA\u0026#46;gtag(...args)\n\n#### ReactGA\u0026#46;ga(...args)\n\n#### ~~ReactGA.pageview(path, \\_, title)~~\n\nDeprecated Use `.send(\"pageview\")` instead\n\n#### ~~ReactGA.outboundLink({ label }, hitCallback)~~\n\nDeprecated Use `enhanced measurement` feature in Google Analytics.\n\n### Extending\n\n```js\nimport { ReactGAImplementation } from \"react-ga4\";\n\nclass MyCustomOverriddenClass extends ReactGAImplementation {}\n\nexport default new MyCustomOverriddenClass();\n```\n\n## Debugging\n\nUse [Google Analytics Debugger Chrome Extension](https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna?hl=en) to see logs\n\n## Maintainer\n\n[Han Lin Yap](https://github.com/codler)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPriceRunner%2Freact-ga4","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FPriceRunner%2Freact-ga4","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPriceRunner%2Freact-ga4/lists"}