Created
July 18, 2022 14:39
-
-
Save JasonSznol/79545c03c4151b2138e1d79b98319690 to your computer and use it in GitHub Desktop.
Dynamic Price
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NimbusGAMDynamicPrice: NimbusRequestManagerDelegate { | |
public func didCompleteNimbusRequest(request: NimbusRequest, ad: NimbusAd) { | |
let mapping: NimbusDynamicPriceMapping | |
if let pubMapping = self.mapping { | |
mapping = pubMapping | |
} else { | |
mapping = ad.isInterstitial ? | |
NimbusGAMLinearPriceMapping.fullscreen() : NimbusGAMLinearPriceMapping.banner() | |
} | |
guard let keywords = mapping.getKeywords(ad: ad) else { | |
Nimbus.shared.logger.log("No keywords to add for GAM", level: .error) | |
requestDelegate?.didCompleteNimbusRequest(request: request, ad: ad) | |
return | |
} | |
Nimbus.shared.logger.log( | |
"Inserting keywords `\(keywords)` for GAM request `\(self.request?.description ?? "Unknown")`", | |
level: .debug | |
) | |
guard let gamRequest = self.request else { return } | |
if gamRequest.customTargeting == nil { gamRequest.customTargeting = [:] } | |
gamRequest.customTargeting?["na_id"] = ad.auctionId | |
if ad.auctionType == .video { | |
gamRequest.customTargeting?["na_bid_video"] = keywords | |
if let duration = ad.duration { | |
gamRequest.customTargeting?["na_duration"] = String(duration) | |
} | |
} else { | |
gamRequest.customTargeting?["na_bid"] = keywords | |
} | |
let extras = GADCustomEventExtras() | |
extras.setExtras(["na_id": ad.auctionId], forLabel: NimbusGAMDynamicPrice.eventLabel) | |
gamRequest.register(extras) | |
NimbusGAMDynamicPrice.auctionIdToAdMap[ad.auctionId] = ad | |
requestDelegate?.didCompleteNimbusRequest(request: request, ad: ad) | |
} | |
public func didFailNimbusRequest(request: NimbusRequest, error: NimbusError) { | |
switch error as? NimbusRequestError { | |
case .noAdFill: | |
Nimbus.shared.logger.log( | |
"No bid for GAM request: `\(self.request?.description ?? "Unknown")`", | |
level: .debug | |
) | |
default: break | |
} | |
requestDelegate?.didFailNimbusRequest(request: request, error: error) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment