The Google User Messaging Platform (UMP) SDK is a privacy and messaging tool to help you manage privacy choices. For more information, see About Privacy & messaging. You can see a working IMA implementation with the UMP SDK in either the Objective-C or Swift UMP sample apps.
Create a message type
Create user messages with one of the Available user message types under the Privacy & messaging tab of your Ad Manager account. The UMP SDK attempts to display a privacy message created from the Interactive Media Ads Application ID set in your project.
For more details, see About privacy and messaging.
Import the SDK
The UMP SDK is not included as a dependency of the IMA SDK, so you must explicitly add it yourself.
CocoaPods (preferred)
The easiest way to import the SDK into an iOS project is to use CocoaPods. Open your project's Podfile and add this line to your app's target:
pod 'GoogleUserMessagingPlatform'
Then, run the following command:
pod install --repo-update
If you're new to CocoaPods, see Using CocoaPods for details on how to create and use Podfiles.
Swift Package Manager
The UMP SDK also supports the Swift Package Manager. Follow these steps to import the Swift package.
In Xcode, install the UMP SDK Swift Package by navigating to File > Add Packages....
In the prompt that appears, search for the UMP SDK Swift Package GitHub repository:
https://github.com/googleads/swift-package-manager-google-user-messaging-platform.git
Select the version of the UMP SDK Swift Package you want to use. For new projects, we recommend using the Up to Next Major Version.
Xcode then resolves your package dependencies and downloads them in the background. For more details on how to add package dependencies, see Apple's article.
Add the application ID
You can find your application ID in the
Ad Manager UI.
Add the ID to your
Info.plist
with the following code snippet:
<key>UMPApplicationIdentifier</key>
<string>ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy</string>
Get the user's consent information
You should request an update of the user's consent information at every app
launch, using
requestConsentInfoUpdateWithParameters:completionHandler:
. This request checks the following:
- Whether consent is required. For example, consent is required for the first time, or the previous consent decision expired.
- Whether a privacy options entry point is required. Some privacy messages require apps to allow users to modify their privacy options at any time.
Swift
// Requesting an update to consent information should be called on every app launch.
UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) {
requestConsentError in
// ...
}
Objective-C
// Requesting an update to consent information should be called on every app launch.
[UMPConsentInformation.sharedInstance
requestConsentInfoUpdateWithParameters:parameters
completionHandler:^(NSError *_Nullable requestConsentError) {
// ...
}];
Load and present the privacy message form
After you have received the most up-to-date consent status, call
loadAndPresentIfRequiredFromViewController:completionHandler:
to load any forms required to
collect user consent. After loading, the forms present immediately.
Swift
try await UMPConsentForm.loadAndPresentIfRequired(from: viewController)
Objective-C
[UMPConsentForm
loadAndPresentIfRequiredFromViewController:viewController
completionHandler:^(NSError *_Nullable loadAndPresentError) {
// Consent gathering process is complete.
}];
Privacy options
Some privacy message forms are presented from a publisher-rendered privacy options entry point, letting users manage their privacy options at any time. To learn more about which message your users see at the privacy options entry point, see Available user message types.
Check if a privacy options entry point is required
After you have called
requestConsentInfoUpdateWithParameters:completionHandler:
, check
UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus
to
determine if a privacy options entry point is required for your app. If an entry
point is required, add a visible and interactable UI element to your app that
presents the privacy options form. If a privacy entry point is not required,
configure your UI element to be not visible and interactable.
Swift
var isPrivacyOptionsRequired: Bool {
return UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus == .required
}
Objective-C
- (BOOL)areGDPRConsentMessagesRequired {
return UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus ==
UMPPrivacyOptionsRequirementStatusRequired;
}
- (void)gatherConsentFromConsentPresentationViewController:(UIViewController *)viewController
consentGatheringComplete:
(void (^)(NSError *_Nullable))consentGatheringComplete {
UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
// Set tag for under age of consent. Use NO constant to indicate that the user is not under age.
parameters.tagForUnderAgeOfConsent = NO;
UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
// Uncomment the following line to simulate a consent request from users in the
// European Economic Area (EEA) for testing purposes.
// debugSettings.geography = UMPDebugGeographyEEA;
parameters.debugSettings = debugSettings;
// Requesting an update to consent information should be called on every app launch.
[UMPConsentInformation.sharedInstance
requestConsentInfoUpdateWithParameters:parameters
completionHandler:^(NSError *_Nullable requestConsentError) {
// ...
}];
}
- (void)loadAndPresentIfRequiredFromViewController:(UIViewController *)viewController
completionHandler:(void (^)(NSError *_Nullable))completionHandler {
[UMPConsentForm
loadAndPresentIfRequiredFromViewController:viewController
completionHandler:^(NSError *_Nullable loadAndPresentError) {
// Consent gathering process is complete.
}];
}
- (void)presentPrivacyOptionsFormFromViewController:(UIViewController *)viewController
completionHandler:
(void (^)(NSError *_Nullable))completionHandler {
[UMPConsentForm presentPrivacyOptionsFormFromViewController:viewController
completionHandler:completionHandler];
}
@end
For the full list of privacy options requirement statuses, see
UMPPrivacyOptionsRequirementStatus
.
Present the privacy options form
When the user interacts with your element, present the privacy options form:
Swift
UMPConsentForm.presentPrivacyOptionsForm(
from: viewController, completionHandler: completionHandler)
Objective-C
[UMPConsentForm presentPrivacyOptionsFormFromViewController:viewController
completionHandler:completionHandler];
Request ads with user consent
Before requesting ads, use
UMPConsentInformation.sharedInstance.canRequestAds
to check if you've
obtained consent from the user:
Swift
UMPConsentInformation.sharedInstance.canRequestAds
Objective-C
UMPConsentInformation.sharedInstance.canRequestAds;
Listed are the following places to check if you can request ads while gathering consent:
- After the UMP SDK gathers consent in the current session.
- Immediately after you have called
requestConsentInfoUpdateWithParameters:completionHandler:
. The UMP SDK might have obtained consent in the previous app session.
If an error occurs during the consent gathering process, check if you can request ads. The UMP SDK uses the consent status from the previous app session.
Prevent redundant ad request work
As you check
UMPConsentInformation.sharedInstance.canRequestAds
after gathering consent and after calling
requestConsentInfoUpdateWithParameters:completionHandler:
, ensure your logic prevents redundant ad requests that
might result in both checks returning true
. For example, with a boolean
variable.
Testing
If you want to test the integration in your app as you're developing, follow these steps to programmatically register your test device. Be sure to remove the code that sets these test device IDs before you release your app.
- Call
requestConsentInfoUpdateWithParameters:completionHandler:
. Check the log output for a message similar to the following example, which shows your device ID and how to add it as a test device:
<UMP SDK>To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[2077ef9a63d2b398840261c8221a0c9b]
Copy your test device ID to your clipboard.
Modify your code to call
UMPDebugSettings().testDeviceIdentifiers
and pass in a list of your test device IDs.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){ // ... }];
Force a geography
The UMP SDK provides a way to test your app's behavior as though the device were located in various regions, such as the EEA or UK, using UMPDebugGeography. Note that debug settings only work on test devices.
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){
// ...
}];
Reset consent state
When testing your app with the UMP SDK, you might find it helpful to reset the
state of the SDK so that you can simulate a user's first install experience.
The SDK provides the reset
method to do this.
Swift
UMPConsentInformation.sharedInstance.reset()
Objective-C
[UMPConsentInformation.sharedInstance reset];
Examples on GitHub
See a full example of the UMP SDK integration covered in this page in Swift UmpExample and Objective-C UmpExample.