Aller au contenu principal

Rewarded Ad

Integration

Step 1. Import component

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

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

Step 2. Load Rewarded ad

You can load a Rewarded ad right after SDK finishes it's initialization. You have to pass the platform specific Rewarded ad placement id in loadAd method.

Here's an example of how to load an rewarded ad:

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

View the AdPreference documentation for more details about ad preferences.

Step 3. Display Rewarded ad

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

info

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

Here's an example of how to load an rewarded ad:

RewardedAdManager.displayAd();

Step 2. Register event listeners

Rewarded Ad exposes the following events through it's lifecycle. Register for rewarded ad events before loading 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

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 event listener once.