Başlama

Google Kullanıcı Mesajlaşma Platformu (UMP) SDK'sı, gizlilik tercihlerini yönetmenize yardımcı olan bir gizlilik ve mesajlaşma aracıdır. Daha fazla bilgi için Gizlilik ve Mesajlaşma hakkında başlıklı makaleyi inceleyin.

Ön koşullar

  • Android API düzeyi 21 veya daha yüksek (Android için)

Mesaj türü oluşturma

AdMob hesabınızın Gizlilik ve Mesajlaşma sekmesindeki Kullanılabilen kullanıcı mesajı türleri bölümünde yer alan türlerden birini kullanarak kullanıcı mesajları oluşturun. UMP SDK, projenizde ayarlanan AdMob uygulama kimliğinden oluşturulan bir gizlilik mesajı göstermeye çalışır.

Daha fazla bilgi için Gizlilik ve mesajlaşma hakkında başlıklı makaleyi inceleyin.

SDK'yı yükleme

  1. Firebase C++ SDK'sını yükleme adımlarını uygulayın. UMP C++ SDK'sı, Firebase C++ SDK'sına dahildir.

  2. Devam etmeden önce projede uygulamanızın AdMob uygulama kimliğini yapılandırdığınızdan emin olun.

  3. Kodunuzda ConsentInfo::GetInstance() işlevini çağırarak UMP SDK'sını başlatın.

    • Android'de, NDK tarafından sağlanan JNIEnv ve Activity değerlerini iletmeniz gerekir. Bunu yalnızca GetInstance()'ı ilk aradığınızda yapmanız gerekir.
    • Alternatif olarak, uygulamanızda Firebase C++ SDK'sını kullanıyorsanız GetInstance() işlevini ilk kez çağırdığınızda firebase::App değerini iletebilirsiniz.
    #include "firebase/ump/ump.h"
    
    namespace ump = ::firebase::ump;
    
    // Initialize using a firebase::App
    void InitializeUserMessagingPlatform(const firebase::App& app) {
      ump::ConsentInfo* consent_info = ump::ConsentInfo::GetInstance(app);
    }
    
    // Initialize without a firebase::App
    #ifdef ANDROID
    void InitializeUserMessagingPlatform(JNIEnv* jni_env, jobject activity) {
      ump::ConsentInfo* consent_info = ump::ConsentInfo::GetInstance(jni_env, activity);
    }
    #else  // non-Android
    void InitializeUserMessagingPlatform() {
      ump::ConsentInfo* consent_info = ump::ConsentInfo::GetInstance();
    }
    #endif
    

ConsentInfo::GetInstance() için sonraki tüm çağrılar aynı örneği döndürür.

UMP SDK'yı kullanmayı bitirdiyseniz ConsentInfo örneğini silerek SDK'yı kapatabilirsiniz:

void ShutdownUserMessagingPlatform() {
  ump::ConsentInfo* consent_info = ump::ConsentInfo::GetInstance();
  delete consent_info;
}

Eşzamansız işlemleri izlemek için Future kullanma

A firebase::Future eşzamansız yöntem çağrılarının tamamlanma durumunu belirlemenize olanak tanır.

Eşzamansız olarak çalışan tüm UMP C++ işlevleri ve yöntem çağrıları bir Future döndürür ve en son işlemden Future'yı almak için bir "sonuç" işlevi sağlar.

Future öğesinden sonuç almanın iki yolu vardır:

  1. İşlem tamamlandığında çağrılan kendi geri çağırma işlevinizi ileterek OnCompletion() işlevini çağırın.
  2. Future'nın status() bölümünü düzenli olarak kontrol edin. kFutureStatusPending olan durum kFutureStatusCompleted olarak değiştiğinde işlem tamamlanmış demektir.

Asenkron işlem tamamlandıktan sonra, işlemin hata kodunu almak için Future'nın error() değerini kontrol etmeniz gerekir. Hata kodu 0 (kConsentRequestSuccess veya kConsentFormSuccess) ise işlem başarıyla tamamlanmıştır. Aksi takdirde, neyin yanlış gittiğini belirlemek için hata kodunu ve error_message()'yi kontrol edin.

Tamamlama geri araması

