-1

I'm using Firebase Analytics in an iOS app. I've created two "environments" - one for production and one for staging. The idea of staging is to separate app data in development builds from production builds (for example, I use a different database instance in prod vs. stage).

Analytics recording in my app looks something like:

import Firebase Analytics

// do this somewhere
Analytics.logEvent(name, parameters: ["param" : value])

However, Google Analytics will aggregate events from both prod and staging environments, which can skew data based on what's happening in development builds. I want to be able to see analytics only for prod builds.

I have a mechanism to detect which environment we're in, so I could create a function

func logEvent(name: String, parameters: [String: Any]) {
    if DatabaseClient.environment == .production {
        Analytics.logEvent(name, parameters: ["param" : value])
    }
}

However, my main concern is that this would make it difficult to verify that analytics events are being triggered while running staging builds. I currently use the -FIRAnalyticsDebugEnabled environment argument when testing out events so that I can see logged events in the console, but if we restrict event logging to just production builds, we wouldn't be able to verify this in staging builds.

7
  • I'm not clear what you're trying to do. Firebase Analytics isn't linked to Firestore in any way. They both operate completely independently of each other. Commented Sep 27, 2024 at 15:29
  • Right, so any analytics events that you record in a "staging environment" will get blended with events from real users. Another way to put this is that we don't want events to get logged during development / in development builds. Commented Sep 27, 2024 at 16:04
  • All that has nothing to do with Firestore or any other database. I suggest rewriting your question to remove all reference to Firestore since it's not relevant here. Firebase Analytics collects and aggregates information per application and per project, if that's what you mean. Commented Sep 27, 2024 at 16:05
  • I will rewrite the question shortly, but it seems like you understand that I'm asking if we can separate Analytics based on production/development environments? Commented Sep 27, 2024 at 16:51
  • Sure, and your question should explain what exactly you're doing right now to define and implement those environments. Commented Sep 27, 2024 at 17:08

1 Answer 1

2

You haven't said how you created these so-called "environments" for your app, but I'm going to guess that you are somehow putting them all in the same Firebase project. And, based on your prior edits, you assumed that creating a new Firestore instance in that project would effectively separate the data for each one of your apps using that project. Unfortunately, that's not the way it works at all.

The only real way to create deployment environments in Firebase is to use a different project for each environment. With that, each app in each environment will have no knowledge of each other and will have no way to read and write each others' data, including Firebase Analytics data. The use of multiple project for multiple environments is covered in more detail in the documentation - you should read that thoroughly:

Quoting from the docs:

  • All Firebase Apps registered to the same Firebase project share and have access to all the same resources and services provisioned for the project. Here are some examples:

    • All the Firebase Apps registered to the same Firebase project share the same backends, like Firebase Hosting, Authentication, Realtime Database, Cloud Firestore, Cloud Storage, and Cloud Functions.

    • All Firebase Apps registered to the same Firebase project are associated with the same Google Analytics property, where each Firebase App is a separate data stream in that property.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.