Skip to content

Commit

Permalink
First party data fixes (#547)
Browse files Browse the repository at this point in the history
* fix: fix app.content & user.data process argument parsing

* fix: fix parameter

* fix(original api): revert changes to user.ext.data & app.ext.data

* fix(original api): fix naming

* fix(rendering): revert changes to user.ext.data & app.ext.data & fix naming

* fix: fix user.ext.data

* fix(rendering): fix argument parsing

* chore: edit Internal Test App scheme

* fix(rendering): fix test
  • Loading branch information
OlenaPostindustria authored Feb 23, 2022
1 parent a031255 commit abb74a7
Show file tree
Hide file tree
Showing 40 changed files with 550 additions and 495 deletions.
7 changes: 4 additions & 3 deletions Example/PrebidDemo/PrebidDemoObjectiveC/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,17 @@ -(void) enableCOPPA {
-(void) addFirstPartyData:(AdUnit *)adUnit {
//Access Control List
[Targeting.shared addBidderToAccessControlList: Prebid.bidderNameAppNexus];

[Targeting.shared addUserDataWithKey:@"globalUserDataKey1" value:@"globalUserDataValue1"];
[Targeting.shared addContextDataWithKey:@"globalContextDataKey1" value:@"globalContextDataValue1"];
//global user data
PBAdUnitContentDataObject *userData = [PBAdUnitContentDataObject new];
userData.id = @"globalUserDataValue1";
[adUnit addUserDataObjects:@[userData]];
[adUnit addUserData:@[userData]];

//global context data
PBAdUnitContentDataObject *appData = [PBAdUnitContentDataObject new];
appData.id = @"globalContextDataValue1";
[adUnit addAppContentDataObjects:@[appData]];
[adUnit addAppContentData:@[appData]];

//adunit context data
[adUnit addContextDataWithKey:@"adunitContextDataKey1" value:@"adunitContextDataValue1"];
Expand Down
7 changes: 4 additions & 3 deletions Example/PrebidDemo/PrebidDemoSwift/BannerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ class BannerController:
gamBanner.delegate = self

appBannerView.addSubview(gamBanner)

prebidAdUnit.fetchDemand(adObject: self.gamRequest) { [weak self] (resultCode: ResultCode) in
print("Prebid demand fetch for AdManager \(resultCode.name())")
self?.gamBanner.load(self?.gamRequest)
Expand Down Expand Up @@ -452,16 +451,18 @@ class BannerController:
func addFirstPartyData(adUnit: AdUnit) {
//Access Control List
Targeting.shared.addBidderToAccessControlList(Prebid.bidderNameAppNexus)
Targeting.shared.addContextData(key: "globalContextDataKey1", value: "globalContextDataValue1")
Targeting.shared.addUserData(key: "globalUserDataKey1", value: "globalUserDataValue1")

//global context data
let userData = ContentDataObject()
userData.id = "globalUserDataValue1"
adUnit.addUserDataObjects([userData])
adUnit.addUserData([userData])

//adunit context data
let appData = ContentDataObject()
appData.id = "adunitContextDataValue1"
adUnit.addAppContentDataObjects([appData])
adUnit.addAppContentData([appData])

//global context keywords
Targeting.shared.addContextKeyword("globalContextKeywordValue1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,19 @@
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "ADD_USER_DATA alpha beta ADD_USER_DATA gamma delta ADD_USER_DATA gamma epsilon"
argument = "ADD_USER_EXT_DATA bravo charlie ADD_USER_EXT_DATA bravo tango ADD_USER_EXT_DATA mango sushi"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "ADD_APP_CONTEXT bravo charlie ADD_APP_CONTEXT bravo tango ADD_APP_CONTEXT mango sushi"
argument = "ADD_APP_EXT bravo charlie ADD_APP_EXT bravo tango ADD_APP_EXT mango sushi"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "ADD_USER_DATA_EXT bravo charlie ADD_USER_DATA_EXT bravo tango ADD_USER_DATA_EXT mango sushi"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "ADD_APP_CONTENT_DATA_EXT bravo charlie ADD_APP_CONTENT_DATA_EXT bravo tango ADD_APP_CONTENT_DATA_EXT mango sushi"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
Expand Down
18 changes: 18 additions & 0 deletions InternalTestApp/PrebidMobileDemoRendering/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
appConfig.adUnitContext = (appConfig.adUnitContext ?? []) + [(key: params[0], value: params[1])]
}

processArgumentsParser.addOption("ADD_USER_EXT_DATA", paramsCount: 2) { params in
PrebidRenderingTargeting.shared.addUserData(params[1], forKey: params[0])
}

processArgumentsParser.addOption("ADD_APP_EXT", paramsCount: 2) { params in
PrebidRenderingTargeting.shared.addContextData(params[1], forKey: params[0])
}

processArgumentsParser.addOption("ADD_USER_DATA_EXT", paramsCount: 2) { params in
let appConfig = AppConfiguration.shared
appConfig.userData = (appConfig.userData ?? []) + [(key: params[0], value: params[1])]
}

processArgumentsParser.addOption("ADD_APP_CONTENT_DATA_EXT", paramsCount: 2) { params in
let appConfig = AppConfiguration.shared
appConfig.appContentData = (appConfig.appContentData ?? []) + [(key: params[0], value: params[1])]
}

processArgumentsParser.parseProcessArguments(ProcessInfo.processInfo.arguments)

// MoPub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ final class AppConfiguration: NSObject {
var adPosition: AdPosition?
var videoPlacementType: VideoPlacementType?
var adUnitContext: [(key: String, value: String)]?
var userData: [(key: String, value: String)]?
var appContentData: [(key: String, value: String)]?
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class PrebidAdMobBannerViewController:
stopRefreshButton.addTarget(self, action: #selector(stopRefresh), for: .touchUpInside)

setupAdapterController()
setProccesArgumentParser()
}

func configurationController() -> BaseConfigurationController? {
Expand Down Expand Up @@ -112,6 +111,22 @@ class PrebidAdMobBannerViewController:
}
}

if let userData = AppConfiguration.shared.userData {
for dataPair in userData {
let appData = PBMORTBContentData()
appData.ext = [dataPair.key: dataPair.value]
adUnit?.addUserData([appData])
}
}

if let appData = AppConfiguration.shared.appContentData {
for dataPair in appData {
let appData = PBMORTBContentData()
appData.ext = [dataPair.key: dataPair.value]
adUnit?.addAppContentData([appData])
}
}

adUnit?.fetchDemand { [weak self] result in
guard let self = self,
let adBannerView = self.adBannerView,
Expand Down Expand Up @@ -247,20 +262,4 @@ class PrebidAdMobBannerViewController:
stopRefreshButton.isEnabled = false
adUnit?.stopRefresh()
}

private func setProccesArgumentParser() {
let processArgumentsParser = ProcessArgumentsParser()
processArgumentsParser.addOption("ADD_USER_DATA", paramsCount: 2) { [weak self] params in
let userData = PBMORTBContentData()
userData.ext = [params[0]: params[1]]
self?.adUnit?.addUserData([userData])
}

processArgumentsParser.addOption("ADD_APP_CONTEXT", paramsCount: 2) { [weak self] params in
let appData = PBMORTBContentData()
appData.ext = [params[0]: params[1]]
self?.adUnit?.addAppContentData([appData])
}
processArgumentsParser.parseProcessArguments(ProcessInfo.processInfo.arguments)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class PrebidAdMobInterstitialViewController: NSObject, AdaptedController, Prebid
super.init()

setupAdapterController()
setProccesArgumentParser()
}

func configurationController() -> BaseConfigurationController? {
Expand All @@ -76,6 +75,22 @@ class PrebidAdMobInterstitialViewController: NSObject, AdaptedController, Prebid
}
}

if let userData = AppConfiguration.shared.userData {
for dataPair in userData {
let appData = PBMORTBContentData()
appData.ext = [dataPair.key: dataPair.value]
adUnit?.addUserData([appData])
}
}

if let appData = AppConfiguration.shared.appContentData {
for dataPair in appData {
let appData = PBMORTBContentData()
appData.ext = [dataPair.key: dataPair.value]
adUnit?.addAppContentData([appData])
}
}

adUnit?.fetchDemand { [weak self] result in
guard let self = self else { return }
let extras = GADCustomEventExtras()
Expand Down Expand Up @@ -165,20 +180,4 @@ class PrebidAdMobInterstitialViewController: NSObject, AdaptedController, Prebid
interstitial?.present(fromRootViewController: adapterViewController)
}
}

private func setProccesArgumentParser() {
let processArgumentsParser = ProcessArgumentsParser()
processArgumentsParser.addOption("ADD_USER_DATA", paramsCount: 2) { [weak self] params in
let userData = PBMORTBContentData()
userData.ext = [params[0]: params[1]]
self?.adUnit?.addUserData([userData])
}

processArgumentsParser.addOption("ADD_APP_CONTEXT", paramsCount: 2) { [weak self] params in
let appData = PBMORTBContentData()
appData.ext = [params[0]: params[1]]
self?.adUnit?.addAppContentData([appData])
}
processArgumentsParser.parseProcessArguments(ProcessInfo.processInfo.arguments)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,27 @@ class PrebidAdMobNativeViewController: NSObject, AdaptedController, GADNativeAdL
super.init()
self.rootController = rootController
setupActions(rootController: rootController)
setProccesArgumentParser()
}

func loadAd() {
setUpBannerArea(rootController: rootController!)
setupMediationNativeAdUnit()
if let userData = AppConfiguration.shared.userData {
for dataPair in userData {
let appData = ContentDataObject()
appData.ext = [dataPair.key: dataPair.value]
nativeAdUnit?.addUserData([appData])
}
}

if let appData = AppConfiguration.shared.appContentData {
for dataPair in appData {
let appData = ContentDataObject()
appData.ext = [dataPair.key: dataPair.value]
nativeAdUnit?.addAppContentData([appData])
}
}

nativeAdUnit.fetchDemand { [weak self] result in
guard let self = self else { return }
let extras = GADCustomEventExtras()
Expand Down Expand Up @@ -167,20 +182,4 @@ class PrebidAdMobNativeViewController: NSObject, AdaptedController, GADNativeAdL
PBMLog.message("GAD ad loader did finished loading.")
adLoaderDidFinishLoadingButton.isEnabled = true
}

private func setProccesArgumentParser() {
let processArgumentsParser = ProcessArgumentsParser()
processArgumentsParser.addOption("ADD_USER_DATA", paramsCount: 2) { [weak self] params in
let userData = ContentDataObject()
userData.ext = [params[0]: params[1]]
self?.nativeAdUnit?.addUserData([userData])
}

processArgumentsParser.addOption("ADD_APP_CONTEXT", paramsCount: 2) { [weak self] params in
let appData = ContentDataObject()
appData.ext = [params[0]: params[1]]
self?.nativeAdUnit?.addAppContentData([appData])
}
processArgumentsParser.parseProcessArguments(ProcessInfo.processInfo.arguments)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class PrebidAdMobRewardedViewController: NSObject, AdaptedController, PrebidConf
self.adapterViewController = rootController
super.init()
setupAdapterController()
setProccesArgumentParser()
}

func configurationController() -> BaseConfigurationController? {
Expand All @@ -67,6 +66,22 @@ class PrebidAdMobRewardedViewController: NSObject, AdaptedController, PrebidConf
}
}

if let userData = AppConfiguration.shared.userData {
for dataPair in userData {
let appData = PBMORTBContentData()
appData.ext = [dataPair.key: dataPair.value]
adUnit?.addUserData([appData])
}
}

if let appData = AppConfiguration.shared.appContentData {
for dataPair in appData {
let appData = PBMORTBContentData()
appData.ext = [dataPair.key: dataPair.value]
adUnit?.addAppContentData([appData])
}
}

adUnit?.fetchDemand { [weak self] result in
guard let self = self else { return }
GADRewardedAd.load(withAdUnitID: self.adMobAdUnitId, request: self.request) { [weak self] ad, error in
Expand Down Expand Up @@ -153,20 +168,4 @@ class PrebidAdMobRewardedViewController: NSObject, AdaptedController, PrebidConf
})
}
}

