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.consttrackingId='UA-12345678-1'// replace with your ownconstga=GoogleAnalytics(trackingId, GoogleAnalyticsTracker);constgaMiddleware=createMiddleware(eventsMap, ga);
Additional Settings
You also have access to some additional settings from the underlying react-native-google-analytics-bridge. These settings can be used to:
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';consttrackingId='UA-12345678-1'// replace with your ownconstga=GoogleAnalytics(trackingId, GoogleAnalyticsTracker);GoogleAnalyticsSettings.setDryRun(true);GoogleAnalyticsSettings.setOptOut(true);
Don't see your event listed? Please submit a pull request to the Redux Beacon repository 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.
import { trackEvent } from'@redux-beacon/react-native-google-analytics';constsomeEvent=trackEvent((action, prevState, nextState) => {return { action:/* fill me in */, category:/* fill me in */, label:/* (optional) */, value:/* (optional) */, customDimensions: { /* (optional) */ [/* dimension index */]:/* dimension value */ }, };});
import { trackPurchase } from'@redux-beacon/react-native-google-analytics';constsomePurchaseEvent=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 */, };});
import { trackTiming } from'@redux-beacon/react-native-google-analytics';consttimingEvent=trackTiming((action, prevState, nextState) => {return { category:/* fill me in */, value:/* fill me in */, name:/* (optional) */, label:/* (optional) (requires name if provided)*/, };});
import { trackSocialInteraction } from'@redux-beacon/react-native-google-analytics';constsocialInteraction=trackSocialInteraction((action, prevState, nextState) => {return { network:/* fill me in */, action:/* fill me in */, target:/* (optional) */, };});
import { setUser } from'@redux-beacon/react-native-google-analytics';constuser=setUser((action, prevState, nextState) => {constuserId=/* fill me in */;return userId;});
import { setClient } from'@redux-beacon/react-native-google-analytics';constclient=setClient((action, prevState, nextState) => {constclientId=/* fill me in */;return clientId;});