Aller au contenu principal
Version: 6.x.x

Banner Ads

Overview

A Banner ad typically appears as a rectangular or square graphic within your app's user interface. Banner ads are usually embedded at the top, bottom, or inline within the scrollable content of a screen.

Before You Start. Make sure that you have correctly integrated the BlueStack React Native Plugin into your application. Integration is outlined here.

For a working implementation of this ad format, see the azerion-inapp-demo-reactnative demo app.

Create a BannerView

You need to import the BannerAdView component in order to display BlueStack banner ads.

import { BannerAdView } from "@azerion/bluestack-sdk-react-native";

The SDK module provides a BannerAdView component, that must be used to display the ads. Each render of the component loads a single ad, allowing you to display multiple ads at once. It has the following props:

PropertyTypeRequirementDescription
typeBannerAdTypeMandatoryBanner ad type
placementIdstringMandatoryID of impression placement provided in BlueStack console
shouldLoadWhenReadybooleanOptionalIf true, the ad will be automatically loaded as soon as all the props are set
preferenceAdPreferenceOptionalTo pass additional request preferences before loading an ad

Here's an example of how to create and auto load a banner ad:

const refBanner = useRef<any>(null);
....

<View>
<BannerAdView
type='standard'
shouldLoadWhenReady={true}
placementId={'/' + appId + '/banner'}
preference={preference!}
ref={refBanner}
/>
</View>

Load a Banner Ad

BannerAdView has a load method that takes an instance of AdPreference as an optional parameter. You can use this method to "manually" load a new ad.

info

Banner load call is not required when the shouldLoadWhenReady prop is set to true.

Without AdPreference

// Load a banner ad.
refBanner.current?.load();

With AdPreference

To request a banner ad using AdPreference, provide an instance of AdPreference in the BannerAdView's load method:

// Load a banner ad with preferences.
refBanner.current?.load(preference);
attention

You don't need to set preferences in both the preference prop and the load method. If preferences are set in both, the one passed to the load method will be used.

Ad events

Register for banner events

BannerAdView exposes props for listening to events, allowing you to handle the state of your app:

MethodsDefinition
onAdLoadedAd is successfully loaded and SDK is ready to display the ad.
onAdFailedToLoadThe ad failed to load or display.
onAdClickedUser has clicked the ad. Ad may open a link in browser.
onAdRefreshedThe banner ad has been refreshed.
onAdFailedToRefreshThe banner ad has been failed to refresh.

Implement banner events

Here's an example of how to use event listeners:

const [bannerHeight, setBannerHeight] = useState<number>(0);
const refBanner = useRef<any>(null);
....

// Load a banner ad with preferences.
refBanner.current?.load(preference);
....

<View
style={{
height: bannerHeight,
}}
>
<BannerAdView
type="standard"
shouldLoadWhenReady={false}
placementId={'/' + appId + '/banner'}
onAdLoaded={(object: any) => {
console.log('Banner Ad Loaded');
setBannerHeight(+object.nativeEvent.size);
}}
onAdFailedToLoad={(error: any) => {
console.log('Banner Ad load failed: ' +error?.nativeEvent?.error);
}}
onAdRefreshed={() => {
console.log('Banner Ad refresh succeed');
}}
onAdFailedToRefresh={(error: any) => {
console.log('Banner Ad refresh failed: ' + error?.nativeEvent?.error);
}}
onAdClicked={() => {
console.log('Banner Ad Clicked');
}}
ref={refBanner}
/>
</View>

Show / Hide Banner Ad

After loading the banner ad you can hide it using the hide method and show it again using the show method.

// Hide banner ad
refBanner.current?.hide();
// Show banner ad
refBanner.current?.show();

Destroying Banner Ad

You can destroy / remove the banner using the destroy method.

refBanner.current?.destroy();

Enable / Disable Banner Refresh

You can enable or disable the banner auto refresh using the toggleRefresh method. Pass true to enable refresh and false to disable it.

refBanner.current?.toggleRefresh(true);

BlueStack ads provide a variety of pre-defined sizes. See the table below for details about our supported standard banner sizes:

TypeValueDescriptionDimensions in dp (WxH)
StandardstandardStandard Banner320 x 50
LargelargeLarge Banner320 x 100
FullfullFull Banner468 x 60
Medium RectanglemediumRectangleMedium Rectangle300 x 250
LeaderboardleaderboardLeaderboard728 x 90
DynamicdynamicAdjusted BannerScreen width x 50
Dynamic LeaderboarddynamicLeaderboardAdjusted LeaderboardScreen width x 90