Skip to content

Rewarded

To use rewarded ads, you need to request their load at some point in the app; we recommend doing so as soon as possible. This can be done by using the following code:

import { RNWortiseRewarded } from '@wortise/react-native-sdk';
RNWortiseRewarded.setAdUnitId('Wortise Ad Unit ID');
RNWortiseRewarded.loadAd();

The setAdUnitId() method must be called once, before loadAd(). Calling it again discards the ad that was already loaded.

Next, to show the ad in the desired moment, you can use the showAd() and isAvailable methods as shown in the following example:

if (await RNWortiseRewarded.isAvailable) {
RNWortiseRewarded.showAd();
}

Some listeners can be added to receive the different events that may occur during the ad lifecycle. For this, you need to use the addEventListener method and specify which event type to receive, which can be one of the following:

  • onRewardedClicked
  • onRewardedCompleted
  • onRewardedDismissed
  • onRewardedFailedToLoad
  • onRewardedFailedToShow
  • onRewardedImpression
  • onRewardedLoaded
  • onRewardedRevenuePaid
  • onRewardedShown

The addEventListener method returns a subscription, which must be removed when the listener is no longer needed (for example, when the component is unmounted):

useEffect(() => {
const subscriptions = [
RNWortiseRewarded.addEventListener('onRewardedCompleted', ({ amount, label, success }) => {
// The callback will be invoked when the ad is completed. The reward
// must only be granted when "success" is true
}),
RNWortiseRewarded.addEventListener('onRewardedLoaded', () => {
// The callback will be invoked when an ad is loaded
})
];
return () => subscriptions.forEach((subscription) => subscription.remove());
}, []);