Aller au contenu principal

Interstitial Ad

Integration

Step 1. Import component

You need to import InterstitialAdManager component in order to display Bluestack interstitial ads.

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

Step 2. Load Interstitial ad

You can load a Interstitial ad right after SDK finishes it's initialization. You have to pass the platform specific interstitial placement id in loadAd method.

Here's an example of how to load an interstitial ad:

/**
* Load interstitial ad.
* @param: placementId
* @param: autoDisplay: to chose if the interstitial will be displayed automatically (optional)
* @param: preference (optional)
*/
InterstitialAdManager.loadAd("/" + appId + "/interstitial", false, preference);

View the AdPreference documentation for more details about ad preferences.

Step 3. Display Interstitial ad

After loading the interstitial ad you can request it to be displayed using displayAd method.

info

Listen to interstitial ad events to make sure the ad was successfully loaded before you call displayAd method

Here's an example of how to load an interstitial ad:

InterstitialAdManager.displayAd();

Step 2. Register event listeners

InterstitialAd exposes the following events through it's lifecycle. Register for interstitial ad events before loading InterstitialAd.

EventsDefinition
onAdLoadedAd is successfully loaded and SDK is ready to display the ad.
onAdFailedErrorThe ad failed to load or display.
onAdClickedUser has clicked the ad. Ad may open a link in browser.
onAdDisplayedAd has appeared on the screen.
onAdDismissedThe ad has disappeared.

Here's an example of how to register event listeners for interstitial ads:

InterstitialAdManager.addEventListener((event) => {
switch (event.interstitialEvent) {
case "onAdLoaded":
console.log("Interstitial Ad Loaded");
break;
case "onAdDismissed":
console.log("Interstitial Ad disappeared");
break;
case "onAdDisplayed":
console.log("Interstitial Ad displayed");
break;
case "onAdClicked":
console.log("Interstitial Ad did click");
break;
case "onAdFailedError":
console.log("Interstitial Ad failed:" + event.errorBluestackMessage);
break;
default:
break;
}
});

Here's an example of how to remove all event listeners:

InterstitialAdManager.removeAllEventListeners();
attention

Make sure you only register event listener once.