ocm_ads 0.0.5
ocm_ads: ^0.0.5 copied to clipboard
Flutter bindings for the OCM AdNetwork SDK, supporting initialization and banner, interstitial, rewarded, and native ad formats on Android and iOS.
ocm_ads #
Flutter bindings for the OCM AdNetwork SDK on Android and iOS.
Installation #
Add the package to your app:
flutter pub add ocm_ads
Import the plugin:
import 'package:ocm_ads/ocm_ads.dart';
Requirements #
- Flutter 3.24 or later (Dart 3.5 or later).
- Android API 25 or later and Java 17.
- iOS 15.0 or later.
- OCM publisher/configuration IDs and the ad network IDs required by your setup.
The example app has been build-tested with Flutter 3.47.5 and Dart 3.13.4.
Supported ad formats #
- SDK initialization with a publisher ID or local
OcmConfig - Banner ads through
OcmBannerView - Interstitial ads through
OcmInterstitialAd - Rewarded ads through
OcmRewardedAd - Native ads:
OcmNativeAdViewon Android and iOSOcmNativeAdLoader.load()data loading on Android only
iOS setup #
The iOS implementation supports both Flutter Swift Package Manager integration
and CocoaPods. SwiftPM is the default path for the example app and uses the
plugin package at ios/ocm_ads/Package.swift, which depends on the
OCM iOS SDK 1.2.7 release tag from the public
SwiftPM distribution repository.
The minimum iOS version is 15.0.
For CocoaPods fallback mode, disable Flutter SwiftPM and install pods:
flutter config --no-enable-swift-package-manager
cd example
cp ios/Podfile.cocoapods-fallback ios/Podfile
flutter clean
flutter pub get
cd ios
pod install --repo-update
The plugin podspec depends on OCMAdNetworkIOS ~> 1.2.7, so host apps can
still use CocoaPods when SwiftPM is disabled.
To switch back to SwiftPM mode:
flutter config --enable-swift-package-manager
cd example
flutter clean
flutter pub get
flutter run
Host apps must add the ad network requirements to ios/Runner/Info.plist:
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-3940256099942544~3347511713</string>
<key>NSUserTrackingUsageDescription</key>
<string>This identifier will be used to deliver personalized ads to you.</string>
Production apps should use their own Google Mobile Ads application ID. Add the SKAdNetwork identifiers required by the ad networks you enable, and add App Transport Security exceptions only when your inventory requires them:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><true/>
<key>NSAllowsArbitraryLoadsForMedia</key><true/>
<key>NSAllowsArbitraryLoadsInWebContent</key><true/>
</dict>
Android setup #
Host Android apps must declare network permissions and their Google Mobile Ads application ID:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713" />
Basic usage #
await OcmFlutterPlugin.initializeWithConfig(
const OcmConfig(
adUnits: <OcmAdUnit>[
OcmAdUnit(
id: 'banner-config-id',
format: 'banner',
size: '300x250',
position: 'custom',
refresh: 30,
renderMode: OcmRenderMode.prebidGam,
),
],
gam: OcmGamConfig(
networkCode: '75351959',
adUnitPath: '/75351959/testadunit/test_app_320x50',
),
privacy: OcmPrivacyConfig(gdpr: 0, ccpa: '1---', coppa: 0),
),
prebidAccountId: 'your-prebid-account-id',
);
OcmRenderMode.prebidGam is the backward-compatible default and renders the
winning Prebid demand through Google Ad Manager. Use OcmRenderMode.prebid to
fetch and render the banner directly through Prebid Mobile; in that mode the ad
unit id must be the Prebid configuration ID.
For diagnostics, PBS debug mode changes subsequent auction requests, while PBS event logging only prints the raw auction request and response:
await OcmFlutterPlugin.setPrebidDebug(true);
await OcmFlutterPlugin.setPbsEventLogging(true);
Both settings are disabled unless explicitly enabled. Raw PBS logs may contain request identifiers or other integration data and should not normally be enabled in production.
Render a banner:
const OcmBannerView(
configId: 'banner-config-id',
width: 300,
height: 250,
);
Render a native ad:
const OcmNativeAdView(
prebidConfigId: 'native-prebid-config-id',
gamAdUnitId: '/75351959/testadunit/test_app_native',
gamNativeFormatId: 'gam-prebid-custom-native-format-id',
mode: OcmNativeLoadMode.gam,
width: 320,
height: defaultTargetPlatform == TargetPlatform.iOS ? 400 : null,
);
For direct Prebid native demand, set mode: OcmNativeLoadMode.prebid and omit
the GAM IDs. Use OcmNativeAdView for displayed ads so the SDK registers click
and impression tracking. On Android, omit height to size the view to the
rendered ad. An explicit height keeps the view at that size. On iOS, provide
a height for the native platform view. defaultTargetPlatform is available from
package:flutter/foundation.dart.
License #
This Flutter plugin is licensed under the MIT License. The native OCM SDKs and third-party dependencies retain their respective licenses. Use of OCM services remains subject to the applicable service terms.