Skip to content

Commit

Permalink
Release 6.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mobile-ads-github committed Feb 12, 2024
1 parent 5dee12c commit 54e0ce8
Show file tree
Hide file tree
Showing 48 changed files with 1,135 additions and 194 deletions.
22 changes: 14 additions & 8 deletions Examples/ThirdPartyMediationAdapterTemplate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ See [also](https://yandex.ru/support2/mobile-ads/en/dev/ios/quick-start#app).
Copy [YandexAdapters](./ThirdPartyMediationAdapterTemplate/AdapterTemplate/YandexAdapters.swift) file content and change stub API to your actual API.
This way you will get a separate adapter class for each of the ad formats. If your API requires a single class for all formats, you can merge classes.

* Mediation parameters must be set for each request as shown in the [template](./ThirdPartyMediationAdapterTemplate/AdapterTemplate/YandexAdapters.swift#L40):
* Mediation parameters must be set for each request as shown in the [template](./ThirdPartyMediationAdapterTemplate/AdapterTemplate/YandexAdapters.swift#L82):
* `"adapter_network_name"` represents your ad network name in lowercase.
* `"adapter_version"` represents Yandex adapter version. Construct this version by adding one more number to the Yandex SDK version. For example, `6.3.0.0` if the Yandex SDK version is `6.3.0`. If you need to update an adapter without changing the Yandex SDK version, increment the fourth number like `6.3.0.1`.
* `"adapter_network_sdk_version"` represents your ad network SDK version.

* `Interstitial`, `Rewarded`, `AppOpen` formats provide loader classes. A loader object can be [created](./ThirdPartyMediationAdapterTemplate/AdapterTemplate/YandexAdapters.swift#L139) once and can be reused. This speeds up loading and can be helpful to implement preloading logic, if your network supports it.
* `Interstitial`, `Rewarded`, `AppOpen` formats provide loader classes. A loader object can be [created](./ThirdPartyMediationAdapterTemplate/AdapterTemplate/YandexAdapters.swift#L165) once and can be reused. This speeds up loading and can be helpful to implement preloading logic, if your network supports it.

### 4. Test integration

Expand Down Expand Up @@ -74,14 +74,20 @@ See also: [GDPR](https://ads.yandex.com/helpcenter/en/dev/ios/gdpr).

### S2S bidding integration

As shown in the [template](./ThirdPartyMediationAdapterTemplate/AdapterTemplate/YandexAdapters.swift#L25), the bidder token can be obtained as follows:
As shown in the [template](./ThirdPartyMediationAdapterTemplate/AdapterTemplate/YandexAdapters.swift#L42), the bidder token can be obtained as follows:

```swift
private static let bidderTokenLoader = YMABidderTokenLoader()

Self.bidderTokenLoader.loadBidderToken() { token in
completion(token)
let bidderTokenLoader = YMABidderTokenLoader()
bidderTokenLoader.loadBidderToken(requestConfiguration: requestConfiguraton) { token in
completion(token)
}
```

You need to load a bidder token for each new ad request.
You need to load a bidder token for each new ad request. Token request can be created as follows (also shown in [template](./ThirdPartyMediationAdapterTemplate/AdapterTemplate/YandexAdapters.swift#L27)):

```swift
let requestConfiguraton = YMABidderTokenRequestConfiguration(adType: adType)
if adType == .banner {
requestConfiguraton.bannerAdSize = bannerAdSize
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 6.3.0;
CURRENT_PROJECT_VERSION = 6.4.0;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand All @@ -305,7 +305,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MARKETING_VERSION = 6.3.0;
MARKETING_VERSION = 6.4.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -349,7 +349,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 6.3.0;
CURRENT_PROJECT_VERSION = 6.4.0;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand All @@ -364,7 +364,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MARKETING_VERSION = 6.3.0;
MARKETING_VERSION = 6.4.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ struct AdData {
/// This is a mock of the object that represents the scope of parameters for successful adapter configuration and ads request.
/// You can pass these parameters as required by your network API, but they must be passed.
/// - Parameters:
/// - adFormat: Requested ad format. Used if ad network supported in-app bidding integration with Yandex.
/// - adapterVersion: Version of your adapter you are using for Yandex mediation.
/// - adapterSdkVersion: Version of you ad network sdk.
/// - adapterNetworkName: Yor ad network name.
/// - userConsent: User consent parameter. False - by default.
/// - locationTracking: Used for collecting location data if the user allowed the app to track the location. True - by default.
/// - isTesting: Used for extended YandexSDK logging. Extended logging is disabled - by default.
struct AdapterParameters {
let adFormat: MediationAdFormat
let adapterVersion: String
let adapterSdkVersion: String
let adapterNetworkName: String
Expand All @@ -36,7 +38,15 @@ struct AdapterParameters {
let isTesting: Bool?
}

///List of adUnits for checking inegration with Yandex.
/// This is a mock of the object that represents supported ad formats.
enum MediationAdFormat {
case banner(size: CGSize)
case interstitial
case rewarded
case appOpen
}

/// List of adUnits for checking inegration with Yandex.
enum DemoAdUnit: String {
case demoBannerAdUinitId = "demo-banner-yandex"
case demoInterstititalAdUinitId = "demo-interstitital-yandex"
Expand All @@ -55,7 +65,7 @@ protocol MediationInitialization {

/// This protocol describes methods for getting a bidding token in order to use it with in-app bidding integration with Yandex.
protocol MediationBidding {
static func getBiddingToken(completion: @escaping (String?) -> Void)
static func getBiddingToken(parameters: AdapterParameters, completion: @escaping (String?) -> Void)
}

//MARK: - Banner API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,42 @@ private let mockPresentingError = AdapterError(errorDescription: "Ad Display Fai
class YandexBaseAdapter: NSObject, MediationBidding, MediationInitialization {
private static let bidderTokenLoader = YMABidderTokenLoader()

/// Get a bidding token in order to use it with in-app bidding integration with Yandex.
/// This method implements obtaining a bid token in order to use it with in-app bidding integration with Yandex.
/// https://yastatic.net/s3/doc-binary/src/dev/mobile-ads/ru/jazzy/Classes/YMABidderTokenLoader.html
static func getBiddingToken(completion: @escaping (String?) -> Void) {
Self.bidderTokenLoader.loadBidderToken() { token in
completion(token)
static func getBiddingToken(parameters: AdapterParameters, completion: @escaping (String?) -> Void) {

/// Configure all necessary parameters and create YMABidderTokenRequestConfiguration.
let requestConfiguraton: YMABidderTokenRequestConfiguration
switch parameters.adFormat {
case .banner(let size):
requestConfiguraton = YMABidderTokenRequestConfiguration(adType: .banner)
requestConfiguraton.bannerAdSize = YMABannerAdSize.fixedSize(withWidth: size.width, height: size.height)
case .interstitial:
requestConfiguraton = YMABidderTokenRequestConfiguration(adType: .interstitial)
case .rewarded:
requestConfiguraton = YMABidderTokenRequestConfiguration(adType: .rewarded)
case .appOpen:
requestConfiguraton = YMABidderTokenRequestConfiguration(adType: .appOpenAd)
}
}

/// Successfully initializing the Yandex Mobile Ads SDK is an important condition for correctly integrating the library.
/// By default, SDK initialization happens automatically before ads load, but manual initialization will speed up how quickly the first ad loads
/// and therefore increase revenue from monetization.
/// https://yandex.ru/support2/mobile-ads/en/dev/ios/quick-start
static func initializeSDK() {
YMAMobileAds.initializeSDK()
requestConfiguraton.parameters = Self.makeConfigurationParameters(parameters)
Self.setupYandexSDK(with: parameters)
Self.bidderTokenLoader.loadBidderToken(requestConfiguration: requestConfiguraton) { token in
completion(token)
}
}

/// Configure all necessary parameters and create YMAAdRequestConfiguration.
func makeAdRequestConfiguration(with adData: AdData, parameters: AdapterParameters) -> YMAAdRequestConfiguration {
let configParameters = [
/// This method implements creation of general parameters that have to be presented in each request to the Yandex API.
private static func makeConfigurationParameters(_ parameters: AdapterParameters) -> [String: String] {
[
"adapter_network_name": parameters.adapterNetworkName,
"adapter_version": parameters.adapterVersion,
"adapter_network_sdk_version": parameters.adapterSdkVersion
]
let configuration = YMAMutableAdRequestConfiguration(adUnitID: adData.adUinitId)

configuration.parameters = configParameters

if let biddingData = adData.bidId {
configuration.biddingData = biddingData
}
}

/// This method implements setting up YMAMobileAds parameters, which must be current before each request to the Yandex API.
static func setupYandexSDK(with parameters: AdapterParameters) {
if let userConsent = parameters.userConsent {
YMAMobileAds.setUserConsent(userConsent)
}
Expand All @@ -61,6 +66,26 @@ class YandexBaseAdapter: NSObject, MediationBidding, MediationInitialization {
if let isTesting = parameters.isTesting, isTesting {
YMAMobileAds.enableLogging()
}
}

/// Successfully initializing the Yandex Mobile Ads SDK is an important condition for correctly integrating the library.
/// By default, SDK initialization happens automatically before ads load, but manual initialization will speed up how quickly the first ad loads
/// and therefore increase revenue from monetization.
/// https://yandex.ru/support2/mobile-ads/en/dev/ios/quick-start
static func initializeSDK() {
YMAMobileAds.initializeSDK()
}

/// This method implements creation of YMAAdRequestConfiguration with all the necessary parameters.
func makeAdRequestConfiguration(with adData: AdData, parameters: AdapterParameters) -> YMAAdRequestConfiguration {
let configuration = YMAMutableAdRequestConfiguration(adUnitID: adData.adUinitId)
let configParameters = Self.makeConfigurationParameters(parameters)

configuration.parameters = configParameters

if let biddingData = adData.bidId {
configuration.biddingData = biddingData
}

return configuration
}
Expand All @@ -80,7 +105,7 @@ final class YandexBannerAdapter: YandexBaseAdapter, MediationBanner {

/// Creates an object of the YMABannerAdSize class with the specified maximum height and width of the banner.
/// Also you coud use another sizes: https://yastatic.net/s3/doc-binary/src/dev/mobile-ads/ru/jazzy/Classes/YMABannerAdSize.html
let adSize = YMABannerAdSize.inlineSize(withWidth: size.width, maxHeight: size.height)
let adSize = YMABannerAdSize.fixedSize(withWidth: size.width, height: size.height)
let adView = YMAAdView(adUnitID: adData.adUinitId,
adSize: adSize)
let requestConfiguration = makeAdRequestConfiguration(with: adData, parameters: parameters)
Expand All @@ -89,6 +114,7 @@ final class YandexBannerAdapter: YandexBaseAdapter, MediationBanner {
request.parameters = requestConfiguration.parameters

adView.delegate = self
Self.setupYandexSDK(with: parameters)
adView.loadAd(with: request)
}

Expand Down Expand Up @@ -126,7 +152,7 @@ extension YandexBannerAdapter: YMAAdViewDelegate {
delegate?.didFailToLoadAdView(with: error)
}

func adView(_ adView: YMAAdView, didTrackImpressionWith impressionData: YMAImpressionData?) {
func adView(_ adView: YMAAdView, didTrackImpression impressionData: YMAImpressionData?) {
delegate?.didTrackImpression()
}
}
Expand All @@ -148,6 +174,7 @@ final class YandexInterstitialAdapter: YandexBaseAdapter, MediationInterstitial
parameters: AdapterParameters) {
self.delegate = delegate
let configuration = makeAdRequestConfiguration(with: adData, parameters: parameters)
Self.setupYandexSDK(with: parameters)
loader.loadAd(with: configuration)
}

Expand Down Expand Up @@ -223,6 +250,7 @@ final class YandexRewardedAdapter: YandexBaseAdapter, MediationRewarded {
parameters: AdapterParameters) {
self.delegate = delegate
let configuration = makeAdRequestConfiguration(with: adData, parameters: parameters)
Self.setupYandexSDK(with: parameters)
loader.loadAd(with: configuration)
}

Expand Down Expand Up @@ -302,6 +330,7 @@ final class YandexAppOpenAdapter: YandexBaseAdapter, MediationAppOpen {
parameters: AdapterParameters) {
self.delegate = delegate
let configuration = makeAdRequestConfiguration(with: adData, parameters: parameters)
Self.setupYandexSDK(with: parameters)
loader.loadAd(with: configuration)
}

Expand Down
Loading

0 comments on commit 54e0ce8

Please sign in to comment.