💡Tips
- 插屏通过
ATInterstitialAd实例接入:一个 placementId 对应一个实例。- 与激励视频不同,插屏无发奖回调,但有展示成功(
onInterstitialAdShow)与视频播放回调。- 加载失败经
onInterstitialAdLoadFail回调上报;展示失败经onInterstitialAdShowFailed回调上报,均不走 Promise.reject。- 展示前可调用
ATInterstitialAd.entryAdScenario(placementId, scenarioId)上报进入广告场景(用于场景化统计)。- 如需由 SDK 托管加载、关闭后自动补量,请参考自动加载模式。
import {
ATInterstitialAd,
type ATInterstitialListener,
} from '@anythink/react-native-sdk';
const listener: ATInterstitialListener = {
onInterstitialAdLoaded: () => {
// 加载成功
},
onInterstitialAdLoadFail: (error) => {
console.log('load fail:', error.fullErrorInfo);
},
onInterstitialAdShow: (info) => {
// 展示成功
},
onInterstitialAdShowFailed: (error) => {
console.log('show fail:', error.fullErrorInfo);
},
onInterstitialAdClicked: (info) => {
// 点击
},
onInterstitialAdClose: (info) => {
// 关闭
},
onInterstitialAdVideoStart: (info) => {
// 视频开始(视频类插屏)
},
onInterstitialAdVideoEnd: (info) => {
// 视频结束
},
onInterstitialAdVideoError: (error) => {
console.log('video error:', error.fullErrorInfo);
},
};
import { useEffect, useRef } from 'react';
import { ATInterstitialAd } from '@anythink/react-native-sdk';
const adRef = useRef<ATInterstitialAd | null>(null);
useEffect(() => {
const ad = new ATInterstitialAd('your placement id');
ad.setAdListener(listener);
adRef.current = ad;
return () => ad.removeAdListener();
}, []);
adRef.current?.load();
// 或带请求参数
adRef.current?.load({
adxBidFloorInfo: { bidFloor: 1.0, currency: 'USD' },
});
const ready = await adRef.current?.isAdReady();
show() 支持三种入参形态:
// ① 直接展示
adRef.current?.show();
// ② 带广告场景 ID
adRef.current?.show('your_scenario_id');
// ③ 带展示配置
adRef.current?.show({
scenarioId: 'your_scenario_id',
showCustomExt: 'your_custom_ext',
});
import { useEffect, useRef } from 'react';
import { Button, View } from 'react-native';
import {
ATInterstitialAd,
type ATInterstitialListener,
} from '@anythink/react-native-sdk';
export function InterstitialDemo() {
const adRef = useRef<ATInterstitialAd | null>(null);
const listener: ATInterstitialListener = {
onInterstitialAdLoaded: () => console.log('loaded'),
onInterstitialAdLoadFail: (e) => console.log('fail', e.fullErrorInfo),
onInterstitialAdClose: () => console.log('closed'),
};
useEffect(() => {
const ad = new ATInterstitialAd('your placement id');
ad.setAdListener(listener);
adRef.current = ad;
return () => ad.removeAdListener();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
<View>
<Button title="加载" onPress={() => adRef.current?.load()} />
<Button
title="展示"
onPress={async () => {
if (await adRef.current?.isAdReady()) {
adRef.current?.show();
}
}}
/>
</View>
);
}
| 回调 | 入参 | 说明 |
|---|---|---|
onInterstitialAdLoaded |
— | 加载成功 |
onInterstitialAdLoadFail |
AdError |
加载失败 |
onInterstitialAdShow |
ATAdInfo |
展示成功 |
onInterstitialAdShowFailed |
AdError |
展示失败 |
onInterstitialAdClose |
ATAdInfo |
关闭 |
onInterstitialAdClicked |
ATAdInfo |
点击 |
onInterstitialAdVideoStart |
ATAdInfo |
视频开始 |
onInterstitialAdVideoEnd |
ATAdInfo |
视频结束 |
onInterstitialAdVideoError |
AdError |
视频播放失败 |
onDeeplinkCallback |
ATAdInfo, boolean |
DeepLink 跳转结果 |
onDownloadConfirm |
ATAdInfo |
下载二次确认 |