Inizia

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, ove richiesto dalla legge, nonché di utilizzare dati personali (ad esempio l'ID pubblicità) per la pubblicazione di 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 User Messaging Platform (UMP). L'SDK UMP è stato aggiornato per supportare i più recenti standard IAB. Ora tutte queste configurazioni possono essere gestite comodamente nella sezione AdMob Privacy e messaggi.

Prerequisiti

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 utente creato dall' AdMob ID applicazione impostato nel progetto. Se non viene configurato alcun messaggio per la tua applicazione, l'SDK restituisce un errore.

Per maggiori dettagli, consulta Informazioni su privacy e messaggi.

Devi richiedere un aggiornamento delle informazioni sul consenso dell'utente a ogni avvio dell'app utilizzando Update(). In questo modo viene stabilito se l'utente deve fornire il consenso, se non l'ha già fatto o se è scaduto.

Ecco un esempio di come controllare lo stato all'avvio 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.
}

Carica e mostra un modulo di consenso, se necessario

Dopo aver ricevuto lo stato del consenso più aggiornato, chiama LoadAndShowConsentFormIfRequired() il corso ConsentForm per caricare un modulo di consenso. Se lo stato del consenso è obbligatorio, l'SDK carica un modulo e lo presenta immediatamente fornito. Il campo Action<FormError> callback viene richiamato dopo che il modulo è stato ignorato. Se il consenso non è richiesto, il Action<FormError> callback viene richiamato 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.
    });
}

Se devi eseguire un'azione dopo che l'utente ha scelto o ignorato il modulo, inserisci tale logica nel Action<FormError> callback modulo.

Richiedi annunci

Prima di richiedere annunci nella tua app, verifica di aver ottenuto il consenso da parte dell'utente che utilizza CanRequestAds(). Ci sono due punti da controllare durante la raccolta del consenso:

  1. Una volta raccolto il consenso nella sessione corrente,
  2. Subito dopo aver chiamato Update(). È possibile che il consenso sia stato ottenuto nella sessione precedente. Come best practice sulla latenza, ti consigliamo di non attendere il completamento del callback per poter iniziare a caricare gli annunci il prima possibile dopo il lancio dell'app.

Se si verifica un errore durante la procedura di raccolta del consenso, dovresti comunque tentare di richiedere gli annunci. L'SDK UMP utilizza lo stato del consenso della sessione precedente.

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.
            });
        }
    });
    
}

Opzioni di privacy

Alcuni moduli di consenso richiedono all'utente di modificare il proprio consenso in qualsiasi momento. Segui i passaggi riportati di seguito per implementare un pulsante delle opzioni sulla privacy, se necessario.

A questo scopo:

  1. Implementare un elemento UI, ad esempio un pulsante nella pagina delle impostazioni dell'app, che può attivare un modulo per le opzioni sulla privacy.
  2. Una volta LoadAndShowConsentFormIfRequired() completato, controlla PrivacyOptionsRequirementStatus per stabilire se visualizzare l'elemento UI che può presentare il modulo delle opzioni di privacy.
  3. Quando un utente interagisce con l'elemento UI, chiama ShowPrivacyOptionsForm() per mostrare il modulo in modo che l'utente possa aggiornare le proprie opzioni di privacy in qualsiasi momento.

L'esempio seguente mostra come mostrare il modulo delle opzioni per la privacy da un Button.

[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.
        if (_privacyButton != null)
        {
            _privacyButton.interactable =
                ConsentInformation.PrivacyOptionsRequirementStatus ==
                PrivacyOptionsRequirementStatus.Required;
        }
    });
}

Test in corso

Se vuoi testare l'integrazione nella tua app durante lo sviluppo, segui questi passaggi per registrare il dispositivo di test in modo programmatico. Assicurati di rimuovere il codice che imposta questi ID dispositivo di test prima di rilasciare l'app.

  1. Chiama il numero Update().
  2. Controlla nell'output del log un messaggio simile all'esempio seguente, 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]
    
  3. Copia l'ID del dispositivo di test negli appunti.

  4. Modifica il codice per chiamare DebugGeography.TestDeviceHashedIds e passare un elenco dei tuoi ID dispositivo 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 consente di testare il comportamento della tua app come se il dispositivo si trovasse nello Spazio economico europeo o nel Regno Unito utilizzando the DebugGeography field on ConsentDebugSettings. 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);
}

Durante il test della tua app con l'SDK UMP, potrebbe essere utile reimpostare lo stato dell'SDK in modo da simulare l'esperienza della prima installazione di un utente. L'SDK fornisce il Reset() metodo per farlo.

ConsentInformation.Reset();