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

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

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

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

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

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

/6499/example/rewarded-interstitial

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

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

इनाम वाले इंटरस्टीशियल विज्ञापन को लोड करने के लिए, स्टैटिक Load() का इस्तेमाल किया जाता है RewardedInterstitialAd क्लास में मेथड. लोड करने के तरीके के लिए विज्ञापन की ज़रूरत है यूनिट आईडी, 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 को पास की जाती है SSV कॉलबैक का क्वेरी पैरामीटर. अगर कोई कस्टम डेटा वैल्यू सेट नहीं है, तो एसएसवी कॉलबैक में 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();
    };
}

अन्य संसाधन

  • HeyWorld का उदाहरण: सभी विज्ञापन फ़ॉर्मैट को कम से कम तरीके से लागू करना चाहिए.