Skip to content

Firebase setup for Saral App Telemetry

navin9584 edited this page Mar 13, 2023 · 14 revisions

Firebase setup for Saral App Telemetry

setup react native side

some libraries have to be installed to add firebase Google Analytics and firebase Google Crashlytics in react native

  • npm i @react-native-firebase/app
  • npm i @react-native-firebase/analytics
  • npm i @react-native-firebase/crashlytics

add In your module (app-level) Gradle file under dependencies

implementation "com.google.firebase:firebase-iid:21.1.0"
implementation "com.google.firebase:firebase-bom:31.2.2"
implementation 'com.google.firebase:firebase-analytics'
implementation ('com.google.firebase:firebase-iid:21.1.0'){
transitive = true}

on the top of (app-level) Gradle file add this line

apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.analytics'
apply plugin: 'com.google.firebase.crashlytics'

add In your root-level (project-level) Gradle file under dependencies

classpath("com.google.gms:google-services:4.3.3")
classpath "com.google.firebase:firebase-iid:19.0.0"
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'

To link the app to firebase, go to the firebae console and make project firebase console

To link the app after the project is created add google-service.json under android/app

App Debug Time

Enable or Disable firebase Analytics data collection from app

set the value of firebase_analytics_collection_enabled to false for disable or true for enable in your app's AndroidManifest.xml in the application

< meta-data android:name="firebase_analytics_collection_enabled" android:value="false" />

< meta-data android:name="firebase_analytics_collection_enabled" android:value="true" />

App Run Time

for enable or disable at run time environment firebase_analytics_collection_enabled in App.js file frontend/SaralApp/App.js

useEffect(async()=>{ let hasFBAnalytics = await getLoginData();

const hasFBAnalyticsValue = hasFBAnalytics.school && hasFBAnalytics.school.enableFBAnalytics

if(hasFBAnalyticsValue != null){
if (__DEV__) {
  analytics().setAnalyticsCollectionEnabled(hasFBAnalyticsValue);
  crashlytics().setCrashlyticsCollectionEnabled(hasFBAnalyticsValue);}  else{
  analytics().setAnalyticsCollectionEnabled(hasFBAnalyticsValue);
  crashlytics().setCrashlyticsCollectionEnabled(hasFBAnalyticsValue);

} }},[])

here hasFBAnalyticsValue is the flag which is come from backend as boolean form

after adding all dependencie rebuild the app using npx react-native run-android

Clone this wiki locally