शुरू करें

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

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

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

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

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

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

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

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

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

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

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

ऐप्लिकेशन आईडी जोड़ें

आप यहां अपना ऐप्लिकेशन आईडी देख सकते हैं: Ad Manager का यूज़र इंटरफ़ेस (यूआई). आईडी को अपने AndroidManifest.xml के लिए यहां दिए गए कोड स्निपेट का इस्तेमाल करें:

<manifest>
  <application>
    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
  </application>
</manifest>

आपको हर ऐप्लिकेशन में, उपयोगकर्ता की सहमति से जुड़ी जानकारी अपडेट करने का अनुरोध करना चाहिए 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, "${requestConsentError.errorCode}: ${requestConsentError.message}")
        })
  }
}

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

सहमति की अप-टू-डेट स्थिति मिलने के बाद, loadAndShowConsentFormIfRequired() ConsentForm क्लास का इस्तेमाल करें. अगर सहमति की स्थिति डालना ज़रूरी है. 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 ->
              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}")
        })
  }
}

अगर आपको उपयोगकर्ता के चुनने या खारिज करने के बाद कोई कार्रवाई करने की ज़रूरत है फ़ॉर्म भरने के बाद, उस लॉजिक को 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;
    }

    new Thread(
            () -> {
              // Initialize the Google Mobile Ads SDK on a background thread.
              
              MobileAds.initialize(this, initializationStatus -> {});
              runOnUiThread(
                  () -> {
                    // TODO: Request an ad.
                    // loadInterstitialAd();
                  });
              
            })
        .start();
  }
}

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 ->
              if (loadAndShowError != null) {
                // Consent gathering failed.
                Log.w(TAG, "${loadAndShowError.errorCode}: ${loadAndShowError.message}")
              }

              // Consent has been gathered.
              if (consentInformation.canRequestAds()) {
                initializeMobileAdsSdk()
              }
            }
          )
        },
        ConsentInformation.OnConsentInfoUpdateFailureListener {
          requestConsentError ->
          // Consent gathering failed.
          Log.w(TAG, "${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
    }

    val backgroundScope = CoroutineScope(Dispatchers.IO)
    backgroundScope.launch {
      
      MobileAds.initialize(this@MainActivity) {}
      runOnUiThread {
        // TODO: Request an ad.
        // loadInterstitialAd()
      }
      
    }
  }
}

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

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

इसके लिए:

  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. अपने कोड को DebugGeography.TestDeviceHashedIds और पास करें आपके टेस्ट डिवाइस आईडी की सूची.

जगह के हिसाब से कॉन्टेंट बनाना

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 टूल reset() तरीका उपलब्ध कराता है.

Java

consentInformation.reset();

Kotlin

consentInformation.reset()

GitHub पर उदाहरण

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