Başlama

Google AB Kullanıcı Rızası Politikası uyarınca, Avrupa Ekonomik Alanı (AEA) ve Birleşik Krallık'taki kullanıcılarınıza belirli açıklamalar yapmanız ve yasal olarak gerekli olduğu durumlarda çerez veya başka yerel depolama bilgilerinin kullanımının yanı sıra kişisel verilerin (AdID) reklam yayınlamak amacıyla kullanılması için kullanıcıların iznini almanız gerekir. Bu politika AB eGizlilik Yönergesi ve Genel Veri Koruma Yönetmeliği (GDPR) gereksinimlerini yansıtmaktadır.

Google, yayıncıları bu politika kapsamındaki şartları yerine getirmeleri konusunda desteklemek amacıyla Kullanıcı Mesajlaşma Platformu (UMP) SDK'sını sunmaktadır. UMP SDK'sı, en son IAB standartlarını destekleyecek şekilde güncellenmiştir. Artık bu yapılandırmaların hepsi, Interactive Media Ads gizlilik ve mesajlaşma bölümünden kullanılabilir.

UMP örnek uygulamasında UMP SDK ile çalışan bir IMA uygulaması görebilirsiniz.

Ön koşullar

  • Android API düzeyi 21 veya sonraki sürümler

Mesaj türü oluşturma

mevcut kullanıcı mesajı türlerinden birini kullanarak kullanıcı mesajları oluşturun Ad Manager hesabınızdaki Gizlilik ve mesajlaşma UMP SDK'sı, projenizde ayarlanan Interactive Media Ads Uygulama Kimliği'nden oluşturulan bir kullanıcı mesajını göstermeye çalışır. Uygulamanız için herhangi bir mesaj yapılandırılmamışsa SDK hata döndürür.

Daha fazla bilgi için Gizlilik ve mesajlaşma hakkında

Gradle ile yükle

Google Kullanıcı Mesajlaşma Platformu SDK'sı bağımlılığını, modülünüzün uygulama düzeyindeki Gradle dosyasına (normalde app/build.gradle) ekleyin:

dependencies {
  implementation("com.google.android.ump:user-messaging-platform:2.2.0")
}

Uygulamanızın build.gradle öğesinde değişiklikleri yaptıktan sonra, projenizi Gradle dosyalarıyla senkronize ettiğinizden emin olun.

requestConsentInfoUpdate()kullanarak her uygulama lansmanında kullanıcının rıza bilgilerinin güncellenmesini istemelisiniz. Bu sayede, kullanıcınız henüz yapmadıysa veya izninin süresi dolduysa izin vermesi gerekip gerekmediğini belirleyebilirsiniz.

onCreate() yönteminde MainActivity öğesinin durumunu nasıl kontrol edeceğinize dair bir örneği aşağıda bulabilirsiniz.

Java

package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.google.android.ump.ConsentInformation;
import com.google.android.ump.ConsentRequestParameters;
import com.google.android.ump.FormError;
import com.google.android.ump.UserMessagingPlatform;

public class MainActivity extends AppCompatActivity {
  private ConsentInformation consentInformation;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Create a ConsentRequestParameters object.
    ConsentRequestParameters params = new ConsentRequestParameters
        .Builder()
        .build();

    consentInformation = UserMessagingPlatform.getConsentInformation(this);
    consentInformation.requestConsentInfoUpdate(
        this,
        params,
        (OnConsentInfoUpdateSuccessListener) () -> {
          // TODO: Load and show the consent form.
        },
        (OnConsentInfoUpdateFailureListener) requestConsentError -> {
          // Consent gathering failed.
          Log.w(TAG, String.format("%s: %s",
              requestConsentError.getErrorCode(),
              requestConsentError.getMessage()));
        });
  }
}

Kotlin

package com.example.myapplication

import com.google.android.ump.ConsentInformation
import com.google.android.ump.ConsentInformation.OnConsentInfoUpdateFailureListener
import com.google.android.ump.ConsentInformation.OnConsentInfoUpdateSuccessListener
import com.google.android.ump.ConsentRequestParameters
import com.google.android.ump.UserMessagingPlatform

class MainActivity : AppCompatActivity() {
  private lateinit var consentInformation: ConsentInformation

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    // Create a ConsentRequestParameters object.
    val params = ConsentRequestParameters
        .Builder()
        .build()

    consentInformation = UserMessagingPlatform.getConsentInformation(this)
    consentInformation.requestConsentInfoUpdate(
        this,
        params,
        ConsentInformation.OnConsentInfoUpdateSuccessListener {
          // TODO: Load and show the consent form.
        },
        ConsentInformation.OnConsentInfoUpdateFailureListener {
          requestConsentError ->
          // Consent gathering failed.
          Log.w(TAG, "${requestConsentError.errorCode}: ${requestConsentError.message}")
        })
  }
}

