Implement the new beta privacy APIs by following the opt-in consent, opt-out signal, and age-restricted user specification APIs, respectively, for iOS (Swift, Objective-C) and Android (Kotlin, Java) development.
Read time 2 minutesLast updated 3 hours ago
Use the new beta privacy APIs
Review the opt-in consent, opt-out signal, and age-restricted specification APIs and relevant code samples for iOS or Android.
Opt-in consent API
Use the
setUserConsent()
API to display the user's opt-in choices for personalized ads.Refer to the following tabs for platform-specific code examples to communicate whether the user has granted or declined consent for targeted advertising.
public static func setUserConsent(_ consentGranted: Bool)// If the user agrees to personalized adsUnityAds.setUserConsent(true)// If the user doesn't agree to personalized adsUnityAds.setUserConsent(false)
+ (void)setUserConsent:(BOOL)consentGranted;// If the user agrees to personalized ads[UnityAds setUserConsent:YES];// If the user doesn't agree to personalized ads[UnityAds setUserConsent:NO];
@JvmStaticvar userConsent: Boolean? = null// If the user agrees to personalized adsUnityAds.userConsent = true// If the user doesn't agree to personalized adsUnityAds.userConsent = false
@JvmStaticvar userConsent: Boolean? = null// If the user agrees to personalized adsUnityAds.setUserConsent(true);// If the user doesn't agree to personalized adsUnityAds.setUserConsent(false);
Opt-out signal API
Use the
setUserOptOut()
API to display the user's opt-in choices for personalized ads.Refer to the following tabs for platform-specific code examples to communicate whether the user has granted or declined consent for targeted advertising.
public static func setUserOptOut(_ optOut: Bool)// If the user opts in to personalized adsUnityAds.setUserOptOut(false)// If the user opts out to personalized adsUnityAds.setUserOptOut(true)
+ (void)setUserOptOut:(BOOL)optOut;// If the user opts in to personalized ads[UnityAds setUserOptOut:NO];// If the user opts out to personalized ads[UnityAds setUserOptOut:YES];
@JvmStaticvar userOptOut: Boolean? = null// If the user opts in to personalized adsUnityAds.userOptOut = false// If the user opts out to personalized adsUnityAds.userOptOut = true
@JvmStaticvar userOptOut: Boolean? = null// If the user opts in to personalized adsUnityAds.setUserOptOut(false);// If the user opts out to personalized adsUnityAds.setUserOptOut(true);
Age-restricted users specification
Use the
setNonBehavioral()
API to indicate a user's eligibility for non-behavioral (contextual) ads.Refer to the following tabs for platform-specific code examples to communicate whether a privacy framework requires contextual-only ad delivery, typically for content directed to children or younger users.
public static func setNonBehavioral(_ nonBehavioral: Bool)// If the user opts out to personalized adsUnityAds.setNonBehavioral(true)// If the user opts in to personalized adsUnityAds.setNonBehavioral(false)
+ (void)setNonBehavioral:(BOOL)nonBehavioral;// If the user opts out to personalized ads[UnityAds setNonBehavioral:YES];// If the user opts in to personalized ads[UnityAds setNonBehavioral:NO];
@JvmStaticvar nonBehavioral: Boolean? = null// If the user opts out to personalized adsUnityAds.nonBehavioral = true// If the user opts in to personalized adsUnityAds.nonBehavioral = false
@JvmStaticvar nonBehavioral: Boolean? = null// If the user opts out to personalized adsUnityAds.setNonBehavioral(true);// If the user opts in to personalized adsUnityAds.setNonBehavioral(false);