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, e per l'utilizzo dei dati personali (ad esempio AdID) per la pubblicazione degli annunci. Queste norme riflettono i requisiti della direttiva e-Privacy e del Regolamento generale sulla protezione dei dati (GDPR) dell'UE.
Per supportare i publisher nell'adempimento degli obblighi previsti da queste norme, Google offre l'SDK UMP (User Messaging Platform). L'SDK UMP è stato aggiornato per supportare gli ultimi standard IAB. Tutte queste configurazioni ora possono essere gestite facilmente in AdMob privacy e messaggi.
Prerequisiti
- Completa la Guida introduttiva.
- Configura i messaggi nella scheda Privacy e messaggi del tuo accountAdMob . Per maggiori dettagli, consulta Informazioni su privacy e messaggi,
- Se stai lavorando ai requisiti relativi al GDPR, leggi In che modo i requisiti IAB incidono sui messaggi per il consenso degli utenti dell'Unione europea.
Tipi di messaggi per gli utenti
Consulta l'articolo Tipi di messaggi per gli utenti per un elenco completo dei messaggi supportati. Per istruzioni specifiche sull'implementazione di ogni tipo di messaggio, consulta la barra di navigazione a sinistra.
Importa l'SDK
CocoaPods (preferito)
L'SDK UMP è incluso come dipendenza dal 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 iOS è utilizzare CocoaPods. Apri il pod del 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 esperienza con CocoaPods, consulta la sezione Utilizzo di CocoaPods per informazioni su come creare e utilizzare i file pod.
Download manuale
L'altro metodo consiste nell'importare l'SDK manualmente.
Trascina il framework nel tuo progetto Xcode, assicurandoti di selezionare Copia elementi se necessario.
Puoi quindi includere il framework in qualsiasi file necessario utilizzando:
Swift
import UserMessagingPlatform
Objective-C
#include <UserMessagingPlatform/UserMessagingPlatform.h>
Aggiorna il tuo file Info.plist
Trova il tuo ID app e aggiungilo aInfo.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.
Questo può determinare se l'utente deve o meno dare il consenso se non lo 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 al fatto che l'utente ha attivato il monitoraggio degli annunci con limitazioni o perché sono stati taggati come minorenni.
Per controllare la disponibilità di un modulo, utilizza
the formStatus
property on the UMPConsentInformation
instance hai creato prima.
Quindi, aggiungi un metodo del 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.
Usa l'UMPConsentInformation
oggetto di prima per controllareconsent status e aggiornare il 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 effettuato una scelta o ha ignorato il modulo, inserisci questa logica nel gestore di completamento o nel callback per il modulo.
Test
Forza un'area geografica
L'SDK UMP fornisce un modo per 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 utilizzare la funzionalità di debug, devi fornire l'ID hash del dispositivo di test nelle impostazioni di debug dell'app. Se chiami
requestConsentInfoUpdateWithParameters:completionHandler:
senza impostare questo valore, la tua 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
, hai la possibilità di
forzare l'area geografica a una di queste opzioni:
Regione di debug | Descrizione |
---|---|
UMPDebugGeographyDisabled |
Regione di debug disabilitata. |
UMPDebugGeographyEEA |
La posizione geografica viene visualizzata nel SEE per i dispositivi di debug. |
UMPDebugGeographyNotEEA |
Per i dispositivi di debug, la geografia è indicata come non nel SEE. |
Tieni presente che le impostazioni di debug funzionano solo su dispositivi di test. Non è necessario aggiungere gli emulatori all'elenco degli ID dispositivo perché i test sono già attivi per impostazione predefinita.
Reimposta stato del consenso
Durante il 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.
Swift
UMPConsentInformation.sharedInstance.reset()
Objective-C
[UMPConsentInformation.sharedInstance reset];
Devi anche chiamare reset
se decidi di rimuovere completamente
l'SDK UMP dal tuo progetto.