बैनर विज्ञापन सेट अप करना

प्लैटफ़ॉर्म चुनें: Android नई सुविधा Android iOS Unity Flutter

बैनर विज्ञापन रेक्टैंगल के आकार वाले विज्ञापन होते हैं. ये विज्ञापन, ऐप्लिकेशन के लेआउट का कुछ हिस्सा घेरते हैं. ऐंकर अडैप्टिव बैनर, तय आसपेक्ट रेशियो (चौड़ाई-ऊंचाई का अनुपात) वाले विज्ञापन होते हैं. जब उपयोगकर्ता ऐप्लिकेशन से इंटरैक्ट करते हैं, तब ये विज्ञापन स्क्रीन पर दिखते रहते हैं. ये विज्ञापन, स्क्रीन के सबसे ऊपर या सबसे नीचे दिखते हैं.

इस गाइड में, Android ऐप्लिकेशन में ऐंकर अडैप्टिव बैनर विज्ञापन लोड करने का तरीका बताया गया है.

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

  • सेट अप करें Google Mobile Ads SDK.
  • ज़रूरी नहीं: बैनर विज्ञापनों को लागू करने के उदाहरण के लिए, इनमें से कोई एक सैंपल ऐप्लिकेशन चुनें:
    • Kotlin
    • Java या Kotlin में Kotlin सुविधाओं का डेमो.

हमेशा टेस्ट विज्ञापनों का इस्तेमाल करके टेस्ट करना

अपने ऐप्लिकेशन बनाने और उनकी टेस्टिंग करने के लिए, लाइव और प्रोडक्शन विज्ञापन इस्तेमाल करने के बजाय, टेस्ट विज्ञापन इस्तेमाल करें. ऐसा न करने पर, आपका खाता निलंबित हो सकता है.

टेस्ट विज्ञापन लोड करने का सबसे आसान तरीका, Android बैनर के लिए हमारे खास टेस्ट विज्ञापन यूनिट आईडी का इस्तेमाल करना है:

ca-app-pub-3940256099942544/9214589741

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

Google Mobile Ads SDK टेस्ट विज्ञापन कैसे काम करते हैं, इस बारे में ज़्यादा जानने के लिए, टेस्ट विज्ञापन चालू करना लेख पढ़ें.

विज्ञापन व्यू तय करना

एक्सएमएल लेआउट

ऐंकर अडैप्टिव बैनर विज्ञापन के लिए कंटेनर के तौर पर काम करने के लिए, अपने लेआउट की एक्सएमएल फ़ाइल में एक व्यू जोड़ें:

<!-- Ad view container that fills the width of the screen and adjusts its
    height to the content of the ad. -->
<FrameLayout
        android:id="@+id/ad_view_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_alignParentBottom="true" />

Jetpack Compose

  1. JetpackCompose Utilities फ़ोल्डर शामिल करें. इस फ़ोल्डर में, AdView ऑब्जेक्ट और ऐसेट कंपोज़ करने के लिए हेल्पर शामिल होते हैं.

  2. AdView कंपोज़ करें:


// Place the ad view at the bottom of the screen.
Column(modifier = modifier.fillMaxSize(), verticalArrangement = Arrangement.Bottom) {
  Box(modifier = modifier.fillMaxWidth()) { BannerAd(adView, modifier) }
}

विज्ञापन का साइज़ सेट करना

AdSize को, तय चौड़ाई वाले ऐंकर अडैप्टिव बैनर टाइप पर सेट करें:

Java


// Request a large anchored adaptive banner with a width of 360.
adView.setAdSize(AdSize.getLargeAnchoredAdaptiveBannerAdSize(this, 360));

Kotlin


// Request a large anchored adaptive banner with a width of 360.
adView.setAdSize(AdSize.getLargeAnchoredAdaptiveBannerAdSize(this, 360))

Jetpack Compose


// Set a large anchored adaptive banner ad size with a given width.
val adSize = AdSize.getLargeAnchoredAdaptiveBannerAdSize(LocalContext.current, 360)
adView.setAdSize(adSize)

लेआउट में AdView जोड़ना

