diff --git a/example/lib/home_container.dart b/example/lib/home_container.dart index 43d8d82..a474830 100644 --- a/example/lib/home_container.dart +++ b/example/lib/home_container.dart @@ -7,12 +7,14 @@ import 'utils.dart'; class HomeContainer extends StatefulWidget { final Map onData; final Future Function(String, Map) logEvent; + final void Function() logAdRevenueEvent; Object deepLinkData; HomeContainer({ required this.onData, required this.deepLinkData, required this.logEvent, + required this.logAdRevenueEvent, }); @override @@ -136,6 +138,20 @@ class _HomeContainerState extends State { ), ), ), + ElevatedButton( + onPressed: () { + widget.logAdRevenueEvent(); + }, + child: Text("Trigger AdRevenue Event"), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.white, + padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10), + textStyle: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 16, + ), + ), + ), ], ), ) diff --git a/example/lib/main_page.dart b/example/lib/main_page.dart index e0da017..70ce33b 100644 --- a/example/lib/main_page.dart +++ b/example/lib/main_page.dart @@ -124,6 +124,7 @@ class MainPageState extends State { onData: _gcd, deepLinkData: _deepLinkData, logEvent: logEvent, + logAdRevenueEvent: logAdRevenueEvent, ), ), ElevatedButton( @@ -133,7 +134,8 @@ class MainPageState extends State { showMessage("AppsFlyer SDK initialized successfully."); }, onError: (int errorCode, String errorMessage) { - showMessage("Error initializing AppsFlyer SDK: Code $errorCode - $errorMessage"); + showMessage( + "Error initializing AppsFlyer SDK: Code $errorCode - $errorMessage"); }, ); }, @@ -158,13 +160,29 @@ class MainPageState extends State { return logResult; } + void logAdRevenueEvent() { + try { + Map customParams = { + 'ad_platform': 'Admob', + 'ad_currency': 'USD', + }; + + AdRevenueData adRevenueData = AdRevenueData( + monetizationNetwork: 'SpongeBob', + mediationNetwork: AFMediationNetwork.googleAdMob.value, + currencyIso4217Code: 'USD', + revenue: 100.3, + additionalParameters: customParams); + _appsflyerSdk.logAdRevenue(adRevenueData); + print("Ad Revenue event logged with no errors"); + } catch (e) { + print("Failed to log event: $e"); + } + } + void showMessage(String message) { - ScaffoldMessenger.of(context) - .showSnackBar(SnackBar( - content: - Text(message), + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + content: Text(message), )); } } - - diff --git a/ios/Classes/AppsflyerSdkPlugin.m b/ios/Classes/AppsflyerSdkPlugin.m index 4295044..f497c68 100644 --- a/ios/Classes/AppsflyerSdkPlugin.m +++ b/ios/Classes/AppsflyerSdkPlugin.m @@ -255,20 +255,20 @@ - (void)logAdRevenue:(FlutterMethodCall*)call result:(FlutterResult)result { - (AppsFlyerAdRevenueMediationNetworkType)getEnumValueFromString:(NSString *)mediationNetworkString { NSDictionary *stringToEnumMap = @{ - @"googleadmob": @(AppsFlyerAdRevenueMediationNetworkTypeGoogleAdMob), + @"google_admob": @(AppsFlyerAdRevenueMediationNetworkTypeGoogleAdMob), @"ironsource": @(AppsFlyerAdRevenueMediationNetworkTypeIronSource), - @"applovinmax": @(AppsFlyerAdRevenueMediationNetworkTypeApplovinMax), + @"applovin_max": @(AppsFlyerAdRevenueMediationNetworkTypeApplovinMax), @"fyber": @(AppsFlyerAdRevenueMediationNetworkTypeFyber), @"appodeal": @(AppsFlyerAdRevenueMediationNetworkTypeAppodeal), - @"Admost": @(AppsFlyerAdRevenueMediationNetworkTypeAdmost), - @"Topon": @(AppsFlyerAdRevenueMediationNetworkTypeTopon), - @"Tradplus": @(AppsFlyerAdRevenueMediationNetworkTypeTradplus), - @"Yandex": @(AppsFlyerAdRevenueMediationNetworkTypeYandex), + @"admost": @(AppsFlyerAdRevenueMediationNetworkTypeAdmost), + @"topon": @(AppsFlyerAdRevenueMediationNetworkTypeTopon), + @"tradplus": @(AppsFlyerAdRevenueMediationNetworkTypeTradplus), + @"yandex": @(AppsFlyerAdRevenueMediationNetworkTypeYandex), @"chartboost": @(AppsFlyerAdRevenueMediationNetworkTypeChartBoost), - @"Unity": @(AppsFlyerAdRevenueMediationNetworkTypeUnity), - @"toponpte": @(AppsFlyerAdRevenueMediationNetworkTypeToponPte), - @"customMediation": @(AppsFlyerAdRevenueMediationNetworkTypeCustom), - @"directMonetizationNetwork": @(AppsFlyerAdRevenueMediationNetworkTypeDirectMonetization) + @"unity": @(AppsFlyerAdRevenueMediationNetworkTypeUnity), + @"topon_pte": @(AppsFlyerAdRevenueMediationNetworkTypeToponPte), + @"custom_mediation": @(AppsFlyerAdRevenueMediationNetworkTypeCustom), + @"direct_monetization_network": @(AppsFlyerAdRevenueMediationNetworkTypeDirectMonetization) }; NSNumber *enumValueNumber = stringToEnumMap[mediationNetworkString]; diff --git a/lib/src/appsflyer_constants.dart b/lib/src/appsflyer_constants.dart index 6f86f56..641db02 100644 --- a/lib/src/appsflyer_constants.dart +++ b/lib/src/appsflyer_constants.dart @@ -49,31 +49,31 @@ enum AFMediationNetwork { case AFMediationNetwork.ironSource: return "ironsource"; case AFMediationNetwork.applovinMax: - return "applovinmax"; + return "applovin_max"; case AFMediationNetwork.googleAdMob: - return "googleadmob"; + return "google_admob"; case AFMediationNetwork.fyber: return "fyber"; case AFMediationNetwork.appodeal: return "appodeal"; case AFMediationNetwork.admost: - return "Admost"; + return "admost"; case AFMediationNetwork.topon: - return "Topon"; + return "topon"; case AFMediationNetwork.tradplus: - return "Tradplus"; + return "tradplus"; case AFMediationNetwork.yandex: - return "Yandex"; + return "yandex"; case AFMediationNetwork.chartboost: return "chartboost"; case AFMediationNetwork.unity: - return "Unity"; + return "unity"; case AFMediationNetwork.toponPte: - return "toponpte"; + return "topon_pte"; case AFMediationNetwork.customMediation: - return "customMediation"; + return "custom_mediation"; case AFMediationNetwork.directMonetizationNetwork: - return "directMonetizationNetwork"; + return "direct_monetization_network"; } } }