Page tree

Try out our new and improved Documentation Center!
Learn More

Skip to end of metadata
Go to start of metadata

Lazy Load for iOS


On This Page

Overview

The Lazy Load feature provides a new API call to manage when all trackers are fired, including third-party trackers and MobileSDK trackers.  It also optimizes the Banner AdUnit by allowing the host app to load its webview only when it is needed and just before it is needed.  When this feature is enabled, the traditional loadAd method is followed later by a second method, loadLazyAd.

Firing Trackers

The Lazy Load feature is developed to fire all Mobile SDK and third-party trackers at the same instance, ensuring an alignment between both the metrics can be maintained. This feature splits the AdUnit load process into two steps as loadAd and loadLazyAd. 

The high-level lifecycle of an AdUnit consists of two stages as load and display.  This feature divides the load stage into two further steps as loadAd and loadLazyAd, followed by display stageHaving said that, a banner webview can be attached to the display, even before loadAd is called.  However the display stage is a convenience provided by the platform and is separate from the load portion of the AdUnit lifecycle.

The second step loadLazyAd in load stage accomplishes two tasks :

  • Completes the load of the AdUnit by creating and loading the webview which fires the third-party trackers in the creative.
  • Fires the MobileSDK trackers.

Managing CPU Consumption 

The Lazy Load feature causes the initial loadAd to return a lightweight AdUnit and allows the contents to be loaded later. This functionality reduces the load time for the AdUnit by deferring the creation and configuration of the internal webview to a later point. By delaying the webview load, it reduces the consumption of additional CPU time of loading the ad object returned in the Universal Tag in the cases where the AdUnit is unused.

Additionally, it allows the host app to choose the optimal moment to fire trackers and consume CPU time to load the webview, ideally at the best possible moment before the ad is displayed to the end-user (or is queued for display with a high probability).

Scope of Lazy Load

The scope of this feature is limited to Banner AdUnits that display banner Media Types.  It does not apply to any other AdUnit, including instream video and native, nor does it apply to Media Types returned by a multi-format Banner AdUnit other than banner including banner-video (outstream video) and banner-native. 

Properties

Lazy Load enhances the MobileSDK public API with a property which indicates whether the feature is enabled or not and if not enable the same.


PropertyTypeAttributeDescription
enableLazyLoad
BOOLreadwriteIndicates if Lazy Load is enabled and if not, enable the same.
@property (nonatomic, readwrite)  BOOL  enableLazyLoad


Method 

loadLazyAd

Loads the webview of a lazy loaded AdUnit and fires all trackers, including third-party and MobileSDK trackers.

(BOOL) loadLazyAd;

Delegate Callbacks

lazyAdDidReceiveAd

lazyAdDidReceiveAd is fired when the loadAd method successfully returns a lazy loaded AdUnit, that is an AdUnit with an unallocated webview.  All other features of the AdUnit instance are available, including a populated instance of ANAdResponseInfoIf loadAd fails, then the same callbacks are used as for an AdUnit that was not lazy loaded.

(void)lazyAdDidReceiveAd:(nonnull id)ad;


Example

@property  (nonatomic, strong, nullable)  ANBannerAdView  *lazyBanner;
 
// ...
 
- (void)viewDidLoad
{
    NSString  *placementID  = @"1234567";
      
    CGRect  rect  = CGRectMake(...);  //Set location on display.
    CGSize  size  = CGSizeMake(...);  //Set size of AdUnit.
 
      
    // Create and configure banner ad view; attach to view hierarchy.
    //
    ANBannerAdView  *banner  = [ANBannerAdView adViewWithFrame:rect placementId:placementID adSize:size];
 
    self.lazyBanner = banner;
 
    self.lazyBanner.delegate = self;
    self.lazyBanner.enableLazyLoad = YES;
 
    [self.view addSubview:self.lazyBanner];
 
 
    // Begin the load of AdUnit.
    //
    [self.lazyBanner loadAd];
}
 
// ...
 
- (void)readyToDisplayLazyBanner
{
    // Complete the load of AdUnit.
    //
    [self.lazyBanner loadLazyAd];
}
 
 
 
//
// ANAdProtocol delegate methods.
//
 
- (void)adDidReceiveAd:(id)ad
{
    // Optional processing when lazy banner webview completes loading.
}
 
- (void)lazyAdDidReceiveAd:(id)ad
{
    // Optional Processing when lazy banner is received.
}
  • No labels