Rewarded Ad
Rewarded ads are full-screen video ads that users can choose to watch in exchange for in-app rewards. These ads provide a great way to monetize your app while offering value to users.
Integration
Step 1. Import component
You need to import bluestack_sdk.dart
in order to display BlueStack rewarded ads.
import 'package:bluestack_sdk_flutter/bluestack_sdk.dart';
Step 2. Create Rewarded ad
You have to pass the platform-specific rewarded placement ID while creating an instance of RewardedAd
// Create an rewarded ad instance
rewardedAd = RewardedAd('/YOUR_APP_ID/rewardedVideo');
Step 3. Load Rewarded ad
You can load a Rewarded ad using load
method, right after SDK finishes it's initialization.
Here are examples of how to load an rewarded ad:
rewardedAd?.load();
With "RequestOptions":
/// [options] Optional parameters for customizing the ad request.
rewardedAd?.load(options: requestOptions);
View the RequestOptions documentation for more details.
Step 4. Display Rewarded ad
After loading the rewarded ad you can request it to be displayed using show
method.
Listen to rewarded ad events to make sure the ad was successfully loaded before you call show
method
Here's an example of how to show an rewarded ad:
rewardedAd?.show();
Step 5. Register event listeners
Register for rewarded ad events before loading RewardedAd.
RewardedAd exposes the following ad loading events through it's lifecycle.
Events | Definition |
---|---|
onAdLoaded | Ad is successfully loaded and SDK is ready to display the ad. |
onAdFailedToLoad | The ad failed to load. |
Here's an example of how to register load event listeners for rewarded ads:
// Set up load event listeners
rewardedAd.setLoadEventListener(RewardedAdLoadEventListener(
onAdLoaded: () {
print('Rewarded ad loaded');
},
onAdFailedToLoad: (error) {
print('Rewarded ad failed to load: ${error.message}');
},
));
RewardedAd exposes the following ad show events through it's lifecycle.
Events | Definition |
---|---|
onAdDisplayed | Ad has appeared on the screen. |
onAdFailedToDisplay | The ad failed to display. |
onAdClicked | User has clicked the ad. Ad may open a link in browser. |
onAdDismissed | The ad has disappeared. |
onRewardEarned | SDK will fire this event with rewardType and rewardAmount depending on mediation ad network |
Here's an example of how to register show event listeners for rewarded ads:
// Set up show event listeners
rewardedAd.setShowEventListener(RewardedAdShowEventListener(
onAdDisplayed: () {
print('Rewarded ad displayed');
},
onAdFailedToDisplay: (error) {
print('Rewarded ad failed to display: ${error.message}');
},
onAdDismissed: () {
print('Rewarded ad dismissed');
},
onAdClicked: () {
print('Rewarded ad clicked');
},
onRewarded: (reward) {
print('Rewarded: ${reward.type} - ${reward.amount}');
},
));
Dispose rewarded ad
You can dispose the rewarded using dispose
method
// Don't forget to dispose when done
rewardedAd.dispose();
Best Practices
- Loading: Pre-load rewarded ads before they're needed
- Showing: Check if rewarded was successfully loaded before trying to show
- Event Handling: Make sure you only register event listeners once.
- Error Handling: Always implement error handlers
- Memory Management: Call
dispose()
when the ad is no longer needed
Troubleshooting
Common issues and solutions:
-
Ad Not Loading
- Check internet connectivity
- Verify placement ID
- Ensure SDK is properly initialized
-
Ad Not Showing
- Verify that
load()
was called successfully - Check if rewarded was successfully loaded before trying to show
- Ensure proper timing of
show()
call
- Verify that
-
Memory Issues
- Always call
dispose()
when done - Don't create multiple instances unnecessarily
- Always call