Redux Beacon
  • Introduction
  • Getting Started (Redux)
  • Getting Started (ngrx)
  • Examples & Recipes
  • Targets
    • GoogleAnalytics
    • GoogleAnalyticsGtag
    • GoogleTagManager
    • Segment
    • Amplitude
    • React Native: GoogleAnalytics
    • React Native: GoogleTagManager
    • React Native: Segment
  • API Reference
    • createMiddleware
    • createMetaReducer
    • EventDefinition
    • EventsMap
    • EventsMapper
  • Extensions
    • logger
    • OfflineWeb
    • OfflineReactNative
  • Utils
    • debounceEvent
    • ensure
    • combineEvents
  • FAQ
  • Migration Guide (v1 to v2)
  • Notes on Offline Events
Powered by GitBook
On this page
  • Setup
  • Usage
  • Additional Settings
  • Event Definitions
  • screenView
  • event
  • purchase
  • timing
  • socialInteraction
  • user
  • client
  • exception
  1. Targets

React Native: GoogleAnalytics

PreviousAmplitudeNextReact Native: GoogleTagManager

Last updated 7 years ago

Setup

  1. Sign up for Google Analytics and .

  2. Install the following npm package: .

  3. For each mobile platform (Android or iOS), you need to follow its corresponding .

  4. Install the target:

     npm install --save @redux-beacon/react-native-google-analytics

Usage

import { GoogleAnalyticsTracker } from 'react-native-google-analytics-bridge';
import GoogleAnalytics from '@redux-beacon/react-native-google-analytics';

// Create or import an events map.
// See "getting started" pages for instructions.

const trackingId = 'UA-12345678-1' // replace with your own
const ga = GoogleAnalytics(trackingId, GoogleAnalyticsTracker);

const gaMiddleware = createMiddleware(eventsMap, ga);

Additional Settings

  • Disable your app from sending events to Google Analytics

  • Disable your app from tracking events altogether - this can be used to give your users control over opting in/out from analytics.

These settings can be applied as follows:

import { GoogleAnalyticsTracker, GoogleAnalyticsSettings } from 'react-native-google-analytics-bridge';
import GoogleAnalytics from '@redux-beacon/react-native-google-analytics';

const trackingId = 'UA-12345678-1' // replace with your own
const ga = GoogleAnalytics(trackingId, GoogleAnalyticsTracker);

GoogleAnalyticsSettings.setDryRun(true);
GoogleAnalyticsSettings.setOptOut(true);

Event Definitions

screenView

Docs:

import { trackScreenView } from '@redux-beacon/react-native-google-analytics';

const screenView = trackScreenView((action, prevState, nextState) => {
  return {
    screenName: /* fill me in */,
    customDimensions: { /* (optional) */
      [/* dimension index */]: /* dimension value */,
    },
  };
});

event

Docs:

import { trackEvent } from '@redux-beacon/react-native-google-analytics';

const someEvent = trackEvent((action, prevState, nextState) => {
  return {
    action: /* fill me in */,
    category: /* fill me in */,
    label: /* (optional) */,
    value: /* (optional) */,
    customDimensions: { /* (optional) */
      [/* dimension index */]: /* dimension value */
    },
  };
});

purchase

Docs:

import { trackPurchase } from '@redux-beacon/react-native-google-analytics';

const somePurchaseEvent = trackPurchase((action, prevState, nextState) => {
  return {
    product: { /* fill me in */
      id: /* fill me in */,
      name: /* fill me in */,
      category: /* (optional) */,
      brand: /* (optional) */,
      variant: /* (optional) */,
      price: /* (optional) */,
      quantity: /* (optional) */,
      couponCode: /* (optional) */,
    },
    transaction: { /* fill me in */
      id: /* fill me in */,
      affiliation: /* (optional) */,
      revenue: /* (optional) */,
      tax: /* (optional) */,
      shipping: /* (optional) */,
      couponCode: /* (optional) */,
    },
    action: /* fill me in */,
    category: /* fill me in */,
  };
});

timing

Docs:

import { trackTiming } from '@redux-beacon/react-native-google-analytics';

const timingEvent = trackTiming((action, prevState, nextState) => {
  return {
    category: /* fill me in */,
    value: /* fill me in */,
    name: /* (optional) */,
    label: /* (optional) (requires name if provided)*/,
  };
});

socialInteraction

Docs:

import { trackSocialInteraction } from '@redux-beacon/react-native-google-analytics';

const socialInteraction = trackSocialInteraction((action, prevState, nextState) => {
  return {
    network: /* fill me in */,
    action: /* fill me in */,
    target: /* (optional) */,
  };
});

user

Docs:

import { setUser } from '@redux-beacon/react-native-google-analytics';

const user = setUser((action, prevState, nextState) => {
  const userId = /* fill me in */;
  return userId;
});

client

Docs:

import { setClient } from '@redux-beacon/react-native-google-analytics';

const client = setClient((action, prevState, nextState) => {
  const clientId = /* fill me in */;
  return clientId;
});

exception

Docs:

import { trackException } from '@redux-beacon/react-native-google-analytics';

const exception = trackException((action, prevState, nextState) => {
  return {
    description: /* fill me in */,
    isFatal: /* (optional) */,
  };
});

You also have access to some from the underlying react-native-google-analytics-bridge. These settings can be used to:

Don't see your event listed? Please submit a pull request to the with the missing event. Use the source of the existing event-helpers to guide your work. If you need any support feel free to make the pull request with all you're able to do. We can fill in the gaps from there.

additional settings
Redux Beacon repository
https://developers.google.com/analytics/devguides/collection/ios/v3/screens
https://developers.google.com/analytics/devguides/collection/ios/v3/customdimsmets
https://developers.google.com/analytics/devguides/collection/ios/v3/events
https://developers.google.com/analytics/devguides/collection/ios/v3/customdimsmets
https://developers.google.com/analytics/devguides/collection/ios/v3/ecommerce
https://developers.google.com/analytics/devguides/collection/ios/v3/usertimings
https://developers.google.com/analytics/devguides/collection/ios/v3/social
https://developers.google.com/analytics/devguides/collection/ios/v3/user-id
https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#clientId
https://developers.google.com/analytics/devguides/collection/ios/v3/exceptions
create a new mobile property
GoogleAnalyticsBridge
manual installation
Setup
Usage
Event Definitions
screenView
event
purchase
timing
socialInteraction
user
client
exception