इनाम पाने वाले

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

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

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

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

  • /6499/example/rewarded

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

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

यहां दिए गए उदाहरण में, इनाम वाले विज्ञापन को लोड किया गया है:

class RewardedExampleState extends State<RewardedExample> {
  RewardedAd? _rewardedAd;

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

  /// Loads a rewarded ad.
  void loadAd() {
    RewardedAd.loadWithAdManagerAdRequest(
        adUnitId: adUnitId,
        adManagerAdRequest: const AdManagerAdRequest(),
        adLoadCallback: RewardedAdLoadCallback(
          // Called when an ad is successfully received.
          onAdLoaded: (ad) {
            debugPrint('$ad loaded.');
            // Keep a reference to the ad so you can show it later.
            _rewardedAd = ad;
          },
          // Called when an ad request failed.
          onAdFailedToLoad: (LoadAdError error) {
            debugPrint('RewardedAd failed to load: $error');
          },
        ));
  }
}

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

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

class RewardedExampleState extends State<RewardedExample> {
  RewardedAd? _rewardedAd;

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

  /// Loads a rewarded ad.
  void loadAd() {
    RewardedAd.loadWithAdManagerAdRequest(
        adUnitId: adUnitId,
        adManagerAdRequest: const AdManagerAdRequest(),
        adLoadCallback: RewardedAdLoadCallback(
          // 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.
            _rewardedAd = ad;
          },
          // Called when an ad request failed.
          onAdFailedToLoad: (LoadAdError error) {
            debugPrint('RewardedAd failed to load: $error');
          },
        ));
  }
}

Display Network में दिखने वाला विज्ञापन

RewardedAd को ऐप्लिकेशन के सभी कॉन्टेंट के सबसे ऊपर ओवरले के तौर पर दिखाया जाता है और स्थिर रूप से रखा गया हो; इसलिए, इसे Flutter विजेट ट्री में नहीं जोड़ा जा सकता. आप show() पर कॉल करके चुनें कि विज्ञापन कब दिखाना है. RewardedAd.show() एक OnUserEarnedRewardCallback लेता है, जिसका शुरू होना तब होता है, जब जब उपयोगकर्ता को कोई इनाम मिलता है. इसे लागू करें और उपयोगकर्ता को इसके लिए इनाम दें कोई विज्ञापन देखते समय.

_rewardedAd.show(onUserEarnedReward: (AdWithoutView ad, RewardItem rewardItem) {
  // Reward the user for watching an ad.
});

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

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

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