Adding Google Analytics to React Application
A quick way to add Google Analytics to React.
August 05, 2022 • Code
The steps are pretty simple:
- Install
- react-ga
- package, which is a wrapper for Google Analytics script.
# Yarnyarn add react-ga
- Import and Add
- react-ga
- code in
- App.js
- .
import ReactGoogleAnalytics from 'react-ga'...ReactGoogleAnalytics.initialize('UA-XXXXXXXXX-X'); // Google Analytics IDReactGoogleAnalytics.pageview('/');