Skip to main content

Configuration

SDK Config​

Configure the SDK in your app with an OcmConfig passed to OcmFlutterPlugin.initializeWithConfig. No remote config file is needed.

import 'package:ocm_ads/ocm_ads.dart';

const config = OcmConfig(
adUnits: <OcmAdUnit>[
OcmAdUnit(
id: 'your-banner-config-id', // pass the same value to OcmBannerView's configId
format: 'banner',
size: '300x250',
position: 'custom',
refresh: 30,
renderMode: OcmRenderMode.prebidGam, // optional, this is the default
),
OcmAdUnit(
id: 'your-prebid-config-id', // direct Prebid: must be the Prebid configuration ID
format: 'banner',
size: '320x50',
position: 'custom',
refresh: 0,
renderMode: OcmRenderMode.prebid,
),
],
gam: OcmGamConfig(
networkCode: '75351959',
adUnitPath: '/75351959/your-ad-unit',
),
privacy: OcmPrivacyConfig(gdpr: 0, ccpa: '1---', coppa: 0),
);

await OcmFlutterPlugin.initializeWithConfig(
config,
prebidAccountId: 'your-prebid-account-id',
);

Ad Unit Fields (OcmAdUnit)​

FieldTypeDefaultDescription
idStringrequiredThe value you pass to OcmBannerView's configId. With OcmRenderMode.prebid it must be the Prebid configuration ID.
formatStringrequiredAd format, for example 'banner'.
sizeStringrequiredWidth x height, for example '300x250'.
positionStringrequiredPlacement position, for example 'custom'.
refreshintrequiredRefresh interval for the ad unit, for example 30.
renderModeOcmRenderModeOcmRenderMode.prebidGamHow the banner is rendered. See Render Modes.

Render Modes​

Each banner ad unit picks how its winning bid is rendered with renderMode:

renderModeWhat it does
OcmRenderMode.prebidGam (default)Fetches demand from Prebid and renders it through Google Ad Manager (gam.adUnitPath).
OcmRenderMode.prebidFetches and renders the banner directly through Prebid Mobile, with no GAM. The ad unit id must be the Prebid configuration ID.
FieldTypeDescription
networkCodeStringYour Google Ad Manager network code.
adUnitPathStringThe GAM ad unit path, for example '/1234/my_app/banner'.

Privacy (OcmPrivacyConfig)​

FieldTypeDescription
gdprint1 when GDPR applies to the user, 0 otherwise.
ccpaStringUS Privacy (CCPA) string, for example '1---'.
coppaint1 when the app is directed at children under COPPA, 0 otherwise.

Privacy is set at initialization. Get GDPR applicability and consent from your consent management platform (CMP) before calling initializeWithConfig and build privacy from it. On Android, also pass isGdprApplicable and gdprConsentString in the initialize options.

Initialize Options​

initializeWithConfig takes these optional named arguments after the config:

OptionTypePlatformsDescription
prebidAccountIdString?Android, iOSPrebid Server account ID. Required on Android (missing_argument otherwise). On iOS, Prebid is skipped when it's omitted.
prebidServerUrlString?AndroidOverrides the default Prebid Server endpoint.
gdprConsentStringString?AndroidTCF consent string.
isGdprApplicablebool?AndroidWhether GDPR applies to the user.
await OcmFlutterPlugin.initializeWithConfig(
config,
prebidAccountId: 'your-prebid-account-id',
gdprConsentString: tcfString, // from your CMP
isGdprApplicable: true,
);

Remote Configuration​

Instead of a local config, you can initialize with your OCM publisher ID and let the SDK fetch the ad unit configuration:

await OcmFlutterPlugin.initialize(
publisherId: 'your-publisher-id',
);

initialize also accepts gdprConsentString, isGdprApplicable, and prebidServerUrl, which are used on Android.

🐞 Debugging​

Two switches help while testing. Both are off unless you turn them on:

// Prebid debug mode for subsequent auction requests.
await OcmFlutterPlugin.setPrebidDebug(true);

// Logs raw Prebid Server requests and responses, without debug mode.
await OcmFlutterPlugin.setPbsEventLogging(true);
warning

Keep both disabled in production. Raw Prebid Server logs may contain request identifiers and other integration data.

OcmBannerView Properties​

PropertyTypeRequiredDescription
configIdStringYesThe id of an ad unit in the config passed to initializeWithConfig.
widthdouble?NoBanner width in logical pixels.
heightdouble?NoBanner height in logical pixels.
onAdLoadedVoidCallback?NoCalled when the banner loads.
onAdFailedvoid Function(OcmAdError)?NoCalled when the banner fails to load.
onAdClickedVoidCallback?NoCalled when the user taps the banner.
onImpressionVoidCallback?NoCalled when the banner records an impression.
tip

Always set both width and height, matching the ad unit's size, so the banner renders at the right size.

Common Ad Sizes​

SizeNameTypical placement
320x50Mobile bannerTop or bottom of the screen
320x100Large mobile bannerTop or bottom of the screen
300x250Medium rectangleIn content
728x90LeaderboardTablets

Set the size both on the ad unit (size: '320x50') and on the widget (width: 320, height: 50).

Best Practices​

1. List Every Banner in the Config​

OcmBannerView looks its configId up in the config. Add every banner your app shows to adUnits.

2. Hide Failed Slots​

Handle onAdFailed and hide or replace the ad slot so the layout doesn't show an empty box:

bool _bannerFailed = false;


Widget build(BuildContext context) {
if (_bannerFailed) return const SizedBox.shrink();
return OcmBannerView(
configId: 'your-banner-config-id',
width: 300,
height: 250,
onAdFailed: (_) => setState(() => _bannerFailed = true),
);
}

Next Steps​