diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b67a88..0668c86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## Versions +## 1.0.10 + * Add support for targeting data. ## 1.0.9 * Fix "OnMRecAdExpandedEvent" not being called when MRECs are expanded. ## 1.0.8 diff --git a/plugin/package.json b/plugin/package.json index f3dd4a4..22008f1 100644 --- a/plugin/package.json +++ b/plugin/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-applovin-max", - "version": "1.0.9", + "version": "1.0.10", "description": "AppLovin MAX Cordova Plugin for Android and iOS", "cordova": { "id": "cordova-plugin-applovin-max", diff --git a/plugin/plugin.xml b/plugin/plugin.xml index d81627f..907689b 100644 --- a/plugin/plugin.xml +++ b/plugin/plugin.xml @@ -1,5 +1,5 @@ - + AppLovin MAX AppLovin MAX Cordova Plugin MIT diff --git a/plugin/src/android/AppLovinMAX.java b/plugin/src/android/AppLovinMAX.java index e0c9218..f0baad8 100644 --- a/plugin/src/android/AppLovinMAX.java +++ b/plugin/src/android/AppLovinMAX.java @@ -27,6 +27,8 @@ import com.applovin.mediation.ads.MaxAdView; import com.applovin.mediation.ads.MaxInterstitialAd; import com.applovin.mediation.ads.MaxRewardedAd; +import com.applovin.sdk.AppLovinAdContentRating; +import com.applovin.sdk.AppLovinGender; import com.applovin.sdk.AppLovinMediationProvider; import com.applovin.sdk.AppLovinPrivacySettings; import com.applovin.sdk.AppLovinSdk; @@ -71,6 +73,13 @@ public class AppLovinMAX private String userIdToSet; private List testDeviceAdvertisingIdsToSet; private Boolean verboseLoggingToSet; + private Integer yearOfBirthToSet; + private Integer genderToSet; + private Integer maximumAdContentRatingToSet; + private String emailToSet; + private String phoneNumberToSet; + private List keywordsToSet; + private List interestsToSet; // Fullscreen Ad Fields private final Map mInterstitials = new HashMap<>( 2 ); @@ -162,6 +171,49 @@ private void initialize(final String pluginVersion, final String sdkKey, final C verboseLoggingToSet = null; } + // Set targeting data if needed + if ( yearOfBirthToSet != null ) + { + sdk.getTargetingData().setYearOfBirth( yearOfBirthToSet ); + yearOfBirthToSet = null; + } + + if ( genderToSet != null ) + { + sdk.getTargetingData().setGender( integerToALGender( genderToSet ) ); + genderToSet = null; + } + + if ( maximumAdContentRatingToSet != null ) + { + sdk.getTargetingData().setMaximumAdContentRating( integerToALAdContentRating( maximumAdContentRatingToSet ) ); + maximumAdContentRatingToSet = null; + } + + if ( emailToSet != null ) + { + sdk.getTargetingData().setEmail( emailToSet ); + emailToSet = null; + } + + if ( phoneNumberToSet != null ) + { + sdk.getTargetingData().setPhoneNumber( phoneNumberToSet ); + phoneNumberToSet = null; + } + + if ( keywordsToSet != null ) + { + sdk.getTargetingData().setKeywords( keywordsToSet ); + keywordsToSet = null; + } + + if ( interestsToSet != null ) + { + sdk.getTargetingData().setInterests( interestsToSet ); + interestsToSet = null; + } + sdk.initializeSdk( configuration -> { d( "SDK initialized" ); @@ -185,7 +237,7 @@ public void onOrientationChanged(final int orientation) { callbackContext.success( getInitializationMessage( context ) ); } - catch ( Throwable ignored ) {} + catch ( Throwable ignored ) { } } ); } @@ -339,6 +391,113 @@ public void setTestDeviceAdvertisingIds(final List advertisingIds, final callbackContext.success(); } + // TARGETING DATA + + public void setYearOfBirth(final Integer yearOfBirth, final CallbackContext callbackContext) + { + if ( isPluginInitialized ) + { + sdk.getTargetingData().setYearOfBirth( yearOfBirth ); + yearOfBirthToSet = null; + } + else + { + yearOfBirthToSet = yearOfBirth; + } + + callbackContext.success(); + } + + public void setGender(final Integer gender, final CallbackContext callbackContext) + { + if ( isPluginInitialized ) + { + integerToALGender( gender ); + genderToSet = null; + } + else + { + genderToSet = gender; + } + + callbackContext.success(); + } + + public void setMaximumAdContentRating(final Integer maximumAdContentRating, final CallbackContext callbackContext) + { + if ( isPluginInitialized ) + { + integerToALAdContentRating( maximumAdContentRating ); + genderToSet = null; + } + else + { + maximumAdContentRatingToSet = maximumAdContentRating; + } + + callbackContext.success(); + } + + public void setEmail(final String email, final CallbackContext callbackContext) + { + if ( isPluginInitialized ) + { + sdk.getTargetingData().setEmail( email ); + emailToSet = null; + } + else + { + emailToSet = email; + } + + callbackContext.success(); + } + + public void setPhoneNumber(final String phoneNumber, final CallbackContext callbackContext) + { + if ( isPluginInitialized ) + { + sdk.getTargetingData().setPhoneNumber( phoneNumber ); + phoneNumberToSet = null; + } + else + { + phoneNumberToSet = phoneNumber; + } + + callbackContext.success(); + } + + public void setKeywords(final List keywords, final CallbackContext callbackContext) + { + if ( isPluginInitialized ) + { + sdk.getTargetingData().setKeywords( keywords ); + keywordsToSet = null; + } + else + { + keywordsToSet = keywords; + } + + callbackContext.success(); + } + + public void setInterests(final List interests, final CallbackContext callbackContext) + { + if ( isPluginInitialized ) + { + sdk.getTargetingData().setInterests( interests ); + interestsToSet = null; + } + else + { + interestsToSet = interests; + } + + callbackContext.success(); + } + // EVENT TRACKING public void trackEvent(final String event, final JSONObject parameters, final CallbackContext callbackContext) throws JSONException @@ -1211,6 +1370,46 @@ private JSONObject getAdInfo(final MaxAd ad) return adInfo; } + private static AppLovinGender integerToALGender(final Integer gender) + { + if ( gender == 1 ) + { + return AppLovinGender.FEMALE; + } + else if ( gender == 2 ) + { + return AppLovinGender.MALE; + } + else if ( gender == 3 ) + { + return AppLovinGender.OTHER; + } + else + { + return AppLovinGender.UNKNOWN; + } + } + + private static AppLovinAdContentRating integerToALAdContentRating(final Integer maximumAdContentRating) + { + if ( maximumAdContentRating == 1 ) + { + return AppLovinAdContentRating.ALL_AUDIENCES; + } + else if ( maximumAdContentRating == 2 ) + { + return AppLovinAdContentRating.EVERYONE_OVER_TWELVE; + } + else if ( maximumAdContentRating == 3 ) + { + return AppLovinAdContentRating.MATURE_AUDIENCES; + } + else + { + return AppLovinAdContentRating.NONE; + } + } + // React Native Bridge private void fireWindowEvent(final String name, final JSONObject params) @@ -1289,6 +1488,55 @@ else if ( "setTestDeviceAdvertisingIds".equalsIgnoreCase( action ) ) setTestDeviceAdvertisingIds( testDeviceAdvertisingIdsList, callbackContext ); } + else if ( "setYearOfBirth".equalsIgnoreCase( action ) ) + { + Integer yearOfBirth = args.getInt( 0 ); + setYearOfBirth( yearOfBirth, callbackContext ); + } + else if ( "setGender".equalsIgnoreCase( action ) ) + { + Integer gender = args.getInt( 0 ); + setGender( gender, callbackContext ); + } + else if ( "setMaximumAdContentRating".equalsIgnoreCase( action ) ) + { + Integer adContentRating = args.getInt( 0 ); + setMaximumAdContentRating( adContentRating, callbackContext ); + } + else if ( "setEmail".equalsIgnoreCase( action ) ) + { + String email = args.getString( 0 ); + setEmail( email, callbackContext ); + } + else if ( "setPhoneNumber".equalsIgnoreCase( action ) ) + { + String phoneNumber = args.getString( 0 ); + setPhoneNumber( phoneNumber, callbackContext ); + } + else if ( "setKeywords".equalsIgnoreCase( action ) ) + { + JSONArray keywords = args.getJSONArray( 0 ); + List keywordsList = new ArrayList<>( keywords.length() ); + + for ( int i = 0; i < keywords.length(); i++ ) + { + keywordsList.add( keywords.getString( 0 ) ); + } + + setKeywords( keywordsList, callbackContext ); + } + else if ( "setInterests".equalsIgnoreCase( action ) ) + { + JSONArray interests = args.getJSONArray( 0 ); + List interestsList = new ArrayList<>( interests.length() ); + + for ( int i = 0; i < interests.length(); i++ ) + { + interestsList.add( interests.getString( 0 ) ); + } + + setInterests( interestsList, callbackContext ); + } else if ( "trackEvent".equalsIgnoreCase( action ) ) { String event = args.getString( 0 ); diff --git a/plugin/src/ios/AppLovinMAX.m b/plugin/src/ios/AppLovinMAX.m index a02d3f2..94e7cb3 100644 --- a/plugin/src/ios/AppLovinMAX.m +++ b/plugin/src/ios/AppLovinMAX.m @@ -40,6 +40,13 @@ @interface AppLovinMAX() @property (nonatomic, copy, nullable) NSString *userIdentifierToSet; @property (nonatomic, strong, nullable) NSArray *testDeviceIdentifiersToSet; @property (nonatomic, strong, nullable) NSNumber *verboseLoggingToSet; +@property (nonatomic, strong, nullable) NSNumber *yearOfBirthToSet; +@property (nonatomic, strong, nullable) NSNumber *genderToSet; +@property (nonatomic, strong, nullable) NSNumber *contentRatingToSet; +@property (nonatomic, strong, nullable) NSString *emailToSet; +@property (nonatomic, strong, nullable) NSString *phoneNumberToSet; +@property (nonatomic, strong, nullable) NSArray *keywordsToSet; +@property (nonatomic, strong, nullable) NSArray *interestsToSet; // Fullscreen Ad Fields @property (nonatomic, strong) NSMutableDictionary *interstitials; @@ -139,7 +146,7 @@ - (void)initialize:(CDVInvokedUrlCommand *)command // Set verbose logging state if needed if ( self.verboseLoggingToSet ) { - self.sdk.settings.isVerboseLogging = self.verboseLoggingToSet.boolValue; + self.sdk.settings.verboseLoggingEnabled = self.verboseLoggingToSet.boolValue; self.verboseLoggingToSet = nil; } @@ -291,7 +298,7 @@ - (void)setVerboseLogging:(CDVInvokedUrlCommand *)command if ( [self isPluginInitialized] ) { - self.sdk.settings.isVerboseLogging = enabled; + self.sdk.settings.verboseLoggingEnabled = enabled; self.verboseLoggingToSet = nil; } else @@ -319,6 +326,125 @@ - (void)setTestDeviceAdvertisingIds:(CDVInvokedUrlCommand *)command [self sendOKPluginResultForCommand: command]; } +- (void)setYearOfBirth:(CDVInvokedUrlCommand *)command +{ + NSNumber *yearOfBirth = [command argumentAtIndex: 0]; + + if ( [self isPluginInitialized] ) + { + self.sdk.targetingData.yearOfBirth = yearOfBirth; + self.yearOfBirthToSet = nil; + } + else + { + self.yearOfBirthToSet = yearOfBirth; + } + + [self sendOKPluginResultForCommand: command]; +} + +- (void)setGender:(CDVInvokedUrlCommand *)command +{ + NSNumber *gender = [command argumentAtIndex: 0]; + + if ( [self isPluginInitialized] ) + { + self.sdk.targetingData.gender = [gender intValue]; + self.genderToSet = nil; + } + else + { + self.genderToSet = gender; + } + + [self sendOKPluginResultForCommand: command]; +} + +- (void)setMaximumAdContentRating:(CDVInvokedUrlCommand *)command +{ + NSNumber *contentRating = [command argumentAtIndex: 0]; + + if ( [self isPluginInitialized] ) + { + self.sdk.targetingData.maximumAdContentRating = [contentRating intValue]; + self.contentRatingToSet = nil; + } + else + { + self.contentRatingToSet = contentRating; + } + + [self sendOKPluginResultForCommand: command]; +} + +- (void)setEmail:(CDVInvokedUrlCommand *)command +{ + NSString *email = [command argumentAtIndex: 0]; + + if ( [self isPluginInitialized] ) + { + self.sdk.targetingData.email = email; + self.emailToSet = nil; + } + else + { + self.emailToSet = email; + } + + [self sendOKPluginResultForCommand: command]; +} + +- (void)setPhoneNumber:(CDVInvokedUrlCommand *)command +{ + NSString *phoneNumber = [command argumentAtIndex: 0]; + + if ( [self isPluginInitialized] ) + { + self.sdk.targetingData.phoneNumber = phoneNumber; + self.phoneNumberToSet = nil; + } + else + { + self.phoneNumberToSet = phoneNumber; + } + + [self sendOKPluginResultForCommand: command]; +} + +- (void)setKeywords:(CDVInvokedUrlCommand *)command +{ + NSArray *keywords = [command argumentAtIndex: 0]; + + if ( [self isPluginInitialized] ) + { + self.sdk.targetingData.keywords = keywords; + self.keywordsToSet = nil; + } + else + { + self.keywordsToSet = keywords; + } + + [self sendOKPluginResultForCommand: command]; +} + +- (void)setInterests:(CDVInvokedUrlCommand *)command +{ + NSArray *interests = [command argumentAtIndex: 0]; + + if ( [self isPluginInitialized] ) + { + self.sdk.targetingData.interests = interests; + self.interestsToSet = nil; + } + else + { + self.interestsToSet = interests; + } + + [self sendOKPluginResultForCommand: command]; +} + #pragma mark - Event Tracking - (void)trackEvent:(CDVInvokedUrlCommand *)command @@ -680,16 +806,6 @@ - (void)didCollapseAd:(MAAd *)ad body: [self adInfoForAd: ad]]; } -- (void)didCompleteRewardedVideoForAd:(MAAd *)ad -{ - // This event is not forwarded -} - -- (void)didStartRewardedVideoForAd:(MAAd *)ad -{ - // This event is not forwarded -} - - (void)didRewardUserForAd:(MAAd *)ad withReward:(MAReward *)reward { MAAdFormat *adFormat = ad.format; diff --git a/plugin/www/applovinmax.js b/plugin/www/applovinmax.js index a5105ef..5ecd22a 100644 --- a/plugin/www/applovinmax.js +++ b/plugin/www/applovinmax.js @@ -1,7 +1,7 @@ var exec = require('cordova/exec'); var cordova = require('cordova'); -const VERSION = '1.0.9'; +const VERSION = '1.0.10'; /** * This enum represents whether or not the consent dialog should be shown for this user. @@ -39,7 +39,21 @@ const AdViewPosition = { BOTTOM_CENTER: 'bottom_center', BOTTOM_RIGHT: 'bottom_right', }; + +const MaximumAdContentRating = { + NONE: 0, + ALL_AUDIENCES: 1, + EVERYONE_OVER_TWELVE: 2, + MATURE_AUDIENCES: 3, +}; +const Gender = { + UNKNOWN: 0, + FEMALE: 1, + MALE: 2, + OTHER: 3, +}; + function isFunction(functionObj) { return typeof functionObj === 'function'; } @@ -53,6 +67,8 @@ var AppLovinMAX = { ConsentDialogState, AdFormat, AdViewPosition, + MaximumAdContentRating, + Gender, // NOTE: We have to store states in JS as workaround for callback-based API // since Cordova does not allow for synchronous returns @@ -146,6 +162,38 @@ var AppLovinMAX = { setTestDeviceAdvertisingIds: function (advertisingIds) { callNative('setTestDeviceAdvertisingIds', [advertisingIds]); }, + + /*----------------*/ + /* Targeting Data */ + /*----------------*/ + + setYearOfBirth: function (yearOfBirth) { + callNative('setYearOfBirth', [yearOfBirth]); + }, + + setGender: function (gender) { + callNative('setGender', [gender]); + }, + + setMaximumAdContentRating: function (maximumAdContentRating) { + callNative('setMaximumAdContentRating', [maximumAdContentRating]); + }, + + setEmail: function (email) { + callNative('setEmail', [email]); + }, + + setPhoneNumber: function (phoneNumber) { + callNative('setPhoneNumber', [phoneNumber]); + }, + + setKeywords: function (keywords) { + callNative('setKeywords', [keywords]); + }, + + setInterests: function (interests) { + callNative('setInterests', [interests]); + }, /*----------------*/ /* EVENT TRACKING */