Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

BuzzAd Benefit SDK: Native Ads

...

This documentation provides a guideline for integrating native ads for BuzzAd Benefit.

※ Note

Please proceed with the following process only after BuzzAd Benefit SDK integration is complete.

...

Table of Contents
exclude.*(BuzzAd Benefit SDK: Native Ads|Note)

Basic Usage

...

Step 1: Ad request with BABAdLoader

  1. Instantiate BABAdLoader

    • Insert unit_id in place of YOUR_NATIVE_AD_UNIT_ID

  2. Call loadAdWithOnSuccess:OnFailure

...

Code Block
languageswift
// Swift
let adLoader = BABAdLoader(unitId: YOUR_NATIVE_AD_UNIT_ID)
adLoader.loadAdWith(onSuccess: { ad in
  self.renderAd(ad) // Refer to Step 3
}, onFailure: { error in
  // Handle error
})

Step 2: Creating an ad layout

Create a layout for the ad components and link them to the relevant views.

...

Component

Description

Size

Requirements

Required

Media view

A creative (image or video)

1200x627 px

  • The aspect ratio should be kept

  • Padding can be added around the image

Y

Title view

The title of the ad

Max 25 characters

Ellipses can be used for omission over certain length

Y

Description view

A detailed description of the ad

Max 100 characters

Ellipses can be used for omission over certain length

Y

CTA view

  • Reward text view: Amount of point rewarded for opting in an ad

  • CTA text view: Phrase that drives the user action for the ad

Max 15 characters

Ellipses can be used for omission over certain length

Y

Icon image view

The advertiser's icon image

80x80 px

The aspect ratio should be kept

N

Sponsored 
image/ text view

A Text or an image indicating that it is an ad

-

Expose texts like Ad, Sponsored, etc.

N

Step 3: Constructing the layout with the BABAd

Draw an ad view using the BABAd received from the onSucess in Step 1.

  1. Set each ad property to the components created in Step 2.

  2. Set the MediaView and the ad to a NativeAdView.

  3. Create a clickableViews list to specify the areas where you want to make the ad clickable. Clicking the view area will lead to a landing page of an ad.

    Code Block
    languageobjective-c
    // Objective-C
    - (void)renderAd(BABAd *ad) {
      // 1)
      self.titleLabel.text = ad.creative.title;
      
      // Description field exists as a default in objc
      self.descriptionLabel.text = ad.creative.body;
    
      [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:ad.creative.iconUrl]];
      self.ctaLabel.text = [NSString stringWithFormat:@"+%d %@", (int)ad.reward, ad.creative.callToAction];
      [self.rewardIcon setImage:[UIImage imageNamed:@"point_icon"]];
    
      // 2)
      self.adView.ad = ad;
      self.adView.mediaView = self.mediaView;    
    
      // 3)
      self.adView.clickableViews = @[self.ctaButton, self.iconImageView];
    }


    Code Block
    languageswift
    // Swift
    func renderAd(ad: BABAd) {
      // 1)
      self.titleLabel.text = ad.creative.title
    
      // Description field exists as a default in objc
      self.descriptionLabel.text = ad.creative.body
    
      self.iconImageView.sd_setImage(with: URL(string: ad.creative.iconUrl))
      self.ctaLabel.text = "+\(ad.reward) \(ad.creative.callToAction)"
      self.rewardIcon.image = UIImage(named: "point_icon")
    
      // 2)
      self.adView.ad = ad
      self.adView.mediaView = self.mediaView
    
      // 3)
      self.adView.clickableViews = [self.ctaButton, self.iconImageView]
    }

Step 4: Handling ad events via the BABNativeAdViewDelegate

Ad events can be handled by setting a delegate in the BABAdView (Refer to the document for event definitions and actions)

...

Code Block
languageswift
// Swift
class SampleViewController: UIViewController, BABNativeAdViewDelegate {
  override func viewDidLoad {
    adView.deleagte = self
  }

  // Called when the ad impression is generated.
  func babNativeAdView(_ adView: BABNativeAdView, didImpress ad: BABAd) { }

  // Called when an ad is clicked.
  func babNativeAdView(_ adView: BABNativeAdView, didClick ad: BABAd) { }

  // Called when the reward request is initiated.
  func babNativeAdView(_ adView: BABNativeAdView, willRequestRewardFor ad: BABAd) {
  }

  // Called when the reward request is complete. The result is contained in the `result` argument.
  func babNativeAdView(_ adView: BABNativeAdView, didRewardFor ad: BABAd, with result: BABRewardResult) {
  }

  // Called when the user has completed the required action for the ad. The status of UI needs to be changed to 'complete' here.
  func babNativeAdView(_ adView: BABNativeAdView, didParticipateAd ad: BABAd) {
    self.rewardIcon.image = UIImage(named: "participated_icon")
  }
}

Advanced Usage

...

Loading multiple native ads

Code Block
languageobjective-c
// Objective-C
BABAdLoader *adLoader = [[BABAdLoader alloc] initWithUnitId:YOUR_NATIVE_AD_UNIT_ID];
[adLoader loadAdsWithSize:5 onSuccess:^(NSArray<BABAd *> * _Nonnull ads) {
  NSLog(@"%d ads loaded!", ads.count);
} onFailure:^(NSError * _Nullable error) {
  // Handle error
}];

Code Block
languageswift
// Swift
let adLoader = BABAdLoader(unitId: "YOUR_NATIVE_AD_UNIT_ID")
adLoader.loadAds(withSize: 5, onSuccess: { ads in
  NSLog("%d ads loaded!", ads.count)
}, onFailure: { error in
  // Handle error
})

Handling the UI based on the user’s ad engagement

All ads served via BuzzAd Benefit SDK are rewarded ads. Each ad has “reward period”, a period of time required for users to earn extra reward for participating in the same ad, of 2 hours by default. Thus, there should be a UI displaying whether user is eligible for earning reward for the particular ad engagement.

...