How to Integrate the InMobi SDK in Android and iOS — Step-by-StepIntegrating the InMobi SDK into your Android and iOS apps lets you monetize mobile traffic with display, native, and rewarded ads, while leveraging InMobi’s targeting and optimization features. This guide walks through installation, configuration, common ad formats, consent/GDPR/CCPA considerations, testing, troubleshooting, and performance tips for both platforms.
Before you start
- Create an InMobi account and set up your app(s) in the InMobi dashboard to obtain your account-level and placement-specific IDs.
- Choose the ad formats you want (banner, interstitial, rewarded video, native).
- Ensure you have Android Studio and Xcode installed, and access to your project source.
- For compliance: prepare to collect user consent where required (GDPR, ePrivacy) and signal CCPA opt-out where applicable.
- Use a test device and test ad units initially to avoid policy violations.
Key concepts
- SDK account and property IDs: Account ID and Placement ID (also called Ad Unit ID) are needed to initialize and request ads.
- Initialization: The SDK must be initialized once (commonly in application start).
- Ad lifecycle: load, show/display, and handle events/callbacks (success, failure, click, close).
- Mediation and adapters: If using an ad mediation platform, use InMobi’s dedicated adapters.
Android integration (Step-by-step)
1) Add permissions and repository
- In your app-level build.gradle ensure you have Google’s Maven and JCenter/MavenCentral available (InMobi artifacts are typically on MavenCentral). Example repositories block:
repositories { google() mavenCentral() }
- Add required Android permissions in AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
2) Add the InMobi SDK dependency
In your app module build.gradle add the InMobi dependency (version may change; check your InMobi dashboard for the latest). Example:
dependencies { implementation 'com.inmobi.monetization:inmobi-ads:10.+' // replace with latest stable version }
3) Initialize the SDK
Initialize InMobi in your Application class onCreate. Use your Account ID and optionally set log level or other settings. Example:
public class MyApp extends Application { @Override public void onCreate() { super.onCreate(); InMobiSdk.init(this, "YOUR_ACCOUNT_ID"); InMobiSdk.setLogLevel(InMobiSdk.LogLevel.DEBUG); } }
Declare the Application class in AndroidManifest.xml:
<application android:name=".MyApp" ... >
4) Request and display a banner ad
- Add an AdView in your layout:
<com.inmobi.ads.InMobiBanner android:id="@+id/inmobiBanner" android:layout_width="match_parent" android:layout_height="wrap_content"/>
- Load the banner in your Activity:
InMobiBanner banner = findViewById(R.id.inmobiBanner); banner.setListener(new BannerAdEventListener() { @Override public void onAdLoadSucceeded(InMobiBanner ad) {} @Override public void onAdLoadFailed(InMobiBanner ad, InMobiAdRequestStatus status) {} // implement other callbacks }); banner.load("PLACEMENT_ID");
5) Interstitial ads
- Create and load:
InMobiInterstitial interstitial = new InMobiInterstitial(this, PLACEMENT_ID, new InterstitialAdEventListener() { @Override public void onAdLoadSucceeded(InMobiInterstitial ad) {} @Override public void onAdLoadFailed(InMobiInterstitial ad, InMobiAdRequestStatus status) {} }); interstitial.load();
- Show when ready:
if (interstitial.isReady()) interstitial.show();
6) Rewarded ads
Follow similar pattern using InMobiRewarded to load and show; implement reward callbacks to grant user rewards on completion.
7) Native ads
Request native ad objects and inflate into your custom view, mapping title, description, image, and call-to-action from the native response.
8) GDPR/CCPA & Consent
- Use InMobi’s APIs to set consent status before initializing or loading ads:
InMobiSdk.setPartnerGDPRConsent(...); // Example API — check SDK docs for exact method signatures
- Pass consent parameters via request parameters as required by the latest SDK.
9) Testing and debug
- Use test placement IDs or device IDs to receive test ads.
- Use InMobiSdk.setLogLevel to DEBUG during development.
iOS integration (Step-by-step)
1) Prerequisites
- Xcode (latest stable), CocoaPods or Swift Package Manager.
- Create your app in InMobi dashboard and note your Account ID and Placement IDs.
2) Install SDK (CocoaPods)
Add to your Podfile:
pod 'InMobiSDK', '~> 10.0' # check for latest version
Then run:
pod install
Or use Swift Package Manager by adding InMobi’s package repository if available.
3) Add required Info.plist entries & permissions
Ensure NSAppTransportSecurity allows required domains if needed, and add any metadata keys recommended by InMobi docs (e.g., SKAdNetwork IDs if using attribution).
4) Initialize the SDK
In AppDelegate:
import InMobiSDK func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { IMSDK.initWithAccountID("YOUR_ACCOUNT_ID") IMSDK.setLogLevel(.debug) return true }
5) Banner ads
- Add a banner view to your storyboard or create programmatically:
let banner = IMBanner(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: 50)) banner.placementId = PLACEMENT_ID banner.delegate = self view.addSubview(banner) banner.load()
- Implement delegate methods to handle load, fail, click, and render events.
6) Interstitial ads
Create, load, and show IMInterstitial; use delegate callbacks to know when it’s ready to present.
7) Rewarded ads
Use IMRewarded for loading/showing rewarded content and grant rewards in the appropriate delegate callback.
8) Native ads
Request native ad objects and populate your custom views with the response assets, handling image/video rendering as specified by the SDK.
9) Consent & privacy
- Expose consent UI to users and set consent state in the SDK using InMobi consent APIs before requesting ads.
- Configure SKAdNetwork and AppTrackingTransparency (ATT) flow: request tracking authorization and pass tracking status to InMobi if needed.
10) Testing
- Use test placement IDs or enable test mode.
- Test on real devices for ATT behavior and ad rendering.
Common troubleshooting
- Ads not showing: verify Account ID and Placement ID, ensure SDK initialized before load, check logs, confirm ad inventory for region.
- Crashes: check for missing frameworks, improper SDK version or mismatched ProGuard/R8 rules on Android.
- No fill: try test placements, check geotargeting, ensure ad formats match placement configuration.
- Consent issues: ensure consent state set prior to initialization or ad requests.
Tips to maximize revenue and UX
- Use rewarded and native ads where user experience allows; they often yield higher engagement.
- Cache interstitials and rewarded ads, but show them only at natural breaks.
- Use frequency capping and pacing to avoid ad fatigue.
- Monitor performance in InMobi dashboard and A/B test placements, creatives, and formats.
- Implement graceful fallback or mediation to avoid long empty ad slots.
Example checklist before release
- [ ] InMobi account configured with app and placements
- [ ] Correct Account ID and Placement IDs in app
- [ ] SDK initialized at app start
- [ ] Consent flows implemented (GDPR/CCPA/ATT)
- [ ] Test ads verified on devices
- [ ] ProGuard/R8 rules set (Android)
- [ ] SKAdNetwork and ATT configured (iOS)
- [ ] Logging disabled or set to minimal for production
Integrating the InMobi SDK requires careful attention to initialization, consent, ad lifecycle, and platform-specific setup. Follow InMobi’s official docs for the latest API signatures and version-specific instructions, then test thoroughly across devices and regions.
Leave a Reply