ユーザーが Firebase Performance Monitoring の使用をオプトインまたはオプトアウトできるようにするには、Performance Monitoring を有効または無効にできるようにアプリを構成することをお勧めします。この機能は、アプリの開発およびテスト中にも役立つ場合があります。
考慮すべきいくつかのオプションを次に示します。
アプリのビルド時に Performance Monitoring SDK を無効にすることができますが、実行時に再度有効にするオプションがあります。
Performance Monitoring SDK を有効にしてアプリをビルドできますが、Firebase Remote Config を使用して実行時に無効にするオプションがあります。
Performance Monitoring SDK を完全に非アクティブ化できます。実行時に有効にするオプションはありません。
アプリのビルド プロセス中にパフォーマンス モニタリングを無効にする
アプリのビルド プロセス中にパフォーマンス モニタリングを無効にすることが役立つ状況の 1 つは、アプリの開発およびテスト中にアプリのプレリリース バージョンからパフォーマンス データを報告しないようにすることです。
Performance Monitoring を無効または無効にするには、Apple アプリのプロパティ リスト ファイル ( Info.plist
) に次の 2 つのキーのいずれかを追加します。
Performance Monitoring を無効にして、実行時にアプリで有効にするには、アプリの
Info.plist
ファイルでfirebase_performance_collection_enabled
をfalse
に設定します。パフォーマンス モニタリングを完全に無効にし、実行時に有効にするオプションを指定しない場合は、アプリの
Info.plist
ファイルでfirebase_performance_collection_deactivated
をtrue
に設定します。
Remote Config を使用して実行時にアプリを無効にする
Firebase Remote Config を使用すると、アプリの動作と外観を変更できるため、デプロイされたアプリのインスタンスで Performance Monitoring を無効にする理想的な方法が提供されます。
Apple アプリの次回起動時に Performance Monitoring データ収集を無効にするには、以下に示すサンプル コードを使用します。 Apple アプリで Remote Config を使用する方法の詳細については、 Apple プラットフォームで Firebase Remote Config を使用するを参照してください。
Podfile
で Remote Config が使用されていることを確認します。pod 'Firebase/RemoteConfig'
アプリの
AppDelegate
ファイルの先頭に次を追加します。迅速
注:この Firebase 製品は、macOS、Mac Catalyst、watchOS ターゲットでは使用できません。import FirebaseRemoteConfig
Objective-C
注:この Firebase 製品は、macOS、Mac Catalyst、watchOS ターゲットでは使用できません。@import FirebaseRemoteConfig;
AppDelegate
ファイルで、次のコードをapplication:didFinishLaunchingWithOptions:
インスタンス メソッドのlaunchOptions
ステートメントに追加します。迅速
注:この製品は、macOS、Mac Catalyst、watchOS ターゲットでは使用できません。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 all automatic (out-of-the-box) monitoring Performance.sharedInstance().isInstrumentationEnabled = false // The following line disables all custom monitoring Performance.sharedInstance().isDataCollectionEnabled = false } else { Performance.sharedInstance().isInstrumentationEnabled = true Performance.sharedInstance().isDataCollectionEnabled = true } // Use Firebase library to configure APIs FirebaseApp.configure()
Objective-C
注:この Firebase 製品は、macOS、Mac Catalyst、watchOS ターゲットでは使用できません。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 all automatic (out-of-the-box) monitoring [FIRPerformance sharedInstance].instrumentationEnabled = NO; // The following line disables all custom monitoring [FIRPerformance sharedInstance].dataCollectionEnabled = NO; } else { [FIRPerformance sharedInstance].instrumentationEnabled = YES; [FIRPerformance sharedInstance].dataCollectionEnabled = YES; } // Use Firebase library to configure APIs [FIRApp configure];
ViewController.m
またはアプリで使用される別の実装ファイルに、次のコードを追加して、Remote Config の値を取得して有効にします。迅速
注:この Firebase 製品は、macOS、Mac Catalyst、watchOS ターゲットでは使用できません。//RemoteConfig fetch and activation in your app, shortly after startup remoteConfig.fetch(withExpirationDuration: TimeInterval(30.0)) { (status, error) -> Void in if status == .success { print("Config fetched!") self.remoteConfig.activateFetched() } else { print("Config not fetched") print("Error \(error!.localizedDescription)") } }
Objective-C
注:この Firebase 製品は、macOS、Mac Catalyst、watchOS ターゲットでは使用できません。//RemoteConfig fetch and activation in your app, shortly after startup [self.remoteConfig fetchWithExpirationDuration:30.0 completionHandler:^(FIRRemoteConfigFetchStatus status, NSError *error) { if (status == FIRRemoteConfigFetchStatusSuccess) { NSLog(@"Config fetched!"); [self.remoteConfig activateFetched]; } else { NSLog(@"Config not fetched"); NSLog(@"Error %@", error.localizedDescription); } }];
Firebase コンソールで Performance Monitoring を無効にするには、アプリのプロジェクトでperf_disableパラメータを作成し、その値を
true
に設定します。perf_disableの値を
false
に設定すると、パフォーマンス監視は有効のままになります。
自動またはカスタム データ収集を個別に無効にする
上記のコードと Firebase コンソールにいくつかの変更を加えて、カスタム モニタリングとは別に、すべての自動 (すぐに使える) モニタリングを無効にすることができます。
アプリケーションの
launchOptions
ステートメントに次のコードを追加しapplication:didFinishLaunchingWithOptions:
インスタンス メソッド (上記の同じインスタンス メソッドの代わりに):迅速
注:この Firebase 製品は、macOS、Mac Catalyst、watchOS ターゲットでは使用できません。remoteConfig = FIRRemoteConfig.remoteConfig() let remoteConfigSettings = FIRRemoteConfigSettings(developerModeEnabled: true) remoteConfig.configSettings = remoteConfigSettings! // Important! This needs to be applied before FirebaseApp.configure() if remoteConfig["perf_disable_auto"].boolValue { // The following line disables all automatic (out-of-the-box) monitoring Performance.sharedInstance().isInstrumentationEnabled = false } else { Performance.sharedInstance().isInstrumentationEnabled = true } if remoteConfig["perf_disable_manual"].boolValue { // The following line disables all custom monitoring Performance.sharedInstance().isDataCollectionEnabled = false } else { Performance.sharedInstance().isDataCollectionEnabled = true } // Use Firebase library to configure APIs FirebaseApp.configure()
Objective-C
注:この Firebase 製品は、macOS、Mac Catalyst、watchOS ターゲットでは使用できません。self.remoteConfig = [FIRRemoteConfig remoteConfig]; FIRRemoteConfigSettings *remoteConfigSettings = [[FIRRemoteConfigSettings alloc] initWithDeveloperModeEnabled:YES]; self.remoteConfig.configSettings = remoteConfigSettings; // Important! This needs to be applied before [FirebaseApp configure] if (self.remoteConfig[@"perf_disable_auto"].numberValue.boolValue) { // The following line disables all automatic (out-of-the-box) monitoring [FIRPerformance sharedInstance].instrumentationEnabled = NO; } else { [FIRPerformance sharedInstance].instrumentationEnabled = YES; } if (self.remoteConfig[@"perf_disable_manual"].numberValue.boolValue) { // The following line disables all custom monitoring [FIRPerformance sharedInstance].dataCollectionEnabled = NO; } else { [FIRPerformance sharedInstance].dataCollectionEnabled = YES; } // Use Firebase library to configure APIs [FirebaseApp configure];
Firebase コンソールで次の手順を実行します。
- すべての自動 (すぐに使える) 監視を無効にするには、アプリのプロジェクトでperf_disable_autoパラメーターを作成し、その値を
true
に設定します。 - すべてのカスタム モニタリングを無効にするには、アプリのプロジェクトでperf_disable_manualパラメーターを作成し、その値を
true
に設定します。
- すべての自動 (すぐに使える) 監視を無効にするには、アプリのプロジェクトでperf_disable_autoパラメーターを作成し、その値を