अपने ऐप्लिकेशन के लेआउट में जोड़ने के लिए, विज्ञापन के साइज़ का इस्तेमाल करके AdView बनाएं:

Java


// Create a new ad view.
adView = new AdView(this);
adView.setAdUnitId(AD_UNIT_ID);
// Request a large anchored adaptive banner with a width of 360.
adView.setAdSize(AdSize.getLargeAnchoredAdaptiveBannerAdSize(this, 360));

// Replace ad container with new ad view.
adContainerView.removeAllViews();
adContainerView.addView(adView);

Kotlin


// Create a new ad view.
val adView = AdView(this)
adView.adUnitId = AD_UNIT_ID
// Request a large anchored adaptive banner with a width of 360.
adView.setAdSize(AdSize.getLargeAnchoredAdaptiveBannerAdSize(this, 360))
this.adView = adView

// Replace ad container with new ad view.
binding.adViewContainer.removeAllViews()
binding.adViewContainer.addView(adView)

Jetpack Compose


val adView = remember { AdView(context) }

// Setup and load the adview.
// Set the unique ID for this specific ad unit.
adView.adUnitId = BANNER_AD_UNIT_ID

// Set a large anchored adaptive banner ad size with a given width.
val adSize = AdSize.getLargeAnchoredAdaptiveBannerAdSize(LocalContext.current, 360)
adView.setAdSize(adSize)

// Place the ad view at the bottom of the screen.
Column(modifier = modifier.fillMaxSize(), verticalArrangement = Arrangement.Bottom) {
  Box(modifier = modifier.fillMaxWidth()) { BannerAd(adView, modifier) }
}

विज्ञापन लोड करना

यहां दिए गए उदाहरण में, 360 पिक्सल चौड़ाई वाला ऐंकर अडैप्टिव बैनर विज्ञापन, AdView ऑब्जेक्ट में लोड किया गया है:

Java

AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);

Kotlin

val adRequest = AdRequest.Builder().build()
adView.loadAd(adRequest)

विज्ञापन रीफ़्रेश करना

अगर आपने अपनी विज्ञापन यूनिट को रीफ़्रेश करने के लिए कॉन्फ़िगर किया है, तो विज्ञापन लोड न होने पर, आपको किसी दूसरे विज्ञापन का अनुरोध करने की ज़रूरत नहीं है. Google Mobile Ads SDK AdMob यूज़र इंटरफ़ेस (यूआई) में तय की गई किसी भी रीफ़्रेश दर का पालन करता है. अगर आपने रीफ़्रेश करने की सुविधा चालू नहीं की है, तो नया अनुरोध करें. विज्ञापन यूनिट को रीफ़्रेश करने के बारे में ज़्यादा जानने के लिए, जैसे कि रीफ़्रेश दर सेट करना, देखें बैनर विज्ञापनों के लिए, अपने-आप रीफ़्रेश होने की सुविधा का इस्तेमाल करना.

विज्ञापन के संसाधन को रिलीज़ करना

बैनर विज्ञापन का इस्तेमाल पूरा होने के बाद, बैनर विज्ञापन के संसाधनों को रिलीज़ किया जा सकता है.

विज्ञापन के संसाधन को रिलीज़ करने के लिए, विज्ञापन को व्यू के क्रम से हटाएं और उसके सभी रेफ़रंस छोड़ें:

Java

public void destroyBanner() {
  // Remove banner from view hierarchy.
  if (adView != null) {
    View parentView = (View) adView.getParent();
    if (parentView instanceof ViewGroup) {
      ((ViewGroup) parentView).removeView(adView);
    }

    // Destroy the banner ad resources.
    adView.destroy();
  }

  // Drop reference to the banner ad.
  adView = null;
}

Kotlin

fun destroyBanner() {
  // Remove banner from view hierarchy.
  val parentView = adView?.parent
  if (parentView is ViewGroup) {
    parentView.removeView(adView)
  }

  // Destroy the banner ad resources.
  adView?.destroy()

  // Drop reference to the banner ad.
  adView = null
}

विज्ञापन के इवेंट

