Rewarded Ad
In v6.0.0 the class was renamed from RewardedVideoAd to RewardedAd, and the reward event from
OnUserRewardEarned to OnAdRewardEarned, for naming parity across formats. Existing v3.x code
will not compile against v6.0.0 without these renames.
For a working implementation of this ad format, see the bluestack-demo-unity demo app.
Integration
Step 1. Instantiate Rewarded Ad
You can instantiate a RewardedAd right after the SDK finishes initialization.
Pass the platform-specific rewarded placement id to the RewardedAd constructor.
public class BlueStackAdsController : MonoBehaviour
{
private RewardedAd _rewardedAd;
void Start()
{
BlueStackAds.SetDebugMode(true);
BlueStackAds.Initialize("app_id", HandleInitCompleteAction);
}
private void HandleInitCompleteAction(InitializationStatus status)
{
_rewardedAd = new RewardedAd(placementId);
}
}
Step 2. Register event listeners
RewardedAd exposes the following events through its lifecycle.
| Event | Payload | Definition |
|---|---|---|
OnAdLoaded | EventArgs | Ad finished loading and is ready to be shown. |
OnAdFailedToLoad | BlueStackError | The ad failed to load. |
OnAdDisplayed | EventArgs | The ad has appeared on screen. |
OnAdFailedToDisplay | BlueStackError | The ad failed to display after Show() was called. |
OnAdClicked | EventArgs | The user clicked the ad. |
OnAdRewardEarned | RewardedItem | The user earned a reward (typically after watching the video to completion). The payload's Amount and Type may be unset depending on the mediation network. |
OnAdDismissed | EventArgs | The user dismissed the ad. Fired whether or not a reward was earned. |
_rewardedAd.OnAdLoaded += (sender, args) =>
{
Debug.Log("OnAdLoaded");
};
_rewardedAd.OnAdFailedToLoad += (sender, error) =>
{
Debug.LogError("OnAdFailedToLoad: " + error.Message);
};
_rewardedAd.OnAdDisplayed += (sender, args) =>
{
Debug.Log("OnAdDisplayed");
};
_rewardedAd.OnAdFailedToDisplay += (sender, error) =>
{
Debug.LogError("OnAdFailedToDisplay: " + error.Message);
};
_rewardedAd.OnAdClicked += (sender, args) =>
{
Debug.Log("OnAdClicked");
};
_rewardedAd.OnAdRewardEarned += (sender, reward) =>
{
Debug.Log("OnAdRewardEarned reward: '" + reward?.Type + "', amount: " + reward?.Amount);
};
_rewardedAd.OnAdDismissed += (sender, args) =>
{
Debug.Log("OnAdDismissed");
};
Make sure you only register event listeners once.
Step 3. Load Rewarded ad
RewardedAd exposes two Load overloads — one with no parameters, and one taking a Preference instance.
There must be a delay of at least 5 seconds between each rewarded ad Load call.
- Without
Preference
_rewardedAd.Load();
- With
Preference
public class BlueStackAdsController : MonoBehaviour
{
...
private void RequestRewardedAd()
{
Preference _preference = new Preference();
Location myLocation = new Location(Location.NONE_PROVIDER)
{
Latitude = 35.757866,
Longitude = 10.810547
};
_preference.SetAge(25);
_preference.SetLanguage("en");
_preference.SetGender(Gender.Male);
_preference.SetKeyword("brand=myBrand;category=sport");
_preference.SetLocation(myLocation, 1);
_preference.SetContentUrl("https://console.bluestack.app");
_rewardedAd.Load(_preference);
}
...
}
Note:
The SetLocation method takes the following parameters:
- The
Locationinstance. - The CONSENT_FLAG value (corresponds to a int: 0, 1, 2 or 3).
- 0 = Do not send location.
- 1 = Managed location according to consent value.
- 2 and 3 = Allow the SDK to manage location directly in accordance with the consent value (TCF v1 / TCF v2). Check with the Azerion team — behavior depends on your implementation.
Step 4. Display Rewarded ad
After the ad has loaded, request it to be displayed. Check IsReady to confirm the ad is loaded before calling Show().
if (_rewardedAd.IsReady)
{
_rewardedAd.Show();
}
Equivalently, gate on OnAdLoaded:
_rewardedAd.OnAdLoaded += (sender, args) =>
{
_rewardedAd.Show();
};
Destroy Rewarded ad
Destroy the rewarded ad before creating a new one.
_rewardedAd.Destroy();