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:
Kotlin
val config = OcmConfigBuilder()
.adUnit(
id = "1001-sreq-test-300x250-imp-1", // Ad unit identifier
format = "banner", // Ad format
size = "300x250", // Ad size
position = "bottom", // Position on screen
refresh = 30 // Auto-refresh interval (seconds)
)
Java
OcmConfig config = new OcmConfigBuilder()
.adUnit(
"1001-sreq-test-300x250-imp-1", // Ad unit identifier
"banner", // Ad format
"300x250", // Ad size
"bottom", // Position on screen
30 // Auto-refresh interval (seconds)
)
Supported Ad Formats
banner- Standard banner adsinterstitial- Full-screen interstitial adsrewarded- Rewarded video adsnative- Native ads
Common Banner Sizes
300x250- Medium Rectangle320x50- Mobile Banner728x90- Leaderboard160x600- Wide Skyscraper
Banner Positions
top- Top of the screenbottom- Bottom of the screencustom- Custom positioning via layout
Refresh Interval
The refresh parameter controls auto-refresh behavior:
30- Refresh every 30 seconds60- Refresh every 60 seconds0- Disable auto-refresh
Google Ad Manager (GAM) Configuration
Configure your GAM network settings:
Kotlin
.gam(
networkCode = "75351959", // Your GAM network code
adUnitPath = "/75351959/testadunit/test_app_320x50" // Full GAM ad unit path
)
Java
.gam(
"75351959", // Your GAM network code
"/75351959/testadunit/test_app_320x50" // Full GAM ad unit path
)
Privacy Configuration
The SDK supports multiple privacy frameworks:
Kotlin
.privacyFromSdk(
gdpr = 1, // GDPR consent: 1 = consent given, 0 = no consent
ccpa = "", // CCPA consent string (optional)
coppa = 0 // COPPA compliance: 1 = child-directed, 0 = not child-directed
)
Java
.privacyFromSdk(
1, // GDPR consent: 1 = consent given, 0 = no consent
"", // CCPA consent string (optional)
0 // COPPA compliance: 1 = 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
Kotlin
val config = OcmConfigBuilder()
.adUnit(
id = "1001-sreq-test-300x250-imp-1",
format = "banner",
size = "300x250",
position = "bottom",
refresh = 30
)
.gam(
networkCode = "75351959",
adUnitPath = "/75351959/testadunit/test_app_320x50"
)
.privacyFromSdk(
gdpr = 1,
ccpa = "",
coppa = 0
)
.build()
Java
OcmConfig config = new OcmConfigBuilder()
.adUnit(
"1001-sreq-test-300x250-imp-1",
"banner",
"300x250",
"bottom",
30
)
.gam(
"75351959",
"/75351959/testadunit/test_app_320x50"
)
.privacyFromSdk(
1, // gdpr
"", // ccpa
0 // coppa
)
.build();
Remote Configuration
If you prefer to manage configuration remotely, you can initialize with just a config ID:
Kotlin
OcmAdNetworkSDK.initialize(
context = this,
configId = "your-config-id"
) { result -> }
Java
OcmAdNetworkSDK.initialize(
this,
"your-config-id",
() -> {},
error -> {}
);
The SDK will fetch the configuration from the server automatically.
Best Practices
1. Privacy Compliance
Always respect user privacy choices and implement proper consent mechanisms:
val hasConsent = checkUserConsent() // Your consent logic
val gdpr = if (hasConsent) 1 else 0
val config = OcmConfigBuilder()
.privacyFromSdk(
gdpr = gdpr,
ccpa = "",
coppa = 0
)
.build()
2. Environment-Specific Configs
Use different configurations for development and production:
val configId = if (BuildConfig.DEBUG) {
"test-config-id"
} else {
"prod-config-id"
}
OcmAdNetworkSDK.initialize(this, configId) { result -> }
3. Error Handling
Always handle initialization errors gracefully:
OcmAdNetworkSDK.initializeWithConfig(this, config) { result ->
result.onSuccess {
// Proceed with loading ads
}
result.onFailure { error ->
// Log error and inform user
Log.e("SDK", "Failed to initialize: ${error.message}")
// Optionally: Retry or disable ad features
}
}
4. Optimize Refresh Rate
Choose appropriate refresh rates based on your app's UX:
.adUnit(
id = "...",
format = "banner",
size = "300x250",
position = "bottom",
refresh = 60 // Refresh every 60 seconds for better UX
)
Next Steps
- Learn how to load ads in the API Reference
- See complete implementations in Examples