Get started with Prebid Mobile by creating a Prebid Server account. Once your account is set up include the Prebid Mobile SDK in your app by either using dependencies managers or by cloning the repo and using our included script to build the SDK.
If you are not familiar with using Cocoapods for dependency management, visit their getting started page. Once you have your Podfile
setup, include the following:
target 'MyAmazingApp' do
pod 'PrebidMobile'
end
Now run pod install
to add the Prebid SDK to project dependencies.
If you are not familiar with the Carthage package builder, please refer to the project github page for more details.
github "prebid/prebid-mobile-ios" == 2.0.4-carthage
to your Cartfile
.carthage update
.PrebidMobile.xcframework
from Carthage/Build
to General -> Linked Frameworks and Libraries
scripts/buildPrebidMobile.sh
PrebidMobile.xcframework
from generated/output
directory into your project. Make sure “Copy items if needed” is selected.General -> Frameworks, Libraries, and Embedded Content
settings. Use Embed & Sign
for dynamic and Do Not Embed
for static linkingSPM isn’t supported for Prebid SDK 2.0.0
and higher (details).
The next guide is applicable to 1.x
versions of the SDK.
If you are not familiar with the Swift Package Manager, please refer to the project github page for more details.
File -> Swift Packages -> Add Package Dependency...
Build the specific schema CarthageBuild.sh
Variant 1
Run CarthageBuild.sh script from Cartfile folder. The path should be:
.../Carthage/Checkouts/prebid-mobile-ios/scripts/CarthageBuild.sh
Enter Schema name (PrebidMobile or PrebidMobileCore)
chmod +x <path_to_CarthageBuild.sh>
Variant 2
Open PrebidMobile.xcodeproj
at .../Carthage/Checkouts/prebid-mobile-ios/PrebidMobile.xcodeproj
using Xcode
Manage Schemes -> Check Shared checkbox for a necessary schema
run carthage build prebid-mobile-ios
You can find the schema name in the build PrebidSDK framework inside Info.plist with PrebidMobileName
key
Build Prebid Mobile from source code. After cloning the repo, use Terminal or another command line tool, change to the root directory and run:
scripts/buildPrebidMobile.sh
This will output the PrebidMobile.framework.
Once you have a Prebid Server, you will add ‘account’ info to the Prebid Mobile. For example, if you’re using the AppNexus Prebid Server:
Prebid.shared.prebidServerAccountId = YOUR_ACCOUNT_ID
Prebid.shared.prebidServerHost = .Appnexus
If you have opted to host your own Prebid Server solution, you will need to store the URL to the server in your app. Make sure that your URL points to the /openrtb2/auction endpoint.
try! Prebid.shared.setCustomPrebidServer(url: PREBID_SERVER_AUCTION_ENDPOINT)
This method throws an exception if the provided URL is invalid.
Once you set the account ID and the Prebid Server host, you should initialize the Prebid SDK. There are several options for how to do it.
If you integrate Prebid Mobile with GMA SDK, use the following initializer, which checks the compatibility of Prebid SDK with GMA SDK used in the app:
Prebid.initializeSDK(GADMobileAds.sharedInstance()) { status, error in
switch status {
case .succeeded:
print("Prebid SDK successfully initialized")
case .failed:
if let error = error {
print("An error occurred during Prebid SDK initialization: \(error.localizedDescription)")
}
case .serverStatusWarning:
if let error = error {
print("Prebid Server status checking failed: \(error.localizedDescription)")
}
default:
break
}
}
Check the log messages of the app. If the provided GMA SDK version is not verified for compatibility, the Prebid SDK informs about it.
For the No Ad Server scenario, use the following initialization:
Prebid.initializeSDK { status, error in
// ....
}
During the initialization, SDK creates internal classes and performs the health check request to the /status endpoint. If you use a custom PBS host you should provide a custom status endpoint as well:
Prebid.shared.customStatusEndpoint = PREBID_SERVER_STATUS_ENDPOINT
If something goes wrong with the request, the status of the initialization callback will be .serverStatusWarning
. It doesn’t affect an SDK flow and just informs you about the health check result.
Targeting parameters enable you to define the target audience for the bid request. Prebid Mobile supports the following global targeting parameters. These targeting parameters are set only once and apply to all Prebid Mobile ad units. They do not change for a given user session.
View the full list of targeting parameters.
The Prebid
class is a singleton that enables the user to apply global settings.
prebidServerAccountId
: String containing the Prebid Server account ID.
prebidServerHost
: String containing configuration your Prebid Server host with which Prebid SDK will communicate. Choose from the system-defined Prebid Server hosts or define your own custom Prebid Server host.
shareGeoLocation
: Optional Bool, if this flag is True AND the app collects the user’s geographical location data, Prebid Mobile will send the user’s geographical location data to Prebid Server. If this flag is False OR the app does not collect the user’s geographical location data, Prebid Mobile will not populate any user geographical location information in the call to Prebid Server. The default setting is false.
logLevel
: Optional level of logging to output in the console. Options are one of the following sorted by a verbosity of the log:
public static let debug = LogLevel(stringValue: "[💬]", rawValue: 0)
public static let verbose = LogLevel(stringValue: "[🔬]", rawValue: 1)
public static let info = LogLevel(stringValue: "[ℹ️]", rawValue: 2)
public static let warn = LogLevel(stringValue: "[⚠️]", rawValue: 3)
public static let error = LogLevel(stringValue: "[‼️]", rawValue: 4)
public static let severe = LogLevel(stringValue: "[🔥]", rawValue: 5)
timeoutMillis
: The Prebid timeout (accessible to Prebid SDK 1.2+), set in milliseconds, will return control to the ad server SDK to fetch an ad once the expiration period is achieved. Because Prebid SDK solicits bids from Prebid Server in one payload, setting Prebid timeout too low can stymie all demand resulting in a potential negative revenue impact.
storedAuctionResponse
: Set as type string, stored auction responses signal Prebid Server to respond with a static response matching the storedAuctionResponse found in the Prebid Server Database, useful for debugging and integration testing. No bid requests will be sent to any bidders when a matching storedAuctionResponse is found. For more information on how stored auction responses work, refer to the written description on github issue 133.
pbsDebug
: adds the debug flag (“test”:1) on the outbound http call to Prebid Server. The test:1 flag will signal to Prebid Server to emit the full resolved request (resolving any Stored Request IDs) as well as the full Bid Request and Bid Response to and from each bidder.
addStoredBidResponse
: Function containing two properties:
bidder
: Bidder name as defined by Prebid Server bid adapter of type string.responseId
: Configuration ID used in the Prebid Server Database to store static bid responses.Stored Bid Responses are similar to Stored Auction Responses in that they signal to Prebid Server to respond with a static pre-defined response, except Stored Bid Responses is done at the bidder level, with bid requests sent out for any bidders not specified in the bidder parameter. For more information on how stored auction responses work, refer to the written description on github issue 133.
func addStoredBidResponse(bidder: String, responseId: String)
clearStoredBidResponses
: Clears any stored bid responses.
func clearStoredBidResponses()
The following methods enable the customization of the HTTP call to the prebid server:
func addCustomHeader(name: String, value: String)
func clearCustomHeaders()
// Host
Prebid.shared.prebidServerHost = .Rubicon
// or set a custom host
Prebid.shared.prebidServerHost = PrebidHost.Custom
do {
try Prebid.shared.setCustomPrebidServer(url: "https://prebid-server.customhost.com")
} catch {
print(error)
}
// Account Id
Prebid.shared.prebidServerAccountId = "1234"
// Geolocation
Prebid.shared.shareGeoLocation = true
// Log level data
Prebid.shared.logLevel = .verbose
// Set Prebid timeout in milliseconds
Prebid.shared.timeoutMillis = 3000
// Enable Prebid Server debug respones
Prebid.shared.pbsDebug = true
// Stored responses can be one of storedAuction response or storedBidResponse
Prebid.shared.storedAuctionResponse = "111122223333"
//or
Prebid.shared.addStoredBidResponse(bidder: "appnexus", responseId: "221144")
Prebid.shared.addStoredBidResponse(bidder: "rubicon", responseId: "221155")
Follow the corresponding guide to integrate Prebid Mobile:
In the table below, you can find Prebid’s test IDs that are used in the Demo Applications and that you can utilize for SDK integration validation.
Config ID | Ad Format | Description |
---|---|---|
https://prebid-server-test-j.prebid.org/openrtb2/auction |
Custom Prebid Server Host | A PBS instance that is dedicated to testing purposes. |
0689a263-318d-448b-a3d4-b02e8a709d9d |
Stored Request ID | The test account ID on the test server. |
imp-prebid-banner-320-50 |
HTML Banner | Returns a stored response that contains a Banner 320x50 winning bid. |
imp-prebid-display-interstitial-320-480 |
HTML Interstitial | Returns a stored response that contains a Interstitial 320x480 winning bid. |
imp-prebid-video-outstream-original-api |
Outstream Video (Original API) | Returns a stored response that contains a Video 320x50 winning bid. |
imp-prebid-video-outstream |
Outstream Video (Rendering API) | Returns a stored response that contains a Video 320x50 winning bid. |
imp-prebid-video-interstitial-320-480-original-api |
Video Interstitial (Original API) | Returns a stored response that contains a Video Interstitial 320x480 winning bid. |
imp-prebid-video-interstitial-320-480 |
Video Interstitial (Rendering API) | Returns a stored response that contains a Video Interstitial 320x480 winning bid. |
imp-prebid-video-rewarded-320-480-original-api |
Rewarded Video (Original API) | Returns a stored response that contains a Rewarded Video 320x480 winning bid. |
imp-prebid-video-rewarded-320-480 |
Rewarded Video (Original API) | Returns a stored response that contains a Rewarded Video 320x480 winning bid. |
imp-prebid-video-interstitial-320-480 |
Instream Video | Returns a stored response that contains a Video 320x480 winning bid. |
imp-prebid-banner-native-styles |
Native Styles | Returns a stored response that contains a Native winning bid. |
imp-prebid-banner-native-styles |
In-App Native | Returns a stored response that contains a Native winning bid. |