Inizia

L'SDK Google User Messaging Platform (UMP) è uno strumento per la privacy e la messaggistica per per aiutarti a gestire le scelte relative alla privacy. Per ulteriori informazioni, vedi Informazioni su privacy e di messaggistica.

Crea un tipo di messaggio

Crea messaggi per gli utenti con uno Tipi di messaggi per gli utenti disponibili nel menu a discesa Privacy e nella scheda Messaggistica di AdMob . L'SDK UMP tenta di visualizzare messaggio sulla privacy creato dall' AdMob ID applicazione nel progetto.

Per ulteriori dettagli, vedi Informazioni su privacy e messaggi.

Aggiungi l'ID applicazione

Puoi trovare il tuo ID applicazione nel UI di AdMob. Aggiungi l'ID al tuo con il seguente snippet di codice:

Devi richiedere un aggiornamento delle informazioni sul consenso dell'utente in ogni app avvia utilizzando Update(). Questa richiesta controlla le seguenti:

  • Se il consenso è obbligatorio. Ad esempio, il consenso è richiesto per la prima volta oppure la decisione di consenso precedente è scaduta.
  • Indica se è necessario un punto di ingresso per le opzioni di privacy. Alcuni messaggi sulla privacy richiedono alle app di consentire agli utenti di modificare le proprie opzioni di privacy in qualsiasi momento.

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 presenta un modulo di messaggio sulla privacy, se necessario

Dopo aver ricevuto lo stato del consenso più aggiornato, chiama LoadAndShowConsentFormIfRequired() per caricare i moduli richiesti 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.
    });
}

Se devi eseguire azioni dopo che l'utente ha effettuato una scelta o lo ha ignorato del modulo, inserisci questa logica nel Action<FormError> callback per il modulo.

Opzioni di privacy

Alcuni moduli di messaggi sulla privacy vengono presentati da un modello di , consentendo agli utenti di gestire le proprie opzioni di privacy in qualsiasi momento. Per scoprire di più sul messaggio che gli utenti vedono nelle opzioni della privacy del punto di accesso, consulta Tipi di messaggi per gli utenti disponibili:

Per implementare un punto di ingresso delle opzioni di privacy, completa i seguenti passaggi:

  1. Controlla PrivacyOptionsRequirementStatus.
  2. Se un punto di ingresso delle opzioni di privacy aggiungi un elemento UI visibile e interattivo alla tua app.
  3. Attiva il modulo per le opzioni sulla privacy utilizzando ShowPrivacyOptionsForm().

Il seguente esempio di codice illustra 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.
        if (_privacyButton != null)
        {
            _privacyButton.interactable =
                ConsentInformation.PrivacyOptionsRequirementStatus ==
                PrivacyOptionsRequirementStatus.Required;
        }
    });
}

Richiedi annunci

Prima di richiedere annunci nella tua app, verifica di aver ottenuto il consenso dall'utente utilizzando CanRequestAds(). Esistono due metodi luoghi da controllare durante la raccolta del consenso:

  • Dopo aver raccolto il consenso nella sessione corrente.
  • Subito dopo aver chiamato Update(). È possibile che il consenso sia stato ottenuto nella sessione precedente. Come latenza best practice, ti consigliamo di non attendere il completamento della richiamata per poter iniziare a caricare gli annunci il prima possibile dopo l'avvio dell'app.

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

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 il dispositivo di test in modo programmatico. Assicurati di rimuovere 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 passiamo un elenco degli 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 fosse che si trovano nel SEE 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 il lo stato desiderato dell'SDK per simulare l'esperienza di prima installazione di un utente. L'SDK fornisce il Reset() metodo per farlo.

ConsentInformation.Reset();

Esempi su GitHub