From 76404761a38a54c112965f173756c484cf1a661a Mon Sep 17 00:00:00 2001 From: "ivan.obodovskyi" Date: Fri, 4 Oct 2024 13:58:29 +0300 Subject: [PATCH] Update to 6.15.3 * Implement logAdRevenueAPI for iOS --- Classes/AppsFlyer/AFXAdRevenueData.cpp | 41 ++++++++++++++ Classes/AppsFlyer/AFXAdRevenueData.h | 76 ++++++++++++++++++++++++++ Classes/AppsFlyer/AppsFlyerX.cpp | 8 +++ Classes/AppsFlyer/AppsFlyerX.h | 3 + Classes/AppsFlyer/AppsFlyerXApple.h | 12 +--- Classes/AppsFlyer/AppsFlyerXApple.mm | 15 +++++ proj.ios_mac/ios/AppController.h | 2 +- 7 files changed, 147 insertions(+), 10 deletions(-) create mode 100644 Classes/AppsFlyer/AFXAdRevenueData.cpp create mode 100644 Classes/AppsFlyer/AFXAdRevenueData.h diff --git a/Classes/AppsFlyer/AFXAdRevenueData.cpp b/Classes/AppsFlyer/AFXAdRevenueData.cpp new file mode 100644 index 0000000..ceb2250 --- /dev/null +++ b/Classes/AppsFlyer/AFXAdRevenueData.cpp @@ -0,0 +1,41 @@ +// +// AFXAdRevenueData.cpp +// MyGame +// +// Created by ivan.obodovskyi on 04.10.2024. +// + +#include +#include "AFXAdRevenueData.h" + +// Constructor definition +AFXAdRevenueData::AFXAdRevenueData(const std::string& monetizationNetwork, + AppsFlyerXAdRevenueMediationNetworkType mediationNetwork, + const std::string& currencyIso4217Code, + double eventRevenue) + : monetizationNetwork(monetizationNetwork), + mediationNetwork(mediationNetwork), + currencyIso4217Code(currencyIso4217Code), + eventRevenue(eventRevenue) { +} + +// Getters implementation +std::string AFXAdRevenueData::getMonetizationNetwork() const { + return monetizationNetwork; +} + +AppsFlyerXAdRevenueMediationNetworkType AFXAdRevenueData::getMediationNetwork() const { + return mediationNetwork; +} + +std::string AFXAdRevenueData::getCurrencyIso4217Code() const { + return currencyIso4217Code; +} + +double AFXAdRevenueData::getEventRevenue() const { + return eventRevenue; +} + +int convertMeditationType(AppsFlyerXAdRevenueMediationNetworkType a) { + return static_cast(static_cast(a)); +} diff --git a/Classes/AppsFlyer/AFXAdRevenueData.h b/Classes/AppsFlyer/AFXAdRevenueData.h new file mode 100644 index 0000000..9fe0a61 --- /dev/null +++ b/Classes/AppsFlyer/AFXAdRevenueData.h @@ -0,0 +1,76 @@ +// +// AFXAdRevenueData.h +// MyGame +// +// Created by ivan.obodovskyi on 04.10.2024. +// + +#include + +#ifndef AFXAdRevenueData_h +#define AFXAdRevenueData_h + +enum class AppsFlyerXAdRevenueMediationNetworkType { + GoogleAdMob = 1, + IronSource = 2, + ApplovinMax = 3, + Fyber = 4, + Appodeal = 5, + Admost = 6, + Topon = 7, + Tradplus = 8, + Yandex = 9, + ChartBoost = 10, + Unity = 11, + ToponPte = 12, + Custom = 13, + DirectMonetization = 14 +}; + +#define kAppsFlyerAdRevenueMonetizationNetwork @"monetization_network" +#define kAppsFlyerAdRevenueMediationNetwork @"mediation_network" +#define kAppsFlyerAdRevenueEventRevenue @"event_revenue" +#define kAppsFlyerAdRevenueEventRevenueCurrency @"event_revenue_currency" +#define kAppsFlyerAdRevenueCustomParameters @"custom_parameters" +#define kAFADRWrapperTypeGeneric @"adrevenue_sdk" + +//Pre-defined keys for non-mandatory dictionary + +//Code ISO 3166-1 format +#define kAppsFlyerAdRevenueCountry @"country" + +//ID of the ad unit for the impression +#define kAppsFlyerAdRevenueAdUnit @"ad_unit" + +//Format of the ad +#define kAppsFlyerAdRevenueAdType @"ad_type" + +//ID of the ad placement for the impression +#define kAppsFlyerAdRevenuePlacement @"placement" + + +class AFXAdRevenueData { +public: + // Constructor with initialization parameters + AFXAdRevenueData(const std::string& monetizationNetwork, + AppsFlyerXAdRevenueMediationNetworkType mediationNetwork, + const std::string& currencyIso4217Code, + double eventRevenue); + + // Getter functions for each property + std::string getMonetizationNetwork() const; + AppsFlyerXAdRevenueMediationNetworkType getMediationNetwork() const; + std::string getCurrencyIso4217Code() const; + double getEventRevenue() const; + int convertMeditationType(AppsFlyerXAdRevenueMediationNetworkType a); + +private: + // Private member variables + std::string monetizationNetwork; + AppsFlyerXAdRevenueMediationNetworkType mediationNetwork; + std::string currencyIso4217Code; + double eventRevenue; +}; + + +#endif /* AFXAdRevenueData_h */ diff --git a/Classes/AppsFlyer/AppsFlyerX.cpp b/Classes/AppsFlyer/AppsFlyerX.cpp index 4ccd673..c85ff80 100644 --- a/Classes/AppsFlyer/AppsFlyerX.cpp +++ b/Classes/AppsFlyer/AppsFlyerX.cpp @@ -332,6 +332,14 @@ void AppsFlyerX::validateAndLogInAppPurchase(const std::string& publicKey, #endif } +void AppsFlyerX::logAdRevenue(AFXAdRevenueData adRevenueData, cocos2d::ValueMap additionalParameters) { +#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) + // Android implementation +#elif (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) + AppsFlyerXApple::logAdRevenue(adRevenueData, additionalParameters); +#endif +} + void AppsFlyerX::validateAndLogInAppPurchase(AFSDKXPurchaseDetails &details, cocos2d::ValueMap params, std::function completionHandler) { #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) // Android implementation diff --git a/Classes/AppsFlyer/AppsFlyerX.h b/Classes/AppsFlyer/AppsFlyerX.h index 9e7eb6b..316acb3 100644 --- a/Classes/AppsFlyer/AppsFlyerX.h +++ b/Classes/AppsFlyer/AppsFlyerX.h @@ -17,6 +17,7 @@ #include "AppsFlyerXDeepLinkResult.h" #include "AppsFlyerXConsent.cpp" #include "AFSDKXPurchaseDetails.h" +#include "AFXAdRevenueData.h" class AppsFlyerX { @@ -75,6 +76,8 @@ class AppsFlyerX { static void logEvent(const std::string& eventName, cocos2d::ValueMap values); + static void logAdRevenue(AFXAdRevenueData adRevenueData, cocos2d::ValueMap additionalParameters); + static void validateAndLogInAppPurchase(const std::string& productIdentifier, const std::string& price, const std::string& currency, diff --git a/Classes/AppsFlyer/AppsFlyerXApple.h b/Classes/AppsFlyer/AppsFlyerXApple.h index 4307361..7fd76ad 100644 --- a/Classes/AppsFlyer/AppsFlyerXApple.h +++ b/Classes/AppsFlyer/AppsFlyerXApple.h @@ -97,28 +97,22 @@ class AppsFlyerXApple { cocos2d::ValueMap params, std::function completionHandler); + static void logAdRevenue(AFXAdRevenueData adRevenueData, cocos2d::ValueMap additionalParameters); + static void logLocation(double longitude, double latitude); static std::string getAppsFlyerUID(); - static void handleOpenURL(const std::string& url, const std::string& sourceApplication); static void handleOpenURL(std::string url, std::string sourceApplication, void* annotation); static void handleOpenURL(std::string url, cocos2d::ValueMap options); - /* - - (BOOL) continueUserActivity:(NSUserActivity *) userActivity restorationHandler:(void (^)(NSArray *))restorationHandler NS_AVAILABLE_IOS(9_0); - - (void) didUpdateUserActivity:(NSUserActivity *)userActivity NS_AVAILABLE_IOS(9_0); - */ - static void handlePushNotification(cocos2d::ValueMap pushPayload); static void registerUninstall(void* deviceToken, unsigned long length); - // static std::string getSDKVersion(); - static void remoteDebuggingCallWithData(const std::string& data); static void setHost(const std::string& host); @@ -130,7 +124,7 @@ class AppsFlyerXApple { static void stop(bool stop); - // Delegates methods proxy + // MARK: - AppsFlyerLib delegate proxy methods static void setOnConversionDataReceived(void(*callback)(cocos2d::ValueMap installData)); static void setOnConversionDataRequestFailure(void(*callback)(cocos2d::ValueMap error)); static void setOnAppOpenAttribution(void(*callback)(cocos2d::ValueMap attributionData)); diff --git a/Classes/AppsFlyer/AppsFlyerXApple.mm b/Classes/AppsFlyer/AppsFlyerXApple.mm index 0ff46fc..ca1098d 100644 --- a/Classes/AppsFlyer/AppsFlyerXApple.mm +++ b/Classes/AppsFlyer/AppsFlyerXApple.mm @@ -269,10 +269,25 @@ transactionId:transactionId]; [[AppsFlyerLib shared] validateAndLogInAppPurchase:afPurchaseDetails extraEventValues:lParams completionHandler:^(AFSDKValidateAndLogResult * _Nullable result) { + // TODO: - add result to completionHandler NSLog(@"[ValidateAndLog] Result: %@", result); }]; } +void AppsFlyerXApple::logAdRevenue(AFXAdRevenueData adRevenueData, + cocos2d::ValueMap additionalParameters) { + NSDictionary *lParams = AppsFlyerXAppleHelper::valueMap2nsDictionary(additionalParameters); + + NSString * monetizationNetwork = [NSString stringWithUTF8String:adRevenueData.getMonetizationNetwork().c_str()]; + AppsFlyerAdRevenueMediationNetworkType mediationNetwork = static_cast(adRevenueData.getMediationNetwork()); + NSString * currencyIso4217Code = [NSString stringWithUTF8String:adRevenueData.getCurrencyIso4217Code().c_str()]; + NSNumber *eventRevenue = [NSNumber numberWithDouble:adRevenueData.getEventRevenue()]; + + AFAdRevenueData *appsflyerAdRevenueData = [[AFAdRevenueData alloc] initWithMonetizationNetwork:monetizationNetwork mediationNetwork:mediationNetwork currencyIso4217Code:currencyIso4217Code eventRevenue:eventRevenue]; + + [[AppsFlyerLib shared] logAdRevenue:appsflyerAdRevenueData additionalParameters:lParams]; +} + void AppsFlyerXApple::logLocation(double longitude, double latitude) { [[AppsFlyerLib shared] logLocation:longitude latitude:latitude]; } diff --git a/proj.ios_mac/ios/AppController.h b/proj.ios_mac/ios/AppController.h index 8f69e2e..822e4af 100644 --- a/proj.ios_mac/ios/AppController.h +++ b/proj.ios_mac/ios/AppController.h @@ -24,7 +24,7 @@ ****************************************************************************/ #import -#import "AppsFlyerLib.h" +#import "AppsFlyer/libAppsFlyer/AppsFlyerLib.h" @class RootViewController;