विज्ञापन के लाइफ़साइकल में कई इवेंट को सुना जा सकता है. इनमें विज्ञापन लोड होना, विज्ञापन इंप्रेशन और क्लिक, साथ ही विज्ञापन खुलने और बंद होने के इवेंट शामिल हैं. हमारा सुझाव है कि बैनर लोड करने से पहले, कॉलबैक सेट करें.

Java

if (adView != null) {
  adView.setAdListener(
      new AdListener() {
        @Override
        public void onAdClicked() {
          // Code to be executed when the user clicks on an ad.
        }

        @Override
        public void onAdClosed() {
          // Code to be executed when the user is about to return
          // to the app after tapping on an ad.
        }

        @Override
        public void onAdFailedToLoad(@NonNull LoadAdError adError) {
          // Code to be executed when an ad request fails.
        }

        @Override
        public void onAdImpression() {
          // Code to be executed when an impression is recorded
          // for an ad.
        }

        @Override
        public void onAdLoaded() {
          // Code to be executed when an ad finishes loading.
        }

        @Override
        public void onAdOpened() {
          // Code to be executed when an ad opens an overlay that
          // covers the screen.
        }
      });
}

Kotlin

adView?.adListener =
  object : AdListener() {
    override fun onAdClicked() {
      // Code to be executed when the user clicks on an ad.
    }

    override fun onAdClosed() {
      // Code to be executed when the user is about to return
      // to the app after tapping on an ad.
    }

    override fun onAdFailedToLoad(adError: LoadAdError) {
      // Code to be executed when an ad request fails.
    }

    override fun onAdImpression() {
      // Code to be executed when an impression is recorded
      // for an ad.
    }

    override fun onAdLoaded() {
      // Code to be executed when an ad finishes loading.
    }

    override fun onAdOpened() {
      // Code to be executed when an ad opens an overlay that
      // covers the screen.
    }
  }

AdListener में, ओवरराइड किए जा सकने वाले हर तरीके का मतलब, विज्ञापन के लाइफ़साइकल में होने वाला एक इवेंट होता है.

ओवरराइड किए जा सकने वाले तरीके
onAdClicked() The onAdClicked() तरीका तब लागू होता है, जब किसी विज्ञापन के लिए क्लिक रिकॉर्ड किया जाता है.
onAdClosed() The onAdClosed() तरीका तब लागू होता है, जब कोई उपयोगकर्ता, विज्ञापन के डेस्टिनेशन यूआरएल को देखने के बाद, ऐप्लिकेशन पर वापस आता है. आपका ऐप्लिकेशन, निलंबित की गई गतिविधियों को फिर से शुरू करने या इंटरैक्शन के लिए खुद को तैयार करने के लिए, कोई अन्य ज़रूरी काम करने के लिए इसका इस्तेमाल कर सकता है. Android API डेमो ऐप्लिकेशन में, विज्ञापन सुनने वाले तरीकों को लागू करने के लिए, AdMob AdListener का उदाहरण देखें.
onAdFailedToLoad() The onAdFailedToLoad() तरीका, पैरामीटर शामिल करने वाला इकलौता तरीका है. `LoadAdError` टाइप का गड़बड़ी पैरामीटर बताता है कि कौनसी गड़बड़ी हुई है.LoadAdError ज़्यादा जानकारी के लिए, विज्ञापन लोड होने में आने वाली गड़बड़ियों को डीबग करना लेख पढ़ें.
onAdImpression() The onAdImpression() तरीका तब लागू होता है, जब किसी विज्ञापन के लिए इंप्रेशन रिकॉर्ड किया जाता है.
onAdLoaded() The onAdLoaded() तरीका तब लागू होता है, जब कोई विज्ञापन लोड हो जाता है. उदाहरण के लिए, अगर आपको तब तक अपनी गतिविधि या फ़्रैगमेंट में AdView जोड़ने में देरी करनी है, जब तक आपको यह पक्का न हो जाए कि कोई विज्ञापन लोड होगा, तो यहां ऐसा किया जा सकता है.
onAdOpened() The onAdOpened() तरीका तब लागू होता है, जब कोई विज्ञापन, स्क्रीन को कवर करने वाला ओवरले खोलता है.

वीडियो विज्ञापनों के लिए हार्डवेयर से तेज़ी लाने की सुविधा

