インタースティシャル広告
インタースティシャル広告をロード
以下のコードは、リスナーを付与して最初のインタースティシャル広告をロードする方法を示しています。
import { InterstitialAd } from 'react-native-applovin-max';
const INTERSTITIAL_AD_UNIT_ID = Platform.select({ android: '«android-ad-unit-ID»', ios: '«ios-ad-unit-ID»',});
const MAX_EXPONENTIAL_RETRY_COUNT = 6;const retryAttempt = useRef(0);
const initializeInterstitialAds = () => { InterstitialAd.addAdLoadedEventListener((adInfo: AdInfo) => { // Interstitial ad is ready to show. InterstitialAd.isReady(INTERSTITIAL_AD_UNIT_ID) now returns 'true'
// Reset retry attempt retryAttempt.current = 0; }); InterstitialAd.addAdLoadFailedEventListener((errorInfo: AdLoadFailedInfo) => { // Interstitial ad failed to load // AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
retryAttempt.current += 1; if (retryAttempt.current > MAX_EXPONENTIAL_RETRY_COUNT) return; const retryDelay = Math.pow(2, Math.min(MAX_EXPONENTIAL_RETRY_COUNT, retryAttempt.current));
console.log('Interstitial ad failed to load - retrying in ' + retryDelay + 's');
setTimeout(function() { loadInterstitial(); }, retryDelay * 1000); }); InterstitialAd.addAdClickedEventListener((adInfo: AdInfo) => { ... }); InterstitialAd.addAdDisplayedEventListener((adInfo: AdInfo) => { ... }); InterstitialAd.addAdFailedToDisplayEventListener((adInfo: AdDisplayFailedInfo) = { // Interstitial ad failed to display. AppLovin recommends that you load the next ad loadInterstitial(); }); InterstitialAd.addAdHiddenEventListener((adInfo: AdInfo) => { loadInterstitial(); });
// Load the first interstitial loadInterstitial();}
const loadInterstitial = () => { InterstitialAd.loadAd(INTERSTITIAL_AD_UNIT_ID);}
インタースティシャル広告を表示
インタースティシャル広告を表示するには、showAd()
を呼び出します。
const isInterstitialReady = await InterstitialAd.isAdReady(«ad-unit-ID»);if (isInterstitialReady) { InterstitialAd.showAd(«ad-unit-ID»);}