Introduction
If you’re developing a game in Unity and want to monetize with ads, it’s essential to implement AdMob properly, especially around user privacy. Google requires using its User Messaging Platform (UMP) SDK for consent in regions governed by GDPR, and Apple’s App Tracking Transparency (ATT) framework for iOS to request IDFA-based tracking permission. In this guide, you’ll learn how to integrate AdMob ads in Unity and ensure compliance with UMP and ATT.
What You Need to Know: UMP, GDPR, and ATT
- UMP SDK: Google’s tool for handling user consent in the European Economic Area (EEA), UK, and other regions with privacy laws. It shows a consent form asking users if they consent to personalized ads. (Google for Developers)
- GDPR: Regulations in the EU/EEA that require explicit user consent before collecting or processing personal data, including for ads. UMP helps you meet this requirement. (Google for Developers)
- ATT (App Tracking Transparency): Apple’s permission framework (iOS 14.5+) that asks users for permission to track their activities across apps (that is, using the IDFA). Must show ATT prompt on iOS. (Unity Documentation)
Step-by-Step: Integrating AdMob Ads in Unity with UMP & ATT
Here’s how to do it correctly:
1. Install AdMob & UMP SDK
- Import the Google Mobile Ads Unity plugin into your Unity project. Make sure it’s a recent version (AdMob SDK version that supports UMP + iOS ATT). (Google for Developers)
- Add the UMP (User Messaging Platform) SDK if not bundled by the AdMob plugin. UMP handles consent pop-ups (GDPR, etc.). (Google for Developers)
2. Configure Consent Form (UMP) for GDPR & Regions
- In your AdMob dashboard under Privacy & Messaging, create and publish your GDPR consent message. This ensures that users in EEA/UK will receive the UMP consent form. (Gley Assets)
- In Unity, call the UMP initialization code (something like
ConsentInformation.Update(...)
). The UMP consent dialog appears automatically when you initialize if the user is in a region where consent is required. (Gley Assets)
3. Add ATT for iOS (IDFA Authorization)
- Edit
Info.plist
in your Xcode project to include theNSUserTrackingUsageDescription
key. This string explains why you need tracking permission (for personalized ads). (Unity Documentation) - On iOS devices, before loading ads, request tracking authorization. Using
ATTrackingManager.requestTrackingAuthorization(...)
in Swift/Objective-C. Wait for user response before using the IDFA. (Google for Developers) - Optionally show a custom context screen before showing the system’s ATT dialog. This screen can explain the benefit of opting in, to improve user understanding and increase opt-in rates. (Unity Documentation)
4. Order and Logic: Consent → ATT → Ad Loading
- The usual flow is:
- Initialize UMP → show GDPR consent form (if needed)
- If user consents to personalized ads, then show the ATT prompt on iOS
- After ATT decision, then initialize the ad SDK / load ads
- If the user declines GDPR consent, do not request ATT (i.e. do not show the IDFA prompt). Also, don’t load personalized ads. This avoids confusing the user and helps with Apple’s review process. (Google Groups)
5. Test & Debug
- Make sure to test in debug mode or with test devices. UMP allows forcing geography to simulate user in an EEA region so you can check that consent form appears. (Gley Assets)
- On iOS builds, verify the
NSUserTrackingUsageDescription
appears correctly in Info.plist. Also verify that ATT request comes only after consent (where appropriate) and only once per install. (Unity Documentation)
Common Pitfalls You Should Avoid
Pitfall | Why It’s a Problem | How to Avoid |
---|---|---|
Showing ATT prompt even when the user declined consent under GDPR | Apple may reject app; user confused; privacy rules violated. (Google Groups) | Use UMP’s consent status logic: if consent is no, do not trigger ATT. |
Not providing NSUserTrackingUsageDescription in Info.plist | iOS requires this — omission causes rejection. (Unity Documentation) | Add that key with a meaningful description before building. |
Initializing ads before permissions are resolved | Ads may use IDFA or personalized data prematurely, cause violations. | Delay ad initialization until after UMP + ATT flows are done. |
Not customizing the ATT context screen | Users may not understand why they’re being asked → lower opt-in. | Provide clear, transparent context explaining the benefit of tracking. |
Example Code Snippets
Here’s some pseudo-code to show the flow:
using Google.MobileAds;
using Google.MobileAds.Ump;
using UnityEngine;
public class AdManager : MonoBehaviour {
async void Start() {
// Initialize UMP
var request = new ConsentRequestParameters();
// optional: set debugging / geography as needed for testing
ConsentInformation.RequestConsentInfoUpdate(request, OnConsentInfoUpdated);
}
void OnConsentInfoUpdated(ConsentRequestParameters requestParams, ConsentForm form) {
if (form.IsConsentFormAvailable) {
form.Show( formError => {
if (formError == null) {
var status = ConsentInformation.ConsentStatus;
if (status == ConsentStatus.Personalized) {
// On iOS, now request ATT
#if UNITY_IOS
RequestATT();
#endif
InitializeAdMobAds();
} else {
// Non-personalized ads only
InitializeAdMobAds(nonPersonalized:true);
}
}
});
} else {
// Consent not required or form not available
InitializeAdMobAds();
}
}
void RequestATT() {
// Using Unity’s iOS support or native plugin
// call ATTrackingManager.requestTrackingAuthorization(...)
}
void InitializeAdMobAds(bool nonPersonalized = false) {
MobileAds.Initialize(initStatus => {
// setup ad units: banners, interstitials, rewarded, etc.
// specify nonPersonalized flag in ad requests if needed
});
}
}
Summary & Best Practices
- Always use UMP SDK for consent to comply with GDPR and data-privacy laws.
- On iOS, ensure ATT prompt is only shown after user consent for personalized ads (or never shown if consent is denied).
- Provide a clear message in
NSUserTrackingUsageDescription
and optionally a context screen to improve opt-in rates. - Test in all relevant regions, especially EEA/UK and iOS devices.
- Delay ad initialization until after consent/ATT flows are completed to avoid violations.
FAQ
Q: Is UMP mandatory if I only target users outside EU/EEA / UK?
A: For those users, UMP consent form may not be required. But using UMP helps to centrally manage consent if your app gets distributed globally. Also, AdMob offers controls per region. (Gley Assets)
Q: How many times will the user see the ATT prompt?
A: Only once per install (or until they change in Settings). Apple guidelines mandate that. (Unity Documentation)
Q: What if the user declines ATT?
A: Then you can only serve non-personalized ads. The IDFA will not be available. Your ad revenue may be lower, but you are compliant.