Search code examples
androidiosexpofirebase-analytics

Expo Firebase Analytics only work inside the Browser


I am using Firebase for my Expo App. Authentication + Getting Data seems to work fine but I am having trouble implementing Analytics.

Initialising Analytics:

export const analytics = getAnalytics();

I am trying to log my event using following line:

logEvent(analytics, 'login')
    apiKey: "kk",
    authDomain: "kk",
    projectId: "kk",
    storageBucket: "kk",
    messagingSenderId: "kk",
    appId: "kk",
    measurementId: "kk"
};

as you can see the measurmentId exists, besides that an Interesting Note is that, when opening my App inside the Webbrowser it works, but when starting the App on Android or IOS via Expo Go I am getting:

[2023-07-25T14:06:01.633Z] @firebase/analytics: Analytics: Firebase Analytics is not supported in this environment. Wrap initialization of analytics in analytics.isSupported() to prevent initialization in unsupported environments. Details: (1) Cookies are not available. (analytics/invalid-analytics-context).

Also when checking my navigator.cookiesEnabled I am getting "undefined"

As Frank van Puffelen suggested I switched to EAS. But now I am just getting the error:

1) imported the 'io.invertase.firebase.app.ReactNativeFirebaseAppPackage' module in your 'MainApplication.java' file.

2) Added the 'new ReactNativeFirebaseAppPackage()' line inside of the RN 'getPackages()' method list.

I also changed to

import analytics from "@react-native-firebase/analytics";

since it was recommended here https://github.com/expo/fyi/blob/main/firebase-migration-guide.md.

When using the old Version I am still getting the same Error!


Solution

  • The error message seems to indicate that using the JavaScript SDK is not supported in native mobile environments because it uses features that aren't available there. You'll want to upgrade to using the SDKs for native mobile, for example by using React Native Firebase.