|
31 | 31 | import com.facebook.react.bridge.ReactContextBaseJavaModule; |
32 | 32 | import com.facebook.react.bridge.ReactMethod; |
33 | 33 | import com.facebook.react.bridge.ReadableMap; |
| 34 | +import com.facebook.react.bridge.ReadableType; |
34 | 35 | import com.facebook.react.bridge.ReadableArray; |
35 | 36 | import com.facebook.react.modules.core.DeviceEventManagerModule; |
36 | 37 |
|
@@ -362,6 +363,59 @@ public void onError(int i, @NonNull String s) { |
362 | 363 | } |
363 | 364 | } |
364 | 365 |
|
| 366 | +@ReactMethod |
| 367 | + public void logAdRevenue(ReadableMap adRevenueDictionary) { |
| 368 | + if (adRevenueDictionary == null || !adRevenueDictionary.keySetIterator().hasNextKey()) { |
| 369 | + Log.d("AppsFlyer", "adRevenueData is missing, the data is mandatory to use this API."); |
| 370 | + return; |
| 371 | + } |
| 372 | + |
| 373 | + String monetizationNetwork = adRevenueDictionary.getString(MONETIZATION_NETWORK); |
| 374 | + if (monetizationNetwork == null) { |
| 375 | + Log.d("AppsFlyer", "monetizationNetwork is missing"); |
| 376 | + return; |
| 377 | + } |
| 378 | + |
| 379 | + String currencyIso4217Code = adRevenueDictionary.getString(CURRENCY_ISO4217_CODE); |
| 380 | + if (currencyIso4217Code == null) { |
| 381 | + Log.d("AppsFlyer", "currencyIso4217Code is missing"); |
| 382 | + return; |
| 383 | + } |
| 384 | + |
| 385 | + if (!adRevenueDictionary.hasKey(AF_REVENUE) || adRevenueDictionary.getType(AF_REVENUE) != ReadableType.Number) { |
| 386 | + Log.d("AppsFlyer", "revenue is missing or not a number"); |
| 387 | + return; |
| 388 | + } |
| 389 | + double revenue = adRevenueDictionary.getDouble(AF_REVENUE); |
| 390 | + |
| 391 | + ReadableMap additionalParameters = null; |
| 392 | + if (adRevenueDictionary.hasKey(AF_ADDITIONAL_PARAMETERS) && adRevenueDictionary.getType(AF_ADDITIONAL_PARAMETERS) == ReadableType.Map) { |
| 393 | + additionalParameters = adRevenueDictionary.getMap(AF_ADDITIONAL_PARAMETERS); |
| 394 | + } |
| 395 | + |
| 396 | + String mediationNetworkValue = adRevenueDictionary.getString(AF_MEDIATION_NETWORK); |
| 397 | + if (mediationNetworkValue == null || mediationNetworkValue.isEmpty()) { |
| 398 | + Log.d("AppsFlyer", "mediationNetwork is missing"); |
| 399 | + return; |
| 400 | + } |
| 401 | + |
| 402 | + MediationNetwork mediationNetwork = MediationNetwork.valueOf(mediationNetworkValue.toUpperCase()); |
| 403 | + if (mediationNetwork == null) { |
| 404 | + Log.d("AppsFlyer", "Invalid mediation network"); |
| 405 | + return; |
| 406 | + } |
| 407 | + |
| 408 | + AFAdRevenueData adRevenueData = new AFAdRevenueData( |
| 409 | + monetizationNetwork, |
| 410 | + mediationNetwork, |
| 411 | + currencyIso4217Code, |
| 412 | + revenue |
| 413 | + ); |
| 414 | + |
| 415 | + // Log the ad revenue to the AppsFlyer SDK |
| 416 | + AppsFlyerLib.getInstance().logAdRevenue(adRevenueData, RNUtil.toMap(additionalParameters)); |
| 417 | + } |
| 418 | + |
365 | 419 | @ReactMethod |
366 | 420 | public void getAppsFlyerUID(Callback callback) { |
367 | 421 | String appId = AppsFlyerLib.getInstance().getAppsFlyerUID(getReactApplicationContext()); |
|
0 commit comments