Skip to content

Commit

Permalink
Update GMA SDK In PrebidMobileAdMobAdapters and PrebidMobileGAMEventH…
Browse files Browse the repository at this point in the history
…andlers (#696)

* fix: fix available issue

* feat: implement new gam banner mediation api

* fix: fix size for Banner 320x50 (GAM) [Vanilla Prebid Order]

* feat: sort files in PrebidMobile project

* fix: fix building PrebidDemoSwift

* fix: fix building PrebidDemoObjectiveC

* feat: implement new gam sdk interstitial mediation api

* feat: implement new gam rewarded and video interstitial mediation api

* feat: implement new native mediation api

* fix: remove check locationServicesEnabled that causes ui unresponsiveness

* refactor: clean

* fix: update to some recommended settings

* feat: remove hard dependancy on version in AdMod pod spec

* refactor: clear

* feat: add GMA SDK version tests & update Podfile

* feat: update Podfile

* fix: fix building of demo apps

* fix: revert team settings in InternalTestApp

* fix: revert bundle id settings in InternalTestApp

* feat: update AdMob tests
  • Loading branch information
OlenaPostindustria authored Oct 31, 2022
1 parent f85eacd commit a91434f
Show file tree
Hide file tree
Showing 49 changed files with 612 additions and 653 deletions.
76 changes: 26 additions & 50 deletions EventHandlers/EventHandlers.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,31 @@ import Foundation

enum AdMobAdaptersError {
case emptyCustomEventExtras
case noTargetingInfoInEventExtras
case noBidInEventExtras
case noConfigIDInEventExtras
case noServerParameter
case wrongServerParameter
case emptyUserKeywords
case noAd
case adNotValid
case adExpired
}

extension AdMobAdaptersError: LocalizedError {
public var errorDescription: String? {
switch self {

case .emptyCustomEventExtras : return "The custom event extras is empty"
case .noTargetingInfoInEventExtras : return "The targeting info dictionary is absent in the extras"
case .noBidInEventExtras : return "The Bid object is absent in the extras"
case .noConfigIDInEventExtras : return "The Config ID is absent in the extras"
case .noServerParameter : return "Server parameter is absent in request"
case .wrongServerParameter : return "User keywords don't contain server parameter"
case .emptyUserKeywords : return "User keywords are empty"
case .noAd : return "No ad available"
case .adNotValid : return "Ad is not valid"
case .adExpired : return "Ad expired"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,33 @@ public class AdMobMediationBannerUtils: NSObject, PrebidMediationDelegate {

public let bannerView: GADBannerView

private var eventExtras: [AnyHashable: Any]?

public init(gadRequest: GADRequest, bannerView: GADBannerView) {
self.gadRequest = gadRequest
self.bannerView = bannerView
super.init()
}

public func setUpAdObject(with values: [String: Any]) -> Bool {
eventExtras = values.isEmpty ? nil : values
let extras = GADCustomEventExtras()
extras.setExtras(values, forLabel: AdMobConstants.PrebidAdMobEventExtrasLabel)
gadRequest.register(extras)
gadRequest.keywords = AdMobUtils.buildKeywords(existingKeywords: gadRequest.keywords,
targetingInfo: values[PBMMediationTargetingInfoKey] as? [String: String])

return true
}

public func cleanUpAdObject() {
guard let gadKeywords = gadRequest.keywords as? [String] else {
return
if let gadKeywords = gadRequest.keywords {
gadRequest.keywords = AdMobUtils.removeHBKeywordsFrom(gadKeywords)
}
gadRequest.keywords = AdMobUtils.removeHBKeywordsFrom(gadKeywords)
eventExtras = nil

let extras = GADCustomEventExtras()
extras.setExtras(nil, forLabel: AdMobConstants.PrebidAdMobEventExtrasLabel)
gadRequest.register(extras)
}

public func getAdView() -> UIView? {
return bannerView
}

public func getEventExtras() -> [AnyHashable: Any]? {
return eventExtras
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,31 @@ public class AdMobMediationInterstitialUtils: NSObject, PrebidMediationDelegate

public let gadRequest: GADRequest

private var eventExtras: [AnyHashable: Any]?

public init(gadRequest: GADRequest) {
self.gadRequest = gadRequest
super.init()
}

public func setUpAdObject(with values: [String: Any]) -> Bool {
eventExtras = values.isEmpty ? nil : values
let extras = GADCustomEventExtras()
extras.setExtras(values, forLabel: AdMobConstants.PrebidAdMobEventExtrasLabel)
gadRequest.register(extras)
gadRequest.keywords = AdMobUtils.buildKeywords(existingKeywords: gadRequest.keywords,
targetingInfo: values[PBMMediationTargetingInfoKey] as? [String: String])

return true
}

public func cleanUpAdObject() {
guard let gadKeywords = gadRequest.keywords as? [String] else {
return
if let gadKeywords = gadRequest.keywords {
gadRequest.keywords = AdMobUtils.removeHBKeywordsFrom(gadKeywords)
}
gadRequest.keywords = AdMobUtils.removeHBKeywordsFrom(gadKeywords)
eventExtras = nil

let extras = GADCustomEventExtras()
extras.setExtras(nil, forLabel: AdMobConstants.PrebidAdMobEventExtrasLabel)
gadRequest.register(extras)
}

public func getAdView() -> UIView? {
return nil
}

public func getEventExtras() -> [AnyHashable: Any]? {
return eventExtras
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,32 @@ public class AdMobMediationNativeUtils: NSObject, PrebidMediationDelegate {

public let gadRequest: GADRequest

private var eventExtras: [AnyHashable: Any]?

public init(gadRequest: GADRequest) {
self.gadRequest = gadRequest
super.init()
}

public func setUpAdObject(with values: [String: Any]) -> Bool {
eventExtras = values.isEmpty ? nil : values
let extras = GADCustomEventExtras()
extras.setExtras(values, forLabel: AdMobConstants.PrebidAdMobEventExtrasLabel)
gadRequest.register(extras)
gadRequest.keywords = AdMobUtils.buildKeywords(existingKeywords: gadRequest.keywords,
targetingInfo: values[PBMMediationTargetingInfoKey] as? [String: String])

return true
}

public func cleanUpAdObject() {
guard let gadKeywords = gadRequest.keywords as? [String] else {
return
if let gadKeywords = gadRequest.keywords {
gadRequest.keywords = AdMobUtils.removeHBKeywordsFrom(gadKeywords)
}
gadRequest.keywords = AdMobUtils.removeHBKeywordsFrom(gadKeywords)
eventExtras = nil

let extras = GADCustomEventExtras()
extras.setExtras(nil, forLabel: AdMobConstants.PrebidAdMobEventExtrasLabel)
gadRequest.register(extras)
}

public func getAdView() -> UIView? {
return nil
}

public func getEventExtras() -> [AnyHashable: Any]? {
return eventExtras
}

public static func findNative(_ extras: [AnyHashable : Any],
completion: @escaping (Result<PrebidMediatedUnifiedNativeAd, Error>) -> Void) {

switch MediationNativeUtils.findNative(in: extras) {
case .success(let nativeAd):
let admobUnifiedAd = PrebidMediatedUnifiedNativeAd(nativeAd: nativeAd)
completion(.success(admobUnifiedAd))
case .failure(let error):
completion(.failure(error))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,31 @@ public class AdMobMediationRewardedUtils: NSObject, PrebidMediationDelegate {

public let gadRequest: GADRequest

private var eventExtras: [AnyHashable: Any]?

public init(gadRequest: GADRequest) {
self.gadRequest = gadRequest
super.init()
}

public func setUpAdObject(with values: [String: Any]) -> Bool {
eventExtras = values.isEmpty ? nil : values
let extras = GADCustomEventExtras()
extras.setExtras(values, forLabel: AdMobConstants.PrebidAdMobEventExtrasLabel)
gadRequest.register(extras)
gadRequest.keywords = AdMobUtils.buildKeywords(existingKeywords: gadRequest.keywords,
targetingInfo: values[PBMMediationTargetingInfoKey] as? [String: String])
gadRequest.register(PrebidAdMobEventExtras(additionalParameters: eventExtras ?? [:]))

return true
}

public func cleanUpAdObject() {
guard let gadKeywords = gadRequest.keywords as? [String] else {
return
if let gadKeywords = gadRequest.keywords {
gadRequest.keywords = AdMobUtils.removeHBKeywordsFrom(gadKeywords)
}
gadRequest.keywords = AdMobUtils.removeHBKeywordsFrom(gadKeywords)
gadRequest.removeAdNetworkExtras(for: PrebidAdMobEventExtras.self)
eventExtras = nil

let extras = GADCustomEventExtras()
extras.setExtras(nil, forLabel: AdMobConstants.PrebidAdMobEventExtrasLabel)
gadRequest.register(extras)
}

public func getAdView() -> UIView? {
return nil
}

public func getEventExtras() -> [AnyHashable: Any]? {
return eventExtras
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class AdMobUtils: NSObject {
.filter { !$0.hasPrefix(HBKeywordPrefix) }
}

static func buildKeywords(existingKeywords: [Any]?, targetingInfo: [String: String]?) -> [Any]? {
static func buildKeywords(existingKeywords: [String]?, targetingInfo: [String: String]?) -> [String]? {
guard let targetingInfo = targetingInfo else {
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,56 +19,64 @@ import GoogleMobileAds

@objc(PrebidAdMobBannerAdapter)
public class PrebidAdMobBannerAdapter:
NSObject,
GADCustomEventBanner,
PrebidAdMobMediationBaseAdapter,
GADMediationBannerAd,
DisplayViewLoadingDelegate,
DisplayViewInteractionDelegate {

public weak var delegate: GADCustomEventBannerDelegate?
public var view: UIView {
return displayView ?? UIView()
}

public var displayView: PBMDisplayView?
var displayView: PBMDisplayView?

required public override init() {
super.init()
}
weak var delegate: GADMediationBannerAdEventDelegate?
var adConfiguration: GADMediationBannerAdConfiguration?
var completionHandler: GADMediationBannerLoadCompletionHandler?

public func requestAd(_ adSize: GADAdSize, parameter serverParameter: String?, label serverLabel: String?, request: GADCustomEventRequest) {
guard let keywords = request.userKeywords as? [String] else {
let error = AdMobAdaptersError.emptyUserKeywords
delegate?.customEventBanner(self, didFailAd: error)
public func loadBanner(for adConfiguration: GADMediationBannerAdConfiguration,
completionHandler: @escaping GADMediationBannerLoadCompletionHandler) {
self.adConfiguration = adConfiguration
self.completionHandler = completionHandler

guard let serverParameter = adConfiguration.credentials.settings["parameter"] as? String else {
let error = AdMobAdaptersError.noServerParameter
delegate = completionHandler(nil, error)
return
}

guard let serverParameter = serverParameter else {
let error = AdMobAdaptersError.noServerParameter
delegate?.customEventBanner(self, didFailAd: error)
guard let eventExtras = adConfiguration.extras as? GADCustomEventExtras,
let eventExtrasDictionary = eventExtras.extras(forLabel: AdMobConstants.PrebidAdMobEventExtrasLabel),
!eventExtrasDictionary.isEmpty else {
let error = AdMobAdaptersError.emptyCustomEventExtras
delegate = completionHandler(nil, error)
return
}

guard MediationUtils.isServerParameterInTargetingInfo(serverParameter, keywords) else {
let error = AdMobAdaptersError.wrongServerParameter
delegate?.customEventBanner(self, didFailAd: error)
guard let targetingInfo = eventExtrasDictionary[PBMMediationTargetingInfoKey] as? [String: String] else {
let error = AdMobAdaptersError.noTargetingInfoInEventExtras
delegate = completionHandler(nil, error)
return
}

guard let eventExtras = request.additionalParameters, !eventExtras.isEmpty else {
let error = AdMobAdaptersError.emptyCustomEventExtras
delegate?.customEventBanner(self, didFailAd: error)
guard MediationUtils.isServerParameterInTargetingInfoDict(serverParameter, targetingInfo) else {
let error = AdMobAdaptersError.wrongServerParameter
delegate = completionHandler(nil, error)
return
}

guard let bid = eventExtras[PBMMediationAdUnitBidKey] as? Bid else {
guard let bid = eventExtrasDictionary[PBMMediationAdUnitBidKey] as? Bid else {
let error = AdMobAdaptersError.noBidInEventExtras
delegate?.customEventBanner(self, didFailAd: error)
delegate = completionHandler(nil, error)
return
}

guard let configId = eventExtras[PBMMediationConfigIdKey] as? String else {
guard let configId = eventExtrasDictionary[PBMMediationConfigIdKey] as? String else {
let error = AdMobAdaptersError.noConfigIDInEventExtras
delegate?.customEventBanner(self, didFailAd: error)
delegate = completionHandler(nil, error)
return
}

let frame = CGRect(origin: .zero, size: bid.size)

displayView = PBMDisplayView(frame: frame, bid: bid, configId: configId)
Expand All @@ -81,36 +89,37 @@ public class PrebidAdMobBannerAdapter:
// MARK: - DisplayViewLoadingDelegate

public func displayViewDidLoadAd(_ displayView: PBMDisplayView) {
delegate?.customEventBanner(self, didReceiveAd: displayView)
if let handler = completionHandler {
delegate = handler(self, nil)
}
}


public func displayView(_ displayView: PBMDisplayView, didFailWithError error: Error) {
delegate?.customEventBanner(self, didFailAd: error)
if let handler = completionHandler {
delegate = handler(nil, error)
}
}

// MARK: - PBMDisplayViewInteractionDelegate

public func trackImpression(forDisplayView: PBMDisplayView) {
//Impressions will be tracked automatically
//unless enableAutomaticImpressionAndClickTracking = NO
delegate?.reportImpression()
}

public func viewControllerForModalPresentation(fromDisplayView: PBMDisplayView) -> UIViewController? {
return delegate?.viewControllerForPresentingModalView
return adConfiguration?.topViewController ?? UIApplication.shared.windows.first?.rootViewController
}

public func didLeaveApp(from displayView: PBMDisplayView) {
delegate?.customEventBannerWillLeaveApplication(self)
delegate?.reportClick()
}

public func willPresentModal(from displayView: PBMDisplayView) {
delegate?.customEventBannerWillPresentModal(self)
delegate?.customEventBannerWasClicked(self)
delegate?.willPresentFullScreenView()
}

public func didDismissModal(from displayView: PBMDisplayView) {
delegate?.customEventBannerWillDismissModal(self)
delegate?.customEventBannerDidDismissModal(self)
delegate?.willDismissFullScreenView()
delegate?.didDismissFullScreenView()
}
}

This file was deleted.

Loading

0 comments on commit a91434f

Please sign in to comment.