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

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

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

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

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

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

Android

ca-app-pub-3940256099942544/5354046379

iOS

ca-app-pub-3940256099942544/6978759866

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. [ज़रूरी नहीं] सर्वर-साइड वेरिफ़िकेशन (एसएसवी) कॉलबैक की पुष्टि करें
  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;
          });
  }

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

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

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

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

अन्य संसाधन