এবার শুরু করা যাক

Google ব্যবহারকারী মেসেজিং প্ল্যাটফর্ম (UMP) SDK হল একটি গোপনীয়তা এবং মেসেজিং টুল যা আপনাকে গোপনীয়তা পছন্দগুলি পরিচালনা করতে সহায়তা করে৷ আরও তথ্যের জন্য,দেখুন গোপনীয়তা এবং বার্তাপ্রেরণ সম্পর্কে

পূর্বশর্ত

  • Android API স্তর 21 বা উচ্চতর

একটি বার্তা টাইপ তৈরি করুন

আপনারAdMob l10n-placeholder118 AdMob l10n-placeholder118 AdMobplaceholder119-এর গোপনীয়তা এবং মেসেজিং ট্যাবের অধীনে উপলব্ধ ব্যবহারকারীর বার্তা প্রকারব্যবহারকারী বার্তা প্রকারগুলির একটি দিয়ে ব্যবহারকারীর বার্তা তৈরি করুন৷ UMP SDK আপনার প্রকল্পে সেট করা AdMob অ্যাপ্লিকেশন আইডি থেকে তৈরি একটি গোপনীয়তা বার্তা প্রদর্শন করার চেষ্টা করে।

আরও বিশদ বিবরণের জন্য, গোপনীয়তা এবং বার্তাপ্রেরণ সম্পর্কেদেখুন।

Gradle দিয়ে ইনস্টল করুন

Google ব্যবহারকারী মেসেজিং প্ল্যাটফর্ম SDK-এর জন্য আপনার মডিউলের অ্যাপ-লেভেল গ্রেডল ফাইলে নির্ভরতা যোগ করুন, সাধারণত app/build.gradle :

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

আপনার অ্যাপের build.gradle এ পরিবর্তন করার পর, Gradle ফাইলের সাথে আপনার প্রোজেক্ট সিঙ্ক করতে ভুলবেন না।

অ্যাপ্লিকেশন আইডি যোগ করুন

আপনিAdMob UI- তে আপনার অ্যাপ্লিকেশন আইডি খুঁজে পেতে পারেন।নিম্নলিখিত কোড স্নিপেট সহ আপনারAndroidManifest.xmlএ ID যোগ করুন:

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

requestConsentInfoUpdate()ব্যবহার করে প্রতিটি অ্যাপ লঞ্চের সময় আপনার ব্যবহারকারীর সম্মতির তথ্য আপডেট করার অনুরোধ করা উচিত। এই অনুরোধ নিম্নলিখিত পরীক্ষা করে:

  • সম্মতি প্রয়োজন কিনা । উদাহরণস্বরূপ, প্রথমবারের জন্য সম্মতি প্রয়োজন, বা পূর্ববর্তী সম্মতির সিদ্ধান্তের মেয়াদ শেষ হয়ে গেছে।
  • একটি গোপনীয়তা বিকল্প এন্ট্রি পয়েন্ট প্রয়োজন কিনা . কিছু গোপনীয়তা বার্তার জন্য অ্যাপের প্রয়োজন হয় যাতে ব্যবহারকারীরা যে কোনো সময় তাদের গোপনীয়তা বিকল্পগুলি পরিবর্তন করতে পারেন।

onCreate() পদ্ধতিতে MainActivity থেকে কীভাবে স্থিতি পরীক্ষা করতে হয় তার একটি উদাহরণ এখানে দেওয়া হল।

জাভা

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 privacy message form.
        },
        (OnConsentInfoUpdateFailureListener) requestConsentError -> {
          // Consent gathering failed.
          Log.w(TAG, String.format("%s: %s",
              requestConsentError.getErrorCode(),
              requestConsentError.getMessage()));
        });
  }
}

কোটলিন

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 privacy message form.
        },
        ConsentInformation.OnConsentInfoUpdateFailureListener {
          requestConsentError ->
          // Consent gathering failed.
          Log.w(TAG, "${requestConsentError.errorCode}: ${requestConsentError.message}")
        })
  }
}

প্রয়োজনে একটি গোপনীয়তা বার্তা ফর্ম লোড করুন এবং উপস্থাপন করুন

আপনি সর্বাধিক আপ-টু-ডেট সম্মতির স্থিতি পাওয়ার পরে, ব্যবহারকারীর সম্মতি সংগ্রহের জন্য প্রয়োজনীয় যে কোনও ফর্ম লোড করতেloadAndShowConsentFormIfRequired() কল করুন। লোড করার পরে, ফর্মগুলি অবিলম্বে উপস্থিত হয়।

জাভা

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

কোটলিন

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এ রাখুন।

