You can write a custom adapter if you want to support an ad network that is not listed in the AppLovin MAX mediation matrix. The following instructions show you how to do this.
Implement a subclass of com.applovin.mediation.adapters.MediationAdapterBase.
This subclass enables the interface between your mediation adapter and the AppLovin MAX SDK.
That interface handles functions of your SDK such as initialization, versioning, and resource cleanup.
MediationAdapterBase in the com.applovin.mediation.adapters package of your application.
The name of this class should contain the network name (for example, com.mycompanyname.MyNetworkMediationAdapter).initialize(final MaxAdapterInitializationParameters parameters, final Activity activity, final OnCompletionListener onCompletionListener) method.
Implement code that initializes your ad network SDK.
If you need to access the app ID set in the UI, you can do so via parameters.getServerParameters().getString( "app_id", null );.
This logic executes in parallel with the initialization of the AppLovin SDK.
Call onCompletionListener.onCompletion() after you initialize the ad network, and pass that completion handler one of the following values:
InitializationStatus.INITIALIZINGInitializationStatus.INITIALIZED_SUCCESSInitializationStatus.INITIALIZED_FAILURE (with a relevant error message)InitializationStatus.DOES_NOT_APPLYInitializationStatus.INITIALIZED_UNKNOWNgetSdkVersion() method.
Implement code that returns the network SDK version string from that method.Implement a subclass of ALMediationAdapter.
This subclass enables the interface between your mediation adapter and the AppLovin MAX SDK.
That interface handles functions of your SDK such as initialization, versioning, and resource cleanup.
.m and .h extending from ALMediationAdapter in your project.
The name of this class should contain the network name (for example, MyNetworkMediationAdapter).- (void)initializeWithParameters:(id<MAAdapterInitializationParameters>)parameters completionHandler:(void (^)(MAAdapterInitializationStatus, NSString *_Nullable))completionHandler method
Implement code that initializes your ad network SDK.
You can retrieve the app ID set in the UI from parameters.serverParameters[@"app_id"].
This logic executes in parallel with the initialization of the AppLovin SDK.
Call completionHandler after you initialize the ad network, and pass that handler one of the following values:
MAAdapterInitializationStatusInitializingMAAdapterInitializationStatusInitializedSuccessMAAdapterInitializationStatusInitializedFailure (with a relevant error message)MAAdapterInitializationStatusDoesNotApply (with null as the error message)MAAdapterInitializationStatusInitializedUnknown- (NSString *)SDKVersion method.
Implement code that returns the network SDK version string from that method.You can test your custom adapter by using the MAX Demo App (see SDK integration guides > Platform > Testing networks). To get an ad request, raise the CPM of your placement in the waterfall.
If your custom adapter does not appear in the waterfall as you expect, use the following troubleshooting checklist:
getAdapterVersion()onDestroy() method.
Implement the clean-up logic for the network SDK objects in that method.MaxAdViewAdapter interface in your com.mycompanyname.MyNetworkMediationAdapter class.loadAdViewAd() method which requests an ad.
Call the parameters.getThirdPartyAdPlacementId() method to get the placement ID you need for your ad logic.MaxAdViewAdapterListener methods.
They notify the AppLovin MAX SDK about banner lifecycle events:
MaxAdViewAdapterListener.onAdViewAdLoaded().MaxAdViewAdapterListener.onAdViewAdLoadFailed() with an appropriate MaxAdapterError.onAdViewAdClicked(), onAdViewAdCollapsed(), onAdViewAdDisplayed(), onAdViewAdDisplayFailed(), onAdViewAdExpanded(), onAdViewAdHidden().MaxInterstitialAdapter interface in your com.mycompanyname.MyNetworkMediationAdapter class.loadInterstitialAd() method which requests an ad.
Call the parameters.getThirdPartyAdPlacementId() method to get the placement ID you need for your ad logic.showInterstitialAd() method which shows the loaded ad.
Call the parameters.getThirdPartyAdPlacementId() method to get the placement ID you need for your ad logic.
If the ad is not ready, call MaxInterstitialAdapterListener.onInterstitialAdDisplayFailed( MaxAdapterError.AD_NOT_READY ).MaxInterstitialAdapterListener methods.
They notify the AppLovin MAX SDK about interstitial lifecycle events:
MaxInterstitialAdapterListener.onInterstitialAdLoaded().MaxInterstitialAdapterListener.onInterstitialAdLoadFailed() with an appropriate MaxAdapterError.MaxInterstitialAdapterListener.onInterstitialAdHidden().onInterstitialAdClicked(), onInterstitialAdDisplayFailed().MaxRewardedAdapter interface in your com.mycompanyname.MyNetworkMediationAdapter class.loadRewardedAd() method which requests an ad.
Call the parameters.getThirdPartyAdPlacementId() method to get the placement ID you need for your ad logic.showRewardedAd() method which shows the loaded ad.
Call the parameters.getThirdPartyAdPlacementId() method to get the placement ID you need for your ad logic.
If the ad is not ready, call MaxRewardedAdapterListener.onRewardedAdDisplayFailed( MaxAdapterError.AD_NOT_READY ).MaxRewardedAdapterListener methods.
They notify the AppLovin MAX SDK about rewarded video lifecycle events:
MaxRewardedAdapterListener.onRewardedAdLoaded().MaxRewardedAdapterListener.onRewardedAdLoadFailed() with an appropriate MaxAdapterError.MaxRewardedAdapterListener.onRewardedAdDisplayed().MaxRewardedAdapterListener.onUserRewarded() with an appropriate MaxReward amount and currency.
If no amount is available, default to MaxReward.DEFAULT_AMOUNT.
AppLovin recommends that you call this immediately before MaxRewardedAdapterListener.onRewardedAdHidden().MaxRewardedAdapterListener.onRewardedAdHidden().onRewardedAdClicked().MaxNativeAdAdapter interface in your com.mycompanyname.MyNetworkMediationAdapter class.loadNativeAd() method which requests an ad.MaxNativeAdAdapterListener methods.
They notify the AppLovin MAX SDK about native ad lifecycle events:
MaxNativeAdAdapterListener.onNativeAdLoaded().MaxNativeAdAdapterListener.onNativeAdLoadFailed() with an appropriate MaxAdapterError.MaxNativeAdAdapterListener.onNativeAdDisplayed().MaxNativeAdAdapterListener.onNativeAdClicked().MAX offers two boolean flags that indicate whether the user provides privacy consent.
They are Boolean objects.
Their value is null if the user has indicated neither consent or no consent.
MAX passes the parameters object into each method.
To get the value of the privacy flags, use the following methods of the parameters object:
MaxAdapterParameters.hasUserConsent()
: for the GDPR consent flag.
To determine if GDPR applies to the user, read the SDK integration guides > Platform > Overview > Privacy page of this documentation.
MaxAdapterParameters.isDoNotSell()
: for the multi-state targeted advertising consent flag.
AppLovin does not have an API that indicates whether the user belongs in a region to which this applies.
- (NSString *)adapterVersion method.
Implement code that returns the version number of the mediation adapter from that method.
All AppLovin’s adapters use a five-number versioning scheme:
The leftmost four numbers correspond to the network SDK version.
The last number denotes the minor version number, which refers to the adapter release.- (void)destroy method.
Implement clean-up logic for the network SDK objects in that method.MAAdViewAdapter protocol in your MyNetworkMediationAdapter class.- (void)loadAdViewAdForParameters:(id<MAAdapterResponseParameters>)parameters adFormat:(MAAdFormat *)adFormat andNotify:(id<MAAdViewAdapterDelegate>)delegate method which requests an ad.
Call the parameters.thirdPartyAdPlacementIdentifier method to get the Placement ID you need for your ad logic.MAAdViewAdapterDelegate methods.
They notify the AppLovin MAX SDK about banner lifecycle events:
-[MAAdViewAdapterDelegate didLoadAdForAdView].-[MAAdViewAdapterDelegate didFailToLoadAdViewAdWithError:] with an appropriate MAAdapterError.didClickAdViewAd, didCollapseAdViewAd, didDisplayAdViewAd, didExpandAdViewAd, didFailToDisplayAdViewAdWithError, didHideAdViewAd.MAInterstitialAdapter protocol in your MyNetworkMediationAdapter class.- (void)loadInterstitialAdForParameters:(id<MAAdapterResponseParameters>)parameters andNotify:(id<MAInterstitialAdapterDelegate>)delegate method which requests an ad.
Call the parameters.thirdPartyAdPlacementIdentifier method to get the placement ID you need for your ad logic.- (void)showInterstitialAdForParameters:(id<MAAdapterResponseParameters>)parameters andNotify:(id<MAInterstitialAdapterDelegate>)delegate method which shows the loaded ad.
Call the parameters.thirdPartyAdPlacementIdentifier method to get the placement ID you need for your ad logic.
If the ad is not ready, call -[MAInterstitialAdapterDelegate didFailToDisplayInterstitialAdWithError: MAAdapterError.adNotReady].MAInterstitialAdapterDelegate methods.
They notify the AppLovin MAX SDK about interstitial lifecycle events:
-[MAInterstitialAdapterDelegate didLoadInterstitialAd:].-[MAInterstitialAdapterDelegate didFailToLoadInterstitialAdWithError:] with an appropriate MAAdapterError.-[MAInterstitialAdapterDelegate didDisplayInterstitialAd].-[MAInterstitialAdapterDelegate didHideInterstitialAd:].didClickInterstitialAd, didFailToDisplayInterstitialAdWithError.MARewardedAdapter protocol in your MyNetworkMediationAdapter class.- (void)loadRewardedAdForParameters:(id<MAAdapterResponseParameters>)parameters andNotify:(id<MARewardedAdapterDelegate>)delegate; method which requests an ad.
Call the parameters.thirdPartyAdPlacementIdentifier method to get the placement ID you need for your ad logic.- (void)showRewardedAdForParameters:(id<MAAdapterResponseParameters>)parameters andNotify:(id<MARewardedAdapterDelegate>)delegate; method which shows the loaded ad.
Call the parameters.thirdPartyAdPlacementIdentifier method to get the placement ID you need for your ad logic.
If the ad is not ready, call -[MARewardedAdapterDelegate didFailToDisplayRewardedAdWithError: MAAdapterError.adNotReady].MARewardedAdapterDelegate methods.
They notify the AppLovin MAX SDK about rewarded video lifecycle events:
-[MARewardedAdapterDelegate didLoadRewardedAd:].-[MARewardedAdapterDelegate didFailToLoadRewardedAdWithError:] with an appropriate MAAdapterError.-[MARewardedAdapterDelegate didDisplayRewardedAd:].-[MARewardedAdapterDelegate didRewardUserWithReward:] with an appropriate MAReward amount and currency.
If no amount is available, default to MAReward.defaultAmount.
AppLovin recommends that you call this immediately before -[MARewardedAdapterDelegate didHideRewardedAd:].-[MARewardedAdapterDelegate didHideRewardedAd:].didClickRewardedAd.MANativeAdAdapter protocol in your MyNetworkMediationAdapter class.- (void)loadNativeAdForParameters:(id<MAAdapterResponseParameters>)parameters andNotify:(id<MANativeAdAdapterDelegate>)delegate; method which requests an ad.MANativeAdAdapterDelegate methods.
They notify the AppLovin MAX SDK about native ad lifecycle events:
-[MANativeAdAdapterDelegate didLoadAdForNativeAd:].-[MANativeAdAdapterDelegate didFailToLoadNativeAdWithError:] with an appropriate MAAdapterError.-[MANativeAdAdapterDelegate didDisplayNativeAdWithExtraInfo:].-[MANativeAdAdapterDelegate didClickNativeAd:].MAX offers two boolean flags that indicate whether the user provides privacy consent.
They are NSNumber objects.
Their value is nil if the user has indicated neither consent or no consent.
MAX passes the parameters object into each method.
To get the value of the privacy flags, use the following APIs of the parameters object:
-[MAAdapterParameters hasUserConsent]
: for the GDPR consent flag.
To determine if GDPR applies to the user, read the SDK integration guides > Platform > Overview > Privacy page of this documentation.
-[MAAdapterParameters isDoNotSell]
: for the multi-state targeted advertising consent flag.
AppLovin does not have an API that indicates whether the user belongs in a region to which this applies.