private func setProccesArgumentParser() {
let processArgumentsParser = ProcessArgumentsParser()
processArgumentsParser.addOption("ADD_USER_DATA", paramsCount: 2) { [weak self] params in
let userData = PBMORTBContentData()
userData.ext = [params[0]: params[1]]
self?.adUnit?.addUserData([userData])
}

processArgumentsParser.addOption("ADD_APP_CONTEXT", paramsCount: 2) { [weak self] params in
let appData = PBMORTBContentData()
appData.ext = [params[0]: params[1]]
self?.adUnit?.addAppContentData([appData])
}
processArgumentsParser.parseProcessArguments(ProcessInfo.processInfo.arguments)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class PrebidGAMBannerController: NSObject, AdaptedController, PrebidConfigurable
stopRefreshButton.addTarget(self, action: #selector(stopRefresh), for: .touchUpInside)

setupAdapterController()
setProccesArgumentParser()
}

func configurationController() -> BaseConfigurationController? {
Expand Down Expand Up @@ -86,6 +85,22 @@ class PrebidGAMBannerController: NSObject, AdaptedController, PrebidConfigurable
}
}

if let userData = AppConfiguration.shared.userData {
for dataPair in userData {
let appData = PBMORTBContentData()
appData.ext = [dataPair.key: dataPair.value]
adBannerView?.addUserData([appData])
}
}

