Configuration
This guide explains how to initialize and configure the Empower Mobile Ads SDK in your Flutter application.
SDK Initialization
Initialize the SDK as early as possible in your application lifecycle — ideally in your root widget's initState or main() function.
Basic Initialization
import 'dart:io';import 'package:flutter/material.dart';import 'package:empower_mobile_ads/empower_mobile_ads.dart';void main() {WidgetsFlutterBinding.ensureInitialized();final appId = Platform.isAndroid? 'your_android_app_identifier': 'your_ios_app_identifier';EmpowerAds.init(EmpowerAdsConfig(appAdIdentifier: appId,));runApp(const MyApp());}
Important: Replace the identifiers with the app identifiers provided by Empower.
Initialization with Options
import 'package:empower_mobile_ads/empower_mobile_ads.dart';EmpowerAds.init(EmpowerAdsConfig(appAdIdentifier: 'your_app_identifier',debugMode: false, // Enable debug logging (disable in production)logLevel: 'default', // Log verbosity levelprivacyMode: 'automatic', // GDPR privacy modeconsentFormDelay: 1.5, // iOS: delay before showing consent formvariant: 'A', // Optional: A/B test variant));
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
appAdIdentifier | String | — | Required. Your app identifier from Empower. |
debugMode | bool | false | Enables verbose logging and test ads. Disable in production. |
logLevel | String | 'default' | Controls the verbosity of SDK logs. |
privacyMode | String | 'automatic' | Privacy mode for ad personalization. |
consentFormDelay | double | 1.5 | iOS only: delay in seconds before showing the consent form. |
variant | String? | null | Optional A/B test variant string. |
Log Levels
| Level | Description |
|---|---|
'all' | Logs all messages including debug information |
'default' | Logs general information and errors |
'warning' | Logs warnings and errors only |
'error' | Logs errors only |
'none' | Disables all logging |
Privacy Modes
| Mode | Description |
|---|---|
'automatic' | SDK automatically handles privacy and consent |
'nonPersonalized' | Serves only non-personalized ads (GDPR compliance) |
'manual' | Full manual control over privacy settings |
Listening for SDK Events (Optional)
The SDK provides Dart Streams for monitoring SDK and ad status changes:
import 'package:empower_mobile_ads/empower_mobile_ads.dart';// Listen for SDK eventsEmpowerAds.onSdkReady.listen((event) {print('Empower SDK is ready');});// Listen for banner status changesEmpowerAds.onBannerStatusChanged.listen((event) {final status = event['status'];final zoneId = event['zoneId'];print('Banner status: $status for zone: $zoneId');});
Note: This listener is optional. Since all ad types automatically queue, you don't need to wait for SDK ready before loading ads.
Automatic Ad Queueing
Banner and app open ads automatically queue if called before SDK initialization completes. However, interstitial and rewarded ads should be loaded after the SDK is fully initialized to ensure reliable delivery.
A practical approach is to listen for the first banner status event (which signals that the SDK has finished parsing ad zones) before loading interstitials or rewarded ads:
import 'dart:async';import 'package:empower_mobile_ads/empower_mobile_ads.dart';// InitializeEmpowerAds.init(EmpowerAdsConfig(appAdIdentifier: 'your_app_identifier',));// App open ads queue automaticallyEmpowerAds.loadAppOpenAd('app_open_zone_id');// Load interstitial after SDK is ready (banner status is a reliable signal)StreamSubscription? sub;sub = EmpowerAds.onBannerStatusChanged.listen((_) {EmpowerAds.loadInterstitialAd('interstitial_zone_id');sub?.cancel(); // Only need to trigger once});
GDPR Compliance
For users in regions requiring GDPR compliance:
import 'package:empower_mobile_ads/empower_mobile_ads.dart';// Option 1: During initializationEmpowerAds.init(EmpowerAdsConfig(appAdIdentifier: 'your_app_identifier',privacyMode: 'nonPersonalized',));// Option 2: At runtime based on user consentEmpowerAds.setNonPersonalizedAds(!userHasGivenConsent);
Runtime Configuration
You can change SDK settings at runtime using these methods:
import 'package:empower_mobile_ads/empower_mobile_ads.dart';// Enable/disable debug modeEmpowerAds.setDebugMode(false);// Change log levelEmpowerAds.setLogLevel('error');// Toggle non-personalized adsEmpowerAds.setNonPersonalizedAds(true);// Disable all ads (e.g., for premium users)EmpowerAds.setAdsDisabled(true);
Checking SDK Status
import 'package:empower_mobile_ads/empower_mobile_ads.dart';final isReady = await EmpowerAds.isSdkInitialized();if (isReady) {// Safe to load ads}
Disabling Ads for Premium Users
import 'package:empower_mobile_ads/empower_mobile_ads.dart';// Disable all ads for premium usersvoid userPurchasedPremium() {EmpowerAds.setAdsDisabled(true);}// Re-enable ads if subscription expiresvoid premiumSubscriptionExpired() {EmpowerAds.setAdsDisabled(false);}
Shutdown
Use shutdown() when you no longer want to show ads:
import 'package:empower_mobile_ads/empower_mobile_ads.dart';// Stop all ads and release resourcesEmpowerAds.shutdown();// Reinitialize when you want to show ads againEmpowerAds.init(EmpowerAdsConfig(appAdIdentifier: 'your_app_identifier',));