Gerekirse bir izin formu yükleyip gösterin

En güncel izin durumunu aldıktan sonra izin formu yüklemek için sınıfaloadAndShowConsentFormIfRequired() ConsentForm ulaşın. İzin durumu gerekliyse SDK bir form yükler ve sağlanan activitybölümünden hemen gösterir. Form kapatıldıktan sonra callback çağrılır . Rıza gerekmiyorsa callback ve hemen çağrılır.

Java

public class MainActivity extends AppCompatActivity {
  private ConsentInformation consentInformation;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Create a ConsentRequestParameters object.
    ConsentRequestParameters params = new ConsentRequestParameters
        .Builder()
        .build();

    consentInformation = UserMessagingPlatform.getConsentInformation(this);
    consentInformation.requestConsentInfoUpdate(
        this,
        params,
        (OnConsentInfoUpdateSuccessListener) () -> {
          UserMessagingPlatform.loadAndShowConsentFormIfRequired(
            this,
            (OnConsentFormDismissedListener) loadAndShowError -> {
              if (loadAndShowError != null) {
                // Consent gathering failed.
                Log.w(TAG, String.format("%s: %s",
                    loadAndShowError.getErrorCode(),
                    loadAndShowError.getMessage()));
              }

              // Consent has been gathered.
            }
          );
        },
        (OnConsentInfoUpdateFailureListener) requestConsentError -> {
          // Consent gathering failed.
          Log.w(TAG, String.format("%s: %s",
              requestConsentError.getErrorCode(),
              requestConsentError.getMessage()));
        });
  }
}

Kotlin

class MainActivity : AppCompatActivity() {
  private lateinit var consentInformation: ConsentInformation

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    // Create a ConsentRequestParameters object.
    val params = ConsentRequestParameters
        .Builder()
        .build()

    consentInformation = UserMessagingPlatform.getConsentInformation(this)
    consentInformation.requestConsentInfoUpdate(
        this,
        params,
        ConsentInformation.OnConsentInfoUpdateSuccessListener {
          UserMessagingPlatform.loadAndShowConsentFormIfRequired(
            this@MainActivity,
            ConsentForm.OnConsentFormDismissedListener {
              loadAndShowError ->
              if (loadAndShowError != null) {
                // Consent gathering failed.
                Log.w(TAG, "${loadAndShowError.errorCode}: ${loadAndShowError.message}")
              }

              // Consent has been gathered.
            }
          )
        },
        ConsentInformation.OnConsentInfoUpdateFailureListener {
          requestConsentError ->
          // Consent gathering failed.
          Log.w(TAG, "${requestConsentError.errorCode}: ${requestConsentError.message}")
        })
  }
}

Kullanıcı seçim yaptıktan veya formu kapattıktan sonra herhangi bir işlem yapmanız gerekirse bu mantığı formunuzun callbackbölümüne yerleştirin.

Reklam isteğinde bulun

Uygulamanızda reklam isteğinde bulunmadan önce, canRequestAds()uygulamasını kullanan kullanıcıdan izin alıp almadığınızı kontrol edin. İzin alınırken kontrol edilecek iki yer vardır:

  1. Mevcut oturumda izin alındıktan sonra.
  2. requestConsentInfoUpdate()adlı kişiyi aramanızın hemen ardından. Önceki oturumda izin alınmış olabilir. Gecikmeyle ilgili en iyi uygulamalardan biri olarak, geri çağırma işleminin tamamlanmasını beklememenizi öneririz. Böylece, uygulamanız kullanıma sunulduktan hemen sonra reklamları yüklemeye başlayabilirsiniz.

İzin toplama sürecinde bir hata oluşursa yine de reklam isteğinde bulunmanız gerekir. UMP SDK'sı önceki oturumdaki izin durumunu kullanır.

Java

public class MainActivity extends AppCompatActivity {
  private ConsentInformation consentInformation;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Create a ConsentRequestParameters object.
    ConsentRequestParameters params = new ConsentRequestParameters
        .Builder()
        .build();

    consentInformation = UserMessagingPlatform.getConsentInformation(this);
    consentInformation.requestConsentInfoUpdate(
        this,
        params,
        (OnConsentInfoUpdateSuccessListener) () -> {
          UserMessagingPlatform.loadAndShowConsentFormIfRequired(
            this,
            (OnConsentFormDismissedListener) loadAndShowError -> {
              if (loadAndShowError != null) {
                // Consent gathering failed.
                Log.w(TAG, String.format("%s: %s",
                    loadAndShowError.getErrorCode(),
                    loadAndShowError.getMessage()));
              }

              // Consent has been gathered.
              if (consentInformation.canRequestAds()) {
                initializeImaSdk();
              }
            }
          );
        },
        (OnConsentInfoUpdateFailureListener) requestConsentError -> {
          // Consent gathering failed.
          Log.w(TAG, String.format("%s: %s",
              requestConsentError.getErrorCode(),
              requestConsentError.getMessage()));
        });
    
