Aller au contenu principal

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.

info

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.

EventsDefinition
onAdLoadedAd is successfully loaded and SDK is ready to display the ad.
onAdFailedToLoadThe 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.

EventsDefinition
onAdDisplayedAd has appeared on the screen.
onAdFailedToDisplayThe ad failed to display.
onAdClickedUser has clicked the ad. Ad may open a link in browser.
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 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

  1. Loading: Pre-load rewarded ads before they're needed
  2. Showing: Check if rewarded was successfully loaded before trying to show
  3. Event Handling: Make sure you only register event listeners once.
  4. Error Handling: Always implement error handlers
  5. Memory Management: Call dispose() when the ad is no longer needed

Troubleshooting

Common issues and solutions:

  1. Ad Not Loading

    • Check internet connectivity
    • Verify placement ID
    • Ensure SDK is properly initialized
  2. 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
  3. Memory Issues

    • Always call dispose() when done
    • Don't create multiple instances unnecessarily