Jetzt loslegen

Gemäß der Richtlinie zur Einwilligung der Nutzer in der EU von Google müssen Sie Ihren Nutzern im Europäischen Wirtschaftsraum (EWR) sowie im Vereinigten Königreich bestimmte Informationen offenlegen und ihre Einwilligung zur Verwendung von Cookies oder anderen lokalen Speicherverfahren, falls gesetzlich erforderlich, sowie zur Verwendung personenbezogener Daten (z. B. Werbe-ID) zur Anzeigenbereitstellung einholen. Die Richtlinie entspricht den Anforderungen der EU-Datenschutzrichtlinie für elektronische Kommunikation und der EU-Datenschutz-Grundverordnung (DSGVO).

Google bietet das User Messaging Platform (UMP) SDK an, um Publisher bei der Umsetzung dieser Richtlinie zu unterstützen. Das UMP SDK wurde aktualisiert, um die neuesten IAB-Standards zu unterstützen. All diese Konfigurationen lassen sich jetzt bequem unter AdMob Datenschutz und Mitteilungen verwalten.

Voraussetzungen

Mitteilungstyp erstellen

Erstellen Sie Mitteilungen für Nutzer mit einer der verfügbaren Arten von Mitteilungen für Nutzer auf dem Tab Datenschutz und Mitteilungen in Ihrem AdMob Konto. Das UMP SDK versucht, eine Nutzernachricht anzuzeigen, die aus der in Ihrem Projekt festgelegten AdMob Anwendungs-ID erstellt wurde. Wenn für Ihre Anwendung keine Meldung konfiguriert ist, gibt das SDK einen Fehler zurück.

Weitere Informationen finden Sie unter Datenschutz und Mitteilungen.

SDK importieren

CocoaPods (bevorzugt)

Das UMP SDK ist ab Version 7.64.0 des Google Mobile Ads SDK als Abhängigkeit des Google Mobile Ads SDK-Pods enthalten.

Am einfachsten lässt sich das SDK mit CocoaPods in ein iOS-Projekt importieren. Öffnen Sie die Podfile-Datei Ihres Projekts und fügen Sie dem Ziel Ihrer Anwendung diese Zeile hinzu:

pod 'Google-Mobile-Ads-SDK'

Führen Sie dann den folgenden Befehl aus:

pod install --repo-update

Wenn Sie CocoaPods noch nicht kennen, finden Sie unter CocoaPods verwenden Informationen zum Erstellen und Verwenden von Podfiles.

Manueller Download

Alternativ können Sie das SDK manuell importieren.

SDK herunterladen

Ziehen Sie dann das Framework in Ihr Xcode-Projekt und wählen Sie Bei Bedarf Elemente kopieren aus.

Sie können das Framework dann mithilfe von:

Swift

import UserMessagingPlatform

Objective-C

#include <UserMessagingPlatform/UserMessagingPlatform.h>

Sie sollten mit requestConsentInfoUpdateWithParameters:completionHandler:bei jedem Start der App eine Aktualisierung der Einwilligungsinformationen des Nutzers anfordern. So wird festgelegt, ob Nutzer ihre Einwilligung geben müssen, falls sie dies noch nicht getan haben oder ob sie abgelaufen ist.

Das folgende Beispiel zeigt, wie der Status von einem UIViewController in der viewDidLoad()-Methode geprüft wird.

Swift

override func viewDidLoad() {
  super.viewDidLoad()

  // Create a UMPRequestParameters object.
  let parameters = UMPRequestParameters()
  // Set tag for under age of consent. false means users are not under age
  // of consent.
  parameters.tagForUnderAgeOfConsent = false

  // Request an update for the consent information.
  UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) {
    [weak self] requestConsentError in
    guard let self else { return }

    if let consentError = requestConsentError {
      // Consent gathering failed.
      return print("Error: \(consentError.localizedDescription)")
    }

    // TODO: Load and present the consent form.
  }
}

Objective-C

- (void)viewDidLoad {
  [super viewDidLoad];

  // Create a UMPRequestParameters object.
  UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
  // Set tag for under age of consent. NO means users are not under age
  // of consent.
  parameters.tagForUnderAgeOfConsent = NO;

  // Request an update for the consent information.
  [UMPConsentInformation.sharedInstance
      requestConsentInfoUpdateWithParameters:parameters
          completionHandler:^(NSError *_Nullable requestConsentError) {
            if (requestConsentError) {
              // Consent gathering failed.
              NSLog(@"Error: %@", requestConsentError.localizedDescription);
              return;
            }

            // TODO: Load and present the consent form.
          }];
}

Einwilligungsformular laden und präsentieren, falls erforderlich

Wichtig: Die folgenden APIs sind mit dem UMP SDK ab Version 2.1.0 kompatibel.

