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:

  1. Install react-ga package, which is a wrapper for Google Analytics script.
# Yarn 
yarn add react-ga
  1. Import and Add react-ga code in App.js.
import ReactGoogleAnalytics from 'react-ga'


ReactGoogleAnalytics.initialize('UA-XXXXXXXXX-X'); // Google Analytics ID