Menu

Native

Note for Android:
Currently, using Unity to directly build an Android APK cannot use native video ads, because Unity packages the APK with the game's Activity hardware acceleration turned off by default, making it impossible to display video. If you need to display native ad videos, you must use the export project method. The handling method is as follows:

(1) Select the Export Project mode to export the Android project.

(2) Modify the properties in AndroidManifest and set the hardwareAccelerated property shown in the image to true.

After completing the above steps, use the current Android project for packaging.

1. Integration Process Suggestions

  1. When the app starts, load the ad by calling ATNativeAd#loadNativeAd.
  2. At the position where you need to display an ad, check whether it can be shown via ATNativeAd#hasAdReady.
  3. If you need to use Ad Scenarios to differentiate data for different business scenarios, refer to the sample code for details.

2. API Description

ATNativeAd:

API Parameters Description
loadNativeAd string placementid, Dictionary Load an ad (Starting from v5.6.8, for Pangle template rendering, Mintegral auto-render ads, etc., the width and height must be passed through the extra parameter; otherwise, the ad size may display abnormally.)
setListener ATNativeAdListener listener Set the listener callback interface (deprecated after version 5.9.51)
hasAdReady string placementid Check if there is an ad cache
renderAdToScene string placementid, ATNativeAdView anyThinkNativeAdView Display the ad
entryScenarioWithPlacementID string placementId, string scenarioID Set entry into a displayable ad scenario

You can use the following code to load a native ad:

java Copy
public void loadNative() 
{
        Debug.Log ("Developer load native, unit id = " + mPlacementId_native_all);
           ATNativeAd.Instance.client.onAdLoadEvent += onAdLoad;
           ATNativeAd.Instance.client.onAdLoadFailureEvent += onAdLoadFail;
        ATNativeAd.Instance.client.onAdImpressEvent += onAdImpressed;
        ATNativeAd.Instance.client.onAdClickEvent += onAdClick;
        ATNativeAd.Instance.client.onAdCloseEvent += onAdClose;
        ATNativeAd.Instance.client.onAdVideoStartEvent += onAdVideoStart;
        ATNativeAd.Instance.client.onAdVideoEndEvent += onAdVideoEnd;
        ATNativeAd.Instance.client.onAdVideoProgressEvent += onAdVideoProgress;

        //----- v5.6.8 and above -----
        Dictionary jsonmap = new Dictionary();

        #if UNITY_ANDROID
            ATSize nativeSize = new ATSize(width, height);
            jsonmap.Add(ATNativeAdLoadingExtra.kATNativeAdLoadingExtraNativeAdSizeStruct, nativeSize);
        #elif UNITY_IOS || UNITY_IPHONE
            ATSize nativeSize = new ATSize(width, height, false);
            jsonmap.Add(ATNativeAdLoadingExtra.kATNativeAdLoadingExtraNativeAdSizeStruct, nativeSize);

        ATNativeAd.Instance.loadNativeAd(mPlacementId_native_all, jsonmap);
}

Note: Please continue reading to learn how to be notified on load success/failure events.

4. Check if There Is an Ad Cache

java Copy
ATNativeAd.Instance.hasAdReady(mPlacementId_native_all);

You can use the following code to display a native ad:

java Copy
public void showNative()
{
        Debug.Log ("Developer show native....");
        ATNativeConfig conifg = new ATNativeConfig ();

        string bgcolor = "#ffffff";
        string textcolor = "#000000";
        int rootbasex = 100, rootbasey = 100;

        int x = rootbasex,y = rootbasey,width = 300*3,height = 200*3,textsize = 17;
        conifg.parentProperty = new ATNativeItemProperty(x,y,width,height,bgcolor,textcolor,textsize, true);

        //adlogo 
        x = 0*3;y = 0*3;width = 30*3;height = 20*3;textsize = 17;
        conifg.adLogoProperty  = new ATNativeItemProperty(x,y,width,height,bgcolor,textcolor,textsize, true);

        //adicon
        x = 0*3;y = 50*3-50;width = 60*3;height = 50*3;textsize = 17;
        conifg.appIconProperty  = new ATNativeItemProperty(x,y,width,height,bgcolor,textcolor,textsize, true);

        //ad cta 
        x = 0*3;y = 150*3;width = 300*3;height = 50*3;textsize = 17;
        conifg.ctaButtonProperty  = new ATNativeItemProperty(x,y,width,height,"#ff21bcab","#ffffff",textsize, true);

        //ad desc
        x = 60*3;y = 100*3;width = 240*3-20;height = 50*3-10;textsize = 10;
        conifg.descProperty  = new ATNativeItemProperty(x,y,width,height,bgcolor,"#777777",textsize, true);

        //ad image
        x = 60*3;y = 0*3+20;width = 240*3-20;height = 100*3-10;textsize = 17;
        conifg.mainImageProperty  = new ATNativeItemProperty(x,y,width,height,bgcolor,textcolor,textsize, true);

        //ad title 
        x = 0*3;y = 100*3;width = 60*3;height = 50*3;textsize = 12;
        conifg.titleProperty  = new ATNativeItemProperty(x,y,width,height,bgcolor,textcolor,textsize, true);

        //(Added in v5.7.21)ad dislike button (close button)
        x = 300*3 - 75;y = 0;width = 75;height = 75;
        conifg.dislikeButtonProperty  = new ATNativeItemProperty(x,y,width,height,"#00000000",textcolor,textsize, true);

        ATNativeAdView anyThinkNativeAdView = new ATNativeAdView(conifg);
        AnyThinkAds.Demo.ATManager.anyThinkNativeAdView = anyThinkNativeAdView;
        Debug.Log("Developer renderAdToScene--->");
        ATNativeAd.Instance.renderAdToScene(mPlacementId_native_all, anyThinkNativeAdView);
}

