इनाम वाले इंटरस्टीशियल विज्ञापन (बीटा)

प्लैटफ़ॉर्म चुनें: Android iOS Unity Flutter

इनाम वाले इंटरस्टीशियल विज्ञापन, इंसेंटिव वाले विज्ञापन फ़ॉर्मैट का एक टाइप है. इसकी मदद से, ऐप्लिकेशन में स्वाभाविक तौर पर हुए ट्रांज़िशन के दौरान दिखने वाले विज्ञापनों के लिए इनाम दिए जा सकते हैं. उपयोगकर्ताओं को इनाम वाले इंटरस्टीशियल विज्ञापन देखने के लिए, ऑप्ट-इन करना ज़रूरी नहीं होता. इनाम वाले विज्ञापनों के लिए ऐसा करना ज़रूरी है.

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

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

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

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

Android

ca-app-pub-3940256099942544/5354046379

iOS

ca-app-pub-3940256099942544/6978759866

Mobile Ads SDK को शुरू करना

विज्ञापन लोड करने से पहले, अपने ऐप्लिकेशन में Mobile Ads SDK को शुरू करें. इसके लिए, MobileAds.Initialize() को कॉल करें. इसे सिर्फ़ एक बार करना होता है. सबसे सही समय, ऐप्लिकेशन लॉन्च करने के दौरान होता है.

using GoogleMobileAds;
using GoogleMobileAds.Api;

public class GoogleMobileAdsDemoScript : MonoBehaviour
{
    public void Start()
    {
        // Initialize the Google Mobile Ads SDK.
        MobileAds.Initialize((InitializationStatus initStatus) =>
        {
            // This callback is called once the MobileAds SDK is initialized.
        });
    }
}

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

लागू करना

इनाम वाले इंटरस्टीशियल विज्ञापनों को इंटिग्रेट करने के लिए, यह तरीका अपनाएं:

  1. इनाम वाले इंटरस्टीशियल विज्ञापन को लोड करना
  2. [ज़रूरी नहीं] सर्वर साइड से की जाने वाली पुष्टि (एसएसवी) के कॉलबैक की पुष्टि करना
  3. इनाम वाले इंटरस्टीशियल विज्ञापन को इनाम वाले कॉलबैक के साथ दिखाएं
  4. इनाम वाले इंटरस्टीशियल विज्ञापन के इवेंट सुनना
  5. इनाम वाले इंटरस्टीशियल विज्ञापन को ठीक करना
  6. अगले इनाम वाले इंटरस्टीशियल विज्ञापन को पहले से लोड करना

इनाम वाले इंटरस्टीशियल विज्ञापन को लोड करना

इनाम वाले इंटरस्टीशियल विज्ञापन को लोड करने के लिए, RewardedInterstitialAd क्लास में स्टैटिक Load() मेथड का इस्तेमाल किया जाता है. लोड करने के तरीके के लिए, विज्ञापन यूनिट आईडी, AdRequest ऑब्जेक्ट, और पूरा होने वाला हैंडलर ज़रूरी होता है. विज्ञापन लोड होने पर या लोड न होने पर, इसे कॉल किया जाता है. लोड किया गया RewardedInterstitialAd ऑब्जेक्ट, कंप्लीशन हैंडलर में पैरामीटर के तौर पर दिया जाता है. यहां दिए गए उदाहरण में, RewardedInterstitialAd को लोड करने का तरीका बताया गया है.


  // These ad units are configured to always serve test ads.
#if UNITY_ANDROID
  private string _adUnitId = "ca-app-pub-3940256099942544/5354046379";
#elif UNITY_IPHONE
  private string _adUnitId = "ca-app-pub-3940256099942544/6978759866";
#else
  private string _adUnitId = "unused";
#endif

  private RewardedInterstitialAd _rewardedInterstitialAd;

  /// <summary>
  /// Loads the rewarded interstitial ad.
  /// </summary>
  public void LoadRewardedInterstitialAd()
  {
      // Clean up the old ad before loading a new one.
      if (_rewardedInterstitialAd != null)
      {
            _rewardedInterstitialAd.Destroy();
            _rewardedInterstitialAd = null;
      }

      Debug.Log("Loading the rewarded interstitial ad.");

      // create our request used to load the ad.
      var adRequest = new AdRequest();
      adRequest.Keywords.Add("unity-admob-sample");

      // send the request to load the ad.
      RewardedInterstitialAd.Load(_adUnitId, adRequest,
          (RewardedInterstitialAd ad, LoadAdError error) =>
          {
              // if error is not null, the load request failed.
              if (error != null || ad == null)
              {
                  Debug.LogError("rewarded interstitial ad failed to load an ad " +
                                 "with error : " + error);
                  return;
              }

              Debug.Log("Rewarded interstitial ad loaded with response : "
                        + ad.GetResponseInfo());

              _rewardedInterstitialAd = ad;
          });
  }

[ज़रूरी नहीं] सर्वर साइड से की जाने वाली पुष्टि (एसएसवी) के कॉलबैक की पुष्टि करना

जिन ऐप्लिकेशन को सर्वर साइड से की जाने वाली पुष्टि के कॉलबैक में अतिरिक्त डेटा की ज़रूरत होती है उन्हें इनाम वाले इंटरस्टीशियल विज्ञापनों की कस्टम डेटा सुविधा का इस्तेमाल करना चाहिए. इनाम वाले विज्ञापन ऑब्जेक्ट पर सेट की गई कोई भी स्ट्रिंग वैल्यू, एसएसवी कॉलबैक के custom_data क्वेरी पैरामीटर को पास की जाती है. अगर कोई कस्टम डेटा वैल्यू सेट नहीं की जाती है, तो custom_data क्वेरी पैरामीटर की वैल्यू को एसएसवी कॉलबैक में शामिल नहीं किया जाएगा.

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