बैनर विज्ञापन व्यू में वीडियो विज्ञापन दिखाने के लिए, हार्डवेयर से तेज़ी लाने की सुविधा चालू होनी चाहिए.

हार्डवेयर से तेज़ी लाने की सुविधा डिफ़ॉल्ट रूप से चालू होती है. हालांकि, कुछ ऐप्लिकेशन इसे बंद कर सकते हैं. अगर यह आपके ऐप्लिकेशन पर लागू होता है, तो हमारा सुझाव है कि विज्ञापनों का इस्तेमाल करने वाली Activity क्लास के लिए, हार्डवेयर से तेज़ी लाने की सुविधा चालू करें.

हार्डवेयर से तेज़ी लाने की सुविधा चालू करना

अगर आपका ऐप्लिकेशन, हार्डवेयर से तेज़ी लाने की सुविधा को वैश्विक तौर पर चालू करने पर ठीक से काम नहीं करता है, तो इसे अलग-अलग गतिविधियों के लिए भी कंट्रोल किया जा सकता है. हार्डवेयर से तेज़ी लाने की सुविधा को चालू या बंद करने के लिए, आप android:hardwareAccelerated एट्रिब्यूट का इस्तेमाल कर सकते हैं <application> और <activity> एलिमेंट के लिए, अपनी AndroidManifest.xml में. यहां दिए गए उदाहरण में, पूरे ऐप्लिकेशन के लिए हार्डवेयर से तेज़ी लाने की सुविधा चालू की गई है. हालांकि, एक गतिविधि के लिए इसे बंद किया गया है:

<application android:hardwareAccelerated="true">
    <!-- For activities that use ads, hardwareAcceleration should be true. -->
    <activity android:hardwareAccelerated="true" />
    <!-- For activities that don't use ads, hardwareAcceleration can be false. -->
    <activity android:hardwareAccelerated="false" />
</application>

हार्डवेयर से तेज़ी लाने की सुविधा को कंट्रोल करने के विकल्पों के बारे में ज़्यादा जानने के लिए, हार्डवेयर से तेज़ी लाने की सुविधा के बारे में गाइड देखें. ध्यान दें कि अगर गतिविधि के लिए हार्डवेयर से तेज़ी लाने की सुविधा बंद है, तो अलग-अलग विज्ञापन व्यू के लिए इसे चालू नहीं किया जा सकता. इसलिए, गतिविधि के लिए हार्डवेयर से तेज़ी लाने की सुविधा चालू होनी चाहिए.

अगले चरण

छोटे हो जाने वाले बैनर विज्ञापन

छोटे हो जाने वाले बैनर विज्ञापन, ऐसे बैनर विज्ञापन होते हैं जो शुरुआत में बड़े ओवरले के तौर पर दिखते हैं. इनमें एक बटन होता है, जिसकी मदद से विज्ञापन को छोटे साइज़ पर वापस लाया जा सकता है. अपने परफ़ॉर्मेंस को और बेहतर बनाने के लिए, इसका इस्तेमाल करने पर विचार करें. ज़्यादा जानकारी के लिए, छोटे हो जाने वाले बैनर विज्ञापन लेख पढ़ें.

इनलाइन अडैप्टिव बैनर

इनलाइन अडैप्टिव बैनर, ऐंकर अडैप्टिव बैनर की तुलना में बड़े और लंबे होते हैं. इनकी लंबाई कम या ज़्यादा की जा सकती है. अपनी इस विशेषता की वजह से इनलाइन अडैप्टिव बैनर, डिवाइस की डिसप्ले स्क्रीन जितने लंबे भी हो सकते हैं. ऐसे ऐप्लिकेशन के लिए, ऐंकर अडैप्टिव बैनर विज्ञापनों के बजाय, इनलाइन अडैप्टिव बैनर इस्तेमाल करने का सुझाव दिया जाता है जिनमें स्क्रोल किए जा सकने वाले कॉन्टेंट में बैनर विज्ञापन दिखाए जाते हैं. ज़्यादा जानकारी के लिए, इनलाइन अडैप्टिव बैनर लेख पढ़ें.

अन्य विषय एक्सप्लोर करें