We’ve Made Updates to the User Messaging Platform SDK APIs

In case you missed it, we announced new consent management platform requirements for serving ads in the EEA and UK. Beginning January 16, 2024, Google will require all publishers to use a Google-certified consent management platform (CMP) when serving ads to users in the European Economic Area or the UK.

In addition to growing our list of certified CMPs, we explored how to improve the User Messaging Platform (UMP) SDK developer experience for those who choose to use Google’s consent management solution. We are excited to share several updates in the latest iOS and Android versions that we think will streamline your integration.

Loading and presenting a consent form

The latest UMP SDK release introduces a new API, loadAndPresentIfRequired(), that consolidates the existing individual load and present consent form methods into a single method. The new API loads a consent form and if consent is required, automatically presents the consent form. This method is intended to be used at the beginning of a new app session.

Here is a code example of how to use the new API on iOS:

class ViewController: UIViewController {

  private var isMobileAdsStartCalled = false

  override func viewDidLoad() {
    super.viewDidLoad()

    UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) {
      [weak self] requestConsentError in
      guard let self else { return }

      // Call the helper method once consent information has been updated.
      UMPConsentForm.loadAndPresentIfRequired(from: self) {
        [weak self] loadAndPresentError in
        guard let self else { return }

        if UMPConsentInformation.sharedInstance.canRequestAds {
          self.startGoogleMobileAdsSDK()
        }
      }
    }

    // canRequestAds will be true if consent was gathered in the previous session.
    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()
      // Request an ad.
      GADInterstitialAd.load(...)
    }
  }
}

Checking when to request ads

We added a new boolean property canRequestAds to use as a check before initializing the Google Mobile Ads SDK and requesting ads. canRequestAds returns true when the consent status is either OBTAINED or NOT_REQUIRED; as a result you don’t need to implement any enum checking yourself.

You should use the canRequestAds API in two places (as seen in the code snippet above):

  1. Once consent has been gathered in the current session.
  2. Immediately after you have called requestConsentInfoUpdate. It is possible consent has been gathered in the previous session in which case it is not necessary to wait for the callback to finish.

Checking privacy options requirement status

GDPR requires that publishers allow users to withdraw their consent choices at any time. It should be as easy to withdraw consent as it is to gather consent. To simplify this process, we have added two new APIs:

  1. privacyOptionsRequirementStatus to determine whether you should include a UI element that can re-present the consent form, such as a button in your application’s settings page.
  2. presentPrivacyOptionsForm() to show the form so the user can update their consent status at any time.

Here is a code example of how to use the new APIs on iOS:

// Show a privacy options button if required.
private var isPrivacySettingsButtonEnabled: Bool {
  return UMPConsentInformation.shared.privacyOptionsRequirementStatus == .required
}

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

    // Handle the error.
  }
}

Developer resources

We updated our AdMob banner samples applications for iOS and Android to showcase integrating the UMP SDK. Keep an eye out as we add UMP SDK support to the rest of our samples soon.

Also take a look at our iOS and Android developer documentation for instructions on how to implement the UMP SDK.

If you have any questions or need additional help integrating the UMP SDK, please contact us via the developer forum.