शुरू करें

Google की ईयू उपयोगकर्ता की सहमति से जुड़ी नीति के तहत, आपको यूके के साथ-साथ यूरोपियन इकनॉमिक एरिया (ईईए) में अपने उपयोगकर्ताओं को कुछ जानकारी ज़ाहिर करनी होगी. साथ ही, जहां कानूनी तौर पर ज़रूरी है, वहां कुकी या अन्य लोकल स्टोरेज का इस्तेमाल करने और विज्ञापन दिखाने के लिए निजी डेटा (जैसे कि AdID) का इस्तेमाल करने के लिए, उनकी सहमति लेनी होगी. इस नीति में ईयू के ई-निजता निर्देश और सामान्य डेटा से जुड़े सुरक्षा कानून जनरल डेटा प्रोटेक्शन रेगुलेशन (जीडीपीआर) की ज़रूरी शर्तों के बारे में बताया गया है.

Google ने User Messaging Platform (UMP) SDK टूल की सुविधा दी है, ताकि पब्लिशर इस नीति के तहत अपनी ज़िम्मेदारी पूरी कर सकें. UMP SDK टूल को अपडेट किया गया है, ताकि वह नए IAB स्टैंडर्ड के साथ काम कर सके. ये सभी कॉन्फ़िगरेशन अब निजता और मैसेज सेवा AdMob में आसानी से मैनेज किए जा सकते हैं.

ज़रूरी शर्तें

  • Android एपीआई लेवल 21 या उसके बाद का लेवल (Android के लिए)

मैसेज का टाइप बनाना

उपयोगकर्ता मैसेज बनाएं. इसके लिए, अपने AdMob खाते के निजता और मैसेज सेवा टैब में जाकर, उपयोगकर्ता के लिए उपलब्ध मैसेज के टाइप में से किसी एक का इस्तेमाल करें UMP SDK टूल, आपके प्रोजेक्ट में सेट किए गए AdMob ऐप्लिकेशन आईडी से बनाया गया उपयोगकर्ता मैसेज दिखाने की कोशिश करता है. अगर आपके ऐप्लिकेशन के लिए कोई मैसेज कॉन्फ़िगर नहीं किया गया है, तो SDK टूल गड़बड़ी दिखाता है.

ज़्यादा जानकारी के लिए, निजता और मैसेज सेवा के बारे में जानकारी देखें.

SDK टूल इंस्टॉल करें

  1. Google Mobile Ads (GMA) C++ SDK टूल को इंस्टॉल करने के लिए, यह तरीका अपनाएं. UMP C++ SDK टूल को GMA C++ SDK टूल में शामिल किया गया है.

  2. जारी रखने से पहले, पक्का करें कि आपने प्रोजेक्ट में अपने ऐप्लिकेशन का AdMob ऐप्लिकेशन आईडी कॉन्फ़िगर कर लिया हो.

  3. अपने कोड में, ConsentInfo::GetInstance() को कॉल करके UMP SDK टूल को शुरू करें.

    • Android पर, आपको एनडीके से मिले JNIEnv और Activity को पास करना होगा. आपको सिर्फ़ GetInstance() को पहली बार कॉल करते समय ऐसा करना होगा.
    • इसके अलावा, अगर आपके ऐप्लिकेशन में पहले से ही Firebase C++ SDK टूल का इस्तेमाल किया जा रहा है, तो पहली बार GetInstance() को कॉल करते समय firebase::App पास किया जा सकता है.
    #include "firebase/gma/ump.h"
    
    namespace ump = ::firebase::gma::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() को बाद में किए जाने वाले सभी कॉल से एक ही इंस्टेंस मिल जाता है.

अगर आपने UMP SDK टूल का इस्तेमाल कर लिया है, तो ConsentInfo इंस्टेंस को मिटाकर, SDK टूल को बंद किया जा सकता है:

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

एसिंक्रोनस कार्रवाइयों को मॉनिटर करने के लिए Future का इस्तेमाल करें

firebase::Future से, एसिंक्रोनस तरीके के कॉल के पूरा होने की स्थिति का पता लगाया जा सकता है.

एसिंक्रोनस तरीके से ऑपरेट होने वाले सभी UMP C++ फ़ंक्शन और मेथड कॉल से, Future मिलता है. साथ ही, यह सबसे हाल के ऑपरेशन से Future को वापस पाने के लिए, "आखिरी नतीजा" फ़ंक्शन भी देता है.

