initializeWithYourAdIds static method
Initialize with your custom ad IDs - only loads ads that have IDs provided
rewardedAdUnitId - Your rewarded ad unit ID (optional)
bannerAdUnitId - Your banner ad unit ID (optional)
interstitialAdUnitId - Your interstitial ad unit ID (optional)
nativeAdUnitId - Your native ad unit ID (optional)
testDeviceIds - List of test device IDs for development
onAdError - Global error callback
onAdLoaded - Global ad loaded callback
onAdShown - Global ad shown callback
onAdClosed - Global ad closed callback
Implementation
static Future<void> initializeWithYourAdIds({
String? rewardedAdUnitId,
String? bannerAdUnitId,
String? interstitialAdUnitId,
String? nativeAdUnitId,
List<String>? testDeviceIds,
// Optional callbacks
Function(String)? onAdError,
Function(String)? onAdLoaded,
Function(String)? onAdShown,
Function(String)? onAdClosed,
}) async {
// Initialize the ads manager
await GoogleAdsHelper.instance.initialize(
bannerAdUnitId: bannerAdUnitId,
interstitialAdUnitId: interstitialAdUnitId,
rewardedAdUnitId: rewardedAdUnitId,
nativeAdUnitId: nativeAdUnitId,
testDeviceIds: testDeviceIds,
onAdError: onAdError,
onAdLoaded: onAdLoaded,
onAdShown: onAdShown,
onAdClosed: onAdClosed,
);
// Load only ads that have IDs provided
if (bannerAdUnitId != null) {
print('🎯 Loading Banner Ad...');
GoogleAdsHelper.instance.loadBannerAd();
}
if (interstitialAdUnitId != null) {
print('🎯 Loading Interstitial Ad...');
// GoogleAdsHelper.instance.loadInterstitialAd();
}
if (rewardedAdUnitId != null) {
print('🎯 Loading Rewarded Ad...');
GoogleAdsHelper.instance.loadRewardedAd();
}
if (nativeAdUnitId != null) {
print('🎯 Loading Native Ad...');
GoogleAdsHelper.instance.loadNativeAd();
}
// Log what was initialized
List<String> initializedAds = [];
if (bannerAdUnitId != null) initializedAds.add('Banner');
if (interstitialAdUnitId != null) initializedAds.add('Interstitial');
if (rewardedAdUnitId != null) initializedAds.add('Rewarded');
if (nativeAdUnitId != null) initializedAds.add('Native');
print('✅ Initialized ads: ${initializedAds.join(', ')}');
if (initializedAds.isEmpty) {
print('⚠️ No ad IDs provided - no ads will be loaded');
}
}