मध्यवर्ती

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

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

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

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

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

Android

ca-app-pub-3940256099942544/1033173712

iOS

ca-app-pub-3940256099942544/4411468910

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

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

यहां दिया गया उदाहरण, पेज पर अचानक दिखने वाले विज्ञापन को लोड करता है:

class InterstitialExampleState extends State<InterstitialExample> {
  InterstitialAd? _interstitialAd;

  // TODO: replace this test ad unit with your own ad unit.
  final adUnitId = Platform.isAndroid
    ? 'ca-app-pub-3940256099942544/1033173712'
    : 'ca-app-pub-3940256099942544/4411468910';

  /// Loads an interstitial ad.
  void loadAd() {
    InterstitialAd.load(
        adUnitId: adUnitId,
        request: const AdRequest(),
        adLoadCallback: InterstitialAdLoadCallback(
          // Called when an ad is successfully received.
          onAdLoaded: (ad) {
            debugPrint('$ad loaded.');
            // Keep a reference to the ad so you can show it later.
            _interstitialAd = ad;
          },
          // Called when an ad request failed.
          onAdFailedToLoad: (LoadAdError error) {
            debugPrint('InterstitialAd failed to load: $error');
          },
        ));
  }
}

पेज पर अचानक दिखने वाले विज्ञापन के इवेंट

FullScreenContentCallback का इस्तेमाल करके, लाइफ़साइकल इवेंट को सुना जा सकता है, जैसे कि विज्ञापन कब दिखाया जाता है या खारिज किया जाता है. इन इवेंट की सूचनाएं पाने के लिए, विज्ञापन दिखाने से पहले InterstitialAd.fullScreenContentCallback सेट करें. इस उदाहरण में हर तरीका लागू किया गया है:

class InterstitialExampleState extends State<InterstitialExample> {
  InterstitialAd? _interstitialAd;

  // TODO: replace this test ad unit with your own ad unit.
  final adUnitId = Platform.isAndroid
    ? 'ca-app-pub-3940256099942544/1033173712'
    : 'ca-app-pub-3940256099942544/4411468910';

  /// Loads an interstitial ad.
  void loadAd() {
    InterstitialAd.load(
        adUnitId: adUnitId,
        request: const AdRequest(),
        adLoadCallback: InterstitialAdLoadCallback(
          // Called when an ad is successfully received.
          onAdLoaded: (ad) {
             ad.fullScreenContentCallback = FullScreenContentCallback(
                // Called when the ad showed the full screen content.
                onAdShowedFullScreenContent: (ad) {},
                // Called when an impression occurs on the ad.
                onAdImpression: (ad) {},
                // Called when the ad failed to show full screen content.
                onAdFailedToShowFullScreenContent: (ad, err) {
                  // Dispose the ad here to free resources.
                  ad.dispose();
                },
                // Called when the ad dismissed full screen content.
                onAdDismissedFullScreenContent: (ad) {
                  // Dispose the ad here to free resources.
                  ad.dispose();
                },
                // Called when a click is recorded for an ad.
                onAdClicked: (ad) {});

            debugPrint('$ad loaded.');
            // Keep a reference to the ad so you can show it later.
            _interstitialAd = ad;
          },
          // Called when an ad request failed.
          onAdFailedToLoad: (LoadAdError error) {
            debugPrint('InterstitialAd failed to load: $error');
          },
        ));
  }
}

पेज पर अचानक दिखने वाला विज्ञापन दिखाना

InterstitialAd को ऐप्लिकेशन के सभी कॉन्टेंट के ऊपर Overlay के तौर पर दिखाया जाता है और उसे स्टैटिक तौर पर रखा जाता है. इसलिए, इसे Flutter विजेट ट्री में नहीं जोड़ा जा सकता. show() पर कॉल करके, विज्ञापन दिखाने की तारीख तय की जा सकती है.

_interstitiaAd.show();

show() को कॉल करने के बाद, इस तरह से दिखने वाले Ad को प्रोग्राम के हिसाब से खारिज नहीं किया जा सकता. साथ ही, इसके लिए उपयोगकर्ता से इनपुट की ज़रूरत होती है. InterstitialAd को सिर्फ़ एक बार दिखाया जा सकता है. बाद में दिखाए जाने वाले कॉल onAdFailedToShowFullScreenContent ट्रिगर होंगे.

जब किसी विज्ञापन की ज़रूरत न हो, तब उसे हटा देना चाहिए. dispose() को कब कॉल करना है, इसका सबसे सही तरीका FullScreenContentCallback.onAdDismissedFullScreenContent और FullScreenContentCallback.onAdFailedToShowFullScreenContent कॉलबैक में है.

हो गया! अब आपका ऐप्लिकेशन पेज पर अचानक दिखने वाले विज्ञापन दिखाने के लिए तैयार है.

अगले चरण

GitHub पर उदाहरण देखें

अचानक दिखने वाला (इंटरस्टीशियल) विज्ञापन