    // Check if you can initialize the IMA SDK in parallel
    // while checking for new consent information. Consent obtained in
    // the previous session can be used to request ads.
    if (consentInformation.canRequestAds()) {
      initializeImaSdk();
    }
  }
  
  private void initializeImaSdk() {
    sdkFactory = ImaSdkFactory.getInstance();

    // TODO: Initialize IMA by creating an AdDisplayContainer, an AdsLoader,
    // and making an ad request.
  }
}

Kotlin

class MainActivity : AppCompatActivity() {
  private lateinit var consentInformation: ConsentInformation
  
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    // Create a ConsentRequestParameters object.
    val params = ConsentRequestParameters
        .Builder()
        .build()

    consentInformation = UserMessagingPlatform.getConsentInformation(this)
    consentInformation.requestConsentInfoUpdate(
        this,
        params,
        ConsentInformation.OnConsentInfoUpdateSuccessListener {
          UserMessagingPlatform.loadAndShowConsentFormIfRequired(
            this@MainActivity,
            ConsentForm.OnConsentFormDismissedListener {
              loadAndShowError ->
              if (loadAndShowError != null) {
                // Consent gathering failed.
                Log.w(TAG, "${loadAndShowError.errorCode}: ${loadAndShowError.message}")
              }

              // Consent has been gathered.
              if (consentInformation.canRequestAds()) {
                initializeImaSdk()
              }
            }
          )
        },
        ConsentInformation.OnConsentInfoUpdateFailureListener {
          requestConsentError ->
          // Consent gathering failed.
          Log.w(TAG, "${requestConsentError.errorCode}: ${requestConsentError.message}")
        })
    
    // Check if you can initialize the IMA SDK in parallel
    // while checking for new consent information. Consent obtained in
    // the previous session can be used to request ads.
    if (consentInformation.canRequestAds()) {
      initializeImaSdk()
    }
  }
  
  private void initializeImaSdk() {
    sdkFactory = ImaSdkFactory.getInstance()

    // TODO: Initialize IMA by creating an AdDisplayContainer, an AdsLoader,
    // and making an ad request.
  }
}

Gizlilik seçenekleri

Bazı izin formlarında, kullanıcının istediği zaman iznini değiştirmesi gerekir. Gerekirse gizlilik seçenekleri düğmesi uygulamak için aşağıdaki adımları uygulayın.

Bunu yapabilmek için:

  1. Uygulamanızın ayarlar sayfasındaki bir düğme gibi, gizlilik seçenekleri formunu tetikleyebilecek bir kullanıcı arayüzü öğesi uygulayın.
  2. loadAndShowConsentFormIfRequired() Tamamladıktan sonra, gizlilik seçenekleri formunu gösterebilecek kullanıcı arayüzü öğesinin gösterilip gösterilmeyeceğini belirlemek içinprivacyOptionsRequirementStatus() kontrol edin.
  3. Bir kullanıcı, kullanıcı arayüzü öğenizle etkileşime geçtiğinde formun gösterilmesi içinshowPrivacyOptionsForm() çağrısı yapın. Böylece kullanıcının gizlilik seçeneklerini istediği zaman güncelleyebilir.

Aşağıdaki örnekte, bir MenuItem öğesindeki gizlilik seçenekleri formunun nasıl sunulacağı gösterilmektedir.

Java

private final ConsentInformation consentInformation;

// Show a privacy options button if required.
public boolean isPrivacyOptionsRequired() {
  return consentInformation.getPrivacyOptionsRequirementStatus()
      == PrivacyOptionsRequirementStatus.REQUIRED;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
  // ...

  consentInformation = UserMessagingPlatform.getConsentInformation(this);
  consentInformation.requestConsentInfoUpdate(
      this,
      params,
      (OnConsentInfoUpdateSuccessListener) () -> {
        UserMessagingPlatform.loadAndShowConsentFormIfRequired(
          this,
          (OnConsentFormDismissedListener) loadAndShowError -> {
            // ...

            // Consent has been gathered.

            if (isPrivacyOptionsRequired()) {
              // Regenerate the options menu to include a privacy setting.
              invalidateOptionsMenu();
            }
          }
        )
      }
      // ...
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.action_menu, menu);
  MenuItem moreMenu = menu.findItem(R.id.action_more);
  moreMenu.setVisible(isPrivacyOptionsRequired());
  return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
  // ...

  popup.setOnMenuItemClickListener(
      popupMenuItem -> {
        if (popupMenuItem.getItemId() == R.id.privacy_settings) {
          // Present the privacy options form when a user interacts with
          // the privacy settings button.
          UserMessagingPlatform.showPrivacyOptionsForm(
              this,
              formError -> {
                if (formError != null) {
                  // Handle the error.
                }
              }
          );
          return true;
        }
        return false;
      });
  return super.onOptionsItemSelected(item);
}

