Skip to content

Commit

Permalink
add some attempt of adding the adrevenue api
Browse files Browse the repository at this point in the history
  • Loading branch information
noa-kogonia committed Aug 12, 2024
1 parent 7191a6c commit a69c72f
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 4 deletions.
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<config>
</config>
<pods use-frameworks="true">
<pod name="AppsFlyerFramework" spec="6.14.3"/>
<pod name="AppsFlyerFramework" spec="6.15.0"/>
</pods>
</podspec>
</platform>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class AppsFlyerConstants {

final static String PLUGIN_VERSION = "6.14.0";
final static String PLUGIN_VERSION = "6.15.0";
final static String NO_DEVKEY_FOUND = "AppsFlyer 'devKey' is missing or empty";
final static String NO_GCM_PROJECT_NUMBER_PROVIDED = "No GCM Project number provided";
final static String SUCCESS = "Success";
Expand Down
44 changes: 44 additions & 0 deletions src/android/com/appsflyer/cordova/plugin/AppsFlyerPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,54 @@ public boolean execute(final String action, JSONArray args, CallbackContext call
return setConsentData(args);
} else if ("enableTCFDataCollection".equals(action)) {
return enableTCFDataCollection(args);
} else if ("logAdRevenue".equals(action)) {
return logAdRevenue(args);
}
return false;
}

/**
* log AdRevenue event
*
* @param args - event params
* @return true
*/
private boolean logAdRevenue(JSONArray args) {
cordova.getThreadPool().execute(() -> {
Map<String, Object> additionalParameters = null;
try {
JSONObject afAdRevenueDataJsonObj = args.getJSONObject(0);
String monetizationNetwork = afAdRevenueDataJsonObj.optString("monetizationNetwork", null);
String mediationNetwork = afAdRevenueDataJsonObj.optString("mediationNetwork", null);
String currencyIso4217Code = afAdRevenueDataJsonObj.optString("currencyIso4217Code", null);
double revenue = afAdRevenueDataJsonObj.optDouble("revenue", -1);

if(args.get(1) != null){
JSONObject additionalParametersJson = args.getJSONObject(1);
additionalParameters = toObjectMap(additionalParametersJson);
}

if(mediationNetwork != null){
MediationNetwork mediationNetworkEnumVal = null;
for(MediationNetwork mediationNetworkEnum: MediationNetwork.values()){
if(mediationNetworkEnum.name().equals(mediationNetwork)){
mediationNetworkEnumVal = MediationNetwork.valueOf(mediationNetwork);
}
}
if(mediationNetworkEnumVal != null){
AFAdRevenueData afAdRevenueData = new AFAdRevenueData(monetizationNetwork, mediationNetworkEnumVal, currencyIso4217Code, revenue);
AppsFlyerLib.getInstance().logAdRevenue(afAdRevenueData, additionalParameters);
}
}

} catch (JSONException e) {
e.printStackTrace();
}
});
return true;
}


/**
* set consent data according to GDPR if applies or not.
*
Expand Down
2 changes: 1 addition & 1 deletion src/android/cordovaAF.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repositories {

dependencies {
implementation 'com.android.installreferrer:installreferrer:2.1'
implementation 'com.appsflyer:af-android-sdk:6.14.0@aar'
implementation 'com.appsflyer:af-android-sdk:6.15.0@aar'
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.6.20'
}
1 change: 1 addition & 0 deletions src/ios/AppsFlyerPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- (void)setCurrentDeviceLanguage:(CDVInvokedUrlCommand*)command;
- (void)setAdditionalData:(CDVInvokedUrlCommand*)command;
- (void)setConsentData:(CDVInvokedUrlCommand*)command;
- (void)logAdRevenue:(CDVInvokedUrlCommand*)command;
- (void)enableTCFDataCollection:(CDVInvokedUrlCommand*)command;
- (void)setSharingFilter:(CDVInvokedUrlCommand*)command __attribute__((deprecated));
- (void)setSharingFilterForAllPartners:(CDVInvokedUrlCommand*)command __attribute__((deprecated));
Expand Down
46 changes: 45 additions & 1 deletion src/ios/AppsFlyerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ - (void)initSdk:(CDVInvokedUrlCommand*)command
}

// Initialize the SDK
[[AppsFlyerLib shared] setPluginInfoWith:AFSDKPluginCordova pluginVersion:@"6.14.3" additionalParams:nil];
[[AppsFlyerLib shared] setPluginInfoWith:AFSDKPluginCordova pluginVersion:@"6.15.0" additionalParams:nil];
[AppsFlyerLib shared].appleAppID = appId;
[AppsFlyerLib shared].appsFlyerDevKey = devKey;
[AppsFlyerLib shared].isDebug = isDebug;
Expand Down Expand Up @@ -196,6 +196,50 @@ - (void)setCurrencyCode:(CDVInvokedUrlCommand*)command
[AppsFlyerLib shared].currencyCode = currencyId;
}

/**
* log AdRevenue event
*/
- (void)logAdRevenue:(CDVInvokedUrlCommand*)command
{
if ([command.arguments count] == 0) {
return;
}
NSDictionary *afAdRevenueDataMap = (NSDictionary*)[command.arguments objectAtIndex: 0];

id monetizationNetwork = nil;
id mediationNetwork = nil;
id currencyIso4217Code = nil;
id revenue = -1;

id monetizationNetworkValue = nil;
id mediationNetworkValue = nil;
id currencyIso4217CodeValue = nil;
id revenueValue = -1;

monetizationNetworkValue = [afAdRevenueDataMap objectForKey:@"monetizationNetwork"];
if ([monetizationNetworkValue isKindOfClass:[NSString class]]) {
monetizationNetwork = monetizationNetworkValue;
}

mediationNetworkValue = [afAdRevenueDataMap objectForKey:@"mediationNetwork"];
if ([mediationNetworkValue isKindOfClass:[NSString class]]) {
hasConsentForDataUsage = [(NSNumber*)hasConsentForDataUsageValue boolValue];
}

hasConsentForAdsPersonalizationValue = [consentDataMap objectForKey:@"hasConsentForAdsPersonalization"];
if ([hasConsentForAdsPersonalizationValue isKindOfClass:[NSNumber class]]) {
hasConsentForAdsPersonalization = [(NSNumber*)hasConsentForAdsPersonalizationValue boolValue];
}

AppsFlyerConsent *consentData = nil;
if (isUserSubjectToGDPR) {
consentData = [[AppsFlyerConsent alloc] initForGDPRUserWithHasConsentForDataUsage:hasConsentForDataUsage hasConsentForAdsPersonalization:hasConsentForAdsPersonalization];
} else {
consentData = [[AppsFlyerConsent alloc] initNonGDPRUser];
}
[[AppsFlyerLib shared] setConsentData:consentData];
}

