After creating placements in the DT Console, add the following code snippets in the chosen context of your app. Access the Placement ID using the copy button next to the placement name. For more information about creating placements in the DT Console, read here.
DT supports the following ad types:
Banner Ads
Banners are rectangular ads that appear at the top or bottom of the screen when the user interacts with your app. The user can view banners but cannot dismiss them. The DT FairBid SDK automatically refreshes banners after 20 seconds.
Note
The DT FairBid SDK automatically refreshes banners. To avoid discrepancies between DT and third-party network reporting, disable any automatic or manual banner refresh settings on third-party network SDKs.
Showing a Banner
Implement the code below to show a Banner:
val placementId = "12345"
Banner.show(placementId, activity)
Java
String placementId = "12345";
Banner.show(placementId, activity);
extension MyViewController: FYBBannerDelegate {
func bannerDidLoad(_ banner: FYBBannerAdView, impressionData: FYBImpressionData)
{
// set up the banner constraints
myView.addSubview(banner)
banner.center = CGPoint(x: myView.frame.width / 2, y: myView.center.y)
}
…
}
Objective-C
// in implementation of FYBBannerDelegate protocol
- (void)bannerDidLoad:(FYBBannerAdView *)banner impressionData:(FYBImpressionData *)impressionData {
[self.myView addSubview:banner];
banner.center = CGPointMake(self.myView.bounds.size.width / 2, self.bounds.size.height / 2);
}
string placementId = "1234";
Banner.Show(placementId);
Hiding the Banner
If you want to hide the banner temporarily, implement the code below:
//hides the banner for a specific placement
val placementId = "12345"
Banner.hide(placementId)
Java
//hides the banner for a specific placement
String placementId = "12345";
Banner.hide(placementId);
let placementId = "1234" FYBBanner.hide(placementId)
Objective-C
NSString *placementId = @"1234"; [FYBBanner hide:placementId];
string placementId = "1234";
Banner.Hide(placementId);
Destroying the Banner
Once you have decided that you no longer want to use the banner, you must destroy it.
To destroy the banner, implement the code below:
//destroys the banner for a specific placement
val placementId = "12345"
Banner.destroy(placementId)
Java
//destroys the banner for a specific placement
String placementId = "12345";
Banner.destroy(placementId);
let placementId = "1234" FYBBanner.destroy(placementId)
Objective-C
NSString *placementId = @"1234"; [FYBBanner destroy:placementId];
string placementId = "1234";
Banner.Destroy(placementId);
Banner Position
You can show your banner at the top or bottom of your screen. If you want to change this behavior, use the following code:
Top
Kotlinval bannerOptions = BannerOptions().placeAtTheTop()
val placementId = "12345"
Banner.show(placementId, bannerOptions, activity)
Java
BannerOptions bannerOptions = new BannerOptions().placeAtTheTop();
String placementId = "12345";
Banner.show(placementId, bannerOptions, activity);
Custom View
Kotlinval bannerOptions = BannerOptions().placeInContainer(viewGroup)
val placementId = "12345"
Banner.show(placementId, bannerOptions, activity)
Java
BannerOptions bannerOptions = new BannerOptions().placeInContainer(viewGroup);
String placementId = "12345";
Banner.show(placementId, bannerOptions, activity);)
This feature is not available for iOS.
string placementId = "1234";
BannerOptions bannerOptions = new BannerOptions();
bannerOptions.DisplayAtTheTop();
Banner.Show(placementId, bannerOptions);
Loading a Banner
Important
Use this implementation only if FairBid is not your main mediation platform.
If you want to use FairBid with other mediations or demand sources, you can pre-load a banner to review its pricing and other details. This allows you to compare it against banners from other demand sources outside our platform before showing it.
To load a banner, create a BannerView
object instance and then call the load
method. Please be aware that this integration method disables banner refresh, and you must add your own refresh logic.
This is supported starting FairBid Android SDK 3.51.0.
Kotlinval bannerContainer: FrameLayout
val placementId = "12345"
val bannerView = BannerView(requireContext(), placementId)
banner.bannerListener = object : BannerListener {
//...
}
bannerView.load()
//Once the ad is loaded and ready, you can check the pre-impression data
val impressionData = bannerView.impressionData
// To show the banner, attach the bannerView to the Banner Container
bannerContainer.addView(bannerView)
//Once the banner is no longer needed, you can destroy it
bannerView.destroy()
You are responsible for adding FYBBannerAdView
instance to your view hierarchy. This FYBBannerAdView
instance is available on bannerDidLoad:impressionData:
callback
. To pre-load a banner, implement the code below:
/* 1. Assign FYBBannerDelegate instance to handle banner events */
FYBBanner.delegate = self
/* 2. Define the banner placement ID
Replace `placementId` with your actual banner placement ID */
let placementId = "<#banner placementId#>"
/* 3. Initialize a new FYBBannerOptions instance with a specified placement ID and size.
FYBBannerSizeSmart automatically adjusts the banner size based on the device's screen width. */
let bannerOptions = FYBBannerOptions(placementId: placementId, size: .smart)
/* 4. Request to load a banner ad with the specified options.
This method fetches the banner creative but does not show it. */
FYBBanner.request(with: bannerOptions)
Objective-C
#import <FairBidSDK/FairBid.h>
/// 1. Assign FYBBannerDelegate instance to handle banner events
FYBBanner.delegate = self;
/// 2. Define the banner placement ID
/// Replace banner placementId with your actual banner placement id
NSString *placementId = @"<#banner placementId#>";
/// 3. Initialize a new FYBBannerOptions instance with a specified placement ID and size.
/// FYBBannerSizeSmart automatically adjusts the banner size based on the device's screen width.
FYBBannerOptions *bannerOptions = [[FYBBannerOptions alloc] initWithPlacementId:placementId size:FYBBannerSizeSmart];
/// 4. Request to load a banner ad with the specified options. This method fetches the banner creative but does not show it.
[FYBBanner requestWithOptions:bannerOptions];
This feature is not available on Unity.
Adaptive Banners
By enabling the adaptive banner feature, you can receive the best banner size based on the ad width and screen size. This feature is currently supported by Google AdMob, Google Bidding, and Google Ad Manager only. This feature is disabled by default.
Networks that support adaptive banners will return ads with the best-fit height based on your banner size. Other networks will continue to deliver banners according to the specified ad size.
To use this feature, add the adaptive
flag when defining your banner size using the code below:
val bannerOptions = BannerOptions().setAdaptive(true)
val placementId = "12345"
Banner.show(placementId, bannerOptions, activity)
Java
BannerOptions bannerOptions = new BannerOptions().setAdaptive(true);
String placementId = "12345";
Banner.show(placementId, bannerOptions, activity);
let view: UIView = parent!.navigationController!.tabBarController!.view
let placementId = "12345"
let options = FYBBannerOptions(placementId: placementId, position: .bottom)
options.adaptive = true
FYBBanner.show(in: view, options: options)
Objective-C
NSString *placementId = @"12345";
FYBBannerOptions *options = [[FYBBannerOptions alloc] initWithPlacementId:placementId position:FYBBannerAdViewPositionTop];
options.adaptive = YES;
[FYBBanner showBannerInView:view options:options];
This feature is not available on Unity.
Adding Callbacks
The callback code below is required for the SDK to properly track the activity of your ad.
Banner.setBannerListener(object : BannerListener {
override fun onError(placementId: String, error: BannerError) {
// Called when an error arises when showing the banner from placement 'placementId'
}
override fun onLoad(placementId: String) {
// Called when the banner from placement 'placementId' is successfully loaded
}
override fun onShow(placementId: String, impressionData: ImpressionData) {
// Called when the banner from placement 'placementId' is shown
}
override fun onClick(placementId: String) {
// Called when the banner from placement 'placementId' is clicked
}
override fun onRequestStart(placementId: String, requestId: String) {
// Called when the banner from placement 'placementId' is going to be requested
// 'requestId' identifies the request across the whole request/show flow
}
})
Java
Banner.setBannerListener(new BannerListener() {
@Override
public void onError(String placementId, BannerError error) {
// Called when an error arises when showing the banner from placement 'placementId'
}
@Override
public void onLoad(String placementId) {
// Called when the banner from placement 'placementId' is successfully loaded
}
@Override
public void onShow(String placementId, ImpressionData impressionData) {
// Called when the banner from placement 'placementId' is shown
}
@Override
public void onClick(String placementId) {
// Called when the banner from placement 'placementId' is clicked
}
@Override
public void onRequestStart(String placementId, String requestId) {
// Called when the banner from placement 'placementId' is going to be requested
// 'requestId' identifies the request across the whole request/show flow
}
});
class MyBannerDelegate: NSObject, FYBBannerDelegate {
func bannerDidLoad(_ banner: FYBBannerAdView, impressionData: FYBImpressionData) {}
func bannerDidFail(toLoad placementId: String, withError error: Error) {}
func bannerDidShow(_ banner: FYBBannerAdView, impressionData: FYBImpressionData) {}
func bannerDidClick(_ banner: FYBBannerAdView){}
func bannerWillPresentModalView(_ banner: FYBBannerAdView) {}
func bannerDidDismissModalView(_ banner: FYBBannerAdView) {}
func bannerWillLeaveApplication(_ banner: FYBBannerAdView) {}
func banner(_ banner: FYBBannerAdView, didResizeToFrame frame: CGRect) {}
func bannerWillRequest(_ placementId: String, withRequestId requestId: String) {} }
Objective-C
#import FairBidSDK/FairBid.h
@interface MyBannerDelegate : NSObject
@end @implementation MyBannerDelegate
- (void)bannerDidLoad:(FYBBannerAdView *)banner impressionData:(FYBImpressionData *)impressionData {
// Called when an ad is loaded
}
- (void)bannerDidFailToLoad:(NSString *)placementId withError:(NSError *)error {
// Called when an error arises when loading an ad
}
- (void)bannerDidShow:(FYBBannerAdView *)banner impressionData:(FYBImpressionData *)impressionData {
// Called when banner shows up
}
- (void)bannerDidClick:(FYBBannerAdView *)banner {
// Called when banner is clicked
}
- (void)bannerWillPresentModalView:(FYBBannerAdView *)banner {
// Called when banner presents modal view
}
- (void)bannerDidDismissModalView:(FYBBannerAdView *)banner {
// Called when banner hides presented modal view
}
- (void)bannerWillLeaveApplication:(FYBBannerAdView *)banner {
// Called after banner redirects to other application
}
- (void)banner:(FYBBannerAdView *)banner didResizeToFrame:(CGRect)frame {
// Called after banner changes its size to desired frame
}
- (void)bannerWillRequest:(NSString *)placementId withRequestId:(NSString *)requestId {
// Called when a banner is going to be requested.
}
@end
public class MyBannerListener : BannerListener
{
public void OnError(string placementId, string error)
{
// Called when an error from placement 'placementId' arises when loading an ad
}
public void OnLoad(string placementId)
{
// Called when an ad from placement 'placementId' is loaded
}
public void OnShow(string placementId, ImpressionData impressionData)
{
// Called when banner from placement 'placementId' shows up
}
public void OnClick(string placementId)
{
// Called when banner from placement 'placementId' is clicked
}
public void OnRequestStart(string placementId)
{
// Called when a banner from placement 'placementId' is going to be requested
}
}
Banner.SetBannerListener(new MyBannerListener());
Interstitial Ads
Interstitials are either static or video ads presented before, during or after the user interacts with your app. The user can view and then immediately dismiss them. This is a non-rewarded format for the user.
Note
The speed and stability of a user's internet connections may vary. It is highly recommended to fetch as much in advance of showing an ad as possible. This helps to ensure that all necessary assets are downloaded. For example, you may want to fetch an ad when a level starts or after a previous ad has been shown.
Making the Request
Below is an example of making a request for an Intersitial.
import com.fyber.fairbid.ads.Interstitial
val placementId = "12345"
Interstitial.request(placementId)
Java
import com.fyber.fairbid.ads.Interstitial;
String placementId = "12345";
Interstitial.request(placementId);
FYBInterstitial.delegate = MyInterstitialDelegate()
let placementId = "1234"
FYBInterstitial.request(placementId)
Objective-C
#import <FairBidSDK/FairBid.h>
FYBInterstitial.delegate = [[MyInterstitialDelegate alloc] init];
NSString *placementId = @"1234";
[FYBInterstitial request:placementId];
string placementId = "1234";
Interstitial.Request(placementId);
Adding Callbacks
The callback code below is required for the SDK to properly track the activity of your ad
Interstitial.setInterstitialListener(object : InterstitialListener {
override fun onShow(placementId: String, impressionData: ImpressionData) {
// Called when the interstitial from placement 'placementId' shows up.
// In case the ad is a video, audio play will start here.
}
override fun onClick(placementId: String) {
// Called when the interstitial from placement 'placementId' is clicked
}
override fun onHide(placementId: String) {
// Called when the interstitial from placement 'placementId' hides.
// In case the ad is a video, audio play will stop here.
}
override fun onShowFailure(placementId: String, impressionData: ImpressionData) {
// Called when an error arises when showing the interstitial from placement 'placementId'
}
override fun onAvailable(placementId: String) {
// Called when an interstitial from placement 'placementId' becomes available
}
override fun onUnavailable(placementId: String) {
// Called when an interstitial from placement 'placementId' becomes unavailable
}
override fun onRequestStart(placementId: String, requestId: String) {
// Called when an interstitial from placement 'placementId' is going to be requested
// 'requestId' identifies the request across the whole request/show flow
}
})
Java
Interstitial.setInterstitialListener(new InterstitialListener() {
@Override
public void onShow(String placementId, ImpressionData impressionData) {
// Called when the interstitial from placement 'placementId' shows up.
// In case the ad is a video, audio play will start here.
}
@Override
public void onClick(String placementId) {
// Called when the interstitial from placement 'placementId' is clicked
}
@Override
public void onHide(String placementId) {
// Called when the interstitial from placement 'placementId' hides.
// In case the ad is a video, audio play will stop here.
}
@Override
public void onShowFailure(String placementId, ImpressionData impressionData) {
// Called when an error arises when showing the interstitial from placement 'placementId'
}
@Override
public void onAvailable(String placementId) {
// Called when a interstitial from placement 'placementId' becomes available
}
@Override
public void onUnavailable(String placementId) {
// Called when a interstitial from placement 'placementId' becomes unavailable
}
@Override
public void onRequestStart(String placementId, String requestId) {
// Called when a interstitial from placement 'placementId' is going to be requested
// 'requestId' identifies the request across the whole request/show flow
}
});
class MyInterstitialDelegate: NSObject, FYBInterstitialDelegate {
func interstitialIsAvailable(_ placementId: String) {}
func interstitialIsUnavailable(_ placementId: String) {}
func interstitialDidShow(_ placementId: String, impressionData: FYBImpressionData) {}
func interstitialDidFail(toShow placementId: String, withError error: Error, impressionData: FYBImpressionData) {}
func interstitialDidClick(_ placementId: String) {}
func interstitialDidDismiss(_ placementId: String) {}
func interstitialWillRequest(_ placementId: String, withRequestId requestId: String) {}
}
Objective-C
#import <FairBidSDK/FairBid.h>
@interface MyInterstitialDelegate : NSObject
@end
@implementation MyInterstitialDelegate
- (void)interstitialIsAvailable:(NSString *)placementId {
// Called when an Interstitial from placement becomes available
}
- (void)interstitialIsUnavailable:(NSString *)placementId {
// Called when an Interstitial from placement becomes unavailable
}
- (void)interstitialDidShow:(NSString *)placementId impressionData:(FYBImpressionData *)impressionData {
// Called when an Interstitial from placement shows up.
// In case the ad is a video, audio play will start here.
}
- (void)interstitialDidFailToShow:(NSString *)placementId withError:(NSError *)error impressionData:(FYBImpressionData *)impressionData {
// Called when an error arises when showing an Interstitial from placement
}
- (void)interstitialDidClick:(NSString *)placementId {
// Called when an Interstitial from placement is clicked
}
- (void)interstitialDidDismiss:(NSString *)placementId {
// Called when an Interstitial from placement hides.
// In case the ad is a video, audio play will stop here.
}
- (void)interstitialWillRequest:(NSString *)placementId withRequestId:(NSString *)requestId {
// Called when an Interstitial is going to be requested.
}
@end.
public class MyInterstitialListener : InterstitialListener
{
public void OnShow(string placementId, ImpressionData impressionData)
{
// Called when an Interstitial from placement 'placementId' shows up.
// In case the ad is a video, audio play will start here.
// On Android, this callback might be called only once the ad is closed.
}
public void OnClick(string placementId)
{
// Called when an Interstitial from placement 'placementId' is clicked
}
public void OnHide(string placementId)
{
// Called when an Interstitial from placement 'placementId' hides.
}
public void OnShowFailure(string placementId, ImpressionData impressionData)
{
// Called when an error arises when showing an Interstitial from placement 'placementId'
}
public void OnAvailable(string placementId)
{
// Called when an Interstitial from placement 'placementId' becomes available
}
public void OnUnavailable(string placementId)
{
// Called when an Interstitial from placement 'placementId' becomes unavailable
}
public void OnRequestStart(string placementId)
{
// Called when an Interstitial from placement 'placementId' is going to be requested
}
}
Interstitial.SetInterstitialListener(new MyInterstitialListener());
Example Showing an Ad
The following example checks to see if a Placement is available and if it is, uses the show request to display the ad.
val placementId = "12345"
if (Interstitial.isAvailable(placementId)) {
Interstitial.show(placementId, context)
}
Java
String placementId = "12345";
if (Interstitial.isAvailable(placementId)) {
Interstitial.show(placementId, context);
}
let placementId = "1234"
if (FYBInterstitial.isAvailable(placementId)) {
FYBInterstitial.show("placementId")
}
if (FYBInterstitial.isAvailable(placementId)) {
let showOptions = FYBShowOptions()
showOptions.viewController = self.myViewController
FYBInterstitial.show(placementId, options: showOptions)
}
Objective-C
NSString *placementId = @"1234";
if ([FYBInterstitial isAvailable:placementId]) {
[FYBInterstitial show:placementId];
}
if ([FYBInterstitial isAvailable:placementId]) {
FYBShowOptions *showOptions = [FYBShowOptions new];
showOptions.viewController = self.myViewController;
[FYBInterstitial show:placementId options:showOptions];
}
Important
If your game needs to be paused before showing an ad (e.g., stop audio playback), this is the best moment to do so.
The time between calling this API and the ad actually being shown should be negligible.
This approached is preferable compared to relying on the 'OnShow' callback since on Android, we cannot guarantee it will be called before the ad starts playing.
string placementId = "1234";
if (Interstitial.IsAvailable(placementId)) {
Interstitial.Show(placementId);
}
Rewarded Ads
Rewarded ads are an engaging ad format that shows a short video ad to the user and in exchange the user will earn a reward. The user must consent and watch the video completely through to the end in order to earn the reward.
Note
The speed and stability of users internet connections may vary. It is highly recommended to fetch as far in advance of showing an ad as possible. This helps to ensure that all necessary assets are downloaded. For example, you may want to fetch an ad when a level starts, or after a previous ad has been shown.
Making the Request
The following example shows how to make a request to display the Rewarded ads.
Before you can make a request to display a Rewarded ad, you must import the Rewarded class.
Kotlinimport com.fyber.fairbid.ads.Rewarded
Java
import com.fyber.fairbid.ads.Rewarded;
After importing the Rewarded class, you must make a request to display the Rewarded ads.
Kotlinimport com.fyber.fairbid.ads.Rewarded
val placementId = "12345"
Rewarded.request(placementId)
Java
import com.fyber.fairbid.ads.Rewarded;
String placementId = "12345";
Rewarded.request(placementId);
FYBRewarded.delegate = MyRewardedDelegate()
let placementId = "1234"
FYBRewarded.request(placementId)/code
Objective-C
FYBRewarded.delegate = MyRewardedDelegate()
let placementId = "1234"
FYBRewarded.request(placementId)
string placementId = "1234";
Rewarded.Request(placementId);
Adding Callbacks
The callback code below is required for SDK to track the activity of your ad properly.
Rewarded.setRewardedListener(object : RewardedListener {
override fun onShow(placementId: String, impressionData: ImpressionData) {
// Called when the rewarded ad from placement 'placementId' shows up.
// In case the ad is a video, audio play will start here.
}
override fun onClick(placementId: String) {
// Called when the rewarded ad from placement 'placementId' is clicked
}
override fun onHide(placementId: String) {
// Called when the rewarded ad from placement 'placementId' hides.
// In case the ad is a video, audio play will stop here.
}
override fun onShowFailure(placementId: String, impressionData: ImpressionData) {
// Called when an error arises when showing the rewarded ad from placement 'placementId'
}
override fun onAvailable(placementId: String) {
// Called when a rewarded ad from placement 'placementId' becomes available
}
override fun onUnavailable(placementId: String) {
// Called when a rewarded ad from placement 'placementId' becomes unavailable
}
override fun onCompletion(placementId: String, userRewarded: Boolean) {
// Called when a rewarded ad from placement 'placementId' finishes playing
}
override fun onRequestStart(placementId: String, requestId: String) {
// Called when a rewarded ad from placement 'placementId' is going to be requested
// 'requestId' identifies the request across the whole request/show flow
}
})
Java
Rewarded.setRewardedListener(new RewardedListener() {
@Override
public void onShow(String placementId, ImpressionData impressionData) {
// Called when the rewarded ad from placement 'placementId' shows up. In case the ad is a video, audio play will start here.
}
@Override
public void onClick(String placementId) {
// Called when the rewarded ad from placement 'placementId' is clicked
}
@Override
public void onHide(String placementId) {
// Called when the rewarded ad from placement 'placementId' hides. In case the ad is a video, audio play will stop here.
}
@Override
public void onShowFailure(String placementId, ImpressionData impressionData) {
// Called when an error arises when showing the rewarded ad from placement 'placementId'
}
@Override
public void onAvailable(String placementId) {
// Called when a rewarded ad from placement 'placementId' becomes available
}
@Override
public void onUnavailable(String placementId) {
// Called when a rewarded ad from placement 'placementId' becomes unavailable
}
@Override
public void onCompletion(String placementId, boolean userRewarded) {
// Called when a rewarded ad from placement 'placementId' finishes playing
}
@Override
public void onRequestStart(String placementId, String requestId) {
// Called when a rewarded ad from placement 'placementId' is going to be requested
// 'requestId' identifies the request across the whole request/show flow
}
});
class MyRewardedDelegate: NSObject, FYBRewardedDelegate {
func rewardedIsAvailable(_ placementName: String) {}
func rewardedIsUnavailable(_ placementName: String) {}
func rewardedDidShow(_ placementName: String, impressionData: FYBImpressionData) {}
func rewardedDidFail(toShow placementName: String, withError error: Error, impressionData: FYBImpressionData) {}
func rewardedDidClick(_ placementName: String) {}
func rewardedDidComplete(_ placementName: String, userRewarded: Bool) {}
func rewardedDidDismiss(_ placementName: String) {}
func rewardedWillRequest(_ placementId: String, withRequestId requestId: String) {}
}
Objective-C
#import <FairBidSDK/FairBid.h>
@interface MyRewardedDelegate : NSObject
@end
@implementation MyRewardedDelegate
- (void)rewardedIsAvailable:(NSString *)placementId {
// Called when a rewarded ad from placement becomes available
}
- (void)rewardedIsUnavailable:(NSString *)placementId {
// Called when a rewarded ad from placement becomes unavailable
}
- (void)rewardedDidShow:(NSString *)placementId impressionData:(FYBImpressionData *)impressionData {
// Called when a rewarded ad from placement shows up. Audio play will start here.
}
- (void)rewardedDidFailToShow:(NSString *)placementId withError:(NSError *)error impressionData:(FYBImpressionData *)impressionData {
// Called when an error arises when showing a rewarded ad from placement
}
- (void)rewardedDidClick:(NSString *)placementId {
// Called when a rewarded ad from placement is clicked
}
- (void)rewardedDidDismiss:(NSString *)placementId {
// Called when a rewarded ad from placement hides. Audio play will stop here.
}
- (void)rewardedDidComplete:(NSString *)placementId userRewarded:(BOOL)userRewarded {
// Called when a rewarded ad finishes playing
}
- (void)rewardedWillRequest:(NSString *)placementId withRequestId:(NSString *)requestId {
// Called when a rewarded ad is going to be requested.
}
@end
public class MyRewardedListener : RewardedListener
{
public void OnShow(string placementId, ImpressionData impressionData)
{
// Called when a rewarded ad from placementId shows up. In case the ad is a video, audio play will start here.
// On Android, this callback might be called only once the ad is closed.
}
public void OnClick(string placementId)
{
// Called when a rewarded ad from placement 'placementId' is clicked
}
public void OnHide(string placementId)
{
// Called when a rewarded ad from placement 'placementId' hides.
}
public void OnShowFailure(string placementId, ImpressionData impressionData)
{
// Called when an error arises when showing a rewarded ad from placement 'placementId'
}
public void OnAvailable(string placementId)
{
// Called when a rewarded ad from placement 'placementId' becomes available
}
public void OnUnavailable(string placementId)
{
// Called when a rewarded ad from placement 'placementId' becomes unavailable
}
public void OnCompletion(string placementId, bool userRewarded)
{
// Called when a rewarded ad from placement 'placementId' finishes playing.
// In case the ad is a video, audio play will stop here.
}
public void OnRequestStart(string placementId)
{
// Called when a rewarded ad from placement 'placementId' is going to be requested
}
}
Rewarded.SetRewardedListener(new MyRewardedListener());
Example showing an ad
The following example checks to see if a placement is available and, if it is, uses the show request to display the ad.
val placementId = "12345"
if (Rewarded.isAvailable(placementId)) {
Rewarded.show(placementId, context)
}
Java
val placementId = "12345"
if (Rewarded.isAvailable(placementId)) {
Rewarded.show(placementId, context)
}
let placementId = "1234"
if (FYBRewarded.isAvailable(placementId)) {
FYBRewarded.show(placementId)
}
Objective-C
NSString *placementId = @"1234";
if ([FYBRewarded isAvailable:placementId]) {
[FYBRewarded show:placementId];
}
Important
If your game needs to be paused before showing an ad (e.g., stop audio playback), this is the best moment to do so. The time between calling this API and the ad actually being shown should be negligible. This approach is preferable to relying on the 'OnShow' callback since, we cannot guarantee it will be called on Android before the ad starts playing.
string placementId = "1234";
if (Interstitial.IsAvailable(placementId)) {
Interstitial.Show(placementId);
}
Server Side Rewarding
Important
When using Unity, due to technical limitations on the framework side, we notice that for some very low percentage of users, we receive the OnShowFailure followed by the OnCompletion(true). We're currently working on fixing the issue. However, in the meantime, if you're using client-side rewarding and you consider the OnShowFailure as a callback to trigger a new request and unblock your game's logic, we recommend you delay this check with the following workaround:
using System.Collections;
public class RewardedScene : MonoBehaviour, RewardedListener
{
private bool CompletionEventReceived;
private void ShowVideo()
{
// Reset the completion event flag
this.CompletionEventReceived = false;
// Show rewarded video with a specific placement ID
Rewarded.Show("your_placement_id");
}
private void OnShowFailure()
{
// Start a coroutine to wait for user completion
this.StartCoroutine(this.WaitUserCompletion());
}
private void OnCompletion(bool userRewarded)
{
// Mark the completion event as received
this.CompletionEventReceived = true;
if (userRewarded)
{
// Credit the user
}
else
{
// Handle the case where the user was not rewarded
this.UserNotRewarded();
}
}
private IEnumerator WaitUserCompletion()
{
// Delay the check for 1 second, giving enough time to receive the OnCompletion callback
yield return new WaitForSeconds(1);
// If the completion event was not received, handle it
if (!this.CompletionEventReceived)
{
this.UserNotRewarded();
}
}
private void UserNotRewarded()
{
// Handle your logic for users who didn't complete the rewarded ad
}
}
Medium Rectangle Ads
Medium Rectangle (MREC) ads are 300x250 sized ads, serving both static and video, and positioned within editorial content of the app. There is no close button on MREC ads, and they are not skippable. Similar to Banner ads, MREC ads are refreshed according to a set refresh rate of between 10-120 seconds.
Note
MREC Ads are available from FairBid SDK version 3.33.1.
Showing an MREC
Implement the code below to show an MREC:
fun showBanner() {
val bannerOptions = BannerOptions().withSize(BannerSize.MREC)
// if you don't specify your container view,
// we'll display it at the bottom of the screen
.placeInContainer(YOUR_CONTAINER_VIEW_GOES_HERE)
Banner.show("placementId", bannerOptions, activity)
}
Java
private void showBanner() {
BannerOptions bannerOptions = new BannerOptions().withSize(BannerSize.MREC)
// if you don't specify your container view,
// we'll display it at the bottom of the screen
.placeInContainer(YOUR_CONTAINER_VIEW_GOES_HERE);
Banner.show("placementId", bannerOptions, activity);
}
Implement the code below to request an MREC:
Swift FYBBanner.delegate = MyBannerDelegate()
let bannerOptions = FYBBannerOptions(placementId: "1234", size: .MREC)
FYBBanner.request(with: options)
Objective-C
#import <FairBidSDK/FairBid.h>
FYBBanner.delegate = [[MyBannerDelegate alloc] init];
NSString *placementId = @"1234";
FYBBannerOptions *bannerOptions = [[FYBBannerOptions alloc] initWithPlacementId:@"1234" size:FYBBannerSizeMREC];
[FYBBanner requestWithOptions:bannerOptions];
To show an MREC ad, display the view received in the bannerDidLoad:impressionData:, that’s part of FYBBannerDelegate protocol. Swift
extension MyViewController: FYBBannerDelegate {
func bannerDidLoad(_ banner: FYBBannerAdView, impressionData: FYBImpressionData)
{
// set up the MREC banner constraints
myView.addSubview(banner)
banner.center = CGPoint(x: myView.frame.width / 2, y: myView.center.y)
}
…
}
Objective-C
// in implementation of FYBBannerDelegate protocol
- (void)bannerDidLoad:(FYBBannerAdView *)banner impressionData:(FYBImpressionData *)impressionData {
[self.myView addSubview:banner];
banner.center = CGPointMake(self.myView.bounds.size.width / 2, self.bounds.size.height / 2);
}