Banner Ads
After creating placements in the DT Console, add the following code snippets in the chosen context of your app. Access the Placement ID by using the copy button next to the placement name. For more information about creating placements in the DT Console, read here.
Banners are rectangle ads appearing either at the top or bottom of the screen when the user interacts with your app. The user can view banners but cannot dismiss them. Banners are automatically refreshed by the DT FairBid SDK after 20 seconds.
The DT FairBid SDK refreshes banners automatically. To avoid discrepancies between DT and 3rd-party network reporting, disable any automatic or manual banner refresh settings on 3rd-party network SDKs.
Showing a Banner
Implement the code below to show a Banner:
val placementId = "12345"
Banner.show(placementId, activity)
String placementId = "12345";
Banner.show(placementId, activity);
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)
//hides the banner for a specific placement
String placementId = "12345";
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)
//destroys the banner for a specific placement
String placementId = "12345";
Banner.destroy(placementId);
Banner Position
By default, the banners are placed at the bottom of your screen.
You can place them at the top by using the code below:
Top Position
val bannerOptions = BannerOptions().placeAtTheTop()
val placementId = "12345"
Banner.show(placementId, bannerOptions, activity)
BannerOptions bannerOptions = new BannerOptions().placeAtTheTop();
String placementId = "12345";
Banner.show(placementId, bannerOptions, activity);
Or you can provide your custom view and place them in there:
val bannerOptions = BannerOptions().placeInContainer(viewGroup)
val placementId = "12345"
Banner.show(placementId, bannerOptions, activity)
BannerOptions bannerOptions = new BannerOptions().placeInContainer(viewGroup);
String placementId = "12345";
Banner.show(placementId, bannerOptions, activity);
Loading a Banner
Important
Use this implementation only if FairBid is not your main mediation platform, as this method disables banner refresh. So, you'll need to add your own refresh logic.
You can pre-load a banner to review its pricing and other details if you want to use FairBid with other mediations or demand sources. This allows you to compare it against banners from other demand sources outside our platform before showing it.
To load a banner, create an instance of the BannerView
object 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.
val 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()
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)
BannerOptions bannerOptions = new BannerOptions().setAdaptive(true);
String placementId = "12345";
Banner.show(placementId, bannerOptions, activity);
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
}
})
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
}
});
Interstitial Ads
After creating placements in the DT Console, add the following code snippets in the chosen context of your app. Access the Placement ID by using the copy button next to the placement name. For more information about creating placements in the DT Console, read here.
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.
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.
Example Request
import com.fyber.fairbid.ads.Interstitial
val placementId = "12345"
Interstitial.request(placementId)
import com.fyber.fairbid.ads.Interstitial;
String placementId = "12345";
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
}
})
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
}
});
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.
Showing an Ad
val placementId = "12345"
if (Interstitial.isAvailable(placementId)) {
Interstitial.show(placementId, context)
}
String placementId = "12345";
if (Interstitial.isAvailable(placementId)) {
Interstitial.show(placementId, context);
}
Rewarded Ads
After creating placements in the DT Console, add the following code snippets in the chosen context of your app. Access the Placement ID by using the copy button next to the placement name. For more information about creating placements in the DT Console, read here.
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.
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.
Importing the Class
Before you can make a request to display a Rewarded ad, you must import the Rewarded class.
import com.fyber.fairbid.ads.Rewarded
import com.fyber.fairbid.ads.Rewarded;
Make an Ad Request
After importing the Rewarded class, you must must make a request to display the Rewarded ads.
Requesting a Rewarded Ad
import com.fyber.fairbid.ads.Rewarded
val placementId = "12345"
Rewarded.request(placementId)
import com.fyber.fairbid.ads.Rewarded;
String placementId = "12345";
Rewarded.request(placementId);
Adding Callbacks
The callback code below is required for SDK to properly track the activity of your ad
Callbacks
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
}
})
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
}
});
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.
Showing an Ad
val placementId = "12345"
if (Rewarded.isAvailable(placementId)) {
Rewarded.show(placementId, context)
}
String placementId = "12345";
if (Rewarded.isAvailable(placementId)) {
Rewarded.show(placementId, context);
}
Server Side Rewarding
For details on configuring Server Side Rewarding, click here.
Medium Rectangle Ads
After creating placements in the DT Console, add the following code snippets in the chosen context of your app. Access the Placement ID by using the copy button next to the placement name. For more information about creating placements in the DT Console, read here.
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.
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)
}
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);
}