शुरू करें

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

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

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

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

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

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

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

Gradle की मदद से इंस्टॉल करना

अपने मॉड्यूल की ऐप्लिकेशन-लेवल की gradle फ़ाइल में, Google User Messaging Platform SDK (UMP SDK) के लिए डिपेंडेंसी जोड़ें. आम तौर पर, यह app/build.gradle:

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

अपने ऐप्लिकेशन के build.gradle में बदलाव करने के बाद, अपने प्रोजेक्ट को Gradle फ़ाइलों के साथ सिंक करना न भूलें.

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

यहां एक उदाहरण दिया गया है, जिसमें MainActivity से onCreate() तरीके में स्टेटस देखने का तरीका बताया गया है.

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, String.format("%s: %s",
              requestConsentError.errorCode(),
              requestConsentError.message()))
        })
  }
}

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

अहम जानकारी: नीचे दिए गए एपीआई, UMP SDK टूल के 2.1.0 या इसके बाद वाले वर्शन पर काम करते हैं.

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

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 ->
              // Consent gathering failed.
              Log.w(TAG, String.format("%s: %s",
                  loadAndShowError.errorCode(),
                  loadAndShowError.message()))

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

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

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

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

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

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

Java

public class MainActivity extends AppCompatActivity {
  private ConsentInformation consentInformation;
  // Use an atomic boolean to initialize the Google Mobile Ads SDK and load ads once.
  private final AtomicBoolean isMobileAdsInitializeCalled = new AtomicBoolean(false);
  
  @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()) {
                initializeMobileAdsSdk();
              }
            }
          );
        },
        (OnConsentInfoUpdateFailureListener) requestConsentError -> {
          // Consent gathering failed.
          Log.w(TAG, String.format("%s: %s",
              requestConsentError.getErrorCode(),
              requestConsentError.getMessage()));
        });
    
    // Check if you can initialize the Google Mobile Ads SDK in parallel
    // while checking for new consent information. Consent obtained in
    // the previous session can be used to request ads.
    if (consentInformation.canRequestAds()) {
      initializeMobileAdsSdk();
    }
  }
  
  private void initializeMobileAdsSdk() {
    if (isMobileAdsInitializeCalled.getAndSet(true)) {
      return;
    }

    // Initialize the Google Mobile Ads SDK.
    MobileAds.initialize(this);

    // TODO: Request an ad.
    // InterstitialAd.load(...);
  }
}

Kotlin

class MainActivity : AppCompatActivity() {
  private lateinit var consentInformation: ConsentInformation
  // Use an atomic boolean to initialize the Google Mobile Ads SDK and load ads once.
  private var isMobileAdsInitializeCalled = AtomicBoolean(false)
  
  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 ->
              // Consent gathering failed.
              Log.w(TAG, String.format("%s: %s",
                  loadAndShowError.errorCode(),
                  loadAndShowError.message()))

              // Consent has been gathered.
              if (consentInformation.canRequestAds()) {
                initializeMobileAdsSdk()
              }
            }
          )
        },
        ConsentInformation.OnConsentInfoUpdateFailureListener {
          requestConsentError ->
          // Consent gathering failed.
          Log.w(TAG, String.format("%s: %s",
              requestConsentError.errorCode(),
              requestConsentError.message()))
        })
    
    // Check if you can initialize the Google Mobile Ads SDK in parallel
    // while checking for new consent information. Consent obtained in
    // the previous session can be used to request ads.
    if (consentInformation.canRequestAds()) {
      initializeMobileAdsSdk()
    }
  }
  
  private fun initializeMobileAdsSdk() {
    if (isMobileAdsInitializeCalled.getAndSet(true)) {
      return
    }

    // Initialize the Google Mobile Ads SDK.
    MobileAds.initialize(this)

    // TODO: Request an ad.
    // InterstitialAd.load(...)
  }
}

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

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

इसके लिए:

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

नीचे दिए गए उदाहरण में, MenuItem से निजता विकल्प वाले फ़ॉर्म को दिखाने का तरीका बताया गया है.

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

टेस्ट करना

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

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

    Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.
    
  3. अपने टेस्ट डिवाइस आईडी को क्लिपबोर्ड पर कॉपी करें.

  4. कोड में बदलाव करके, कॉल ConsentDebugSettings.Builder().addTestDeviceHashedId() सेट करें और पास करें .

    Java

    ConsentDebugSettings debugSettings = new ConsentDebugSettings.Builder(this)
        .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)
        .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,
        ...
    )
    

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

UMP SDK टूल की मदद से, the setDebugGeography() method which takes a DebugGeography on ConsentDebugSettings.Builderका इस्तेमाल करके यह जांच की जा सकती है कि डिवाइस ईईए या यूके में है या नहीं. ध्यान दें कि डीबग सेटिंग सिर्फ़ टेस्ट डिवाइसों पर काम करती है.

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,
    ...
)

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

Java

consentInformation.reset();

Kotlin

consentInformation.reset()

GitHub पर उदाहरण

UMP SDK टूल के इंटिग्रेशन के उदाहरण: Java | Kotlin