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

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

ग्राहकों की सफलता की कहानियां पढ़ें: केस स्टडी 1, केस स्टडी 2.

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

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

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

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

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

Android

ca-app-pub-3940256099942544/5224354917

iOS

ca-app-pub-3940256099942544/1712485313

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. इनाम वाले अगले विज्ञापन को पहले से लोड करें

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

इनाम वाले विज्ञापन को RewardedAd क्लास में स्टैटिक Load() तरीके से लोड किया जाता है. लोड किए गए RewardedAd ऑब्जेक्ट को, पूरा होने वाले हैंडलर में पैरामीटर के तौर पर दिया जाता है. नीचे दिए गए उदाहरण में RewardedAd को लोड करने का तरीका बताया गया है.


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

  private RewardedAd _rewardedAd;

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

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

      // create our request used to load the ad.
      var adRequest = new AdRequest();

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

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

              _rewardedAd = ad;
          });
  }

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

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

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

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

    // If the operation completed successfully, no error is returned.
    Debug.Log("Rewarded 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 ShowRewardedAd()
{
    const string rewardMsg =
        "Rewarded ad rewarded the user. Type: {0}, amount: {1}.";

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

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

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

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

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

जब आप RewardedAd का काम पूरा कर लें, तो उसमें अपना रेफ़रंस देने से पहले Destroy() तरीके को कॉल करना न भूलें:

_rewardedAd.Destroy();

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

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

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

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

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

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

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

अन्य संसाधन