How to enable Firebase Analytics Debugview on Testflight
Asked Answered
T

6

11

I am unable to view analytics debug view after I install the app through TestFlight into my test phone.

I have passed in argument -FIRDebugEnabled, and have tried -FIRAnalyticsDebugEnabled but no luck.

-FIRDebugEnabled -FIRAnalyticsDebugEnabled

If I directly installed the app into my test phone through Xcode, the debug view will be available. But if it's installed through TestFlight, the debug view cannot be seen.

Trituration answered 25/7, 2019 at 2:53 Comment(2)
Any solution ??Darbydarce
I am also looking for solution. Have you find out how to do this?Dyeline
I
6

This can be done by injecting special flags into Firebase's local storages. -FIRDebugEnabled command line argument is being checked by both: FirebaseCore and FirebaseAnalytics frameworks. While the former is saving the flag into shared UserDefaults, the latter is using APMUserDefaults private class, which can be accessed in runtime:

if let APMUserDefaults = NSClassFromString("APMUserDefaults") as AnyObject?,
   let userDefaults = APMUserDefaults.perform(#selector(getter: UserDefaults.standard))?.takeUnretainedValue() {
   _ = userDefaults.perform(#selector(NSMutableDictionary.setObject(_:forKey:)),
                            with: true, 
                            with: "/google/measurement/debug_mode")
}
UserDefaults.standard.set(true, forKey: "/google/firebase/debug_mode")
Inarticulate answered 15/6, 2020 at 9:34 Comment(1)
Nice - this works! You can also trigger this at runtime and then kill and relaunch and it'll be the same as launching with the debug flags.Necromancy
R
6

Add the following code before FirebaseApp.configure():

var newArguments = ProcessInfo.processInfo.arguments
newArguments.append("-FIRDebugEnabled")
ProcessInfo.processInfo.setValue(newArguments, forKey: "arguments")

Then, go to your target's build settings and update Release's Optimization level to No Optimization [-Onone].

After that, upload to TestFlight. This method works for me!

Rhinitis answered 19/7, 2022 at 12:54 Comment(0)
E
4

Add following code at the first line of application:didFinishLaunchingWithOptions: method of AppDelegate file

CommandLine.arguments.append(contentsOf: ["-FIRDebugEnabled", "-FIRAnalyticsDebugEnabled"])
Euhemerize answered 28/5, 2020 at 11:44 Comment(2)
how to do it in objective c?Dunkirk
Did not work for me when tested now.Syncretize
C
1

An addition to the previous answers and for React Native users looking for this, if you are using a library like react-native-config, you can use an env variable to switch this on/off.

Environment variables file example

ANALYTICS_DEBUG=true

In your AppDelegate.mm, inside the didFinishLaunchingWithOptions method:

  NSString *analyticsDebug = [ReactNativeConfig envFor:@"ANALYTICS_DEBUG"];

  if (analyticsDebug != nil && [analyticsDebug isEqualToString:@"true"]) {
    NSProcessInfo *processInfo = [NSProcessInfo processInfo];
    NSArray *arguments = [processInfo arguments];
    NSMutableArray *newArguments = [NSMutableArray arrayWithArray:arguments];

    [newArguments addObject:@"-FIRDebugEnabled"];
    [newArguments addObject:@"-FIRAnalyticsDebugEnabled"];

    [[NSProcessInfo processInfo] setValue:[newArguments copy] forKey:@"arguments"];
  }

  // Setup Firebase
  [FIRApp configure];

Make sure you setup Firebase after, otherwise this won't work.

Cloraclorinda answered 18/4, 2023 at 13:34 Comment(1)
This fix does not look to work anymore. Do you have a new solution for this ?Padriac
M
1

Not sure if everything is required here, but this works in Swift with the latest versions. In application:didFinishLaunchingWithOptions: and before FirebaseApp.configure():

CommandLine.arguments.append(contentsOf: ["-FIRDebugEnabled", "-FIRAnalyticsDebugEnabled"])
UserDefaults.standard.set(true, forKey: "/google/measurement/debug_mode")
UserDefaults.standard.set(true, forKey: "/google/firebase/debug_mode")

If it does not work for you, in Info.plist, add the key FIREBASE_ANALYTICS_COLLECTION_ENABLED to NO to make sure that the analytics collection will start only after you set the debug mode, and then call after FirebaseApp.configure():

Analytics.setAnalyticsCollectionEnabled(true)
Minne answered 27/2, 2024 at 18:32 Comment(0)
P
0

You can find an effective solution for 2024 here:

https://github.com/invertase/react-native-firebase/issues/7648

Padriac answered 27/2, 2024 at 8:43 Comment(3)
meta.stackexchange.com/a/8259/997587Bently
@Bently Am I supposed to duplicate my own response on Github instead of just link it ?Padriac
It's ironic that you criticize me for posting a link as a response, while responding with another link. I at least explained what the link contains unlike you :PPadriac

© 2022 - 2025 — McMap. All rights reserved.