Native (Google)

The native ads are a kind of ad that can be shown using the same visual style like the rest of the app, which allows a natural and non-intrusive integration with the user interface.

Currently, Wortise provides the possibility of use the native ads from Google's ad platform ("Native Advanced"), in a simple and direct way.

Integration

To request a native ad, it is needed to make an integration by code just as shown in the example below:

class MainActivity : Activity() {

    private var googleNativeAd: GoogleNativeAd? = null
    
    override fun onCreate(savedInstanceState: Bundle?) {
        ...
        googleNativeAd = GoogleNativeAd(
                         this, "Wortise Ad Unit ID", nativeListener).also {
            it.load()
        }
    }
    
    override fun onDestroy() {
        ...
        googleNativeAd?.destroy();
    }
    
    private val nativeListener = object : GoogleNativeAd.Listener() {
            
        override fun onNativeClicked(ad: GoogleNativeAd) {
            // Invoked when the ad has been clicked
        }
        
        override fun onNativeFailedToLoad(ad: GoogleNativeAd, error: AdError) {
            // Invoked when the ad could not be loaded
            // (because of an error or no fill)
        }
        
        override fun onNativeImpression(ad: GoogleNativeAd) {
            // Invoked when the ad has generated an impression
        }
        
        override fun onNativeLoaded(ad: GoogleNativeAd, nativeAd: NativeAd) {
            // Invoked when the ad has been loaded
        }
    }
}

Once the native ad has been successfully loaded, obtaining as result a NativeAd instance, it is needed to complete the integration by following Google's documentation on this matter: https://developers.google.com/ad-manager/mobile-ads-sdk/android/native/advanced?hl=en#display_a_nativead

Specify options

The GoogleNativeAd class includes a method called withNativeAdOptions which allows to specify custom options by using the NativeAdOptions class from Google. This method must be called before loading the ad.

Below you can check a brief usage example:

var adOptions = NativeAdOptions.Builder()
    // Options are set here
    .build();

googleNativeAd.withNativeAdOptions(adOptions)

Última actualización