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
)

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

Configure your GAM network settings:

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

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"
)
.gam(
networkCode: "75351959",
adUnitPath: "/75351959/testadunit/test_app_320x50"
)
.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.

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