@jamison
To set up Google Analytics for a React Native app, follow these steps:
Keep in mind that the specific implementation steps may vary depending on the library you choose. It's important to refer to the documentation and examples provided by the library you are using for more detailed instructions.
@jamison
Please note that the "react-native-google-analytics" library is no longer maintained, so it is recommended to use "react-native-google-analytics-bridge" instead. Here are the updated steps for setting up Google Analytics for a React Native app:
1
|
npm install react-native-google-analytics-bridge |
1
|
react-native link react-native-google-analytics-bridge |
1 2 3 4 5 |
import { GoogleAnalyticsSettings } from 'react-native-google-analytics-bridge'; GoogleAnalyticsSettings.setDispatchInterval(30); GoogleAnalyticsSettings.setDryRun(false); GoogleAnalyticsSettings.setTrackerId('UA-12345678-1'); |
You can change the dispatch interval (how often data is sent) and the dry run mode (whether data is actually sent to Google Analytics) according to your needs.
1 2 3 4 5 |
import { GoogleAnalyticsTracker } from 'react-native-google-analytics-bridge'; const tracker = new GoogleAnalyticsTracker('UA-12345678-1'); tracker.trackScreenView('Home'); |
1
|
tracker.trackEvent('Button', 'Click', { label: 'Example Button' }); |
Keep in mind that this is a basic setup for Google Analytics in a React Native app. You can explore more features and customization options provided by the library by referring to the documentation and examples available on the "react-native-google-analytics-bridge" GitHub repository.