iosreact-nativeexpoplistfirebase-analytics

@react-native-firebase/analytics setup problem after upgrade No Firebase App '[DEFAULT]' has been created - call firebase.initializeApp()


Error: No Firebase App '[DEFAULT]' has been created - call firebase.initializeApp()

"@react-native-firebase/analytics": "^21.11.0",
"@react-native-firebase/app": "^21.11.0",
"react-native": "0.79.5",
"expo": "^53.0.17",

Before the upgrade analytics used to work and there was no issue. The config was ok. After the upgrade we had to change some js init code and the problems arose. Also it is worth mentioning that it works on android, which leads me to believe that there might be an issue with GoogleService-Info.plist

The setup:

"@react-native-firebase/app"

is added to plugins.

both

google-services.json
GoogleService-Info.plist

are added to .env and uploaded to EXPO

analytics.js

import { getApp } from '@react-native-firebase/app'
import {
  logEvent,
  setAnalyticsCollectionEnabled,
  getAnalytics,
} from '@react-native-firebase/analytics'

const app = getApp()

export default {
  analytics: () => {
    const analytics = getAnalytics(app)
    return {
      logScreenView: params => logEvent(analytics, 'screen_view', params),
      setAnalyticsCollectionEnabled: enabled =>
        setAnalyticsCollectionEnabled(analytics, enabled),
      logEvent: (event, params) => logEvent(analytics, event, params),
      setUserProperty: (name, value) => analytics.setUserProperty(name, value),
    }
  },
}

App.js

import analyticsModule from './lib/analytics'

const analytics = analyticsModule.analytics()
analytics?.setAnalyticsCollectionEnabled(true)

useAuth.getState().addOnSignedInListener(() => {
  analytics?.setUserProperty('logged_in', 'true')
})

useAuth.getState().addOnSignedOutListener(() => {
  analytics?.setUserProperty('logged_in', 'false')
})

GoogleService-Info.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CLIENT_ID</key>
    <string>xxxx.apps.googleusercontent.com</string>
    <key>REVERSED_CLIENT_ID</key>
    <string>com.googleusercontent.apps.xxxx</string>
    <key>ANDROID_CLIENT_ID</key>
    <string>xxxx.apps.googleusercontent.com</string>
    <key>API_KEY</key>
    <string>xxxx</string>
    <key>GCM_SENDER_ID</key>
    <string>xxxxx</string>
    <key>PLIST_VERSION</key>
    <string>1</string>
    <key>BUNDLE_ID</key>
    <string>com.xx.xxxxxx</string>
    <key>PROJECT_ID</key>
    <string>xxxxx-mobile</string>
    <key>STORAGE_BUCKET</key>
    <string>xxxxx-mobile.appspot.com</string>
    <key>IS_ADS_ENABLED</key>
    <false></false>
    <key>IS_ANALYTICS_ENABLED</key>
    <false></false>
    <key>IS_APPINVITE_ENABLED</key>
    <true></true>
    <key>IS_GCM_ENABLED</key>
    <true></true>
    <key>IS_SIGNIN_ENABLED</key>
    <true></true>
    <key>GOOGLE_APP_ID</key>
    <string>1:xxxxx:ios:xxxxxxx</string>
</dict>
</plist>

Any idea what the issue might be?


Solution

  • The issue was with the firebase app/analytics lib version. Upgrade to 22 solved the issue.