Skip to main content
Version: Next

Ad

Banner ad.

Reference

Type

ComponentType<AdProps>

Examples

class App extends Component {
render () {
return (
<Ad
unitId=''
adIntervals={60}
onLoad={() => console.log('ad onLoad')}
onError={() => console.log('ad onError')}
onClose={() => console.log('ad onClose')}
/>
)
}
}

AdProps

PropertyTypeRequiredDescription
unitIdstringYesd unit ID, which can be created via the Ad Host module in Mini Program Console.
adIntervalsnumberNoThe interval between the automatic refresh of the advertisements in seconds, the value of the parameter must be greater than or equal to 30.(Banner ads are not refreshed automatically if this parameter is not set.)
onLoadBaseEventOrigFunction<any>NoCallback used when an ad is loaded
onErrorBaseEventOrigFunction<onErrorEventDetail>NoCallback used when ad loading failed. event.detail = {errCode: 1002}
onCloseBaseEventOrigFunction<any>NoCallback used when an ad is closed

Property Support

PropertyWeChat Mini-ProgramH5React Native
AdProps.unitId✔️
AdProps.adIntervals✔️
AdProps.onLoad✔️
AdProps.onError✔️
AdProps.onClose✔️

onErrorEventDetail

ParamType
errCode1000 | 1001 | 1002 | 1003 | 1004 | 1005 | 1006 | 1007 | 1008

AdErrCode

An error code is obtained by executing the binderror callback.

CodeExceptionCauseSolution
1000Call failed due to a backend errorThis error is not caused by developers.Ignore the error, and it will be automatically recovered after a period of time.
1001Parameter errorThe parameter is incorrectly used.
For details, visit developers.weixin.qq.com. (There are different courses specific to Mini Programs and Mini Games. In the top tab, you can switch between the courses on the right of the Design column.)
1002Invalid ad unitThe spelling may be incorrect or the ad ID of another app may be used.Visit mp.weixin.qq.com to confirm the ad ID.
1003Internal errorThis error is not caused by developers.Ignore the error, and it will be automatically recovered after a period of time.
1004No suitable adThe ad does not appear every time. Maybe it is not appropriate to the user.This is a normal case. In addition, you need to improve compatibility in this case.
1005The ad component is being reviewed.Your ad is being reviewed and therefore cannot be displayed.Visit mp.weixin.qq.com to check the review status. In addition, you need to improve compatibility in this case.
1006The ad component is rejected.Your ad failed to pass the review and therefore cannot be displayed.Visit mp.weixin.qq.com to check the review status. In addition, you need to improve compatibility in this case.
1007The ad component is rejected.Your advertising capability is suspended. ads cannot be displayed during the suspension.Visit mp.weixin.qq.com to check the Mini Program ad suspension status.
1008The ad unit is disabled.The advertising capability in the advertising space is disabled.Visit mp.weixin.qq.com to enable the display in the advertising space.

API Support

APIWeChat Mini-ProgramH5React Native
Ad✔️