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

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

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

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

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

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

Android

iOS

Mobile Ads SDK शुरू करें

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

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. [ज़रूरी नहीं] सर्वर साइड वेरिफ़िकेशन (SSV) कॉलबैक की पुष्टि करें
  3. इनाम वाले कॉलबैक के साथ इनाम वाला इंटरस्टीशियल विज्ञापन दिखाएं
  4. इनाम वाले इंटरस्टीशियल विज्ञापन के इवेंट सुनें
  5. इनाम वाले इंटरस्टीशियल विज्ञापन को हटाएं
  6. इनाम वाले अगले पेज पर अचानक दिखने वाला अगला विज्ञापन पहले से लोड करें

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

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


  // This ad unit is configured to always serve test ads.
  private string _adUnitId = "/6499/example/rewarded-interstitial";

  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 AdManagerAdRequest();
      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;
          });
  }

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

जिन ऐप्लिकेशन को सर्वर साइड से पुष्टि के लिए ज़्यादा डेटा की ज़रूरत होती है उन्हें इनाम वाले इंटरस्टीशियल विज्ञापनों की कस्टम डेटा सुविधा का इस्तेमाल करना चाहिए. इनाम वाले विज्ञापन ऑब्जेक्ट पर सेट की गई किसी भी स्ट्रिंग की वैल्यू को एसएसवी कॉलबैक के 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();
    };
}

अन्य संसाधन