Secondo le Norme relative al consenso degli utenti dell'UE di Google, è obbligatorio informare gli utenti nello Spazio economico europeo (SEE) e nel Regno Unito e ricevere il loro consenso per l'utilizzo dei cookie o di altri tipi di archiviazione locale, laddove richiesto dalla legge, nonché per utilizzare i dati personali (ad esempio l'ID pubblicità) per pubblicare gli annunci. Queste norme riflettono i requisiti della direttiva e-Privacy e del Regolamento generale sulla protezione dei dati (GDPR) dell'UE.
Per supportare gli editori nell'adempimento degli obblighi previsti da queste norme, Google offre l'SDK UMP (User Messaging Platform). L'SDK UMP è stato aggiornato per supportare gli standard IAB più recenti. Tutte queste configurazioni ora possono essere gestite comodamente nella AdMob privacy e nei messaggi.
Prerequisiti
- Completa la Guida introduttiva.
- Configura i tuoi messaggi nella scheda Privacy e messaggi del tuo AdMob account. Per ulteriori dettagli, consulta Informazioni su privacy e messaggi,
- Se stai lavorando ai requisiti relativi al GDPR, leggi In che modo i requisiti IAB influiscono sui messaggi per il consenso degli utenti dell'UE.
Tipi di messaggi per gli utenti
Vedi Tipi di messaggi per gli utenti per un elenco completo dei messaggi supportati. Per istruzioni specifiche sull'implementazione di ciascun tipo di messaggio, consulta la barra di navigazione a sinistra.
Importa l'SDK
CocoaPods (consigliato)
L'SDK UMP è incluso come dipendenza del pod dell'SDK Google Mobile Ads a partire dall'SDK Google Mobile Ads 7.64.0.
Il modo più semplice per importare l'SDK in un progetto per iOS è utilizzare CocoaPods. Apri il podfile del tuo progetto e aggiungi questa riga alla destinazione dell'app:
pod 'Google-Mobile-Ads-SDK'
Quindi, esegui il comando seguente:
pod install --repo-update
Se non hai dimestichezza con CocoaPods, consulta Utilizzo di CocoaPods per informazioni dettagliate su come creare e utilizzare i Podfile.
Download manuale
L'altro modo di importare l'SDK è l'operazione manuale.
Quindi, trascina il framework nel tuo progetto Xcode, assicurandoti di selezionare Copia elementi se necessario.
Puoi quindi includere il framework in qualsiasi file di cui hai bisogno:
Swift
import UserMessagingPlatform
Objective-C
#include <UserMessagingPlatform/UserMessagingPlatform.h>
Aggiorna il tuo Info.plist
Trova il tuo ID app e aggiungilo al tuoInfo.plist
:
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy</string>
Determina se un messaggio deve essere visualizzato
Devi richiedere un aggiornamento delle informazioni sul consenso dell'utente a ogni lancio dell'app, utilizzando requestConsentInfoUpdateWithParameters:completionHandler:
prima di caricare un modulo.
In questo modo puoi determinare se l'utente deve o meno fornire il consenso se non l'ha già fatto o se il consenso è scaduto.
Ecco un esempio di come controllare lo stato all'avvio dell'app:
Swift
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Create a UMPRequestParameters object. let parameters = UMPRequestParameters() // Set tag for under age of consent. Here false means users are not under age. parameters.tagForUnderAgeOfConsent = false // Request an update to the consent information. UMPConsentInformation.sharedInstance.requestConsentInfoUpdate( with: parameters, completionHandler: { error in if error != nil { // Handle the error. } else { // The consent information state was updated. // You are now ready to check if a form is // available. } }) }
Objective-C
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Create a UMPRequestParameters object. UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init]; // Set tag for under age of consent. Here NO means users are not under age. parameters.tagForUnderAgeOfConsent = NO; // Request an update to the consent information. [UMPConsentInformation.sharedInstance requestConsentInfoUpdateWithParameters:parameters completionHandler:^(NSError *_Nullable error) { if (error) { // Handle the error. } else { // The consent information state was updated. // You are now ready to check if a form is // available. } }]; }
Carica un modulo, se disponibile
Prima di visualizzare un modulo, devi determinare se è disponibile. I moduli non disponibili possono essere dovuti all'attivazione da parte dell'utente del monitoraggio degli annunci limitato o all'uso di tag sotto l'età del consenso.
Per verificare la disponibilità di un modulo, utilizzathe formStatus
property on the UMPConsentInformation
instance creato in precedenza.
Successivamente, aggiungi un metodo di wrapper per caricare il modulo:
Swift
// Request an update to the consent information. UMPConsentInformation.sharedInstance.requestConsentInfoUpdate( withParameters: parameters, completionHandler: { [self] error in // The consent information has updated. if error != nil { // Handle the error. } else { // The consent information state was updated. // You are now ready to see if a form is available. let formStatus = UMPConsentInformation.sharedInstance.formStatus if formStatus == UMPFormStatus.available { loadForm() } } }) ... func loadForm() { }
Objective-C
// Request an update to the consent information. [UMPConsentInformation.sharedInstance requestConsentInfoUpdateWithParameters:parameters completionHandler:^(NSError* _Nullable error) { // The consent information has updated. if (error) { // Handle the error. } else { // The consent information state was updated. // You are now ready to see if a form is available. UMPFormStatus formStatus = UMPConsentInformation.sharedInstance .formStatus; if (formStatus == UMPFormStatusAvailable) { [self loadForm]; } } }]; ... - (void) loadForm { }
Per caricare il modulo, utilizza the static loadWithCompletionHandler:
method on the UMPConsentForm
class.
Swift
func loadForm() { // Loads a consent form. Must be called on the main thread. UMPConsentForm.load( withCompletionHandler: { form, loadError in if loadError != nil { // Handle the error } else { // Present the form } }) }
Objective-C
- (void)loadForm { [UMPConsentForm loadWithCompletionHandler:^(UMPConsentForm *form, NSError *loadError) { if (loadError) { // Handle the error } else { // Present the form } }]; }
Presenta il modulo se necessario
Dopo aver determinato la disponibilità del modulo e averlo caricato, utilizza il metodopresentFromViewController:completionHandler:
sull'istanzaUMPConsentForm
per presentare il modulo.
Utilizza l'UMPConsentInformation
oggetto precedente per controllareconsent status e aggiornare il tuo metodoloadForm
:
Swift
func loadForm() { UMPConsentForm.load(withCompletionHandler: { form, loadError in if loadError != nil { // Handle the error. } else { // Present the form. You can also hold on to the reference to present // later. if UMPConsentInformation.sharedInstance.consentStatus == UMPConsentStatus.required { form?.present( from: self, completionHandler: { dismissError in if UMPConsentInformation.sharedInstance.consentStatus == UMPConsentStatus.obtained { // App can start requesting ads. } // Handle dismissal by reloading form. loadForm(); }) } else { // Keep the form available for changes to user consent. } } }) }
Objective-C
- (void)loadForm { [UMPConsentForm loadWithCompletionHandler:^(UMPConsentForm *form, NSError *loadError) { if (loadError) { // Handle the error. } else { // Present the form. You can also hold on to the reference to present // later. if (UMPConsentInformation.sharedInstance.consentStatus == UMPConsentStatusRequired) { [form presentFromViewController:self completionHandler:^(NSError *_Nullable dismissError) { if (UMPConsentInformation.sharedInstance.consentStatus == UMPConsentStatusObtained) { // App can start requesting ads. } // Handle dismissal by reloading form. [self loadForm]; }]; } else { // Keep the form available for changes to user consent. } } }]; }
Se devi eseguire azioni dopo che l'utente ha scelto o ignorato il modulo, inserisci questa logica nel gestore o nel callback di completamento del modulo.
Test
Forza un'area geografica
L'SDK UMP consente di testare il comportamento della tua app come se il dispositivo si trovasse nel SEE o nel Regno Unito utilizzando the debugGeography
property of type UMPDebugGeography
on UMPDebugSettings
.
Per poter usare la funzionalità di debug, devi fornire l'ID sottoposto ad hashing del tuo dispositivo di test nelle impostazioni di debug dell'app. Se chiami
requestConsentInfoUpdateWithParameters:completionHandler:
senza impostare questo valore, l'app registra l'hash dell'ID richiesto quando viene eseguito.
Swift
let parameters = UMPRequestParameters() let debugSettings = UMPDebugSettings() debugSettings.testDeviceIdentifiers = ["TEST-DEVICE-HASHED-ID"] debugSettings.geography = UMPDebugGeography.EEA parameters.debugSettings = debugSettings 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; [UMPConsentInformation.sharedInstance requestConsentInfoUpdateWithParameters:parameters completionHandler:^(NSError *_Nullable error){ ... }];
Con UMPDebugGeography
, puoi scegliere di forzare l'area geografica su una di queste opzioni:
Regioni di debug | Descrizione |
---|---|
UMPDebugGeographyDisabled |
Regione di debug disabilitata. |
UMPDebugGeographyEEA |
Per i dispositivi di debug, l'area geografica viene visualizzata come SEE. |
UMPDebugGeographyNotEEA |
Per i dispositivi di debug, l'area geografica risulta non appartenente allo Spazio economico europeo. |
Tieni presente che le impostazioni di debug funzionano solo su dispositivi di test. Non è necessario aggiungere gli emulatori all'elenco degli ID dispositivo in quanto sono già abilitati i test per impostazione predefinita.
Reimposta stato del consenso
Durante i test della tua app con l'SDK UMP, potrebbe essere utile reimpostare lo stato dell'SDK in modo da poter simulare la prima esperienza di installazione di un utente.
L'SDK fornisce il reset
metodo per farlo.
Swift
UMPConsentInformation.sharedInstance.reset()
Objective-C
[UMPConsentInformation.sharedInstance reset];
Dovresti anche chiamare reset
se decidi di rimuovere completamente l'SDK UMP dal progetto.