L'SDK Google User Messaging Platform (UMP) è uno strumento per la privacy e i messaggi che ti aiuta a gestire le scelte relative alla privacy. Per saperne di più, consulta Informazioni su Privacy e messaggi.
Crea un tipo di messaggio
Crea messaggi per gli utenti con uno dei tipi di messaggi per gli utenti disponibili nella scheda Privacy e messaggi del tuo account AdMob. L'SDK UMP tenta di visualizzare un messaggio sulla privacy creato a partire dall'ID applicazione AdMob impostato nel progetto.
Per maggiori dettagli, consulta Informazioni su privacy e messaggi.
Ottenere le informazioni sul consenso dell'utente
Devi richiedere un aggiornamento delle informazioni sul consenso dell'utente a ogni avvio dell'app, utilizzando Update()
. Questa richiesta controlla quanto segue:
- Se è necessario il consenso. Ad esempio, il consenso è richiesto per la prima volta o la decisione precedente relativa al consenso è scaduta.
- Se è richiesto un punto di accesso alle opzioni sulla privacy. Alcuni messaggi relativi alla privacy richiedono alle app di consentire agli utenti di modificare le proprie opzioni per la privacy in qualsiasi momento.
void Start()
{
// Create a ConsentRequestParameters object.
ConsentRequestParameters request = new ConsentRequestParameters();
// Check the current consent information status.
ConsentInformation.Update(request, OnConsentInfoUpdated);
}
void OnConsentInfoUpdated(FormError consentError)
{
// If the error is null, the consent information state was updated.
if (consentError != null)
{
// Handle the error.
UnityEngine.Debug.LogError(consentError);
return;
}
}
Carica e presenta il modulo del messaggio sulla privacy
Dopo aver ricevuto lo stato del consenso più aggiornato, chiama
LoadAndShowConsentFormIfRequired()
per caricare i moduli necessari per
raccogliere il consenso degli utenti. Dopo il caricamento, i moduli vengono visualizzati immediatamente.
void Start()
{
// Create a ConsentRequestParameters object.
ConsentRequestParameters request = new ConsentRequestParameters();
// Check the current consent information status.
ConsentInformation.Update(request, OnConsentInfoUpdated);
}
void OnConsentInfoUpdated(FormError consentError)
{
if (consentError != null)
{
// Handle the error.
UnityEngine.Debug.LogError(consentError);
return;
}
// If the error is null, the consent information state was updated.
// You are now ready to check if a form is available.
ConsentForm.LoadAndShowConsentFormIfRequired((FormError formError) =>
{
if (formError != null)
{
// Consent gathering failed.
UnityEngine.Debug.LogError(consentError);
return;
}
// Consent has been gathered.
});
}
Opzioni per la privacy
Alcuni moduli di messaggi relativi alla privacy vengono presentati da una sezione in cui specificare le opzioni di privacy visualizzata dall'editore, consentendo agli utenti di gestire le proprie opzioni di privacy in qualsiasi momento. Per scoprire di più su quale messaggio viene visualizzato dagli utenti nel punto di accesso alle opzioni della privacy, consulta Tipi di messaggi per gli utenti disponibili.
Per implementare un punto di accesso alle opzioni per la privacy:
- Dopo aver chiamato il numero
Update()
, controllaPrivacyOptionsRequirementStatus
per determinare se è necessario un punto di accesso alle opzioni della privacy. - Se necessario, aggiungi un elemento UI visibile e interattivo alla tua app che funga da punto di accesso alle opzioni della privacy. Se non è richiesto un punto di accesso alla privacy, configura l'elemento dell'interfaccia utente in modo che non sia visibile e interattivo.
- Presenta il modulo delle opzioni per la privacy utilizzando
ShowPrivacyOptionsForm()
.
Il seguente esempio di codice mostra questi passaggi:
[SerializeField, Tooltip("Button to show the privacy options form.")]
private Button _privacyButton;
private void Start()
{
// Enable the privacy settings button.
if (_privacyButton != null)
{
_privacyButton.onClick.AddListener(UpdatePrivacyButton);
// Disable the privacy settings button by default.
_privacyButton.interactable = false;
}
}
/// <summary>
/// Shows the privacy options form to the user.
/// </summary>
public void ShowPrivacyOptionsForm()
{
Debug.Log("Showing privacy options form.");
ConsentForm.ShowPrivacyOptionsForm((FormError showError) =>
{
if (showError != null)
{
Debug.LogError("Error showing privacy options form with error: " + showError.Message);
}
// Enable the privacy settings button.
UpdatePrivacyButton();
});
}
/// <summary>
/// Updates the privacy buttons visual state based on the consent information.
/// </summary>
void UpdatePrivacyButton()
{
if (_privacyButton != null)
{
_privacyButton.interactable =
ConsentInformation.PrivacyOptionsRequirementStatus ==
PrivacyOptionsRequirementStatus.Required;
}
}
Richiedere annunci con il consenso dell'utente
Prima di richiedere annunci, utilizza
CanRequestAds()
per verificare se hai
ottenuto il consenso dell'utente:
Di seguito sono elencati i luoghi in cui puoi verificare se puoi richiedere annunci durante la raccolta del consenso:
- Dopo che l'SDK UMP raccoglie il consenso nella sessione corrente.
- Subito dopo aver chiamato il numero
Update()
. L'SDK UMP potrebbe aver ottenuto il consenso nella sessione precedente dell'app.
Se si verifica un errore durante la procedura di raccolta del consenso, verifica se puoi richiedere annunci. L'SDK UMP utilizza lo stato del consenso della sessione precedente dell'app.
void Start()
{
// Create a ConsentRequestParameters object.
ConsentRequestParameters request = new ConsentRequestParameters();
// Check the current consent information status.
ConsentInformation.Update(request, OnConsentInfoUpdated);
}
void OnConsentInfoUpdated(FormError consentError)
{
if (consentError != null)
{
// Handle the error.
UnityEngine.Debug.LogError(consentError);
return;
}
// If the error is null, the consent information state was updated.
// You are now ready to check if a form is available.
ConsentForm.LoadAndShowConsentFormIfRequired((FormError formError) =>
{
if (formError != null)
{
// Consent gathering failed.
UnityEngine.Debug.LogError(consentError);
return;
}
// Consent has been gathered.
if (ConsentInformation.CanRequestAds())
{
MobileAds.Initialize((InitializationStatus initstatus) =>
{
// TODO: Request an ad.
});
}
});
}
Test
Se vuoi testare l'integrazione nella tua app durante lo sviluppo, segui questi passaggi per registrare a livello di programmazione il tuo dispositivo di test. Assicurati di rimuovere il codice che imposta questi ID dispositivo di test prima di rilasciare l'app.
- Chiama il numero
Update()
. Controlla l'output del log per un messaggio simile al seguente esempio, che mostra l'ID dispositivo e come aggiungerlo come dispositivo di test:
Android
Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.
iOS
<UMP SDK>To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[2077ef9a63d2b398840261c8221a0c9b]
Copia l'ID dispositivo di test negli appunti.
Modifica il codice per chiamare
DebugGeography.TestDeviceHashedIds
e trasmettere un elenco degli ID dei tuoi dispositivi di test.void Start() { var debugSettings = new ConsentDebugSettings { TestDeviceHashedIds = new List<string> { "TEST-DEVICE-HASHED-ID" } }; // Create a ConsentRequestParameters object. ConsentRequestParameters request = new ConsentRequestParameters { ConsentDebugSettings = debugSettings, }; // Check the current consent information status. ConsentInformation.Update(request, OnConsentInfoUpdated); }
Forzare un'area geografica
L'SDK UMP offre un modo per testare il comportamento della tua app come se il dispositivo si trovasse in varie regioni, ad esempio il SEE o il Regno Unito, utilizzando
DebugGeography
. Tieni presente che le impostazioni di debug funzionano solo sui dispositivi di test.
void Start()
{
var debugSettings = new ConsentDebugSettings
{
// Geography appears as in EEA for debug devices.
DebugGeography = DebugGeography.EEA,
TestDeviceHashedIds = new List<string>
{
"TEST-DEVICE-HASHED-ID"
}
};
// Create a ConsentRequestParameters object.
ConsentRequestParameters request = new ConsentRequestParameters
{
ConsentDebugSettings = debugSettings,
};
// Check the current consent information status.
ConsentInformation.Update(request, OnConsentInfoUpdated);
}
Reimposta lo stato del consenso
Quando testi la tua app con l'SDK UMP, potrebbe essere utile reimpostare lo stato dell'SDK per simulare l'esperienza di prima installazione di un utente.
L'SDK fornisce il metodo Reset()
per farlo.
ConsentInformation.Reset();
Esempi su GitHub
Consulta un esempio completo dell'integrazione dell'SDK UMP trattata in questa pagina in HelloWorld.