So in my ionic project I`m trying to load interstitial ad, the same is not showing in my emulator device, I picked the code from applovin documentation cordova, I also integrated the what they asked me in gradle files, and of course I did the plugin. I was wondering if Ionic doesn't accept this way or I should convert it to typescript. I putted this code in home.page.ts calling the interstitial ad when a certain button is clicked.
declare var window: any;
declare var cordova: any;
declare var bannerAdUnitId: any;
var AppLovinMAX = cordova.require('cordova-plugin-applovin-max.AppLovinMAX');
AppLovinMAX.initialize("RAfucl4TfsPn8kt_iKFCoFsaI59861MbWMxU6W_6JIV6eHL42gFPgE6xps14lF00MfnHNCOenKVfPKV8vf7IqN", function (configuration) {
// SDK is initialized, start loading ads
});
var INTER_AD_UNIT_ID;
if (window.cordova.platformId.toUpperCase() === 'IOS') {
INTER_AD_UNIT_ID = 'YOUR_IOS_INTER_AD_UNIT_ID';
} else {
// Assume Android
INTER_AD_UNIT_ID = '';
}
var retryAttempt = 0;
function initializeInterstitialAds()
{
window.addEventListener('OnInterstitialLoadedEvent', function (adInfo) {
// Interstitial ad is ready to be shown. AppLovinMAX.isInterstitialReady(INTER_AD_UNIT_ID) will now return 'true'
// Reset retry attempt
retryAttempt = 0;
});
window.addEventListener('OnInterstitialLoadFailedEvent', function (adInfo) {
// Interstitial ad failed to load
// We recommend retrying with exponentially higher delays up to a maximum delay (in this case 64 seconds)
retryAttempt++;
var retryDelay = Math.pow(2, Math.min(6, retryAttempt));
console.log('Interstitial ad failed to load - retrying in ' + retryDelay + 's');
setTimeout(function() {
loadInterstitial();
}, retryDelay * 1000);
});
window.addEventListener('OnInterstitialClickedEvent', function (adInfo) {});
window.addEventListener('OnInterstitialDisplayedEvent', function (adInfo) {});
window.addEventListener('OnInterstitialAdFailedToDisplayEvent', function (adInfo) {
// Interstitial ad failed to display. We recommend loading the next ad
loadInterstitial();
});
window.addEventListener('OnInterstitialHiddenEvent', function (adInfo) {
loadInterstitial();
});
// Load the first interstitial
loadInterstitial();
}
function loadInterstitial()
{
AppLovinMAX.loadInterstitial(INTER_AD_UNIT_ID);
}
if (AppLovinMAX.isInterstitialReady(INTER_AD_UNIT_ID))
{
AppLovinMAX.showInterstitial(INTER_AD_UNIT_ID);
}