Skip to main content

Configuration

OcmConfigBuilder​

The OcmConfigBuilder provides a fluent API for configuring the SDK with all necessary parameters.

Ad Unit Configuration​

Configure your ad unit with the following parameters:

let config = OcmConfigBuilder()
.adUnit(
id: "1001-sreq-test-300x250-imp-1", // Ad unit identifier
format: "banner", // Ad format (banner, interstitial, etc.)
size: "300x250", // Ad size
renderMode: OcmRenderMode.prebidGam // Or OcmRenderMode.prebid
)

Supported Ad Formats​

  • banner - Standard banner ads
  • interstitial - Full-screen interstitial ads
  • rewarded - Rewarded video ads
  • native - Native ads

Common Banner Sizes​

  • 300x250 - Medium Rectangle
  • 320x50 - Mobile Banner
  • 728x90 - Leaderboard
  • 160x600 - Wide Skyscraper

Set renderMode per banner ad unit:

ValueBehavior
OcmRenderMode.prebidGam ("prebid-gam")Fetch Prebid demand, then render through GAM. This is the default.
OcmRenderMode.prebid ("prebid")Fetch and render the banner directly with Prebid Mobile.

For direct Prebid rendering, the ad unit id must be its Prebid configuration ID. OcmBannerView.load(adUnitId:delegate:) still takes that configured ad unit ID. An omitted or unrecognized render mode uses the GAM path.

Configure your GAM network settings:

.gam(
networkCode: "75351959", // Your GAM network code
adUnitPath: "/75351959/testadunit/test_app_320x50" // Full GAM ad unit path
)

Prebid Configuration​

Configure the Prebid identifiers provided by OCM:

.prebid(
accountId: "your-prebid-account-id", // Prebid account ID
configId: "your-prebid-config-id" // Prebid config ID
)

The SDK uses accountId as the Prebid Server account ID and configId as the Prebid Mobile ad unit configuration ID.

Privacy Configuration​

The SDK supports multiple privacy frameworks:

.privacyFromSdk(
gdpr: 1, // GDPR consent: 1 = consent given, 0 = no consent
ccpa: "", // CCPA consent string (optional)
coppa: 0 // COPPA compliance: 1 = treat as child-directed, 0 = not child-directed
)

GDPR (General Data Protection Regulation)​

  • Value 1: User has given consent for personalized ads
  • Value 0: User has not given consent (non-personalized ads only)

CCPA (California Consumer Privacy Act)​

  • Pass a CCPA consent string if applicable
  • Leave empty ("") if not applicable

COPPA (Children's Online Privacy Protection Act)​

  • Value 1: Treat traffic as child-directed (restricted data collection)
  • Value 0: Not child-directed

Complete Configuration Example​

let config = OcmConfigBuilder()
.adUnit(
id: "1001-sreq-test-300x250-imp-1",
format: "banner",
size: "300x250",
renderMode: OcmRenderMode.prebidGam
)
.gam(
networkCode: "75351959",
adUnitPath: "/75351959/testadunit/test_app_320x50"
)
.prebid(
accountId: "your-prebid-account-id",
configId: "your-prebid-config-id"
)
.privacyFromSdk(
gdpr: 1,
ccpa: "",
coppa: 0
)
.build()

Remote Configuration​

If you prefer to manage configuration remotely, you can initialize with just a publisher ID:

try await OcmAdNetworkSDK.initialize(publisherId: "test_pub_001")

The SDK will fetch the configuration from the server automatically.

Remote configuration payloads can include the same Prebid values:

{
"prebid": {
"accountId": "your-prebid-account-id",
"configId": "your-prebid-config-id"
}
}

To select direct Prebid rendering remotely, set renderMode on the banner ad unit:

{
"adUnits": [
{
"id": "your-prebid-config-id",
"format": "banner",
"size": "300x250",
"position": "bottom",
"refresh": 30,
"renderMode": "prebid"
}
]
}

PBS Logging​

Enable raw Prebid Server auction request and response logging when diagnosing an integration:

OcmAdNetworkSDK.setPbsEventLogging(true)

The SDK prints these events with the [OCM-PBS] prefix. Call setPbsEventLogging(false) to stop logging. This setting is separate from OcmAdNetworkSDK.setPbsDebug(_:), which controls PBS debug mode for subsequent requests.

Best Practices​

1. Privacy Compliance​

Always respect user privacy choices:

// Example: Check for ATT authorization
import AppTrackingTransparency

if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
let gdpr = (status == .authorized) ? 1 : 0
// Use gdpr value in your config
}
}

2. Environment-Specific Configs​

Use different configurations for development and production:

#if DEBUG
let publisherId = "test_pub_001"
#else
let publisherId = "prod_pub_001"
#endif

try await OcmAdNetworkSDK.initialize(publisherId: publisherId)

3. Error Handling​

Always handle initialization errors gracefully:

Task {
do {
try await OcmAdNetworkSDK.initialize(publisherId: publisherId)
// Proceed with loading ads
} catch {
// Log error and inform user
print("Failed to initialize SDK: \(error)")
// Optionally: Retry or disable ad features
}
}

Next Steps​