{"id":20715394,"url":"https://github.com/codler/react-ga4","last_synced_at":"2025-04-12T14:56:27.052Z","repository":{"id":65368385,"uuid":"590993638","full_name":"codler/react-ga4","owner":"codler","description":"React Google Analytics 4","archived":false,"fork":false,"pushed_at":"2024-01-23T18:03:21.000Z","size":419,"stargazers_count":235,"open_issues_count":31,"forks_count":30,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-05-29T12:43:56.517Z","etag":null,"topics":["google-analytics","google-analytics-4"],"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/codler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["codler"],"custom":["https://www.paypal.me/hanlinyap"]}},"created_at":"2023-01-19T17:31:33.000Z","updated_at":"2024-06-18T12:39:58.461Z","dependencies_parsed_at":"2024-06-18T12:39:36.749Z","dependency_job_id":"c1e0d831-ae7e-46f1-b4f7-74e8492b1cf6","html_url":"https://github.com/codler/react-ga4","commit_stats":{"total_commits":39,"total_committers":2,"mean_commits":19.5,"dds":0.02564102564102566,"last_synced_commit":"d0b14c26a7dd5fdbe98e3dd4ef0e6653d0a19ba3"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codler%2Freact-ga4","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codler%2Freact-ga4/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codler%2Freact-ga4/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codler%2Freact-ga4/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codler","download_url":"https://codeload.github.com/codler/react-ga4/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248586244,"owners_count":21128996,"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":["google-analytics","google-analytics-4"],"created_at":"2024-11-17T02:38:19.837Z","updated_at":"2025-04-12T14:56:27.028Z","avatar_url":"https://github.com/codler.png","language":"JavaScript","funding_links":["https://github.com/sponsors/codler","https://www.paypal.me/hanlinyap"],"categories":["JavaScript"],"sub_categories":[],"readme":"# ✨ Looking for sponsors! ✨\n\nMaintainer need help with sponsor!\n\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/sponsors/codler\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/102052?v=4\u0026s=100\" width=\"100px;\" alt=\"Han Lin Yap\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eHan Lin Yap\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#maintenance-jakebolam\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n# React Google Analytics 4\n\n## Migrate from old react-ga\n\n```js\n// Simply replace `react-ga` with `react-ga4` and remove `ReactGA.pageview()`\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\");\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\", title: \"Custom Title\" });\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.gtagUrl     | `string` Default `https://www.googletagmanager.com/gtag/js`                                                             |\n| options.gaOptions   | `object` Optional [Reference](https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference) |\n| options.gtagOptions | `object` Optional                                                                                                       |\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\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### 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%2Fcodler%2Freact-ga4","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodler%2Freact-ga4","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodler%2Freact-ga4/lists"}