ADSOLUTIONS PREBID MOBILE SETUP IOS

Adsolutions / ADSOLUTIONS PREBID MOBILE SETUP IOS

The Adsolutions Prebid Mobile SDK

The Prebid Mobile SDK for iOS and sample app are available via this repository on Github.

Ad Unit Setup for iOS and DFP

Register Prebid Mobile ad units as early as possible in the application’s lifecycle.

When registering a Prebid Mobile ad unit, you must replace with a unique user-defined identifier. Prebid Mobile will use this identifier to determine the unique ad unit to which bid key-values will be associated. This identifier must be unique across all registered Prebid Mobile ad units, and does not need to map to any ad unit ID defined in your ad server.

We recommend doing this in the didFinishLaunchingWithOptions method in AppDelegate.m using the following steps, as shown in the code sample below:

Create the ad units and add sizes for banner ad units. Be sure to replace @”PREBID-MOBILE-SLOT-ID” with a unique user-defined identifier.
NOTE: The fluid ad size (used in DFP) is not supported.

– Add a server-side configuration for each ad unit to Prebid Server Adapter.
– Set targeting parameters for the ad units. (Optional)
– Set the primary adserver for the bid to DFP
– Set the Prebid Server host to Adsolutions.
– Register the ad units with the adapter to start the bid fetching process.

In the code snippets below, any values that must be substituted by your developers are identified in capital letters. These values are defined below:

Value Description

PREBID-SERVER-ACCOUNT-ID Your unique account ID with Adsolutions.
PREBID-MOBILE-SLOT-ID User-defined identifier that must be unique across all registered Prebid Mobile ad units. Note: this value should not map to any ad unit ID defined in your ad server, unless that ID is unique.
PREBID-SERVER-CONFIGURATION-ID The ID of a Prebid Server demand partner configuration. Represents the set of demand that will be fetched for a given ad unit.
SET-APP-NAME User-defined App Name (eg. NewYorkTimes)
SET_APP_PAGE User-defined Page Name (eg. /home)

Ad Unit Registration

Embed the ad unit registration in a try-catch block to catch all the exceptions (if any) thrown by the SDK.

//
//  ViewController.swift
//  AdManagerBannerExample
//
//  Copyright © 2019 adsolutions. All rights reserved.
//

import UIKit
//AS PREBID - Include required files from the Prebid Mobile framework
import PrebidMobile
import GoogleMobileAds

class SingleAdViewController: UIViewController, GADBannerViewDelegate, GADAppEventDelegate {

    @IBOutlet weak var dfpBannerView: DFPBannerView!
    
    var bannerAdUnit:BannerAdUnit!
    var request = DFPRequest()
    


    override func viewDidLoad() {
        super.viewDidLoad()

        /* Replace @"APP-PAGE" With your own app page */
        /* Replace @"APP-NAME" With your own app name */
        Prebid.shared.appPage = "APP-PAGE";
        Prebid.shared.appName = "APP-NAME";

        /* AS PREBID -  Create the ad units and add sizes for banner ad units.
        Replace @"PREBID-MOBILE-SLOT-ID" with the unique ad slot identifier you defined when you registered the ad unit with Prebid Mobile. * 
        Replace @"PREBID-SERVER-CONFIGURATION-ID" with the config ID you received from Adsolutions*/
        
        self.bannerAdUnit = BannerAdUnit(configId: "PREBID-SERVER-CONFIGURATION-ID", size: CGSize(width: 300, height: 250))
        
        self.dfpBannerView.adUnitID = "PREBID-MOBILE-SLOT-ID";
        self.dfpBannerView.rootViewController = self;
        self.dfpBannerView.validAdSizes = [NSValueFromGADAdSize(kGADAdSizeMediumRectangle)];
        self.dfpBannerView.delegate = self;
        self.dfpBannerView.appEventDelegate = self;
        
    }
    

}

Set Ad Server Targeting

Set the Prebid Host and Account ID.

//
//  AppDelegate.swift
//  AdManagerBannerExample
//
//  Copyright © 2019 adsolutions. All rights reserved.
//

import UIKit
//AS PREBID - Include required files from the Prebid Mobile framework
import PrebidMobile

/* AS PREBID - Replace @"PREBID-SERVER-ACCOUNT-ID" with your Prebid Server account ID received from Adsolutions.  */ 

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        Prebid.shared.prebidServerHost = PrebidHost.AdSolutions
        Prebid.shared.prebidServerAccountId = "PREBID-SERVER-ACCOUNT-ID"
        Prebid.shared.shareGeoLocation = true
        return true
    }

//Enable cache

func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
        CacheManager.configure()
    }

Add Events

/// Tells the delegate an ad request loaded an ad.
- (void)adViewDidReceiveAd:(DFPBannerView *)adView {
[PrebidMobile markAdUnitLoaded:(UIView*) adView];
}
/// Tells the delegate an ad request failed.
- (void)adView:(DFPBannerView *)adView
didFailToReceiveAdWithError:(GADRequestError *)error {
if(error.code == kGADErrorNoFill){
[PrebidMobile adUnitReceivedDefault:(UIView*) adView];
[PrebidMobile markAdUnitLoaded:(UIView*) adView];
}
- (void)adView:(DFPBannerView *)banner
didReceiveAppEvent:(NSString *)name
withInfo:(NSString *)info {
[PrebidMobile adUnitReceivedAppEvent:banner andWithInstruction:name andWithParameter:info];
}

Gather Statistics

IMPORTANT! Last but not least: On page leave and app close events please implement the following so the statistics are send to Adsolutions and will be available in the Adsolutions Analytics Dashboard.

[PrebidMobile gatherStats];