Skip to content

Integration of React Native apps with Google Analytics platform

Notifications You must be signed in to change notification settings

mhsaufi/reactGA

Repository files navigation

Google Analytics with React Native

To start an integration to the Google Analytics platform is a really easy. There are two requirements before it can be done :

  • An existing react native apps or create new one
  • Google Analytics account property with view for your react native mobile apps
That are all the requirement needed. When you have the GA account property, go to the Property Setting if you are admin and get the tracking code.


Get Started

  1. Add the Google Analytics Bridge module into your node module package :
  • yarn add react-native-google-analytics-bridge
  • or via npm , npm install --save react-native-google-analytics-bridge

2. Link the added module to your react native app :
  • react-native link react-native-google-analytics-bridge

3. Within your screen file code, let say my screen is App.js, the first and main screen code, add this import :
  • import {GoogleAnalyticsSettings, GoogleAnalyticsTracker} from 'react-native-google-analytics-bridge';

3. Now construct your GA Bridge object, depends on how you want to use it, in my case,
outside the class as i will be using it in multiple screen :
  • const my_tracker = new GoogleAnalyticsTracker('YOUR_GA_TRACKING_CODE');

4. As there are 2 basic hits to use, i will use pageView hit and event hit. To use them :
  • my_tracker.trackScreenView("YOUR_SCREEN_NAME");
  • my_tracker.trackEvent("YOUR_EVENT_NAME","EVENT_TYPE");
YOUR_SCREEN_NAME and YOUR_EVENT_NAME is the name that will be appearing on google analytics.
it has nothing to do with your internal react native apps. But it is a good practise to make everything organized


Done!

Thats it! You are on your way to develop on your own pace!