Future से नतीजा पाने के दो तरीके हैं:

  1. अपने कॉलबैक फ़ंक्शन को पास करके, OnCompletion() को कॉल करें. यह फ़ंक्शन पूरा होने पर कॉल करता है.
  2. समय-समय पर Future के status() देखें. जब स्टेटस kFutureStatusPending से kFutureStatusCompleted में बदल जाता है, तो यह प्रोसेस पूरी हो जाती है.

एसिंक्रोनस कार्रवाई पूरी होने के बाद, कार्रवाई का गड़बड़ी कोड पाने के लिए आपको Future के error() की जांच करनी होगी. अगर गड़बड़ी का कोड 0 (kConsentRequestSuccess या kConsentFormSuccess) है, तो कार्रवाई पूरी हो गई है. अगर ऐसा नहीं है, तो गड़बड़ी का पता लगाने के लिए गड़बड़ी कोड औरerror_message() की जांच करें.

पूरा होने पर कॉलबैक

यहां एक पूरा होने वाले कॉलबैक को सेट करने के लिए, OnCompletion को इस्तेमाल करने के तरीके का उदाहरण दिया गया है. इसे एसिंक्रोनस ऑपरेशन पूरा होने पर कॉल किया जाता है.

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

लूप पोलिंग अपडेट करें

इस उदाहरण में, ऐप्लिकेशन लॉन्च के समय एसिंक्रोनस ऑपरेशन शुरू होने के बाद, नतीजों की जांच गेम के अपडेट लूप फ़ंक्शन (जो एक फ़्रेम में एक बार होती है) में कहीं और की जाती है.

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 के बारे में ज़्यादा जानकारी के लिए, Firebase C++ SDK टूल के दस्तावेज़ और GMA C++ SDK टूल के दस्तावेज़ देखें.

आपको RequestConsentInfoUpdate()का इस्तेमाल करके, हर ऐप्लिकेशन लॉन्च पर उपयोगकर्ता की सहमति की जानकारी को अपडेट करने का अनुरोध करना चाहिए. इससे तय होता है कि अगर आपके उपयोगकर्ता ने सहमति नहीं दी है या सहमति की समयसीमा खत्म हो गई है, तो उसे सहमति देनी होगी या नहीं.

#include "firebase/gma/ump.h"

namespace ump = ::firebase::gma::ump;

void MyApplicationStart() {
  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>& result) {
      if (result.error() != ump::kConsentRequestSuccess) {
        LogMessage("Error requesting consent update: %s", result.error_message());
      } else {
        // Consent status is now available.
      }
    });
}

पूरे होने वाले कॉलबैक के बजाय, अपडेट लूप पोल का इस्तेमाल करके पूरा होने की जांच का उदाहरण देखने के लिए ऊपर देखें.

अगर ज़रूरी हो, तो सहमति फ़ॉर्म लोड करें और दिखाएं

सहमति की स्थिति की अप-टू-डेट जानकारी मिलने के बाद, सहमति फ़ॉर्म लोड करने के लिएConsentInfo क्लास परLoadAndShowConsentFormIfRequired() को कॉल करें. अगर सहमति की स्थिति ज़रूरी है, तो SDK टूल एक फ़ॉर्म लोड करता है और तुरंत उसे दी गई जानकारी से FormParentदिखाता है. Future पूरा हो गया है फ़ॉर्म ख़ारिज करने के बाद कहा जाता है. अगर सहमति की ज़रूरत नहीं है, तो Future पूरी हो गई है कॉल किया जाता है.

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 consent form: %s", form_result.error_message());
          } else {
            // Either the form was shown and completed by the user, or consent was not required.
          }
        });
      }
    });
}

अगर उपयोगकर्ता के विकल्प चुनने या फ़ॉर्म को खारिज करने के बाद आपको कोई कार्रवाई करनी है, तो उस लॉजिक को उस कोड में डालें जो LoadAndShowConsentFormIfRequired() से मिलने वाले Future को हैंडल करता है.

विज्ञापन जोड़ने का अनुरोध करें

अपने ऐप्लिकेशन में विज्ञापनों का अनुरोध करने से पहले, देख लें कि आपने ConsentInfo::GetInstance()‑>CanRequestAds()का इस्तेमाल करने वाले उपयोगकर्ता से सहमति ली है या नहीं. सहमति लेते समय इन दो जगहों पर जांच करनी होगी:

  1. मौजूदा सेशन में सहमति लेने के बाद.
  2. आपके कॉल करने के तुरंत बाद RequestConsentInfoUpdate(). ऐसा हो सकता है कि सहमति पिछले सेशन में ली गई हो. इंतज़ार का समय सबसे सही तरीका है कि हम कॉलबैक के पूरा होने का इंतज़ार न करें, ताकि ऐप्लिकेशन लॉन्च होने के बाद, जल्द से जल्द विज्ञापन लोड करना शुरू किया जा सके.

