Implementing Ads
How-to guide to implementing rewarded ads on Pley.
Interstitial Ads available!
As of Pley Game SDK 5.7.1 ads are no longer in the experimental namespace, and interstitial ads are available everywhere ads are served.
Ads are also now much more reliable as we are getting direct assitance from the Google Adsense for Games team.
Pley supports rewarded and interstitial ads on all platforms which can run ads.
- Call
AdsKit.CanShowAdAsync(PleyAdType.Reward)
when the game displays a reward ad button.
If true, enable/show the button that initiates the reward ad. - Call
AdsKit.ShowRewardAd(PleyAdType.Reward)
.
If it returnsPleyResult.Ok
, grant the user the reward.
Type | Code |
---|---|
Rewarded Ad | PleyAdType.Reward |
Interstitial Ad | PleyAdType.Interstitial |
Example #1: Rewarded Ads.
/// <summary>
/// Rewarded ad handler example
/// </summary>
public class RewardedAdExample : MonoBehaviour
{
[SerializeField] private Button rewardButton;
private bool canShowAd;
/// <summary>
/// Check if reward ad available
/// </summary>
private async void CheckRewardAd()
{
var (result, available) = await AdsKit.CanShowRewardAdAsync(AdType.Reward);
if (result.IsOk()) {
canShowAd = available;
rewardButton.interactable = available;
}
}
/// <summary>
/// Show reward ad and grant reward if completed
/// </summary>
private async void ShowRewardAd()
{
if (!canShowAd) return;
canShowAd = false;
rewardButton.interactable = false;
var result = await AdsKit.ShowRewardAdAsync(AdType.Reward);
if (result.IsOk()) {
GrantReward();
}
}
private void GrantReward() {
// Add reward logic here
}
}
Example #2: Interstitial (with more logging).
/// <summary>
/// Interstitial ad handler example
/// </summary>
public class AdExample : MonoBehaviour
{
[SerializeField] private Button adButton;
private bool canShowAd;
/// <summary>
/// Check if interstitial ad can be shown
/// </summary>
private async void CheckAdAvailability()
{
var (result, available) = await AdService.CanShowAdAsync(AdType.Interstitial);
if (result.IsOk()) {
canShowAd = available;
adButton.interactable = available;
Debug.Log(available ? "Ad ready" : "Ad not available");
}
}
/// <summary>
/// Show interstitial ad if available
/// </summary>
private async void ShowAd()
{
if (!canShowAd) {
Debug.LogError("Check availability first");
return;
}
canShowAd = false;
adButton.interactable = false;
var result = await AdService.ShowAdAsync(AdType.Interstitial);
Debug.Log(result.IsOk() ? "Ad shown" : "Ad failed");
}
}
It is very important that AdsKit.CanShowAdAsync
is called at one time before each call to AdsKit.ShowRewardAd
. This needs to be done to prepare the Google AdSense script and to check if your game can show an ad at this time.
Coded Example

Example code: The user gets a reward, and the game lets them watch an ad to double their reward.
private Button _doubleRewardButton;
void Awake()
{
_doubleRewardButton.onClick.AddListener(ShowDoubleRewardAd);
}
async void OpenRewardWindow()
{
// Triggers when the view above is initialized.
//
var (canShowAdResult, canShowRewardAd) = await AdsKit.CanShowRewardAdAsync();
// If we can not show the ad at this time disable/hide the doubleRewardAdButton
_doubleRewardButton.gameObject.SetActive(canShowRewardAd);
}
async void ShowDoubleRewardAd()
{
// Triggers when the "Double" button is pressed
//
var showRewardAdResult = await AdsKit.ShowRewardAdAsync();
if (showRewardAdResult == PleyResult.Ok)
{
// Give double rewards to the user.
return;
}
if (showRewardAdResult == PleyResult.AdkDismissed)
{
// The reward ad was dismissed/canceled by the user
}
else
{
// Reward ad failed to show
}
}
Finally, you must enable ads in the Game Manager.
And then the user will watch their ad, and get the reward!

Test-ads and real ads
When runnings games locally or in the Game Manager, all ads will be sandboxed. This means they are in "test" mode, and no real ads will be shown. It can be trusted for game-client implementation testing.
If you need to run real ads, you need to make a release track release and play there.
Updated 5 days ago