Inline Placements

Inline ads, commonly referred to as “banners” or “rectangles”, are ad units that appear inline with other app content. Inline Ads are often found at the top or bottom of a mobile device’s screen while reading articles and searching through content. We recommend using inline ads on both smartphones and tablets in cases where the user is reading and/or interacting with content on the same screen for a period of time.

Integrating Inline Ad Placements

To add an inline ad to an application, import the required classes, instantiate an inline ad factory, load the ad, and attach it to the app’s view hierarchy.

1. Import the required classes

Import the following into the Android activity or iOS view controller that will contain the ad.

//Required Verizon Ads SDK imports for inline ads
import com.verizon.ads.ErrorInfo;
import com.verizon.ads.inlineplacement.InlineAdFactory;
import com.verizon.ads.inlineplacement.InlineAdView;
import com.verizon.ads.inlineplacement.AdSize;
//Required Verizon Ads SDK imports for inline ads
#import <VerizonAdsInlinePlacement/VerizonAdsInlinePlacement.h>
//Required Verizon Ads SDK imports for inline ads
import VerizonAdsInlinePlacement

2. Create an inline ad factory

An instance of the inline ad factory is required to load an ad. The factory is created once, typically when the app’s activity or view controller is created.

//Create inline ad factory required to load the ad with example dimensions
int width = 320, height = 50;
adSize = new AdSize(width, height);
List<AdSize> adSizes = new ArrayList<>();
adSizes.add(adSize);
inlineAdFactory = new InlineAdFactory(myInlineActivity, PLACEMENT_ID, adSizes, myAdFactoryListener);
//Create interstitial ad factory required to load the ad with example dimensions
VASInlineAdSize *size = [[VASInlineAdSize alloc] initWithWidth:320 height:50];
self.inlineFactory = [[VASInlineAdFactory alloc]
    initWithPlacementId:kYourAppBannerAdPlacementID adSizes:@[size]
                 vasAds:[VASAds sharedInstance] delegate:myAdFactoryDelegate];
//Create interstitial ad factory required to load the ad with example dimensions
if let size = VASInlineAdSize(width: 320, height: 50) {
    adFactory = VASInlineAdFactory(placementId: sampleBannerPlacementID, adSizes:[size], vasAds: VASAds.sharedInstance, delegate:myAdFactoryDelegate)
}

Inline ad factory callbacks

The Inline ad factory callbacks communicate events related to ad loading, such as success/failure of an ad load or load/update of the cache. These are implemented as an interface (Android) and delegates (iOS). Please refer to the API documentation for Android and iOS for a complete list of available callbacks.

//Inline ad factory callbacks
@Override
public void onLoaded(InlineAdFactory inlineAdFactory, final InlineAdView inlineAdView) {
    Log.i("InlineAdFactory", "Request for inline ad succeeded"); 
}
//etc...
//Inline ad factory callbacks
- (void)inlineAdFactory:(nonnull VASInlineAdFactory *)adFactory didLoadInlineAd:(nonnull VASInlineAdView *)inlineAd
{
    NSLog(@"Request for inline ad succeeded");
}
//etc...
//Inline ad factory callbacks
func inlineAdFactory(_ adFactory: VASInlineAdFactory, didLoadInlineAd inlineAd: VASInlineAdView) {
    print("Request for inline ad succeeded")
}
//etc...

3. Load an ad

Prior to displaying an ad, it must be loaded as seen below.

//Load the inline ad
inlineAdFactory.load(myAdListener);
//Load the inline ad
[self.inlineFactory load:myAdDelegate];
//Load the inline ad
if let adFactory = adFactory {
    adFactory.load(myAdDelegate)
}

Inline ad callbacks

The inline ad callbacks provide information about events related to the ad, such as click events, expand/collapse, resize, and errors. These are implemented as an interface (Android) and delegate methods (iOS). Please refer to the API documentation for Android and iOS for complete list of available callbacks.

//Inline ad callbacks
@Override
public void onClicked(InlineAdView inlineAdView) {
  Log.i("InlineAdView", "Inline ad was clicked");
}
//Inline ad callbacks
- (void)inlineAdClicked:(VASInlineAdView *)inlineAd
{
    NSLog(@"Inline ad was clicked");
}
//Inline ad callbacks
func inlineAdClicked(_ inlineAd: VASInlineAdView) {
    print("Inline ad was clicked")
}

4. Show the ad

After the ad is loaded, the ad factory will call back to the onLoaded (Android) or -didLoadInlineAd: (iOS) method with the ad. Each inline ad is provided as a view, and that view should be inserted at the appropriate place in the app’s view hierarchy. A common strategy is to set up a container view in the view hierarchy, so that the ad view can be easily added to that container.

//Show the ad
public void showAd(final InlineAdView inlineAdView) {
  runOnUiThread(new Runnable() {
     @Override
     public void run() {
        adContainer.addView(inlineAdView);
        Log.i("InlineAd", "Load successful");
     }
  }
}
//Show the ad
- (void)showAd:(VASInlineAdView *)inlineAd
{
    dispatch_async(dispatch_get_main_queue(), ^{
        inlineAd.frame = self.adContainer.bounds;
        [self.adContainer addSubview:inlineAd];
    }
}
//Show the ad
func showAd(_ inlineAd: VASInlineAdView) {
    DispatchQueue.main.async {
        if let container = self.adContainer {
            inlineAd.frame = container.bounds
            container.addSubview(inlineAd)
        }
    }
}

5. Android Only - Destroy the ad

When the ad instance is no longer needed or when the activity is finished, the instance must be destroyed to free up resources.

//Destroy the ad
inlineAdView.destroy()

For a complete example of implementing an Inline Ad within an app, please review the sample application.