Douyin applet creates advertising space

Douyin Open Platform-Traffic Master Behavior Specification  This is a Douyin document, but Nini will teach you how to write code~

Open traffic master

The opening conditions must be met to open the advertising space! ! !

Apply for a slot ID

After meeting the conditions, click the activate button, fill in the bound account and the type of advertising space, and you will have an advertising ID. Congratulations~

code development

incentive video

Nini mainly writes about the Douyin open platform-tt.createRewardedVideoAd  incentive video this time, and the others should be similar

  onLoad() {
    // 创建实例
    this.ad = tt.createRewardedVideoAd({
      adUnitId: "xxx",
    });

    // 监听错误
    this.ad.onError((err) => {
      tt.hideLoading();
      switch (err.errCode) {
        case 1004:
          // 无合适的广告
          break;
        default:
        // 更多请参考错误码文档
      }
    });

    // 监听视频播放完成
    this.ad.onClose((data) => {
      tt.hideLoading();
      if (data.isEnded) {
        console.log("观看了", data.count, "个视频");
      } else {
        console.log("未观看完视频");
      }
    });

    // 预加载资源
    this.ad.load();
  },

  // 处理用户点击,这里就可以打开激励视频啦
  handleClick() {
    tt.showLoading();
    this.ad.show();
  },

Banner advertisement

Douyin open platform-ad advertising component  banner is accessed in the form of a component, and banner the width of the ad is affected by the css style

  <ad
      unit-id="{
   
   {unitId}}" 
      bindload="bindload"
      binderror="binderror"
      bindclose="bindclose"
      ad-intervals="{
   
   {adIntervals}}"
      fixed="{
   
   {fixed}}"
      type="{
   
   {type}}"
      scale="{
   
   {scale}}"
    />


// uniapp的开发的话注意格式哦~
// <ad :unit-id="unitId" @load="bindload" @error="binderror" @close="bindclose" :ad-intervals="adIntervals" :fixed="fixed" :type="type" /> 


data: {
    unitId: '广告位 id,必填',
    adIntervals: 31,//广告自动刷新的间隔时间,只对 banner 型广告生效。单位为秒,参数值必须大于等于 30(该参数不传入时 banner 广告不会自动刷新)
    fixed: false,//广告是否在屏幕中固定展示
    type: 'banner',//广告的类型
    scale: 100,//广告的缩放比例,100 为标准尺寸
  },
methods:{
    bindload(){//广告加载成功的回调方法},
    binderror(err){//广告加载失败的回调方法,可以查看错误码,分析错误},
    bindclose(){//广告加载关闭的回调方法},
}

When I was debugging on the real machine, an error code 1004 would be reported, which is normal. It means that there is no suitable advertisement at present, and the advertisement does not appear every time. This time it may not appear because the user is not suitable for browsing the advertisement. Because there were too many test requests, it was judged as malicious traffic brushing, and the advertisement was not visible that day.

Guess you like

Origin blog.csdn.net/violetta521/article/details/129296465