Adding Google Analytics to React Application
A simple way to add google analytics code to React App.
September 29, 2019 •
Code 💻
1 min read
The steps are pretty simple:
- Install
react-ga
package, which is a wrapper for Google Analytics script.
# Yarn
yarn add react-ga
- Import and Add
react-ga
code inApp.js
.
import ReactGoogleAnalytics from 'react-ga'
...
ReactGoogleAnalytics.initialize('UA-XXXXXXXXX-X'); // Google Analytics ID
ReactGoogleAnalytics.pageview('/');