Kotlin

private val consentInformation: ConsentInformation =
  UserMessagingPlatform.getConsentInformation(context)

// Show a privacy options button if required.
val isPrivacyOptionsRequired: Boolean
  get() =
    consentInformation.privacyOptionsRequirementStatus ==
      ConsentInformation.PrivacyOptionsRequirementStatus.REQUIRED

override fun onCreate(savedInstanceState: Bundle?) {
  ...
  consentInformation = UserMessagingPlatform.getConsentInformation(this)
  consentInformation.requestConsentInfoUpdate(
      this,
      params,
      ConsentInformation.OnConsentInfoUpdateSuccessListener {
        UserMessagingPlatform.loadAndShowConsentFormIfRequired(
          this@MainActivity,
          ConsentForm.OnConsentFormDismissedListener {
            // ...

            // Consent has been gathered.

            if (isPrivacyOptionsRequired) {
              // Regenerate the options menu to include a privacy setting.
              invalidateOptionsMenu();
            }
          }
        )
      }
      // ...
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
  menuInflater.inflate(R.menu.action_menu, menu)
  menu?.findItem(R.id.action_more)?.apply {
    isVisible = isPrivacyOptionsRequired
  }
  return super.onCreateOptionsMenu(menu)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
  // ...

  popup.setOnMenuItemClickListener { popupMenuItem ->
    when (popupMenuItem.itemId) {
      R.id.privacy_settings -> {
        // Present the privacy options form when a user interacts with
        // the privacy settings button.
        UserMessagingPlatform.showPrivacyOptionsForm(this) { formError ->
          formError?.let {
            // Handle the error.
          }
        }
        true
      }
      else -> false
    }
  }
  return super.onOptionsItemSelected(item)
}

Test

Geliştirme sürecinde uygulamanızdaki entegrasyonu test etmek istiyorsanız test cihazınızı programatik olarak kaydetmek için bu adımları uygulayın. Uygulamanızı yayınlamadan önce bu test cihazı kimliklerini oluşturan kodu kaldırdığınızdan emin olun.

  1. requestConsentInfoUpdate()numaralı telefonu arayın.
  2. Günlük çıkışında, cihaz kimliğinizi ve test cihazı olarak nasıl ekleyeceğinizi gösteren aşağıdaki örneğe benzer bir mesaj olup olmadığını kontrol edin:

    Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.
    
  3. Test cihazınızın kimliğini panoya kopyalayın.

  4. Kodu, test cihazı kimliklerinizin listesini telefonlaConsentDebugSettings.Builder().addTestDeviceHashedId() gönderecek şekilde değiştirin.

Bir coğrafi bölgeyi zorunlu kılın

UMP SDK'sı, the setDebugGeography() method which takes a DebugGeography on ConsentDebugSettings.Builderkullanarak cihaz AEA veya Birleşik Krallık'ta bulunuyormuş gibi uygulamanızın davranışını test etmenin bir yolunu sağlar. Hata ayıklama ayarlarının yalnızca test cihazlarında çalıştığını unutmayın.

Java

ConsentDebugSettings debugSettings = new ConsentDebugSettings.Builder(this)
    .setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA)
    .addTestDeviceHashedId("TEST-DEVICE-HASHED-ID")
    .build();

ConsentRequestParameters params = new ConsentRequestParameters
    .Builder()
    .setConsentDebugSettings(debugSettings)
    .build();

consentInformation = UserMessagingPlatform.getConsentInformation(this);
// Include the ConsentRequestParameters in your consent request.
consentInformation.requestConsentInfoUpdate(
    this,
    params,
    ...
);

Kotlin

val debugSettings = ConsentDebugSettings.Builder(this)
    .setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA)
    .addTestDeviceHashedId("TEST-DEVICE-HASHED-ID")
    .build()

val params = ConsentRequestParameters
    .Builder()
    .setConsentDebugSettings(debugSettings)
    .build()

consentInformation = UserMessagingPlatform.getConsentInformation(this)
// Include the ConsentRequestParameters in your consent request.
consentInformation.requestConsentInfoUpdate(
    this,
    params,
    ...
)

Uygulamanızı UMP SDK ile test ederken kullanıcıların ilk yükleme deneyimini simüle edebilmek için SDK'nın durumunu sıfırlamanız faydalı olabilir. SDK, bunu yapmak için reset() yöntemini sağlar.

Java

consentInformation.reset();

Kotlin

consentInformation.reset()