Implementing Reward Ads

How-to guide to implementing rewarded ads on Pley.

πŸ“˜

Requires Pley SDK 5.1.0 or later

Read more here.

🚧

Experimental Feature

Rewarded Ads on Pley are powered by Google Adsense H5 Games - Google's flagship ad product for web gaming. It will improve over time, both in Pley's features and the quality of Google Ads.

For now, it is in an experimental state - giving you an easy way to upsell users to covert to payers through rewarded ads.

  1. Call AdsKit.CanShowAdAsync when the game displays a reward ad button.
    If true, enable/show the button which initiates the reward ad.
  2. Call AdsKit.ShowRewardAd.
    If it returns PleyResult.Ok, grant the user the reward.
//Check if an ad is available. Returns true or false.
var (canShowAdResult, canShowRewardAd) = await AdsKit.CanShowRewardAdAsync();

//If canShowRewardAd == true, show the button to initiate a rewarded ad.



//Show the rewarded ad to the user. Returns PleyResult.Ok or PleyResult.AdkDismissed
var showRewardAdResult = await AdsKit.ShowRewardAdAsync();

//If showRewardAdResult == PleyResult.Ok, grant the user their reward.

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: User gets a reward, and the game lets them watch an ad to double their reward.

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
		}
}