Burada, OnCompletion kullanarak tamamlanma geri çağırması ayarlama örneği verilmiştir. Bu geri çağırma, eşzamansız işlem tamamlandığında çağrılır.

void MyApplicationStart() {
  // [... other app initialization code ...]

  ump::ConsentInfo *consent_info = ump::ConsentInfo::GetInstance();

  // See the section below for more information about RequestConsentInfoUpdate.
  firebase::Future<void> result = consent_info->RequestConsentInfoUpdate(...);

  result.OnCompletion([](const firebase::Future<void>& req_result) {
    if (req_result.error() == ump::kConsentRequestSuccess) {
      // Operation succeeded. You can now call LoadAndShowConsentFormIfRequired().
    } else {
      // Operation failed. Check req_result.error_message() for more information.
    }
  });
}

Döngü yoklamasını güncelleme

Bu örnekte, uygulama başlatılırken eşzamansız bir işlem başlatıldıktan sonra sonuçlar başka bir yerde, oyunun güncelleme döngüsü işlevinde (kare başına bir kez çalışır) kontrol edilir.

ump::ConsentInfo *g_consent_info = nullptr;
bool g_waiting_for_request = false;

void MyApplicationStart() {
  // [... other app initialization code ...]

  g_consent_info = ump::ConsentInfo::GetInstance();
  // See the section below for more information about RequestConsentInfoUpdate.
  g_consent_info->RequestConsentInfoUpdate(...);
  g_waiting_for_request = true;
}

// Elsewhere, in the game's update loop, which runs once per frame:
void MyGameUpdateLoop() {
  // [... other game logic here ...]

  if (g_waiting_for_request) {
    // Check whether RequestConsentInfoUpdate() has finished.
    // Calling "LastResult" returns the Future for the most recent operation.
    firebase::Future<void> result =
      g_consent_info->RequestConsentInfoUpdateLastResult();

    if (result.status() == firebase::kFutureStatusComplete) {
      g_waiting_for_request = false;
      if (result.error() == ump::kConsentRequestSuccess) {
        // Operation succeeded. You can call LoadAndShowConsentFormIfRequired().
      } else {
        // Operation failed. Check result.error_message() for more information.
      }
    }
  }
}

firebase::Future hakkında daha fazla bilgi için Firebase C++ SDK dokümanları ve GMA C++ SDK dokümanları'na bakın.

RequestConsentInfoUpdate() kullanarak her uygulama başlatıldığında kullanıcının izin bilgilerinin güncellenmesini istemelisiniz. Bu istekte aşağıdakiler kontrol edilir:

  • İzin gerekip gerekmediği. Örneğin, ilk kez izin isteniyordur veya önceki izin kararı geçerliliğini yitirmiştir.
  • Gizlilik seçenekleri giriş noktasının gerekli olup olmadığı. Bazı gizlilik mesajları, uygulamaların kullanıcıların gizlilik seçeneklerini istedikleri zaman değiştirmelerine izin vermesini gerektirir.
#include "firebase/ump/ump.h"

namespace ump = ::firebase::ump;

void MyApplicationStart(ump::FormParent parent) {
  ump::ConsentInfo* consent_info = ump::ConsentInfo::GetInstance();

  // Create a ConsentRequestParameters struct..
  ump::ConsentRequestParameters params;
  // Set tag for under age of consent. False means users are NOT under age of consent.
  params.tag_for_under_age_of_consent = false;

  consent_info->RequestConsentInfoUpdate(params).OnCompletion(
    [*](const Future<void>& req_result) {
      if (req_result.error() != ump::kConsentRequestSuccess) {
        // req_result.error() is a kConsentRequestError enum.
        LogMessage("Error requesting consent update: %s", req_result.error_message());
      }
      // Consent information is successfully updated.
    });
}
TCF 3.3 hatasına yol açabilir.

Gizlilik mesajı formunu yükleyip sunma

En güncel izin durumunu aldıktan sonra kullanıcı izni almak için gereken formları yüklemek üzere LoadAndShowConsentFormIfRequired() işlevini çağırın. Yüklendikten sonra formlar hemen gösterilir.

#include "firebase/ump/ump.h"

namespace ump = ::firebase::ump;