When using the scenario feature:

java Copy
public void showNative()
{
    ...
    Dictionary jsonmap = new Dictionary();
    jsonmap.Add(AnyThinkAds.Api.ATConst.SCENARIO, showingScenarioID);
    ATNativeAd.Instance.renderAdToScene(mPlacementId_native_all, anyThinkNativeAdView, jsonmap);
}

The trailing parameter passed to the ATNativeItemProperty class constructor indicates whether to use pixels (only effective for iOS). For example, on an iPhone 6, if you pass 30, 120, 300, 450 for x, y, width, and height respectively, the actual values passed to the Objective-C code on an iPhone 7 will be 15, 60, 150, 225; these values will be 10, 40, 100, 150; that is, the final values depend on the screen ratio of the target device.

As you can see above, we have defined an ATNativeConfig class for you to configure various properties of native ad assets (bgColor, textColor, textSize, position, etc.), such as the CTA button, app icon, title text, description text, cover image, and so on. Feel free to modify the properties in the config object and see what happens based on your modifications.

Detailed Description of ATNativeConfig & ATNativeItemProperty

ATNativeConfig contains multiple ATNativeItemProperty objects, used to control the style of the Native ad. ATNativeItemProperty controls the position and style of a single Native ad element; some elements may not support some properties in ATNativeItemProperty. For example, image elements (icon, main image) only support x, y, width, height, and usesPixel, but do not support background color, font size, and font color, whereas text elements (such as title, cta, desc) support all properties. In iOS games, if you want to specify "transparent", use "clearColor". For example, if you want the background of the ad area to be transparent, assign "clearColor" to the backgroundColor of parentProperty. Note: 1) Only iOS supports clearColor. For Android, if you need to specify a transparent background, simply set the alpha part in rgba to 0; 2) iOS does not support alpha, so the color value should be passed like #5aef00 (six-digit RGB value), while Android can support alpha, with its color containing 8 hexadecimal digits, such as 5a2b3c00.

parentProperty

parentProperty controls the overall size of the Native ad, as shown in the red circled area below.

Native ad element descriptions are as follows:

  • appIconProperty : The appIconProperty attribute controls the ad's icon attribute, as shown in Figure 1 below:
  • mainImageProperty: mainImageProperty controls the ad's cover image, as shown in Figure 2 below:
  • titleProperty: titleProperty controls the ad title, as shown in Figure 3 below:
  • descProperty : descProperty controls the ad description text, as shown in Figure 4 below:
  • adLogoProperty : adLogoProperty controls the ad logo attribute, as shown in Figure 5 below. Note: Some ad networks have an internally fixed position for the ad logo and do not support custom positioning by the developer, such as AdMob.
  • ctaButtonProperty: ctaButtonProperty controls the click button, as shown in Figure 6 below:
  • dislikeButtonProperty(Added in v5.7.21) dislikeButtonProperty controls the close button (if not set, the close button will not be displayed).

Note: All of the above Native ad elements, when returned, need to be rendered.

To remove a native ad from the screen, use the following code:

java Copy
public void cleanView()
{
    Debug.Log ("Developer cleanView native....");
   ATNativeAd.Instance.cleanAdView(mPlacementId_native_all,AnyThinkAds.Demo.ATManager.anyThinkNativeAdView);
}

