アプリの開発時やテスト時に Performance Monitoring を無効にすると便利な場合があります。
たとえば、アプリのビルドプロセス中に Performance Monitoring を無効にすると、次のことができます。
デバッグビルドで Performance Monitoring の特定の機能を無効にし、リリースビルドでその機能を再度有効にする。
アプリのビルド時に Performance Monitoring を無効にし、ランタイム時にアプリが再度有効にすることを許可する。
アプリのビルド時に Performance Monitoring を無効にし、ランタイム時にアプリが再度有効にすることを許可しない。
Performance Monitoring を有効にした状態でアプリをビルドすることもできます。その場合、Firebase Remote Config を使用すると、本番環境アプリで Performance Monitoring を無効にしたり再度有効にしたりするなど、柔軟に切り替えることができます。この方法を使用すると、ユーザーが Performance Monitoring の使用をオプトイン / オプトアウトできるようにアプリを構成できます。
アプリのビルドプロセス中に Performance Monitoring を無効にする
アプリのビルドプロセス中に Performance Monitoring を無効にすると便利な状況の一例としては、開発またはテスト中にプレリリース版アプリからパフォーマンス データが報告されないようにする場合が挙げられます。
詳しくは、プラットフォーム固有の iOS+ および Android のドキュメントをご覧ください。
Remote Config を使用してランタイム時にアプリを無効にする
Firebase Remote Config を使用すると、アプリの動作や外観を変更できるため、デプロイされたアプリのインスタンスで Performance Monitoring を無効にする場合に最適です。
たとえば、perf_disable というパラメータを使用して Performance Monitoring をリモートで制御するとします。Performance Monitoring を有効または無効にするには、起動コードに以下を追加します。
// Activate previously-fetched values, falling back on the defaults if
// nothing is available yet.
await FirebaseRemoteConfig.instance
.setDefaults(YOUR_REMOTE_CONFIG_DEFAULTS);
await FirebaseRemoteConfig.instance.activate();
// Enable or disable Performance Monitoring based on the value of
// "perf_disable".
final perfMonDisabled =
FirebaseRemoteConfig.instance.getBool("perf_disable");
FirebasePerformance.instance
.setPerformanceCollectionEnabled(!perfMonDisabled);
// Fetch values for next time. (Don't await the result!)
FirebaseRemoteConfig.instance.fetch();