void MyApplicationStart(ump::FormParent parent) {
  ump::ConsentInfo* consent_info = ump::ConsentInfo::GetInstance();

  // Create a ConsentRequestParameters struct..
  ump::ConsentRequestParameters params;
  // Set tag for under age of consent. False means users are NOT under age of consent.
  params.tag_for_under_age_of_consent = false;

  consent_info->RequestConsentInfoUpdate(params).OnCompletion(
    [*](const Future<void>& req_result) {
      if (req_result.error() != ump::kConsentRequestSuccess) {
        // req_result.error() is a kConsentRequestError enum.
        LogMessage("Error requesting consent update: %s", req_result.error_message());
      } else {
        consent_info->LoadAndShowConsentFormIfRequired(parent).OnCompletion(
        [*](const Future<void>& form_result) {
          if (form_result.error() != ump::kConsentFormSuccess) {
            // form_result.error() is a kConsentFormError enum.
            LogMessage("Error showing privacy message form: %s", form_result.error_message());
          } else {
            // Either the form was shown and completed by the user, or consent was not required.
          }
        });
      }
    });
}

Tamamlama geri çağırması yerine güncelleme döngüsü yoklaması kullanarak tamamlanma kontrolü yapma örneği için yukarıya bakın.

Kullanıcı bir seçim yaptıktan veya formu kapattıktan sonra herhangi bir işlem yapmanız gerekiyorsa bu mantığı, Future tarafından döndürülen LoadAndShowConsentFormIfRequired() değerini işleyen koda yerleştirin.

Gizlilik seçenekleri

Bazı gizlilik mesajı formları, yayıncı tarafından oluşturulan bir gizlilik seçenekleri giriş noktasından sunulur. Bu sayede kullanıcılar, gizlilik seçeneklerini istedikleri zaman yönetebilir. Kullanıcılarınızın gizlilik seçenekleri giriş noktasında hangi mesajı gördüğü hakkında daha fazla bilgi edinmek için Mevcut kullanıcı mesajı türleri başlıklı makaleyi inceleyin.

Kullanıcı izniyle reklam isteğinde bulunma

Reklam isteğinde bulunmadan önce, kullanıcıdan izin alıp almadığınızı kontrol etmek için ConsentInfo::GetInstance()‑> CanRequestAds() kullanın:

İzin toplarken reklam isteğinde bulunup bulunamayacağınızı kontrol etmek için aşağıdaki yerlere bakabilirsiniz:

  • UMP SDK'sı, mevcut oturumda izin topladıktan sonra.
  • RequestConsentInfoUpdate()'ı aradıktan hemen sonra UMP SDK, önceki uygulama oturumunda izin almış olabilir.

İzin toplama işlemi sırasında bir hata oluşursa reklam isteğinde bulunup bulunamayacağınızı kontrol edin. UMP SDK, önceki uygulama oturumundaki izin durumunu kullanır.

Aşağıdaki eksiksiz örnekte güncelleme döngüsü yoklaması kullanılmaktadır ancak asenkron işlemleri izlemek için geri çağırma işlevlerini de kullanabilirsiniz OnCompletion. Kod yapınıza daha uygun olan tekniği kullanın.

#include "firebase/future.h"
#include "firebase/gma/gma.h"
#include "firebase/ump/ump.h"

namespace gma = ::firebase::gma;
namespace ump = ::firebase::ump;
using firebase::Future;

ump::ConsentInfo* g_consent_info = nullptr;
// State variable for tracking the UMP consent flow.
enum { kStart, kRequest, kLoadAndShow, kInitGma, kFinished, kErrorState } g_state = kStart;
bool g_ads_allowed = false;

void MyApplicationStart() {
  g_consent_info = ump::ConsentInfo::GetInstance(...);

  // Create a ConsentRequestParameters struct..
  ump::ConsentRequestParameters params;
  // Set tag for under age of consent. False means users are NOT under age of consent.
  params.tag_for_under_age_of_consent = false;

  g_consent_info->RequestConsentInfoUpdate(params);
  // CanRequestAds() can return a cached value from a previous run immediately.
  g_ads_allowed = g_consent_info->CanRequestAds();
  g_state = kRequest;
}