About Template-Rendered Ads

  • You can only control template-rendered ads through parentProperty. Adjusting other properties (appIcon, title, desc, adLogo, ctaButton, mainImage, etc.) has no effect. Among them, parentProperty and mainImageProperty must be set. The parameters of mainImageProperty can be the same as parentProperty.
  • The width and height of parentProperty should be consistent with the width and height passed during loading, otherwise partial display or oversized display issues may occur.
  • Template ads have their own width-to-height ratio, which can be viewed in the ad network's dashboard. Try to select templates with the same or similar width-to-height ratio in the ad network's dashboard and use that width-to-height ratio to pass the width and height for loading and displaying ads in the code to achieve the best display effect.
  • Adaptive height for template-rendered ads: Developers can achieve adaptive height through the following steps (adaptive height during loading is only effective for Android's Pangle and YLH networks). Note:
  • When using adaptive height, taller template ads may appear. Developers can select the desired width-height ratio templates and remove templates that do not meet expectations in the ad network's dashboard.
  • Adaptive height is not controlled by the height of parentProperty.
    1. (This point only applies to Android) Enable adaptive height during loading (requires passing Key: ADAPTIVE_HEIGHT):
java Copy
Dictionary jsonmap = new Dictionary();

#if UNITY_ANDROID
    ATSize nativeSize = new ATSize(width, height);
    jsonmap.Add(ATNativeAdLoadingExtra.kATNativeAdLoadingExtraNativeAdSizeStruct, nativeSize);
    jsonmap.Add(AnyThinkAds.Api.ATConst.ADAPTIVE_HEIGHT, AnyThinkAds.Api.ATConst.ADAPTIVE_HEIGHT_YES);  
...
ATNativeAd.Instance.loadNativeAd(mPlacementId_native_all, jsonmap);
    1. Enable adaptive height during display (requires passing Key: ADAPTIVE_HEIGHT):
java Copy
...
Dictionary jsonmap = new Dictionary();
jsonmap.Add(AnyThinkAds.Api.ATConst.ADAPTIVE_HEIGHT, AnyThinkAds.Api.ATConst.ADAPTIVE_HEIGHT_YES);

ATNativeAd.Instance.renderAdToScene(mPlacementId_native_all, anyThinkNativeAdView, jsonmap);
    1. During display, you can control the ad to be centered at the top or bottom of the screen:
java Copy
...
Dictionary jsonmap = new Dictionary();
jsonmap.Add(AnyThinkAds.Api.ATConst.POSITION, AnyThinkAds.Api.ATConst.POSITION_BOTTOM);//Centered at the bottom of the screen
//jsonmap.Add(AnyThinkAds.Api.ATConst.POSITION, AnyThinkAds.Api.ATConst.POSITION_TOP);//Centered at the top of the screen

ATNativeAd.Instance.renderAdToScene(mPlacementId_native_all, anyThinkNativeAdView, jsonmap);

6. Implement the Native Ad Listener

For callback information details, please see: Callback Information Description

Use the following code to implement multiple listeners:

java Copy
        // Ad loading succeeded
           ATNativeAd.Instance.client.onAdLoadEvent += onAdLoad;
           // Ad loading failed
        ATNativeAd.Instance.client.onAdLoadFailureEvent += onAdLoadFail;
        // Ad display succeeded
        ATNativeAd.Instance.client.onAdImpressEvent += onAdImpressed;
        // Ad clicked
        ATNativeAd.Instance.client.onAdClickEvent += onAdClick;
        // Ad close button was clicked (some ad networks have this callback)
        ATNativeAd.Instance.client.onAdCloseEvent += onAdClose;
        // Ad video started playing (some ad networks have this callback)
        ATNativeAd.Instance.client.onAdVideoStartEvent += onAdVideoStart;
        // Ad video finished playing (some ad networks have this callback)
        ATNativeAd.Instance.client.onAdVideoEndEvent += onAdVideoEnd;
        // Ad video playback progress (some ad networks have this callback)
        ATNativeAd.Instance.client.onAdVideoProgressEvent += onAdVideoProgress;

The method parameter definitions are as follows in the code (Note: The method name can follow the code below or be a custom method name, but the parameters must be consistent.):

java Copy
    // sender is the ad type object, erg is the returned information
   // Ad loading succeeded
    public void onAdLoad(object sender, ATAdEventArgs erg)
    {
        Debug.Log("Developer onAdLoaded------:" + erg.placementId);
    }
    // Ad loading failed
    public void onAdLoadFail(object sender, ATAdEventArgs erg)
    {
        Debug.Log("Developer onAdLoadFail------:" + erg.placementId + "--code:" + erg.code + "--msg:" + erg.message);
    }
    // Ad display succeeded
    public void onAdImpressed(object sender, ATAdEventArgs erg)
    {
        Debug.Log("Developer onAdImpressed------:" + erg.placementId);
    }
    // Ad clicked
    public void onAdClicked(object sender, ATAdEventArgs erg)
    {
        Debug.Log("Developer onAdClicked------:" + erg.placementId);
    }
    // Ad video started playing (some ad networks have this callback)
    public void onAdVideoStart(object sender, ATAdEventArgs erg)
    {
        Debug.Log("Developer onAdVideoStart------:" + erg.placementId);
    }
    // Ad video finished playing (some ad networks have this callback)
    public void onAdVideoEnd(object sender, ATAdEventArgs erg)
    {
        Debug.Log("Developer onAdVideoEnd------:" + erg.placementId);
    }
    // Ad video playback progress (some ad networks have this callback)
    public void onAdVideoProgress(object sender, ATAdProgressEventArgs erg)
    {
        Debug.Log("Developer onAdVideoProgress------:" + erg.placementId);
    }
    // Ad close button was clicked (some ad networks have this callback)
    public void onAdCloseButtonClicked(object sender, ATAdEventArgs erg)
    {
        Debug.Log("Developer onAdCloseButtonClicked------:" + erg.placementId);
   }

    
Previous
Banner Ad
Next
Splash ad
Last modified: 2026-07-03Powered by