Menu

Native Ads


typescript Copy
import {ATNativeSDK} from "db://assets/script/AnyThinkAds/ATNative";

// When loading native ads, you need to pass in the width and height of the ad display
// Special note: If it is a native template ad, the size passed in should preferably be consistent with the nativeAdViewProperty.parent size displayed later, otherwise clipping or incomplete display may occur.
ATNativeSDK.loadAd("your placement id", ATNativeSDK.createLoadAdSize(cc.screen.windowSize.width, cc.screen.windowSize.width * 4/5));

2. Setting the Listener

typescript Copy
private NativeAdListener = {
    onNativeAdLoaded: (placementId: any) => {
        console.log("onNativeAdLoaded", placementId)
    },
    onNativeAdLoadFail: (placementId: any, errorInfo: any) => {
        console.log("onNativeAdLoadFail", placementId, errorInfo)
    },
    onNativeAdShow: (placementId: any, callbackInfo: any) => {
        console.log("onNativeAdShow", placementId, callbackInfo)
    },
    onNativeAdClick: (placementId: any, callbackInfo: any) => {
        console.log("onNativeAdClick", placementId, callbackInfo)
    },
    onNativeAdVideoStart: (placementId: any) => {
        console.log("onNativeAdVideoStart", placementId)
    },
    onNativeAdVideoEnd: (placementId: any) => {
        console.log("onNativeAdVideoEnd", placementId)
    },
    onNativeAdCloseButtonTapped: (placementId: any, callbackInfo: any) => {
        console.log("onNativeAdCloseButtonTapped", placementId, callbackInfo)
        ATNativeSDK.removeAd(Constant.NativePlacementId);
    }
};

ATNativeSDK.setAdListener(this.NativeAdListener);

Please note that the unit of size passed in may differ between iOS and Android platforms, and conversion may be required.

typescript Copy
import {AdViewProperty} from "db://assets/script/AnyThinkAds/ATNative";

ATNativeSDK.entryAdScenario("your placement id", "your scenario id");
if (ATNativeSDK.hasAdReady("your placement id")) {
    const windowSize = cc.screen.windowSize;
    const windowWidth = windowSize.width;
    const windowHeight = windowSize.height;
    const padding = windowSize.width / 35;
    const parentWidth = windowWidth;
    const parentHeight = windowWidth * 4 / 5;
    const appIconSize = windowWidth / 7;
    const nativeAdViewProperty = new AdViewProperty();
    nativeAdViewProperty.parent = nativeAdViewProperty.createItemViewProperty(0, windowHeight - parentHeight, parentWidth, parentHeight, "#ffffff", "", 0);
    nativeAdViewProperty.appIcon = nativeAdViewProperty.createItemViewProperty(0, parentHeight - appIconSize, appIconSize, appIconSize, "", "", 0);
    nativeAdViewProperty.cta = nativeAdViewProperty.createItemViewProperty(parentWidth - appIconSize * 2, parentHeight - appIconSize, appIconSize * 2, appIconSize, "#2095F1", "#ffffff", appIconSize / 3);
    nativeAdViewProperty.mainImage = nativeAdViewProperty.createItemViewProperty(padding, padding, parentWidth - 2 * padding, parentHeight - appIconSize - 2 * padding, "#ffffff", "#ffffff", 14);
    nativeAdViewProperty.title = nativeAdViewProperty.createItemViewProperty(appIconSize + padding, parentHeight - appIconSize, parentWidth - 3 * appIconSize - 2 * padding, appIconSize / 2, "", "#000000", appIconSize / 3);
    nativeAdViewProperty.desc = nativeAdViewProperty.createItemViewProperty(appIconSize + padding, parentHeight - appIconSize / 2, parentWidth - 3 * appIconSize - 2 * padding, appIconSize / 2, "#ffffff", "#000000", appIconSize / 4);
    nativeAdViewProperty.dislike = nativeAdViewProperty.createItemViewProperty(parentWidth - appIconSize / 2, 0, appIconSize / 2, appIconSize / 2, "#00ffffff", "#ffffff", 14);
    nativeAdViewProperty.elements = nativeAdViewProperty.createItemViewProperty(0, parentHeight - appIconSize / 2, parentWidth, appIconSize / 2, "#7f000000", "#ffffff", 14)
    ATNativeSDK.showAdInScenario("your placement id" nativeAdViewProperty, "your scenario id");
} else {
    // When loading native ads, you need to pass in the width and height of the ad display
    // Special note: If it is a native template ad, the size passed in should preferably be consistent with the nativeAdViewProperty.parent size displayed later, otherwise clipping or incomplete display may occur.
    ATNativeSDK.loadAd("your placement id", ATNativeSDK.createLoadAdSize(cc.screen.windowSize.width, cc.screen.windowSize.width * 4/5));
}

Previous
Banner Ads
Next
The Callback Info
Last modified: 2025-06-04Powered by