Nachdem Sie den aktuellen Einwilligungsstatus erhalten haben, rufen SieloadAndPresentIfRequiredFromViewController:completionHandler: in der KlasseUMPConsentForm auf, um ein Einwilligungsformular zu laden. Wenn der Einwilligungsstatus erforderlich ist, lädt das SDK ein Formular und stellt es sofort aus dem bereitgestellten view controllerbereit. Der completion handler wird aufgerufen , nachdem das Formular geschlossen wurde. Wenn keine Einwilligung erforderlich ist, wird die completion handler mit sofort aufgerufen.

Swift

override func viewDidLoad() {
  super.viewDidLoad()

  // Create a UMPRequestParameters object.
  let parameters = UMPRequestParameters()
  // Set tag for under age of consent. false means users are not under age
  // of consent.
  parameters.tagForUnderAgeOfConsent = false

  // Request an update for the consent information.
  UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) {
    [weak self] requestConsentError in
    guard let self else { return }

    if let consentError = requestConsentError {
      // Consent gathering failed.
      return print("Error: \(consentError.localizedDescription)")
    }

    UMPConsentForm.loadAndPresentIfRequired(from: self) {
      [weak self] loadAndPresentError in
      guard let self else { return }

      if let consentError = loadAndPresentError {
        // Consent gathering failed.
        return print("Error: \(consentError.localizedDescription)")
      }

      // Consent has been gathered.
    }
  }
}

Objective-C

- (void)viewDidLoad {
  [super viewDidLoad];

  // Create a UMPRequestParameters object.
  UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
  // Set tag for under age of consent. NO means users are not under age
  // of consent.
  parameters.tagForUnderAgeOfConsent = NO;

  __weak __typeof__(self) weakSelf = self;
  // Request an update for the consent information.
  [UMPConsentInformation.sharedInstance
      requestConsentInfoUpdateWithParameters:parameters
          completionHandler:^(NSError *_Nullable requestConsentError) {
            if (requestConsentError) {
              // Consent gathering failed.
              NSLog(@"Error: %@", requestConsentError.localizedDescription);
              return;
            }

            __strong __typeof__(self) strongSelf = weakSelf;
            if (!strongSelf) {
              return;
            }

            [UMPConsentForm loadAndPresentIfRequiredFromViewController:strongSelf
                completionHandler:^(NSError *loadAndPresentError) {
                  if (loadAndPresentError) {
                    // Consent gathering failed.
                    NSLog(@"Error: %@", loadAndPresentError.localizedDescription);
                    return;
                  }

                  // Consent has been gathered.
                }];
          }];
}

Wenn Sie Aktionen ausführen möchten, nachdem der Nutzer eine Auswahl getroffen oder das Formular geschlossen hat, fügen Sie die entsprechende Logik im completion handlerfür Ihr Formular ein.

Anzeigenanfrage senden

Bevor Sie in Ihrer App Anzeigen anfordern, prüfen Sie, ob Sie über UMPConsentInformation.sharedInstance.canRequestAdsdie Einwilligung des Nutzers eingeholt haben. Es gibt zwei Möglichkeiten, die Einwilligung beim Einholen der Einwilligung zu prüfen:

  1. Sobald die Einwilligung in der aktuellen Sitzung eingeholt wurde.
  2. Sofort nach dem Anruf bei requestConsentInfoUpdateWithParameters:completionHandler:. Möglicherweise wurde bereits in der vorherigen Sitzung eine Einwilligung eingeholt. Als Best Practice für die Latenz sollten Sie nicht warten, bis der Callback abgeschlossen ist. So können Sie die Anzeigen so schnell wie möglich nach dem Start Ihrer App laden.
aufgerufen haben.

Falls beim Einholen der Einwilligung ein Fehler auftritt, sollten Sie trotzdem versuchen, Anzeigen anzufordern. Das UMP SDK verwendet den Einwilligungsstatus aus der vorherigen Sitzung.

Swift

class ViewController: UIViewController {

  // Use a boolean to initialize the Google Mobile Ads SDK and load ads once.
  private var isMobileAdsStartCalled = false

  override func viewDidLoad() {
    super.viewDidLoad()

    // Create a UMPRequestParameters object.
    let parameters = UMPRequestParameters()
    // Set tag for under age of consent. false means users are not under age
    // of consent.
    parameters.tagForUnderAgeOfConsent = false

    // Request an update for the consent information.
    UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) {
      [weak self] requestConsentError in
      guard let self else { return }

      if let consentError = requestConsentError {
        // Consent gathering failed.
        return print("Error: \(consentError.localizedDescription)")
      }

      UMPConsentForm.loadAndPresentIfRequired(from: self) {
        [weak self] loadAndPresentError in
        guard let self else { return }

        if let consentError = loadAndPresentError {
          // Consent gathering failed.
          return print("Error: \(consentError.localizedDescription)")
        }

        // Consent has been gathered.
        if UMPConsentInformation.sharedInstance.canRequestAds {
          self.startGoogleMobileAdsSDK()
        }
      }
    }
    