// send the request to load the ad.
RewardedInterstitialAd.Load(_adUnitId,
                            adRequest,
                            (RewardedInterstitialAd ad, LoadAdError error) =>
    {
        // If the operation failed, an error is returned.
        if (error != null || ad == null)
        {
            Debug.LogError("Rewarded interstitial ad failed to load an ad " +
                           " with error : " + error);
            return;
        }

        // If the operation completed successfully, no error is returned.
        Debug.Log("Rewarded interstitial ad loaded with response : " +
                   ad.GetResponseInfo());
        
        // Create and pass the SSV options to the rewarded ad.
        var options = new ServerSideVerificationOptions
                              .Builder()
                              .SetCustomData("SAMPLE_CUSTOM_DATA_STRING")
                              .Build()
        ad.SetServerSideVerificationOptions(options);
        
});

अगर आपको कस्टम इनाम स्ट्रिंग सेट करनी है, तो आपको विज्ञापन दिखाने से पहले ऐसा करना होगा.

इनाम वाले इंटरस्टीशियल विज्ञापन को इनाम वाले कॉलबैक के साथ दिखाएं

विज्ञापन दिखाते समय, आपको उपयोगकर्ता को इनाम देने के लिए कॉलबैक फ़ंक्शन उपलब्ध कराना होगा. विज्ञापन, हर लोड पर सिर्फ़ एक बार दिखाए जा सकते हैं. CanShowAd() तरीके का इस्तेमाल करके, यह पुष्टि करें कि विज्ञापन दिखाने के लिए तैयार है.

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

public void ShowRewardedInterstitialAd()
{
    const string rewardMsg =
        "Rewarded interstitial ad rewarded the user. Type: {0}, amount: {1}.";

    if (rewardedInterstitialAd != null && rewardedInterstitialAd.CanShowAd())
    {
        rewardedInterstitialAd.Show((Reward reward) =>
        {
            // TODO: Reward the user.
            Debug.Log(String.Format(rewardMsg, reward.Type, reward.Amount));
        });
    }
}

इनाम वाले इंटरस्टीशियल विज्ञापन के इवेंट सुनना

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

private void RegisterEventHandlers(RewardedInterstitialAd ad)
{
    // Raised when the ad is estimated to have earned money.
    ad.OnAdPaid += (AdValue adValue) =>
    {
        Debug.Log(String.Format("Rewarded interstitial ad paid {0} {1}.",
            adValue.Value,
            adValue.CurrencyCode));
    };
    // Raised when an impression is recorded for an ad.
    ad.OnAdImpressionRecorded += () =>
    {
        Debug.Log("Rewarded interstitial ad recorded an impression.");
    };
    // Raised when a click is recorded for an ad.
    ad.OnAdClicked += () =>
    {
        Debug.Log("Rewarded interstitial ad was clicked.");
    };
    // Raised when an ad opened full screen content.
    ad.OnAdFullScreenContentOpened += () =>
    {
        Debug.Log("Rewarded interstitial ad full screen content opened.");
    };
    // Raised when the ad closed full screen content.
    ad.OnAdFullScreenContentClosed += () =>
    {
        Debug.Log("Rewarded interstitial ad full screen content closed.");
    };
    // Raised when the ad failed to open full screen content.
    ad.OnAdFullScreenContentFailed += (AdError error) =>
    {
        Debug.LogError("Rewarded interstitial ad failed to open " +
                       "full screen content with error : " + error);
    };
}

इनाम वाले इंटरस्टीशियल विज्ञापन को ठीक करना

RewardedInterstitialAd का इस्तेमाल करने के बाद, यह पक्का करें कि आपने इसका रेफ़रंस हटाने से पहले, Destroy() तरीके को कॉल किया हो:

_rewardedInterstitialAd.Destroy();

इससे प्लगिन को सूचना मिलती है कि अब ऑब्जेक्ट का इस्तेमाल नहीं किया जा रहा है. साथ ही, यह सूचना भी मिलती है कि ऑब्जेक्ट के लिए इस्तेमाल की गई मेमोरी को वापस लिया जा सकता है. इस तरीके को कॉल न करने पर, मेमोरी लीक हो सकती है.

अगले इनाम वाले इंटरस्टीशियल विज्ञापन को पहले से लोड करना

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

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

private void RegisterReloadHandler(RewardedInterstitialAd ad)
{
    // Raised when the ad closed full screen content.
    ad.OnAdFullScreenContentClosed += ()
    {
        Debug.Log("Rewarded interstitial ad full screen content closed.");

        // Reload the ad so that we can show another as soon as possible.
        LoadRewardedInterstitialAd();
    };
    // Raised when the ad failed to open full screen content.
    ad.OnAdFullScreenContentFailed += (AdError error) =>
    {
        Debug.LogError("Rewarded interstitial ad failed to open " +
                       "full screen content with error : " + error);

        // Reload the ad so that we can show another as soon as possible.
        LoadRewardedInterstitialAd();
    };
}

अन्य संसाधन

  • HelloWorld का उदाहरण: इसमें सभी विज्ञापन फ़ॉर्मैट को कम से कम लागू किया गया है.