/**
* Sets new currency code. currencyId: ISO 4217 Currency Codes.
*/
Expand Down
54 changes: 54 additions & 0 deletions www/appsflyer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var exec = require('cordova/exec'),
AppsFlyerError = require('./AppsFlyerError');
var callbackMap = {};

let AFAdRevenueData;

if (!window.CustomEvent) {
window.CustomEvent = function (type, config) {
var e = document.createEvent('CustomEvent');
Expand Down Expand Up @@ -37,6 +39,45 @@ if (!window.CustomEvent) {
};
})();

// AFAdRevenueData object with MediationNetwork enum
global.AFAdRevenueData = (function() {
const MediationNetwork = {
IRONSOURCE:"ironsource",
APPLOVIN_MAX:"applovinmax",
GOOGLE_ADMOB:"googleadmob",
FYBER:"fyber",
APPODEAL:"appodeal",
ADMOST:"Admost",
TOPON:"Topon",
TRADPLUS:"Tradplus",
YANDEX:"Yandex",
CHARTBOOST:"chartboost",
UNITY:"Unity",
TOPON_PTE:"toponpte",
CUSTOM_MEDIATION:"customMediation",
DIRECT_MONETIZATION_NETWORK:"directMonetizationNetwork"
};

function AFAdRevenueData(monetizationNetwork, mediationNetwork, currencyIso4217Code, revenue) {
if (!Object.values(MediationNetwork).includes(mediationNetwork)) {
throw new Error("Invalid enum value for 'mediationNetwork'.");
}
this.monetizationNetwork = monetizationNetwork;
this.mediationNetwork = mediationNetwork;
this.currencyIso4217Code = currencyIso4217Code;
this.revenue = revenue;
}

return AFAdRevenueData; // Expose the constructor directly
})();

function validateAFAdRevenueData(afAdRevenueData) {
if (!(afAdRevenueData instanceof AFAdRevenueData)) {
throw new Error("Invalid AFAdRevenueData object.");
}
return afAdRevenueData;
}

/**
* initialize the SDK.
* args: SDK configuration
Expand Down Expand Up @@ -109,6 +150,19 @@ if (!window.CustomEvent) {
exec(null, null, 'AppsFlyerPlugin', 'setCurrencyCode', [currencyId]);
};

/**
* Public API - logAdRevenue function
*/
AppsFlyer.prototype.logAdRevenue = function(afAdRevenueData, additionalParameters) {
argscheck.checkArgs('S', 'AppsFlyer.logAdRevenue', arguments);

// Validate AFAdRevenueData before logging
const validatedAfAdRevenueData = validateAFAdRevenueData(afAdRevenueData);

// Call the 'logAdRevenue' API method with the validated data
exec(null, null, 'AppsFlyerPlugin', 'logAdRevenue', [validatedAfAdRevenueData, additionalParameters]);
};

/**
* Setting your own Custom ID enables you to cross-reference your own unique ID with AppsFlyer’s user ID and the other devices’ IDs.
*/
Expand Down

0 comments on commit a69c72f

Please sign in to comment.