मध्यवर्ती

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

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

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

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

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

  • /6499/example/interstitial

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

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

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

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

  // TODO: replace this test ad unit with your own ad unit.
  final adUnitId = '/6499/example/interstitial';

  /// Loads an interstitial ad.
  void loadAd() {
    AdManagerInterstitialAd.load(
        adUnitId: adUnitId,
        request: const AdManagerAdRequest(),
        adLoadCallback: AdManagerInterstitialAdLoadCallback(
          // 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('AdManagerInterstitialAd failed to load: $error');
          },
        ));
  }
}

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

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

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

  // TODO: replace this test ad unit with your own ad unit.
  final adUnitId = '/6499/example/interstitial';

  /// Loads an interstitial ad.
  void loadAd() {
    AdManagerInterstitialAd.load(
        adUnitId: adUnitId,
        request: const AdManagerAdRequest(),
        adLoadCallback: AdManagerInterstitialAdLoadCallback(
          // 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('AdManagerInterstitialAd failed to load: $error');
          },
        ));
  }
}

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

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

_interstitiaAd.show();

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

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

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

अगले चरण