Interstitial Ad
Integration
Step 1. Instantiate Interstitial Ad
You can instantiate an InterstitialAd right after the SDK finishes initialization.
Pass the platform-specific interstitial placement id to the InterstitialAd constructor.
public class BlueStackAdsController : MonoBehaviour
{
private InterstitialAd _interstitialAd;
void Start()
{
BlueStackAds.SetDebugMode(true);
BlueStackAds.Initialize("app_id", HandleInitCompleteAction);
}
private void HandleInitCompleteAction(InitializationStatus status)
{
_interstitialAd = new InterstitialAd(placementId);
}
}
Step 2. Register event listeners
InterstitialAd exposes the following events through its lifecycle.
| Event | Payload | Definition |
|---|---|---|
OnAdLoaded | EventArgs | Ad finished loading and is ready to be shown. |
OnAdFailedToLoad | BlueStackError | The ad failed to load. |
OnAdDisplayed | EventArgs | The ad has appeared on screen. |
OnAdFailedToDisplay | BlueStackError | The ad failed to display after Show() was called. |
OnAdClicked | EventArgs | The user clicked the ad. |
OnAdDismissed | EventArgs | The user dismissed the full-screen ad. This is terminal — the instance cannot be re-shown. |
_interstitialAd.OnAdLoaded += (sender, args) =>
{
Debug.Log("OnAdLoaded");
};
_interstitialAd.OnAdFailedToLoad += (sender, error) =>
{
Debug.LogError("OnAdFailedToLoad: " + error.Message);
};
_interstitialAd.OnAdDisplayed += (sender, args) =>
{
Debug.Log("OnAdDisplayed");
};
_interstitialAd.OnAdFailedToDisplay += (sender, error) =>
{
Debug.LogError("OnAdFailedToDisplay: " + error.Message);
};
_interstitialAd.OnAdClicked += (sender, args) =>
{
Debug.Log("OnAdClicked");
};
_interstitialAd.OnAdDismissed += (sender, args) =>
{
Debug.Log("OnAdDismissed");
};
Make sure you only register event listeners once.
Step 3. Load Interstitial ad
InterstitialAd exposes two Load overloads; one parameterless, and one taking a
RequestOptions instance for audience targeting.
- Without targeting
_interstitialAd.Load();
- With targeting
var requestOptions = new RequestOptions(
age: 25,
gender: Gender.Male,
location: new Location(35.757866, 10.810547, Location.GPS_PROVIDER),
consentFlag: 1,
language: "en",
keyword: "brand=myBrand;category=sport",
contentUrl: "https://console.bluestack.app");
_interstitialAd.Load(requestOptions);
RequestOptions is immutable and reusable across Load calls. See
Targeting Audiences for the full field reference and
consent-flag semantics.
Step 4. Display Interstitial ad
After the ad has loaded, request it to be displayed. Check IsReady to confirm the ad is loaded before calling Show().
if (_interstitialAd.IsReady)
{
_interstitialAd.Show();
}
Equivalently, gate on OnAdLoaded:
_interstitialAd.OnAdLoaded += (sender, args) =>
{
_interstitialAd.Show();
};
Destroy interstitial ad
Destroy the interstitial before creating a new one.
_interstitialAd.Destroy();