Help Center/Details/

Template Banner Ads

Introduction

Template rendering Banner: Developers do not need to edit and render the ad style by themselves, but can directly call the relevant interface for ad display.

Note: Developers are not supported to add buttons to the view and block ads

Authority

**Template rendering Banner ads: ** Provided by default

Template rendering banner ads

Create TTAdNative object

//创建TTAdNative对象,createAdNative(Context context) context需要传入Activity对象
TTAdNative mTTAdNative = TTAdSdk.getAdManager().createAdNative(this);

Create ad request AdSlot

Note:

  1. The template advertisement request method requires the developer to set the setExpressViewAcceptedSize parameter in dp.
  2. In the parameter setting of the desired personalized template size, the personalized template Banner ad height cannot be set to 0
  3. For the setExpressViewAcceptedSize parameter, please make a request according to the proportion checked by the platform. The platform now supports 8 sizes. If the requested ratio is inconsistent with the size selected when the platform creates the code bit ID, a badcase of the display effect will appear. Therefore, the request ratio should be consistent with the platform ticked
AdSlot adSlot = new AdSlot.Builder()
        .setCodeId(codeId) //广告位id
        .setSupportDeepLink(true)
        .setAdCount(1) //请求广告数量为1到3条
        .setExpressViewAcceptedSize(expressViewWidth,expressViewHeight) //期望模板广告view的size,单位dp
        .build();

Parameter description

Parameter description
setCodeId The code ID created by the platform starts with 9 and 9 digits
setAdCount The number of requests is 1-3. It is recommended to set to 1
setExpressViewAcceptedSize Set the size of the request template creative unit: dp

Request ad

loadBannerExpressAd(AdSlot adSlot, @NonNull NativeExpressAdListener listener)Load ads asynchronously

Note:
-When creating the code bit, you need to choose whether to support carousel

  • If you choose carousel, you need to call TTNativeExpressAd.setSlideIntervalTime(30 * 1000); in the onNativeExpressAdLoad callback to set the carousel time
    Set the interval of banner advertisement rotation. If not set, the rotation will not be turned on by default. Banner advertisement rotation interval, the allowable value is between 30 * 1000 ~ 120 *1000
mTTAdNative.loadBannerExpressAd(adSlot, new TTAdNative.NativeExpressAdListener() {
			//请求失败回调
            @Override
            public void onError(int code, String message) {
               
            }
			
			//请求成功回调
            @Override
            public void onNativeExpressAdLoad(List<TTNativeExpressAd> ads) {
               
            }
        });

NativeExpressAdListener description

Callback Description
onError() Advertisement request failed callback The returned error code (code) indicates the reason for the failure of the advertisement request.,详情请见链接
onNativeExpressAdLoad() Callback for successful ad request, the client can call render() in this callback for ad rendering

Ad click event listener

mTTAd.setExpressInteractionListener(new TTNativeExpressAd.ExpressAdInteractionListener() {

	//广告点击回调
    @Override
    public void onAdClicked(View view, int type) {
       
    }

	//广告展示回调
    @Override
    public void onAdShow(View view, int type) {
       
    }
	
	//广告渲染失败回调
    @Override
    public void onRenderFail(View view, String msg, int code) {

    }
	//广告渲染成功回调
    @Override
    public void onRenderSuccess(View view, float width, float height) {
       
    }
});

ExpressAdInteractionListener Description

Callback Description
onAdDismiss() Ad close callback
onAdClicked() Callback when the ad is clicked
onAdShow() Ad show callback
onRenderFail() Ad rendering failed callback
onRenderSuccess() The personalized template is rendered successfully, and the client can add the advertisement directly to the control in the callback

Note: Before addView, you need to call the removeAllViews method to remove all the views on the control

Dislike monitoring

The dislike logic helps us to improve the advertising experience and match, please follow the access instructions to set
The following logic is the logic in the CSJ version 3500 SDK. SDK developers below 3500 version can refer to the corresponding demo for integration

 /**
         * 设置广告的不喜欢,开发者可自定义样式
         * @param ad
         * @param customStyle 是否自定义样式,true:样式自定义
         */
        private void bindDislike(TTNativeExpressAd ad, boolean customStyle) {
        if (customStyle) {
            //使用自定义样式,用户选择"为什么看到此广告",开发者需要执行startPersonalizePromptActivity逻辑进行跳转
            final DislikeInfo dislikeInfo = ad.getDislikeInfo();
            if (dislikeInfo == null || dislikeInfo.getFilterWords() == null || dislikeInfo.getFilterWords().isEmpty()) {
                return;
            }
            final DislikeDialog dislikeDialog = new DislikeDialog(this, dislikeInfo);
            dislikeDialog.setOnDislikeItemClick(new DislikeDialog.OnDislikeItemClick() {
                @Override
                public void onItemClick(FilterWord filterWord) {
                    //屏蔽广告
                    TToast.show(mContext, "点击 " + filterWord.getName());
                    //用户选择不喜欢原因后,移除广告展示
                    mExpressContainer.removeAllViews();
                }
            });
            dislikeDialog.setOnPersonalizationPromptClick(new DislikeDialog.OnPersonalizationPromptClick() {
                @Override
                public void onClick(PersonalizationPrompt personalizationPrompt) {
                    TToast.show(mContext, "点击了为什么看到此广告");
                }
            });
            ad.setDislikeDialog(dislikeDialog);
            return;
        }
        //使用默认模板中默认dislike弹出样式
        ad.setDislikeCallback(BannerExpressActivity.this, new TTAdDislike.DislikeInteractionCallback() {
            @Override
            public void onShow() {

            }

            @Override
            public void onSelected(int position, String value, boolean enforce) {
                TToast.show(mContext, "点击 " + value);
                mExpressContainer.removeAllViews();
                //用户选择不喜欢原因后,移除广告展示
                if (enforce) {
                    TToast.show(mContext, "模版Banner 穿山甲sdk强制将view关闭了");
                }
            }

            @Override
            public void onCancel() {
                TToast.show(mContext, "点击取消 ");
            }

            @Override
            public void onRefuse() {

            }

        });
        }

DislikeInteractionCallback Description

Callback Description
onItemClick() Callback when the user clicks on filterWord in the case of a custom style
onClick() In the case of custom styles, the user clicked "Why see this ad"
onSelected() The default dislike style, click filterWord to call back. The developer can remove the ad in this callback
onCancel() Default dislike style, click to cancel callback
onShow() Default dislike style, dislike pop-up window shows back
onRefuse() The default dislike style, the user repeatedly clicks the dislike button to call back. Version 3600 is abolished

Destroy the ad object

//在Activity的onDestroy回调方法中销毁广告对象
@Override
protected void onDestroy() {
    super.onDestroy();
    if (mTTAd != null) {
        mTTAd.destroy();
    }
}

Reference Demo

For template rendering of Banner ads, please refer to the BannerExpressActivity example in Demo

Note on template rendering Banner:

  1. Banner advertisements have their own unique usage scenarios. Banner advertisements are small bar advertisements displayed at the bottom or top of the content. It is not currently supported for use in the list.
  2. Created on the platform, for example: a code bit with a ratio of 600*300 represents that the aspect ratio of the standard template is 2:1. Developers need to advertise at a 2:1 ratio according to the actual width and height when requesting the size of the advertisement. Request.
  3. The code ID that has been created on the platform does not support modifying the size, so the developer is required to create it according to actual needs.
  4. The template banner does not support the removal of dislike, and the logic of dislike helps to improve the advertising experience and matching degree
Did the content solve your problem?
Contact us