গোপনীয়তা বিকল্প

কিছু গোপনীয়তা বার্তা ফর্ম প্রকাশক-রেন্ডার করা গোপনীয়তা বিকল্প এন্ট্রি পয়েন্ট থেকে উপস্থাপিত হয়, ব্যবহারকারীদের যে কোনো সময় তাদের গোপনীয়তা বিকল্পগুলি পরিচালনা করতে দেয়। গোপনীয়তা বিকল্প এন্ট্রি পয়েন্টে আপনার ব্যবহারকারীরা কোন বার্তা দেখেন সে সম্পর্কে আরও জানতে, দেখুনউপলব্ধ ব্যবহারকারীর বার্তা প্রকারগুলি

একটি গোপনীয়তা বিকল্প এন্ট্রি পয়েন্ট বাস্তবায়ন করতে, নিম্নলিখিত পদক্ষেপগুলি সম্পূর্ণ করুন:

  1. ConsentInformation.PrivacyOptionsRequirementStatusচেক করুন।
  2. যদি একটি গোপনীয়তা বিকল্প এন্ট্রি পয়েন্ট প্রয়োজন হয়, আপনার অ্যাপে একটি দৃশ্যমান এবং ইন্টারঅ্যাক্টেবল UI উপাদান যোগ করুন।
  3. showPrivacyOptionsForm()ব্যবহার করে গোপনীয়তা বিকল্প ফর্মটি ট্রিগার করুন।

নিম্নলিখিত কোড উদাহরণ এই পদক্ষেপগুলি প্রদর্শন করে:

জাভা

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

কোটলিন

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

বিজ্ঞাপনের জন্য অনুরোধ করুন

আপনার অ্যাপে বিজ্ঞাপনের অনুরোধ করার আগে, আপনি canRequestAds()ব্যবহার করে ব্যবহারকারীর কাছ থেকে সম্মতি পেয়েছেন কিনা তা পরীক্ষা করে দেখুন। সম্মতি সংগ্রহ করার সময় চেক করার দুটি জায়গা আছে:

  • বর্তমান অধিবেশনে সম্মতির পর।
  • আপনি requestConsentInfoUpdate()কল করার পরপরই। পূর্ববর্তী অধিবেশনে সম্ভাব্য সম্মতি পাওয়া গেছে। লেটেন্সি সর্বোত্তম অনুশীলন হিসাবে, আমরা সুপারিশ করি যে কলব্যাক সম্পূর্ণ হওয়ার জন্য অপেক্ষা করবেন না যাতে আপনি আপনার অ্যাপ চালু হওয়ার পরে যত তাড়াতাড়ি সম্ভব বিজ্ঞাপন লোড করা শুরু করতে পারেন।

সম্মতি সংগ্রহের প্রক্রিয়া চলাকালীন কোনও ত্রুটি দেখা দিলে, আপনাকে এখনও বিজ্ঞাপনের অনুরোধ করার চেষ্টা করা উচিত। UMP SDK আগের সেশনের সম্মতি স্ট্যাটাস ব্যবহার করে।

জাভা

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

কোটলিন

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. requestConsentInfoUpdate()কল করুন।
  2. নিম্নলিখিত উদাহরণের অনুরূপ একটি বার্তার জন্য লগ আউটপুট পরীক্ষা করুন, যা আপনার ডিভাইস আইডি দেখায় এবং এটিকে একটি পরীক্ষা ডিভাইস হিসাবে কীভাবে যুক্ত করতে হয়:

    Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.
    
  3. আপনার ক্লিপবোর্ডে আপনার টেস্ট ডিভাইস আইডি কপি করুন।

  4. আপনার কোড পরিবর্তন করুন কল করুনConsentDebugSettings.Builder().addTestDeviceHashedId() এবং পাস করুন এ আপনার পরীক্ষার ডিভাইস আইডিগুলির একটি তালিকা৷

একটি ভূগোল জোর করে

UMP SDK আপনার অ্যাপের আচরণ পরীক্ষা করার একটি উপায় প্রদান করে যেন ডিভাইসটি the setDebugGeography() method which takes a DebugGeography on ConsentDebugSettings.Builderব্যবহার করে EEA বা UK-তে অবস্থিত। মনে রাখবেন যে ডিবাগ সেটিংস শুধুমাত্র পরীক্ষা ডিভাইসে কাজ করে।

জাভা

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

কোটলিন

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() পদ্ধতি প্রদান করে।

জাভা

consentInformation.reset();

কোটলিন

consentInformation.reset()

গিটহাবের উদাহরণ

UMP SDK ইন্টিগ্রেশন উদাহরণ: Java | Kotlin