Rewarded interstitial is a type of incentivized ad format that lets you offer rewards for ads that appear automatically during natural app transitions. Unlike rewarded ads, users aren't required to opt-in to view a rewarded interstitial.
পূর্বশর্ত
- শুরু করুন নির্দেশিকাটি সম্পূর্ণ করুন।
সর্বদা পরীক্ষামূলক বিজ্ঞাপন দিয়ে পরীক্ষা করুন
The following sample code contains an ad unit ID which you can use to request test ads. It's been specially configured to return test ads rather than production ads for every request, making it safe to use.
However, after you've registered an app in the Ad Manager web interface and created your own ad unit IDs for use in your app, explicitly configure your device as a test device during development.
/21775744923/example/rewarded-interstitial
মোবাইল বিজ্ঞাপন SDK চালু করুন
বিজ্ঞাপন লোড করার আগে, আপনার অ্যাপটিকে MobileAds.Initialize() কল করে Google Mobile Ads Unity Plugin চালু করতে বলুন। এটি শুধুমাত্র একবার করতে হবে, আদর্শভাবে অ্যাপ লঞ্চের সময়।
using GoogleMobileAds;
using GoogleMobileAds.Api;
public class GoogleMobileAdsDemoScript : MonoBehaviour
{
public void Start()
{
// Initialize Google Mobile Ads Unity Plugin.
MobileAds.Initialize((InitializationStatus initStatus) =>
{
// This callback is called once the MobileAds SDK is initialized.
});
}
}
যদি আপনি মধ্যস্থতা ব্যবহার করেন, তাহলে বিজ্ঞাপন লোড করার আগে কলব্যাক না হওয়া পর্যন্ত অপেক্ষা করুন কারণ এটি নিশ্চিত করবে যে সমস্ত মধ্যস্থতা অ্যাডাপ্টার শুরু হয়েছে।
বাস্তবায়ন
পুরস্কৃত ইন্টারস্টিশিয়াল বিজ্ঞাপনগুলিকে একীভূত করার প্রধান ধাপগুলি হল:
- পুরস্কৃত ইন্টারস্টিশিয়াল বিজ্ঞাপনটি লোড করুন
- [ঐচ্ছিক] সার্ভার-সাইড যাচাইকরণ (SSV) কলব্যাক যাচাই করুন
- পুরষ্কার কলব্যাক সহ পুরস্কৃত ইন্টারস্টিশিয়াল বিজ্ঞাপনটি দেখান
- পুরস্কৃত ইন্টারস্টিশিয়াল বিজ্ঞাপন ইভেন্টগুলি শুনুন
- পুরস্কৃত ইন্টারস্টিশিয়াল বিজ্ঞাপনটি পরিষ্কার করুন
- পরবর্তী পুরস্কৃত ইন্টারস্টিশিয়াল বিজ্ঞাপনটি প্রিলোড করুন
পুরস্কৃত ইন্টারস্টিশিয়াল বিজ্ঞাপনটি লোড করুন
RewardedInterstitialAd ক্লাসে স্ট্যাটিক Load() পদ্ধতি ব্যবহার করে একটি পুরস্কৃত ইন্টারস্টিশিয়াল বিজ্ঞাপন লোড করা হয়। লোড পদ্ধতিতে একটি বিজ্ঞাপন ইউনিট আইডি, একটি AdManagerAdRequest অবজেক্ট এবং একটি সমাপ্তি হ্যান্ডলার প্রয়োজন হয় যা বিজ্ঞাপন লোডিং সফল বা ব্যর্থ হলে কল করা হয়। লোড করা RewardedInterstitialAd অবজেক্টটি সমাপ্তি হ্যান্ডলারে একটি প্যারামিটার হিসাবে সরবরাহ করা হয়। নীচের উদাহরণটি দেখায় কিভাবে একটি RewardedInterstitialAd লোড করতে হয়।
// This ad unit is configured to always serve test ads.
private string _adUnitId = "/21775744923/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) কলব্যাক যাচাই করুন
Apps that require extra data in server-side verification callbacks should use the custom data feature of rewarded interstitial ads. Any string value set on a rewarded ad object is passed to the custom_data query parameter of the SSV callback. If no custom data value is set, the custom_data query parameter value won't be included in the SSV callback.
নিম্নলিখিত কোড নমুনাটি দেখায় যে পুরস্কৃত ইন্টারস্টিশিয়াল বিজ্ঞাপন লোড হওয়ার পরে কীভাবে 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);
});
আপনি যদি কাস্টম পুরষ্কার স্ট্রিং সেট করতে চান, তাহলে বিজ্ঞাপন দেখানোর আগে আপনাকে তা করতে হবে।
পুরষ্কার কলব্যাক সহ পুরস্কৃত ইন্টারস্টিশিয়াল বিজ্ঞাপনটি দেখান
When presenting your ad, you must provide a callback to handle the reward for the user. Ads can only be shown once per load. Use the CanShowAd() method to verify that the ad is ready to be shown.
নিম্নলিখিত কোডটি একটি পুরস্কৃত ইন্টারস্টিশিয়াল বিজ্ঞাপন প্রদর্শনের জন্য সর্বোত্তম পদ্ধতি উপস্থাপন করে।
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 is a one-time-use object. This means once a rewarded interstitial ad is shown, the object can't be used again. To request another rewarded interstitial ad, you'll need to load a new RewardedInterstitialAd object.
To prepare an rewarded interstitial ad for the next impression opportunity, preload the rewarded interstitial ad once the OnAdFullScreenContentClosed or OnAdFullScreenContentFailed ad event is raised.
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 উদাহরণ : সকল বিজ্ঞাপন ফর্ম্যাটের একটি ন্যূনতম বাস্তবায়ন।