if let appData = AppConfiguration.shared.appContentData {
for dataPair in appData {
let appData = PBMORTBContentData()
appData.ext = [dataPair.key: dataPair.value]
adBannerView?.addAppContentData([appData])
}
}

adBannerView?.loadAd()

rootController?.bannerView.addSubview(self.adBannerView!)
Expand Down Expand Up @@ -195,20 +210,4 @@ class PrebidGAMBannerController: NSObject, AdaptedController, PrebidConfigurable
stopRefreshButton.isEnabled = false
adBannerView?.stopRefresh()
}

private func setProccesArgumentParser() {
let processArgumentsParser = ProcessArgumentsParser()
processArgumentsParser.addOption("ADD_USER_DATA", paramsCount: 2) { [weak self] params in
let userData = PBMORTBContentData()
userData.ext = [params[0]: params[1]]
self?.adBannerView?.addUserData([userData])
}

processArgumentsParser.addOption("ADD_APP_CONTEXT", paramsCount: 2) { [weak self] params in
let appData = PBMORTBContentData()
appData.ext = [params[0]: params[1]]
self?.adBannerView?.addAppContentData([appData])
}
processArgumentsParser.parseProcessArguments(ProcessInfo.processInfo.arguments)
}
}
Loading

0 comments on commit abb74a7

Please sign in to comment.