Implement a custom mediation adapter on iOS
With the open mediation you are now able to implement your own mediation adapter. This page describes how to proceed on iOS.
Overview
The Smart Display SDK cannot use a third party SDK directly.
It must instead call an intermediate component called an adapter that will be responsible of retrieving an ad from the third party SDK. This adapter will then forward the ad to the Smart Display SDK through an adapter delegate.
This page is focused on custom adapter implementation on iOS. For general information about the mediation, check the 'mediation as a primary SDK' section of this documentation.
Custom adapter implementation
Adapter class
Your custom adapter must be a class that implement a SASMediationAdapter protocol. The Smart Display SDK gives you 4 protocols to implement depending on which ad format you want to mediate:
SASMediationBannerAdapter
SASMediationInterstitialAdapter
SASMediationRewardedVideoAdapter
SASMediationNativeAdAdapter
SASMediationBannerAdapter
protocol,
and if you also want to mediate interstitial, create another custom adapter that implements the SASMediationInterstitialAdapter
protocol.
The exact methods that must be implemented depends of the chosen adapter, check the API documentation for exhaustive information.
Please note that all methods MUST be overriden for your adapter to work properly: incomplete adapter implementation can lead to crashes.
Adapter delegate
When implementing an adapter, you will retrieve an adapter delegate from the adapter init:
method. This delegate can be used to forward information about the third party SDK to the Smart Display SDK.
While some of these info are optional, some other delegate methods must be called otherwise the mediation might not work as expected (no ad display, not waterfall, no impression counting, …).
The following sections list the required delegate methods for each adapter type:
Banner adapter delegate
When implementing a banner adapter, you MUST at least call these delegate methods:
mediationBannerAdapter:didLoadBanner:
when the third party banner is loaded successfullymediationBannerAdapter:didFailToLoadWithError:noFill:
when the third party banner did fail to load
Interstitial adapter delegate
When implementing an interstitial adapter, you MUST at least call these delegate methods:
mediationInterstitialAdapterDidLoad:
when the third party interstitial is loaded successfullymediationInterstitialAdapter:didFailToLoadWithError:noFill:
when the third party interstitial did fail to loadmediationInterstitialAdapterDidShow:
when the third party interstitial is displayedmediationInterstitialAdapterDidClose:
when the third party interstitial is dismissed
Rewarded video adapter delegate
When implementing an rewarded video adapter, you MUST at least call these delegate methods:
mediationRewardedVideoAdapterDidLoad:
when the third party rewarded video is loaded successfullymediationRewardedVideoAdapter:didFailToLoadWithError:noFill:
when the third party rewarded video did fail to loadmediationRewardedVideoAdapterDidShow:
when the third party rewarded video is displayedmediationRewardedVideoAdapter:didCollectReward:
when the third party rewarded video has completed or collected a rewardmediationRewardedVideoAdapterDidClose:
when the third party rewarded video is dismissed
Native ad adapter delegate
When implementing an native ad adapter, you MUST at least call these delegate methods:
mediationNativeAdAdapter:didLoadAdInfo:
when the third party native ad is loadedmediationNativeAdAdapter:didFailToLoadWithError:noFill:
when the third party native ad did fail to load
Client parameters
The Smart Display SDK will provide to all adapters a dictionary called clientParameters
for the ad requests. This dictionary contains several useful information that can be used when developing the adapter.
Here are the keys you can expect to find in the clientParameters
dictionary:
Key | Description |
---|---|
Misc Client parameters | |
SASMediationClientParameterLocation |
The current user location, if available |
SASMediationClientParameterAdViewSize |
The current ad view size (only for banners) |
GDPR client parameters | |
SASMediationClientParameterGDPRApplies |
Boolean that states if GDPR applies for this particular app/user |
SASMediationClientParameterGDPRConsent |
Consent string associated with this user if any |
Overridable views (native ads only)
The Smart Display SDK will provide to native ad adapters a dictionary called overridableViews
during ad registering. This dictionary contains references to views that you might want to replace by views provided by the third party SDK.
Here are the keys you can expect to find in the overridableViews
dictionary:
Key | Description |
---|---|
SASMediationOverridableNativeAdMediaView |
The view used to display a video media |
SASMediationOverridableAdChoicesView |
The button used to redirect the user to the privacy policy |
Implementation samples
Smart provides open source adapters for some common third party SDK, you can use them as implementation samples for your own custom adapter.