Show Sidebar

Requesting Native Ads – Android SDK without Helper Libraries

ขออภัยรายการนี้จะใช้ได้เฉพาะในภาษาอังกฤษ English. For the sake of viewer convenience, the content is shown below in the alternative language. You may click the link to switch the active language.

It is recommended to use the VMAX Helper Library.

Alternatively, you can use getter functions to get Ad Elements and then render Native Ad. Once the native ad is cached, success callbacks is received as adViewDidCacheAd() in sdk version below 3.6.0 and onAdReady() in sdk version 3.6.0 onwards.

To Fetch Native Ad always use only cacheAd().
showAd() or loadAd() apis are not supported for invoking Native Ads.

Note: For all ad partners except AdMob follow below table.

Parameter Recommended Description
nativeAd.getTitle();  Yes  the title property of the ad
nativeAd.getDesc();  Yes  the description property of the ad
nativeAd.getCtaText();  Yes  the call to action title property of the ad
nativeAd.getRating();  Optional
nativeAd.getMediaView();  Yes to be used only for Facebook and Vserv Ads
nativeAd.getNativeAdPartner();  Yes to get Ad partner
nativeAd.getAdChoiceUrl();  Yes to be used only for Facebook
nativeAd.getObjective();  Optional
nativeAd.getVastVideoTag();  Optional
nativeAd.getDesc2();  Optional
nativeAd.getPrice();  Optional
nativeAd.getDownloads();  Optional
nativeAd.getAdChoiceView();  Yes  getAdChoiceView() used only for Facebook. While using this Adchoice view of Facebook than ignore getAdChoiceUrl().It automatically handles click on it.
nativeAd.getNativeAdType();  Optional
nativeAd.getSalePrice();  Optional
nativeAd.getSponsored();  Optional
nativeAd.getLikes();  Optional
nativeAd.getPhone();  Optional
nativeAd.getAddress();  Optional
nativeAd.getDisplayurl();  Optional
nativeAd.getIcon().getUrl();  Yes
nativeAd.getIcon().getWidth();
nativeAd.getIcon().getHeight();
nativeAd.getImageMain().getUrl();
nativeAd.getImageMain().getWidth();
nativeAd.getImageMain().getHeight();
nativeAd.getImageMedium().getUrl();
nativeAd.getImageMedium().getWidth();
nativeAd.getImageMedium().getHeight();
nativeAd.getImageTile().getUrl();
nativeAd.getImageTile().getWidth();
nativeAd.getImageTile().getHeight();
nativeAd.getImageAdChoice().getUrl();
nativeAd.getImageAdChoice().getWidth();
nativeAd.getImageAdChoice().getHeight();

Additional notes for InMobi Native Ads

From InMobi version 6.0.0 (supported from VMAX Android SDK v3.5.19), InMobi returns a ‘screenshots’ element on their dashboard as shown in the accompanying image.

inmobi_json

  • If you select an image with aspectRatio ‘1.91’, this is mapped to the ‘imageMain’ element of the Native Ad object. Thus, requesting for imageMedium will result in a nil value.
  • If you select an image with aspectRatio ‘1’, this is mapped to the ‘imageMedium’ & ‘imageTile’ elements of the Native Ad object. Thus, requesting for imageMain will result in a nil value.

As a best practice, you should always check if the requested element is nil or not and for non-nil, use the native ad element in rendering your custom native ad layout.

Ad Network Policies

In addition, you need to adhere to the policies shared by AdMob and Facebook here:

If using any ad network other than AdMob or Facebook, be sure to include an Ad symbol so that app users can identify that it’s an ad. The below example shows a test ad from VMAX having an icon, large image, title, CTA button and the ad attribution symbol in the top right.

image00

Once all elements are assigned to Ad parentview and just when your Ad parentView is visible use below function to track impressions and clicks. No need to set any listener on Ad. This function is very important used only when native Ads rendering is without helper libraries.

// very important function used only when native Ads render without helper libraries.

Implementation

Add vmax_custom_native_layout.xml in your Layouts

Add below code in your Activity class

SDK 3.6.0 onwards

In this snippet,  registerViewForInteraction() api is mandatory and is used to track impression and clicks. It should be called as shown below.
Parameters:

adView is mandatory for proper handling of Native Ads.
vgroup is main Ad parnetView and is compulsory to be of type RelativeLayout.
view is mandatory so as to set listener, it should be CTA view or any other Native Ad element view.
listview is Optional if click on multiple views required. If listview is provided than third argument View view should be parent of the view available in list.

Note: For AdMob AdChoice View icon, pass second parameter in above function that is Ad container Layout and keep top right space empty say 15px. VMAX SDK will handle to render AdMob Adchoice icon for AdMob.

Before SDK 3.6.0

In this snippet, registerViewForInteraction() api is mandatory and is used to track impression and clicks. It should be called as shown below.
Parameters:

adView is mandatory for proper handling of Native Ads.
vgroup is main Ad parnetView and it is mandatory.
view is mandatory so as to set listener, it should be CTA view or any other Native Ad element view.
listview is Optional if click on multiple views required. If listview is provided than third argument View view should be parent of the view available in list.

Note: For AdMob AdChoice View icon, pass second parameter in above function that is Ad container Layout and keep top right space empty say 15px. VMAX SDK will handle to render AdMob Adchoice icon for AdMob.

 

Make sure to handle Activity life cycle callbacks with VmaxAdview for proper functioning of Ads

What would you like to do next?