Aller au contenu principal
Version: 6.x.x

Rewarded Ads

Overview

Rewarded ads are full-screen, non-skippable video ads (15–30 seconds) that users voluntarily watch in exchange for in-app rewards like virtual currency, in-app items or exclusive content. After the video ends, a callback confirms completion so the reward can be granted.

Before You Start. Make sure that you have correctly integrated the BlueStack React Native Plugin into your application. Integration is outlined here.

For a working implementation of this ad format, see the azerion-inapp-demo-reactnative demo app.

Create a Rewarded Ad

You need to import the RewardedAdManager component in order to display BlueStack rewarded ads.

import { RewardedAdManager } from "@azerion/bluestack-sdk-react-native";

Load a Rewarded Ad

You can load a rewarded ad right after the SDK finishes its initialization. You have to pass the platform specific rewarded placement id to the loadAd method.

Without AdPreference

RewardedAdManager.loadAd("/" + appId + "/rewarded");

With AdPreference

To request a rewarded ad using AdPreference, provide an instance of AdPreference in the loadAd method:

/**
* Load rewarded ad.
* @param: placementId
* @param: preference (optional)
*/
RewardedAdManager.loadAd("/" + appId + "/rewarded", preference);

Ad events

Register for Rewarded events

RewardedAdManager exposes the following events through its lifecycle. Register for rewarded ad events before loading the rewarded ad.

EventsDefinition
onAdLoadedAd is successfully loaded and SDK is ready to display the ad.
onAdFailedErrorThe ad failed to load or display.
onAdClickedUser has clicked the ad. Ad may open a link in browser.
onAdDisplayedAd has appeared on the screen.
onAdDismissedThe ad has disappeared.
onRewardEarnedSDK will fire this event with rewardType and rewardAmount depending on mediation ad network

Implement Rewarded events

Here's an example of how to register event listeners for rewarded ads:

RewardedAdManager.addEventListener((event) => {
switch (event.rewardedEvent) {
case "onAdLoaded":
console.log(event.rewardedEvent);
break;
case "onAdDismissed":
console.log(event.rewardedEvent);
break;
case "onAdDisplayed":
console.log(event.rewardedEvent);
break;
case "onAdClicked":
console.log(event.rewardedEvent);
break;
case "onRewardEarned":
console.log(
"Reward Earned: Type-" +
event.rewardType +
", Amount-" +
event.rewardAmount
);
break;
case "onAdFailedError":
console.log(event.errorMessage);
break;
default:
break;
}
});

Here's an example of how to remove all event listeners:

RewardedAdManager.removeAllEventListeners();
attention

Make sure you only register the event listener once.

Show a Rewarded Ad

After loading the rewarded ad you can request it to be displayed using the displayAd method.

info

Listen to rewarded ad events to make sure the ad was successfully loaded before you call the displayAd method.

RewardedAdManager.displayAd();