Mini Program Advertising Traffic Owner Guide: Document Link Developers can use the ad-custom component to create Native Template ad components. Once created, Native Template ad components will automatically retrieve and display ad data.
Ad Size Settings
Native template ads do not allow direct style attribute settings. The default width is 100% (width: 100%), and the height is automatically calculated proportionally. Therefore, developers can adjust the ad size by setting the width of the outer component of the ad.
The width of the ad's outer component varies by specific template. For details, please refer to the Template Editor documentation.
/* The width of the outer component can be set to 100% or a specific value */
.adContainer {
width: 100%;
}
<view class="adContainer">
<ad-custom unit-id="xxxx"></ad-custom>
</view>
Ad Event Listening
Native template ads are automatically fetched after creation. Developers can listen for successful or failed ad fetching using the onload and onerror events of the ad-custom component, and can also listen for ad closure via the onclose event.
<view class="adContainer">
<ad-custom unit-id="xxxx" bindload="adLoad" binderror="adError" bindclose="adClose"></ad-custom>
</view>
Page({
adLoad() {
console.log('Native template ad loaded successfully')
},
adError(err) {
console.log('Native template ad loading failed', err)
},
adClose() {
console.log('Native template ad closed')
},
})
Scheduled Ad Refresh
Developers can achieve scheduled ad refresh by passing the ad-intervals parameter when creating a Native Template ad. The ad-intervals parameter is of numeric type, with seconds as the unit. Note: The interval for automatic refresh must not be less than 30 seconds, so the value of the ad-intervals parameter must be greater than or equal to 30.
<view class="adContainer">
<ad-custom unit-id="xxxx" ad-intervals="30"></ad-custom>
</view>
Monitor Ad Hiding
- Special notes for trigger-based matrix cell ads:
When the user taps the close button in the top-right corner, the ad will be hidden by controlling the style
display: noneof the<ad-custom />element. Developers can monitor the hiding event through theonhideevent of the ad-custom component, and make the ad reappear by modifying thedisplaystyle at the appropriate time.
<ad-custom unit-id="xxxx" bindhide="adHide"></ad-custom>