Interstitial Ad
For a working implementation of this ad format, see the bluestack-demo-unity demo app.
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");
};
caution
Make sure you only register event listeners once.
Step 3. Load Interstitial ad
InterstitialAd exposes two Load overloads — one with no parameters, and one taking a Preference instance.
- Without
Preference
_interstitialAd.Load();
- With
Preference
public class BlueStackAdsController : MonoBehaviour
{
...
private void RequestInterstitialAd()
{
Preference _preference = new Preference();
Location myLocation = new Location(Location.NONE_PROVIDER)
{
Latitude = 35.757866,
Longitude = 10.810547
};
_preference.SetAge(25);
_preference.SetLanguage("en");
_preference.SetGender(Gender.Male);
_preference.SetKeyword("brand=myBrand;category=sport");
_preference.SetLocation(myLocation, 1);
_preference.SetContentUrl("https://console.bluestack.app");
_interstitialAd.Load(_preference);
}
...
}
Note:
The SetLocation method takes the following parameters:
- The
Locationinstance. - The CONSENT_FLAG value (corresponds to a int: 0, 1, 2 or 3).
- 0 = Do not send location.
- 1 = Managed location according to consent value.
- 2 and 3 = Allow the SDK to manage location directly in accordance with the consent value (TCF v1 / TCF v2). Check with the Azerion team — behavior depends on your implementation.
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();