Firebase Performance Monitoring deaktivieren


Damit Ihre Nutzer der Verwendung von Firebase Performance Monitoring zustimmen oder widersprechen können, haben Sie folgende Möglichkeiten: Sie Ihre App so konfigurieren möchten, dass Sie Performance Monitoring aktivieren und deaktivieren können. Ich könnte diese Funktion auch bei der App-Entwicklung und beim Testen nützlich sein.

Sie haben folgende Möglichkeiten:

  • Du kannst das Performance Monitoring SDK beim Erstellen deiner App deaktivieren und dabei Folgendes tun: zur Laufzeit wieder aktivieren.

  • Du kannst deine App mit aktiviertem Performance Monitoring SDK erstellen, hast aber die Möglichkeit, zur Laufzeit mit Firebase Remote Config deaktivieren.

  • Sie können das Performance Monitoring SDK vollständig deaktivieren, ohne es zu aktivieren. während der Laufzeit.

Performance Monitoring während des App-Build-Prozesses deaktivieren

Eine Situation, in der das Deaktivieren von Performance Monitoring während des App-Build-Prozesses ist es hilfreich, keine Leistungsdaten aus einer Vorabveröffentlichung Ihrer bei der Entwicklung und beim Testen der App.

Wenn Sie Performance Monitoring deaktivieren möchten, können Sie der Property-Liste (Info.plist) Ihrer Apple-App einen der beiden folgenden Schlüssel hinzufügen:

  • Um Performance Monitoring zu deaktivieren, aber Ihrer App zu erlauben, es zur Laufzeit zu aktivieren, legen Sie Folgendes fest: firebase_performance_collection_enabled bis false in der Info.plist-Datei.

  • Wenn Sie Performance Monitoring vollständig deaktivieren möchten, ohne es zur Laufzeit zu aktivieren, gehen Sie so vor: firebase_performance_collection_deactivated in den Einstellungen deiner App auf true festlegen Info.plist-Datei.

Anwendung mit Remote Config zur Laufzeit deaktivieren

Mit Firebase Remote Config können Sie Verhalten und Darstellung ändern Ihrer App. Sie bietet daher eine ideale Möglichkeit, Performance Monitoring in bereitgestellten Instanzen Ihrer Anwendung.

So deaktivieren Sie die Performance Monitoring-Datenerhebung beim nächsten Start der Apple-App: verwenden Sie den unten stehenden Beispielcode. Weitere Informationen zur Verwendung Remote Config in einer Apple-App finden Sie unter Verwenden Sie Firebase Remote Config auf Apple-Plattformen.

  1. Achten Sie darauf, dass Remote Config in Ihrem Podfile verwendet wird:

    pod 'Firebase/RemoteConfig'
    
  2. Fügen Sie der Datei AppDelegate Ihrer App oben Folgendes hinzu:

    Swift

    Hinweis:Dieses Firebase-Produkt ist nicht für macOS-, Mac-Catayst- und watchOS-Ziele verfügbar.
    import FirebaseRemoteConfig
    

    Objective-C

    Hinweis:Dieses Firebase-Produkt ist nicht für macOS-, Mac-Catayst- und watchOS-Ziele verfügbar.
    @import FirebaseRemoteConfig;
    
  3. Fügen Sie in der Datei AppDelegate den folgenden Code in die Datei launchOptions ein: Anweisungen in der application:didFinishLaunchingWithOptions:-Instanz :

    Swift

    Hinweis:Dieses Produkt ist nicht für macOS-, Mac-Catayst- und watchOS-Ziele verfügbar.
    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

    Hinweis:Dieses Firebase-Produkt ist nicht für macOS-, Mac-Catayst- und watchOS-Ziele verfügbar.
    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];
    
  4. Fügen Sie in ViewController.m oder einer anderen Implementierungsdatei, die von Ihrer App verwendet wird, den folgenden Code hinzu, um Remote Config-Werte abzurufen und zu aktivieren:

    Swift

    Hinweis:Dieses Firebase-Produkt ist nicht für macOS-, Mac-Catayst- und watchOS-Ziele verfügbar.
    //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

    Hinweis:Dieses Firebase-Produkt ist nicht für macOS-, Mac-Catayst- und watchOS-Ziele verfügbar.
    //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);
      }
    }];
    
  5. Wenn Sie Performance Monitoring in der Firebase-Konsole deaktivieren möchten, erstellen Sie im Projekt Ihrer App den Parameter perf_disable und legen Sie seinen Wert auf true fest.

    Wenn Sie den Wert von perf_disable auf false setzen, bleibt Performance Monitoring unverändert. aktiviert.

Automatische oder benutzerdefinierte Datenerhebung separat deaktivieren

Du kannst einige Änderungen am oben angezeigten Code und in der Firebase-Konsole vornehmen Sie können damit das gesamte automatische Monitoring getrennt vom benutzerdefiniertes Monitoring.

  1. Fügen Sie den launchOptions-Anweisungen im application:didFinishLaunchingWithOptions:-Instanzmethode (anstelle von wie oben für dieselbe Instanzmethode gezeigt):

    Swift

    Hinweis:Dieses Firebase-Produkt ist nicht für macOS-, Mac-Catayst- und watchOS-Ziele verfügbar.
    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

    Hinweis:Dieses Firebase-Produkt ist nicht für macOS-, Mac-Catayst- und watchOS-Ziele verfügbar.
    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];
    
  2. Führen Sie in der Firebase-Konsole die folgenden Schritte aus:

    • Wenn Sie das gesamte automatische Monitoring deaktivieren möchten, erstellen Sie einen perf_disable_auto-Parameter im Projekt Ihrer App an und legen Sie dann Wert auf true setzen.
    • Erstellen Sie ein perf_disable_manual, um das gesamte benutzerdefinierte Monitoring zu deaktivieren. im Projekt Ihrer App und setzen Sie dann seinen Wert auf true.