    // Check if you can initialize the Google Mobile Ads SDK in parallel
    // while checking for new consent information. Consent obtained in
    // the previous session can be used to request ads.
    if UMPConsentInformation.sharedInstance.canRequestAds {
      startGoogleMobileAdsSDK()
    }
  }
  
  private func startGoogleMobileAdsSDK() {
    DispatchQueue.main.async {
      guard !self.isMobileAdsStartCalled else { return }

      self.isMobileAdsStartCalled = true

      // Initialize the Google Mobile Ads SDK.
      GADMobileAds.sharedInstance().start()

      // TODO: Request an ad.
      // GADInterstitialAd.load(...)
    }
  }
}

Objective-C

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  // Create a UMPRequestParameters object.
  UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
  // Set tag for under age of consent. NO means users are not under age
  // of consent.
  parameters.tagForUnderAgeOfConsent = NO;

  __weak __typeof__(self) weakSelf = self;
  // Request an update for the consent information.
  [UMPConsentInformation.sharedInstance
      requestConsentInfoUpdateWithParameters:parameters
          completionHandler:^(NSError *_Nullable requestConsentError) {
            if (requestConsentError) {
              // Consent gathering failed.
              NSLog(@"Error: %@", requestConsentError.localizedDescription);
              return;
            }
            __strong __typeof__(self) strongSelf = weakSelf;
            if (!strongSelf) {
              return;
            }

            [UMPConsentForm loadAndPresentIfRequiredFromViewController:strongSelf
                completionHandler:^(NSError *loadAndPresentError) {
                  if (loadAndPresentError) {
                    // Consent gathering failed.
                    NSLog(@"Error: %@", loadAndPresentError.localizedDescription);
                    return;
                  }

                  // Consent has been gathered.
                  __strong __typeof__(self) strongSelf = weakSelf;
                  if (!strongSelf) {
                    return;
                  }

                  if (UMPConsentInformation.sharedInstance.canRequestAds) {
                    [strongSelf startGoogleMobileAdsSDK];
                  }
                }];
          }];

  // Check if you can initialize the Google Mobile Ads SDK in parallel
  // while checking for new consent information. Consent obtained in
  // the previous session can be used to request ads.
  if (UMPConsentInformation.sharedInstance.canRequestAds) {
    [self startGoogleMobileAdsSDK];
  }
}

- (void)startGoogleMobileAdsSDK {
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
    // Initialize the Google Mobile Ads SDK.
    [GADMobileAds.sharedInstance startWithCompletionHandler:nil];

    // TODO: Request an ad.
    // [GADInterstitialAd loadWithAdUnitID...];
  });
}

Datenschutzoptionen

Bei einigen Einwilligungsformularen muss der Nutzer seine Einwilligung jederzeit ändern. Führen Sie bei Bedarf die folgenden Schritte aus, um eine Schaltfläche für Datenschutzoptionen zu implementieren.

Folgende Schritte sind hierzu nötig:

  1. Implementieren Sie ein UI-Element, z. B. eine Schaltfläche auf der Einstellungsseite Ihrer App, durch die ein Formular mit Datenschutzoptionen aufgerufen werden kann.
  2. Wenn loadAndPresentIfRequiredFromViewController:completionHandler: abgeschlossen ist, klicken Sie aufprivacyOptionsRequirementStatus , um zu bestimmen, ob das UI-Element angezeigt werden soll, das das Formular für Datenschutzoptionen anzeigen kann.
  3. Wenn ein Nutzer mit Ihrem UI-Element interagiert, rufen SiepresentPrivacyOptionsFormFromViewController:completionHandler: auf, um das Formular aufzurufen, sodass der Nutzer seine Datenschutzoptionen jederzeit aktualisieren kann.

Das folgende Beispiel zeigt, wie das Formular für Datenschutzoptionen aus einem UIBarButtonItem dargestellt wird.

Swift

@IBOutlet weak var privacySettingsButton: UIBarButtonItem!

var isPrivacyOptionsRequired: Bool {
  return UMPConsentInformation.shared.privacyOptionsRequirementStatus == .required
}

override func viewDidLoad() {
  // ...

  // Request an update for the consent information.
  UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) {
    // ...

    UMPConsentForm.loadAndPresentIfRequired(from: self) {
      //...

      // Consent has been gathered.

      // Show the button if privacy options are required.
      self.privacySettingsButton.isEnabled = isPrivacyOptionsRequired
    }
  }
  // ...
}

