{"library":"react-ga","title":"React Google Analytics Module (Universal Analytics)","description":"react-ga is a JavaScript module designed for integrating Google Universal Analytics (UA-xxxxxx-x properties) tracking into React applications. It provides a React-friendly wrapper around the core Google Analytics library, offering an opinionated API to standardize instrumentation. The current stable version is 3.3.1, released in June 2022. However, this library is now considered deprecated because Google Universal Analytics ceased processing new hits on July 1, 2023, in favor of Google Analytics 4 (GA4). react-ga does not support GA4's `G-` measurement IDs, making it unsuitable for new analytics implementations or existing ones that have migrated to GA4. For GA4 integration, users should consider `react-ga4` or direct `gtag.js` implementations.","language":"javascript","status":"deprecated","last_verified":"Sun Apr 19","install":{"commands":["npm install react-ga"],"cli":null},"imports":["import ReactGA from 'react-ga';","import ReactGA from 'react-ga/core';","import { OutboundLink } from 'react-ga';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import ReactGA from 'react-ga';\nimport React, { useEffect } from 'react';\n\nconst GA_TRACKING_ID = process.env.REACT_APP_GA_UA_ID ?? 'UA-000000-01'; // Use a Universal Analytics ID\n\nfunction App() {\n  useEffect(() => {\n    if (GA_TRACKING_ID.startsWith('UA-')) {\n      ReactGA.initialize(GA_TRACKING_ID, { debug: process.env.NODE_ENV === 'development' });\n      ReactGA.pageview(window.location.pathname + window.location.search);\n      console.log('ReactGA initialized and pageview sent for UA ID:', GA_TRACKING_ID);\n    } else {\n      console.warn('GA_TRACKING_ID is not a Universal Analytics ID (UA-). react-ga only supports Universal Analytics. Please use react-ga4 for GA4 (G-) IDs.');\n    }\n  }, []);\n\n  const handleButtonClick = () => {\n    if (GA_TRACKING_ID.startsWith('UA-')) {\n      ReactGA.event({\n        category: 'User',\n        action: 'Clicked Button',\n        label: 'Demo Button'\n      });\n      console.log('GA Event sent: Clicked Demo Button');\n    }\n  };\n\n  return (\n    <div>\n      <h1>Welcome to React-GA Demo</h1>\n      <p>This demo uses react-ga for Universal Analytics tracking.</p>\n      <button onClick={handleButtonClick}>Track Me</button>\n      <p>Check your Universal Analytics dashboard for data.</p>\n      <p>Note: Universal Analytics is deprecated. For GA4, use react-ga4.</p>\n    </div>\n  );\n}\n\nexport default App;\n","lang":"typescript","description":"This quickstart demonstrates how to initialize `react-ga` with a Universal Analytics tracking ID and send a pageview and a custom event. It includes a warning for users attempting to use GA4 IDs.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}