AdTech Integration Guides

AdTech Integration Guides

  • App (SDK)
  • App (Somquery)
  • Desktop
  • CTV

›Ad Integration

Getting Started

  • Introduction

Setup

  • iOS
  • Android
  • Mandatory Functions
  • CMP Implementation

Ad Integration

  • Display Ads
  • Overlay Ads
  • Video Ads
  • Ad Event Listener

Revenue Optimisation

  • Mediation
  • Headerbidding
  • Criteo SDK

Display Ads

Display ads can be added to your application in two ways. You can either add it programatically to your code and handle the view hierarchies accordingly, or you can add it through storyboards (iOS) or XML (Android) without writing any code.

Creating display ads programmatically

To create a display ad programmatically, simply create a SomAdContainer, specify the ad type and add it to your view:

  • Android
  • iOS
val bannerAd = SomAdContainer(AdType.banner)
let bannerAd = SomAdContainer(ofType: .banner)

Creating display ads through XML or Storyboard

If you prefer to add the display ads through UI, you can do the following:

Android

To add an ad through XML on Android, add a SomAdContainer to your view and specify the adType:

<com.sevenonemedia.sevenoneads.containers.SomAdContainer
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:adType="@string/adType_banner"
                />

iOS

To add an ad through the Storyboard on iOS, you need to do the following:

  • Drag a UIView representing the ad into your application's view in the storyboard. Set the class of this UIView to SomAdContainer. Make sure you connect the outlet of your view to your corresponding view controller and handle the constraints programatically as you like.
  • In the storyboard, under the UIView’s User Defined Runtime Attributes, add an entry with the Key Path storyboardAdType of type String, and set its value to the ad type you prefer. e.g. rectangle, banner, etc. Note that only single slot ads are supported. If no value is set, the default value banner will be used.

alt text 2

Note The ads are automatically requested and loaded when the container is within the boundary of the user's screen. Ads can be added to the view at any point of the lifetime of the application. If SevenOneAds is not done initialising, the ads will automatically wait for initialisation to complete. There exist dedicated ad sizes for tablets: tabletBanner, tabletBillboard. It is up to the developer to ensure that the correct AdType is used for mobile and tablets devices.

Supported Display Ad Types

  • banner: 320x50
  • performanceBanner: 320x50
  • sponsor: 320x50
  • rectangle: 300x250
  • billboard: 320x150
  • tabletBanner: 728x90
  • tabletBillboard: 728x250

Android: Recycle-able views

Important Note:If your Android application is using recycle-able views such as RecycleView, please read this section carefully, otherwise your application may be marked as fraudulent! Recycle-able views allow views to be recycled/re-used. This can cause issues if this view holds an advertisement because the reused view can continue to trigger new ad requests in the background leading to multiple ad requests even though only a single ad is visible.

To avoid this happening, inside the function onBindViewHolder() in your custom RecyleView.Adapter class (see here on how to create an custom adapter), any cell that contains an advertisement must disable recycling for that single view by calling: viewHolder.setIsRecyclable(false).

override fun onBindViewHolder(viewHolder: MyViewHolder, position: Int) {
    // Get the custom cell
    val myCustomCell: CustomCell = dataset[position]
    
    // Given the cell knows if it should hold an ad or content
    // Check if the cell is ad or content
    if (myCustomCell.showAd) {
        // Define the AdViewHolder
        val adViewHolder: AdViewHolder = viewHolder as AdViewHolder
        
        // IMPORTANT: Set recycleable to false
        adViewHolder.setIsRecyclable(false)
        
        // Add ad to view
        adViewHolder.layout.addView(SomAdContainer(AdType.banner))
    } else {
        // Create a viewholder and add content to view, no need to set isRecycleable
    }
}

Memory management

To optimize the memory management of your app and to prevent possible memory leaks from happening, you will have to implement the SomAdContainer's destroy() method into your app in the appropriate places:

  • Android
  • iOS
class ExampleActivity : AppCompatActivity() {
    private var myAd: SomAdContainer? = null
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        ...

        myAd = SomAdContainer(AdType.banner)
        val myAdContainer: FrameLayout = findViewById(R.id.my_ad_container)
        myAdContainer.addView(myAd)
    }

    ...

    override fun onDestroy() {
        myAd?.destroy()
        super.onDestroy()
    }
}
class ExampleViewController: UIViewController {
    var myAd: SomAdContainer? = nil

    ...

    override func viewDidLoad() {
        super.viewDidLoad()
        myAd = SomAdContainer(ofType: AdType.banner)
        
        if let myAd = myAd {
            myAd.heightAnchor.constraint(equalToConstant: 50).isActive = true
            myAd.center.x = self.view.center.x
            self.view.addSubview(myAd)
        }
    }

    override func viewWillDisappear(_ animated: Bool) {
        myAd?.destroy()
        super.viewWillDisappear(animated)
    }
}

Note: Depending on your implementation, you might need to add the destroy method in other locations as well. This is especially the case for Recycler Views and View Pagers on Android and UICollectionViews on iOS.

Android: Additional Lifecycle Methods

On Android, it is highly recommended to implement the pause() and resume() methods as well:

class ExampleActivity : AppCompatActivity() {
    ...

    override fun onPause() {
        myAd.pause()
        super.onPause()
    }

    override fun onResume() {
        super.onResume()
        myAd.resume()
    }
}

Note: Adding these methods guarantees that background tasks for loading and reloading ads are paused and resumed correctly according to their parent's lifecycle events.

Multislot Ads

SevenOneAds allows you to create a multislot ad by specifying multiple ad types which may be eligible to your ad view. This way, the ad may be any of the specified ad types and sizes. To create a multislot ad, simply create a SomAdContainer, pass in a list with desired ad types and add it to your view:

  • Android
  • iOS
val multiAd = SomAdContainer(arrayListOf(AdType.rectangle, AdType.banner))
let multiAd = SomAdContainer(adTypes: [AdType.rectangle, AdType.banner])

Note Your layout should be able to automatically adapt to the different ad sizes by responsively matching the ad view's dimensions to the received ad's size.

Ad Reloading

To increase revenue, ads can be reloaded after a minimum time of 30 seconds after the ad rendered on the screen. If configured, this will happen automatically in the background.

Ad Events

It is also possible to add live information to a display ad to improve targeting. This could be for example information about a live football match or weather information. To add an AdEvent to an ad such as goal or rain use:

  • Android
  • iOS
ad.addAdEvent(“goal”)
ad.addAdEvent(adEvent: "goal")

The ad event is only added to the request if it's called before the ad is rendered. If the ad event is not configured it will not be added the request.

Note: Ad events must be agreed apon beforehand and set up by SOM, otherwise they will be ignored. To enable certain ad events, please contact your publisher manager at SOM.

Ad Exclusions

If you want to prevent certain categories of ads from appearing on your content (e.g. alcohol, betting etc.), you can contact SOM and specify which categories you wish to exclude, and SOM will handle it for you.

← CMP ImplementationOverlay Ads →
  • Creating display ads programmatically
  • Creating display ads through XML or Storyboard
  • Android: Recycle-able views
  • Memory management
  • Android: Additional Lifecycle Methods
  • Multislot Ads
  • Ad Reloading
  • Ad Events
  • Ad Exclusions
AdTech Integration Guides
Guides
AppDesktopCTV
More
GitHub
Contact

SevenOne Media GmbH
Medienallee 4
85774 Unterföhring

71.adtechnology@gmail.com
SevenOne Media - Wir bewegen Marken
Copyright © 2023 SevenOne Media GmbH