// This function runs once per frame.
void MyGameUpdateLoop() {
  // [... other game logic here ...]

  if (g_state == kRequest) {
    Future<void> req_result = g_consent_info->RequestConsentInfoUpdateLastResult();

    if (req_result.status() == firebase::kFutureStatusComplete) {
      g_ads_allowed = g_consent_info->CanRequestAds();
      if (req_result.error() == ump::kConsentRequestSuccess) {
        // You must provide the FormParent (Android Activity or iOS UIViewController).
        ump::FormParent parent = GetMyFormParent();
        g_consent_info->LoadAndShowConsentFormIfRequired(parent);
        g_state = kLoadAndShow;
      } else {
        LogMessage("Error requesting consent status: %s", req_result.error_message());
        g_state = kErrorState;
      }
    }
  }
  if (g_state == kLoadAndShow) {
    Future<void> form_result = g_consent_info->LoadAndShowConsentFormIfRequiredLastResult();

    if (form_result.status() == firebase::kFutureStatusComplete) {
      g_ads_allowed = g_consent_info->CanRequestAds();
      if (form_result.error() == ump::kConsentRequestSuccess) {
        if (g_ads_allowed) {
          // Initialize GMA. This is another asynchronous operation.
          firebase::gma::Initialize();
          g_state = kInitGma;
        } else {
          g_state = kFinished;
        }
        // Optional: shut down the UMP SDK to save memory.
        delete g_consent_info;
        g_consent_info = nullptr;
      } else {
        LogMessage("Error displaying privacy message form: %s", form_result.error_message());
        g_state = kErrorState;
      }
    }
  }
  if (g_state == kInitGma && g_ads_allowed) {
    Future<gma::AdapterInitializationStatus> gma_future = gma::InitializeLastResult();

    if (gma_future.status() == firebase::kFutureStatusComplete) {
      if (gma_future.error() == gma::kAdErrorCodeNone) {
        g_state = kFinished;
        // TODO: Request an ad.
      } else {
        LogMessage("Error initializing GMA: %s", gma_future.error_message());
        g_state = kErrorState;
      }
    }
  }
}

Test

Geliştirme sürecinde entegrasyonu uygulamanızda 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 ayarlayan kodu kaldırdığınızdan emin olun.

  1. RequestConsentInfoUpdate() Hizmetleri İçin Arayın.
  2. Günlük çıktısında, cihaz kimliğinizi ve bunu nasıl test cihazı olarak ekleyeceğinizi gösteren aşağıdaki örneğe benzer bir mesaj olup olmadığını kontrol edin:

    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. Test cihazı kimliğinizi panoya kopyalayın.

  4. Kodunuzu, test cihazı kimliklerinizin listesini ConsentRequestParameters.debug_settings.debug_device_ids olarak ayarlayacak şekilde değiştirin.

    void MyApplicationStart() {
      ump::ConsentInfo consent_info = ump::ConsentInfo::GetInstance(...);
    
      ump::ConsentRequestParameters params;
      params.tag_for_under_age_of_consent = false;
      params.debug_settings.debug_device_ids = {"TEST-DEVICE-HASHED-ID"};
    
      consent_info->RequestConsentInfoUpdate(params);
    }
    

Coğrafya zorlama

UMP SDK, debug_settings.debug_geography kullanarak cihazın AEA veya Birleşik Krallık gibi çeşitli bölgelerdeymiş gibi uygulamanızın davranışını test etmenizi sağlar. Hata ayıklama ayarlarının yalnızca test cihazlarında çalıştığını unutmayın.

void MyApplicationStart() {
  ump::ConsentInfo consent_info = ump::ConsentInfo::GetInstance(...);

  ump::ConsentRequestParameters params;
  params.tag_for_under_age_of_consent = false;
  params.debug_settings.debug_device_ids = {"TEST-DEVICE-HASHED-ID"};
  // Geography appears as EEA for debug devices.
  params.debug_settings.debug_geography = ump::kConsentDebugGeographyEEA

  consent_info->RequestConsentInfoUpdate(params);
}

Uygulamanızı UMP SDK'sı ile test ederken, kullanıcını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.

  ConsentInfo::GetInstance()->Reset();