Disable Firebase Performance Monitoring

To let your users opt-in or opt-out of using Firebase Performance Monitoring, you might
want to configure your app so that you can enable and disable Performance Monitoring. You
might also find this capability to be useful during app development and testing.

The following are some options to consider:

You can disable the Performance Monitoring SDK when building your app, with the option to
re-enable it at runtime.

You can build your app with the Performance Monitoring SDK enabled but have the option to
disable it at runtime using Firebase Remote Config.

You can completely deactivate the Performance Monitoring SDK, with no option to enable it
at runtime.

Disable Performance Monitoring during your app build process

One situation where disabling Performance Monitoring during your app build process could be
useful is to avoid reporting performance data from a pre-release version of your
app during app development and testing.

To disable or deactivate Performance Monitoring, you can add one of two keys to the
property list file (Info.plist) for your iOS app:

To disable Performance Monitoring, but allow your app to enable it at runtime, set
firebase_performance_collection_enabled to false in your app's
Info.plist file.

To completely deactivate Performance Monitoring, with no option to enable it at runtime,
set firebase_performance_collection_deactivated to true in your app's
Info.plist file.

Note: This setting overrides the firebase_performance_collection_enabled
setting and must be removed from your app's Info.plist file to re-enable
Performance Monitoring.

Disable your app at runtime using Remote Config

Firebase Remote Config lets you make changes to the behavior and appearance
of your app, so it provides an ideal way to let you disable Performance Monitoring in
deployed instances of your app.

To disable Performance Monitoring data collection the next time that your iOS app starts,
use the example code shown below. For more information about using
Remote Config in an iOS app, see
Use Firebase Remote Config on iOS.

Ensure that Remote Config is used in your Podfile:

pod 'Firebase/RemoteConfig'

Add the following to the top of your app's AppDelegate file:

Swift

import FirebaseRemoteConfig

Objective-C

@import FirebaseRemoteConfig;

In your AppDelegate file, add the following code to the launchOptions
statements in the application:didFinishLaunchingWithOptions: instance
method:

Swift

remoteConfig = RemoteConfig.remoteConfig()
// You can change the "false" below to "true" to permit more fetches when validating
// your app, but you should change it back to "false" or remove this statement before
// distributing your app in production.
let remoteConfigSettings = RemoteConfigSettings(developerModeEnabled: false)
remoteConfig.configSettings = remoteConfigSettings!
// Load in-app defaults from a plist file that sets perf_disable to false until
// you update values in the Firebase Console.
remoteConfig.setDefaultsFromPlistFileName("RemoteConfigDefaults")
// Important! This needs to be applied before FirebaseApp.configure()
if !remoteConfig["perf_disable"].boolValue {
// The following line disables automatic traces and HTTP/S network monitoring
Performance.sharedInstance().isInstrumentationEnabled = false
// The following line disables custom traces
Performance.sharedInstance().isDataCollectionEnabled = false
}
else {
Performance.sharedInstance().isInstrumentationEnabled = true
Performance.sharedInstance().isDataCollectionEnabled = true
}
// Use Firebase library to configure APIs
FirebaseApp.configure()

Objective-C

self.remoteConfig = [FIRRemoteConfig remoteConfig];
// You can change the NO below to YES to permit more fetches when validating
// your app, but you should change it back to NO or remove this statement before
// distributing your app in production.
FIRRemoteConfigSettings *remoteConfigSettings =
[[FIRRemoteConfigSettings alloc] initWithDeveloperModeEnabled:NO];
self.remoteConfig.configSettings = remoteConfigSettings;
// Load in-app defaults from a plist file that sets perf_disable to false until
// you update values in the Firebase Console.
[self.remoteConfig setDefaultsFromPlistFileName:@"RemoteConfigDefaults"];
// Important! This needs to be applied before [FIRApp configure]
if (!self.remoteConfig[@"perf_disable"].numberValue.boolValue) {
// The following line disables automatic traces and HTTP/S network monitoring
[FIRPerformance sharedInstance].instrumentationEnabled = NO;
// The following line disables custom traces
[FIRPerformance sharedInstance].dataCollectionEnabled = NO;
}
else {
[FIRPerformance sharedInstance].instrumentationEnabled = YES;
[FIRPerformance sharedInstance].dataCollectionEnabled = YES;
}
// Use Firebase library to configure APIs
[FIRApp configure];

In ViewController.m, or another implementation file used by your app, add
the following code to fetch and activate Remote Config values:

To disable Performance Monitoring in the Firebase console, create a perf_disable
parameter in your app's project, then set its value to true.

If you set the value of perf_disable to false, Performance Monitoring remains
enabled.

Disable automatic or manual data collection separately

You can make some changes to the code shown above and in the Firebase console
to let you disable automatic data collection (app start traces and HTTP/S
network requests) separately from manual data collection (custom traces).

Add the following code to the launchOptions statements in the
application:didFinishLaunchingWithOptions: instance method (instead of
what's shown above for the same instance method):