Using Expo Firebase Analytics in the Expo Go app not working

Viewed 1852

I am trying to use the expo-firebase-analytics package in the Expo Go app as a first step to making sure I have the set up correct before I see if it is working in standalone apps. However it is not working right now. Events are not being logged on my Firebase analytics console. I am following this installation guide: https://docs.expo.io/versions/latest/sdk/firebase-analytics/

I have run expo install expo-firebase-analytics. I have also run expo install firebase. I have set up a Firebase web project and added the config to my app.json.

{
  "expo": {
    ...
    "web": {
      "config": {
        "apiKey": "AIxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "authDomain": "my-app.firebaseapp.com",
        "projectId": "my-app",
        "storageBucket": "my-app.appspot.com",
        "messagingSenderId": "mySenderId",
        "appId": "1:myApp:web:myAppId",
        "measurementId": "G-MYMEASUREMENTID"
      }
    },
  }

Here is my App.js file

import React, { useEffect } from "react";
import { Text, View } from "react-native";
import * as Analytics from 'expo-firebase-analytics';

export default function App() {
  useEffect(() => {
    (async() => {
      console.log("App.js useEffect");
      await Analytics.logEvent('ScreenLoaded');
    })();
  }, []);

  return <View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}><Text>MAIN SCREEN</Text></View>
}

Can anyone help me understand what I'm missing?

1 Answers

I figured it out. The set up is correct. What I realized is that you don't actually see the logs in the Firebase console when you use this package within the Expo Go app. Rather, the log appears in your Terminal console to confirm the package is working. However, once you build the standalone app the logs should appear in your Firebase console.

Another potential trip up is in the Expo docs it says to use put your config object in expo.web.config.firebase in app.json, but I had to have it in expo.web.config (as it is written above) and not have a firebase keyword for it to work.

Related