अगर सहमति पाने की प्रोसेस के दौरान कोई गड़बड़ी होती है, तब भी आपको विज्ञापनों का अनुरोध करने की कोशिश करनी चाहिए. UMP SDK टूल, पिछले सेशन की सहमति की स्थिति का इस्तेमाल करता है.

इस पूरे उदाहरण में, अपडेट लूप पोलिंग का इस्तेमाल किया गया है. हालांकि, एसिंक्रोनस ऑपरेशन को मॉनिटर करने के लिए OnCompletion कॉलबैक का इस्तेमाल भी किया जा सकता है. अपने कोड के स्ट्रक्चर के लिए सबसे सही तकनीक का इस्तेमाल करें.

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

namespace gma = ::firebase::gma;
namespace ump = ::firebase::gma::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 consent 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;
      }
    }
  }
}

निजता के विकल्प

कुछ सहमति फ़ॉर्म के लिए, उपयोगकर्ता को किसी भी समय अपनी सहमति में बदलाव करने की ज़रूरत होती है. अगर ज़रूरी हो, तो निजता के विकल्प वाले बटन को लागू करने के लिए, यह तरीका अपनाएं.

इसके लिए:

  1. अपने ऐप्लिकेशन के सेटिंग पेज पर बटन जैसा कोई यूज़र इंटरफ़ेस (यूआई) लागू करें, जो निजता विकल्प फ़ॉर्म को ट्रिगर कर सके.
  2. LoadAndShowConsentFormIfRequired() पूरा होने के बाद,getPrivacyOptionsRequirementStatus() यह तय करें कि निजता विकल्प फ़ॉर्म दिखाने वाला यूज़र इंटरफ़ेस (यूआई) एलिमेंट दिखाना है या नहीं.
  3. जब कोई उपयोगकर्ता आपके यूज़र इंटरफ़ेस (यूआई) एलिमेंट से इंटरैक्ट करता है, तो फ़ॉर्म दिखाने के लिए showPrivacyOptionsForm() को कॉल करें, ताकि उपयोगकर्ता किसी भी समय अपने निजता विकल्पों को अपडेट कर सके.

टेस्ट करना

डेवलप करने के दौरान, अगर आपको अपने ऐप्लिकेशन के इंटिग्रेशन की जांच करनी है, तो यह तरीका अपनाकर अपने टेस्ट डिवाइस को प्रोग्राम के हिसाब से रजिस्टर करें. अपना ऐप्लिकेशन रिलीज़ करने से पहले, उस कोड को ज़रूर हटा दें जो इन टेस्ट डिवाइस आईडी को सेट करता है.

  1. RequestConsentInfoUpdate()पर कॉल करें.
  2. नीचे दिए गए उदाहरण से मिलते-जुलते मैसेज के लिए, लॉग आउटपुट की जांच करें. यह मैसेज आपका डिवाइस आईडी दिखाता है और उसे टेस्ट डिवाइस के तौर पर जोड़ने का तरीका बताता है:

    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. अपने टेस्ट डिवाइस आईडी को क्लिपबोर्ड पर कॉपी करें.

  4. कोड में बदलाव करके, अपने टेस्ट डिवाइस आईडी की सूची ConsentRequestParameters.debug_settings.debug_device_ids को .

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

भूगोल लागू करें

UMP SDK टूल की मदद से, ConsentRequestParameters.debug_settings.debug_geographyका इस्तेमाल करके यह जांच की जा सकती है कि डिवाइस ईईए या यूके में है या नहीं. ध्यान दें कि डीबग सेटिंग सिर्फ़ टेस्ट डिवाइसों पर काम करती है.

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

UMP SDK टूल की मदद से अपने ऐप्लिकेशन की जांच करते समय, आपको SDK टूल की स्थिति को रीसेट करने में मदद मिल सकती है. इससे, यह जानने में मदद मिलेगी कि उपयोगकर्ता को पहली बार ऐप्लिकेशन इंस्टॉल करने का कैसा अनुभव मिला. ऐसा करने का तरीका, SDK टूल Reset() की मदद से मिलता है.

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