// Present the privacy options form when a user interacts with the
// privacy settings button.
@IBAction func privacySettingsTapped(_ sender: UIBarButtonItem) {
  UMPConsentForm.presentPrivacyOptionsForm(from: self) {
    [weak self] formError in
    guard let self, let formError else { return }

    // Handle the error.
  }
}

Objective-C

@interface ViewController ()
@property(weak, nonatomic) IBOutlet UIBarButtonItem *privacySettingsButton;
@end

- (BOOL)isPrivacyOptionsRequired {
  return UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus ==
         UMPPrivacyOptionsRequirementStatusRequired;
}

- (void)viewDidLoad {
  // ...

  __weak __typeof__(self) weakSelf = self;
  // Request an update for the consent information.
  [UMPConsentInformation.sharedInstance
      requestConsentInfoUpdateWithParameters:parameters
          completionHandler:^(NSError *_Nullable requestConsentError) {
            // ...

            [UMPConsentForm loadAndPresentIfRequiredFromViewController:strongSelf
                completionHandler:^(NSError *loadAndPresentError) {
                  // ...

                  // Consent has been gathered.

                  // Show the button if privacy options are required.
                  strongSelf.privacySettingsButton.enabled = isPrivacyOptionsRequired;
                }];
          }];
}

// Present the privacy options form when a user interacts with your
// privacy settings button.
- (IBAction)privacySettingsTapped:(UIBarButtonItem *)sender {
  [UMPConsentForm presentPrivacyOptionsFormFromViewController:self
                                completionHandler:^(NSError *_Nullable formError) {
                                  if (formError) {
                                    // Handle the error.
                                  }
                                }];
}

Testen

Wenn du die Einbindung in deine App während der Entwicklung testen möchtest, führe die folgenden Schritte aus, um dein Testgerät programmatisch zu registrieren.

  1. Rufen Sie requestConsentInfoUpdateWithParameters:completionHandler:an.
  2. Suchen Sie in der Logausgabe nach einer Nachricht, die in etwa so aussieht:

    <UMP SDK>To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[2077ef9a63d2b398840261c8221a0c9b]
    
  3. Kopiere die Testgeräte-ID in die Zwischenablage.

  4. Ändern Sie den Code so, dass Aufrufen UMPDebugSettings().testDeviceIdentifiers und Übergeben einer Liste Ihrer Testgeräte-IDs gesetzt wird.

Swift

let parameters = UMPRequestParameters()
let debugSettings = UMPDebugSettings()
debugSettings.testDeviceIdentifiers = ["TEST-DEVICE-HASHED-ID"]
parameters.debugSettings = debugSettings
// Include the UMPRequestParameters in your consent request.
UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(
    with: parameters,
    completionHandler: { error in
      ...
    })

Objective-C

UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
debugSettings.testDeviceIdentifiers = @[ @"TEST-DEVICE-HASHED-ID" ];
parameters.debugSettings = debugSettings;
// Include the UMPRequestParameters in your consent request.
[UMPConsentInformation.sharedInstance
    requestConsentInfoUpdateWithParameters:parameters
                        completionHandler:^(NSError *_Nullable error){
                          ...
}];

Region erzwingen

Mit dem UMP SDK können Sie mithilfe von the debugGeography property of type UMPDebugGeography on UMPDebugSettingsdas Verhalten Ihrer App so testen, als befände sich das Gerät im EWR oder im Vereinigten Königreich. Die Einstellungen zur Fehlerbehebung funktionieren nur auf Testgeräten.

Swift

let parameters = UMPRequestParameters()
let debugSettings = UMPDebugSettings()
debugSettings.testDeviceIdentifiers = ["TEST-DEVICE-HASHED-ID"]
debugSettings.geography = .EEA
parameters.debugSettings = debugSettings
// Include the UMPRequestParameters in your consent request.
UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(
    with: parameters,
    completionHandler: { error in
      ...
    })

Objective-C

UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
debugSettings.testDeviceIdentifiers = @[ @"TEST-DEVICE-HASHED-ID" ];
debugSettings.geography = UMPDebugGeographyEEA;
parameters.debugSettings = debugSettings;
// Include the UMPRequestParameters in your consent request.
[UMPConsentInformation.sharedInstance
    requestConsentInfoUpdateWithParameters:parameters
                         completionHandler:^(NSError *_Nullable error){
                           ...
}];

Beim Testen Ihrer App mit dem UMP SDK kann es hilfreich sein, den Status des SDK zurückzusetzen, damit Sie die erste Installation eines Nutzers simulieren können. Das SDK bietet dazu die Methode reset .

Swift

UMPConsentInformation.sharedInstance.reset()

Objective-C

[UMPConsentInformation.sharedInstance reset];

Beispiele auf GitHub

Beispiele für die UMP SDK-Integration: Swift | Objective-C