插屏广告
插屏广告是由客户端原生渲染,由开发者控制广告组件的显示。
广告创建
插屏广告组件默认是隐藏的。
const ad = tt.createInterstitialAd({ adUnitId: "YOUR_UNIT", });
广告拉取成功与失败
const interstitialAd = tt.createInterstitialAd({ adUnitId: "YOUR_AD_UNITID", }); interstitialAd.onLoad(() => { console.log('interstitialAd load') }) interstitialAd.load()
interstitialAd.onError(({ errCode, errMsg }) => { console.log('监听到错误', errCode, errMsg) })
显示/隐藏
插屏广告组件默认是隐藏的,开发者需要调用 InterstitialAd.show() 进行显示。如果广告拉取失败或触发频率限制,InterstitialAd.show() 方法会返回一个rejected Promise,开发者可自行监听错误信息。常见异常错误参考文档
const ad = tt.createInterstitialAd({ adUnitId: "YOUR_UNIT", }); ad.load() .then(() => { ad.show().then(() => { console.log("插屏广告展示成功"); }); }) .catch((err) => { console.log(err); });
用户可以主动关闭插屏广告。开发者不可控制插屏广告组件的隐藏。
监听用户关闭广告
interstitialAd.onClose(() => { console.log('插屏广告关闭') })
注意事项
插屏广告频控
对于插屏广告的展示,有一定的频率控制,具体如下:
1. 小游戏启动后的前30s(秒),不能展示插屏广告。 2. 已经展示一次插屏广告后,第二次展示需要距离上一次展示60s。 3. 展示过一次激励视频广告后,后续需要展示插屏广告的情况下,需要与激励视频广告的展示间隔60s。
展示异常处理
对于插屏广告的展示,对于异常情况的处理有以下注意:
1. 插屏广告的show调用时,如果出现错误,该错误可以通过onError或者 Promise.catch 捕获,该错误一般为频控错误,建议等待一段时间(参考频控)后再次调用 load->onLoad-> show
interstitiaAd.onLoad(onLoadHandle);function onLoadHandle() { interstitiaAd .show().then(() => { console.log("插屏广告展示成功");}).catch((err) => {// 这里出现错误,可以等待一定时间后再次load->onLoad-> show。}); console.log("广告加载完成");}
2. 为保证双端体验,建议始终监听onError,如果需要,可以在 onError 中等待一定时间后再次调用load->onLoad-> show(参考频控和展示逻辑) 。
最佳实践
const interstitiaAd = tt.createInterstitialAd(); canReTry = true; interstitiaAd.onLoad(onLoadHandle); //创建会自动loadfunction onLoadHandle() { interstitiaAd.show().then(() => { console.log("插屏广告展示成功");});} interstitiaAd.onError(onErrorHandle); // 自动load 的失败会走到这里function onErrorHandle(err) {// 这里要等待一定时间后,或者等待下次需要展示的时候,参考频控,尝试一次,或者几次,不能一直尝试。if (canReTry) { canReTry = false; interstitiaAd.load(); //如果需要,这里等待一定时间后,或者等待下次需要展示的时候,再次 load->onLoad-> show。} else { tt.showToast({title: "暂无广告",icon: "none",});}}