神蓍广告插件接入文档
2025年8月12日大约 4 分钟
神蓍广告插件接入文档
原生小程序接入文档
使用插件前,您需要:
- 在神蓍广告平台注册账号并创建应用
- 获取应用的 appKey
- 获取对应广告位的 advertId
- 在小程序项目中引入插件
插件初始化
在使用广告功能前,需要先引入插件并进行初始化:
// app.json中
"plugins": {
"adset": {
"version": "3.1.0",
"provider": "wx36639e7463c02264"
}
},
"usingComponents": {
"adset-draw": "plugin://adset/adset-draw",
"adset-inter":"plugin://adset/adset-inter"
}广告类型
激励视频广告
激励视频广告是全屏视频广告,用户观看完整视频后可以获得奖励。
初始化和使用
// 引入插件
const plugin = requirePlugin('adset')
// 初始化激励视频广告
Page({
data: {
rewardedVideoAd: null
},
onLoad() {
plugin.initReward('your_app_key', 'your_advert_id').then(res => {
// 保存广告实例
this.setData({
rewardedVideoAd: res
})
// 监听广告加载事件
this.data.rewardedVideoAd.onLoad(() => {
console.log('激励广告加载成功')
})
// 监听错误事件
this.data.rewardedVideoAd.onError((err) => {
console.error('激励视频广告加载失败', err)
})
// 监听关闭事件
this.data.rewardedVideoAd.onClose((res) => {
console.log('激励视频广告关闭', res)
})
}).catch(err => {
console.error(err)
})
},
// 展示广告
showRewardAd() {
this.data.rewardedVideoAd.show()
}
})插屏广告
插屏广告是一种全屏展示的广告形式,通常在页面切换时展示。
初始化和使用
// wxml
<button id="showInter" bindtap="showInter">播放插屏</button>
<adset-inter appKey="your_appKey" advertId="your_advertId" show="{{showAd}}"
bind:adShow="adShow" bind:adClose="adClose" app="{{app}}"
></adset-inter>
/// js
Page({
data: {
showAd:false,
app:null,
},
async onLoad() {
this.setData({
app:wx
})
},
async showInter() {
this.setData({
showAd:true
})
},
adShow(e){
console.log(e)
},
adClose(e){
console.log(e)
}
})原生模板广告
原生模板广告是可以融入到页面内容中的广告组件,支持自定义样式和布局。
使用方法
- 在页面wxml中使用组件:
<adset-draw
appKey="your_app_key"
advertId="your_advert_id"
bind:adLoad="onAdLoad"
bind:adError="onAdError"
bind:adClose="onAdClose"
/>- 在页面js中处理广告事件:
Page({
onAdLoad(e) {
console.log('原生模板广告加载成功', e.detail.message)
},
onAdError(e) {
console.error('原生模板广告加载失败', e.detail.message, e.detail.err)
},
onAdClose(e) {
console.log('原生模板广告关闭', e.detail.message)
}
})错误处理
在使用插件过程中可能遇到的错误及处理方法:
初始化错误
- appKey为空:请确保传入正确的appKey
- advertId为空:请确保传入正确的advertId
广告加载失败
- 检查网络连接
- 确认广告位ID是否正确
- 查看具体的错误信息进行处理
广告展示失败
- 确保广告已经加载完成
- 检查广告实例是否正确保存
- 避免频繁调用show方法
注意事项:
- 建议在页面加载时就初始化广告,避免在需要展示时才进行初始化
- 妥善保存广告实例,避免重复初始化
- 合理处理广告加载失败的情况,提供良好的用户体验
- 遵守微信小程序的广告展示规则和频率限制
UniApp 小程序接入文档
在小程序后台申请 uniAD和adcore插件
在使用到广告位的页面路径后缀加上广告位,例如:pages/test-ad/test-ad_1013000002,其中1013000002是广告位id(实际换成你自己申请下来的广告位),如果一个页面使用到多种类型的广告位,任选一个加上

Banner/视频/格子广告
<template>
<view class="adContainer">
<ad adpid="xxxx" @load="adLoad" @error="adError"></ad>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
adLoad() {
console.log("adLoad");
},
adError(e) {
console.log("adError", e);
}
}
}
</script>激励视频
提示
不支持纯API方式调用
<template>
<view>
<ad-rewarded-video ref="adRewardedVideo" adpid="1507000689" :preload="false" :loadnext="false" :disabled="true"
v-slot:default="{loading, error}" @load="onadload" @close="onadclose" @error="onaderror">
<view class="ad-error" v-if="error">{{error}}</view>
</ad-rewarded-video>
<button type="primary" :disabled="isLoading" :loading="isLoading" @click="showAd">显示广告</button>
</view>
</template>
<script>
export default {
data() {
return {
isLoading: false
}
},
onReady() {
this.isLoading = true;
this.$refs.adRewardedVideo.load();
},
methods: {
showAd() {
if (this.isLoading) {
return
}
this.$refs.adRewardedVideo.show();
},
onadload(e) {
this.isLoading = false;
console.log('广告数据加载成功');
},
onadclose(e) {
const detail = e.detail
// 用户点击了【关闭广告】按钮
if (detail && detail.isEnded) {
// 正常播放结束
console.log("onClose " + detail.isEnded);
} else {
// 播放中途退出
console.log("onClose " + detail.isEnded);
}
//this.isLoading = true;
//this.$refs.adRewardedVideo.load();
},
onaderror(e) {
// 广告加载失败
console.log(e.detail);
this.isLoading = false;
}
}
}
</script>
<style>
.ad-error {
color: orangered;
margin-top: 5px;
}
</style>插屏广告
提示
不支持纯API方式调用
<template>
<view>
<ad-interstitial ref="adInterstitial" adpid="1111111113" :loadnext="false" v-slot:default="{loading, error}" @load="onadload" @close="onadclose" @error="onaderror">
<view v-if="error">{{error}}</view>
</ad-interstitial>
<button type="primary" :disabled="isLoading" :loading="isLoading" @click="showAd">显示广告</button>
</view>
</template>
<script>
export default {
data() {
return {
isLoading: false
}
},
methods: {
showAd() {
this.isLoading = true;
this.$refs.adInterstitial.show();
},
onadload(e) {
this.isLoading = false;
console.log('广告数据加载成功');
},
onadclose(e) {
// 用户点击了关闭广告
console.log("onadclose",e);
},
onaderror(e) {
// 广告加载失败
console.log("onaderror: ", e.detail);
}
}
}
</script>