Skip to content

Commit

Permalink
Support ad position in Original, Rendering and Mediation ad units (#1066
Browse files Browse the repository at this point in the history
)

* feat: support ad position in original, rendering and mediation ad units

* feat: add adPosition to InterstitialRenderingAdUnit and RewardedAdUnit
  • Loading branch information
OlenaPostindustria authored Dec 11, 2024
1 parent 833d351 commit cb51b11
Show file tree
Hide file tree
Showing 15 changed files with 202 additions and 13 deletions.
10 changes: 9 additions & 1 deletion PrebidMobile.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
534C61462CB562E40026119A /* CloseActionManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 534C61452CB562E40026119A /* CloseActionManagerTests.swift */; };
535145E02CCB758800D40B19 /* NSObject+PBMExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 535145DF2CCB758800D40B19 /* NSObject+PBMExtensions.m */; };
535145E12CCB758800D40B19 /* NSObject+PBMExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = 535145DE2CCB758800D40B19 /* NSObject+PBMExtensions.h */; settings = {ATTRIBUTES = (Public, ); }; };
53514CC62D01B5B900A480C0 /* InterstitialRenderingAdUnitTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53514CC52D01B5AF00A480C0 /* InterstitialRenderingAdUnitTest.swift */; };
53514CC82D01B5F900A480C0 /* RewardedAdUnitTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53514CC72D01B5F200A480C0 /* RewardedAdUnitTest.swift */; };
5355ACA929C454070014F16E /* VAST_with_empty_companion.xml in Resources */ = {isa = PBXBuildFile; fileRef = 5355ACA829C454070014F16E /* VAST_with_empty_companion.xml */; };
5355ACAB29C454770014F16E /* CreativeModelCollectionMakerVASTTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5355ACAA29C454770014F16E /* CreativeModelCollectionMakerVASTTests.swift */; };
536A39262A84C50F00B1CCEA /* StringExtensionsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 536A39252A84C50F00B1CCEA /* StringExtensionsTest.swift */; };
Expand Down Expand Up @@ -985,6 +987,8 @@
534C61452CB562E40026119A /* CloseActionManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CloseActionManagerTests.swift; sourceTree = "<group>"; };
535145DE2CCB758800D40B19 /* NSObject+PBMExtensions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSObject+PBMExtensions.h"; sourceTree = "<group>"; };
535145DF2CCB758800D40B19 /* NSObject+PBMExtensions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSObject+PBMExtensions.m"; sourceTree = "<group>"; };
53514CC52D01B5AF00A480C0 /* InterstitialRenderingAdUnitTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterstitialRenderingAdUnitTest.swift; sourceTree = "<group>"; };
53514CC72D01B5F200A480C0 /* RewardedAdUnitTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RewardedAdUnitTest.swift; sourceTree = "<group>"; };
5355ACA829C454070014F16E /* VAST_with_empty_companion.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = VAST_with_empty_companion.xml; sourceTree = "<group>"; };
5355ACAA29C454770014F16E /* CreativeModelCollectionMakerVASTTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreativeModelCollectionMakerVASTTests.swift; sourceTree = "<group>"; };
536A39252A84C50F00B1CCEA /* StringExtensionsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtensionsTest.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3051,16 +3055,18 @@
isa = PBXGroup;
children = (
925D5DA92737C4E800A8A2B5 /* AdLoadFlow */,
927ADB2528058170006EB8D5 /* MediationAPI */,
925D5E082737DF5F00A8A2B5 /* PBMBannerViewTest.swift */,
925D5E112737E04B00A8A2B5 /* PBMBidRequesterTest.swift */,
925D5E132737E74C00A8A2B5 /* PBMBidResponseTransformerTest.swift */,
925D5E152737E77200A8A2B5 /* DemandResponseInfoTest.swift */,
925D5E172737E7D200A8A2B5 /* PBMErrorTest.swift */,
925D5E1B2737E89400A8A2B5 /* PBMORTBTest.swift */,
925D5E1D2737E8BF00A8A2B5 /* PBMBaseInterstitialAdUnit_DelegationTest.swift */,
927ADB2528058170006EB8D5 /* MediationAPI */,
925D5E2C2737ECEA00A8A2B5 /* PBMWinNotifierTest.swift */,
92F6720727F252E500EA3B8D /* BaseInterstitialAdUnitTest.swift */,
53514CC52D01B5AF00A480C0 /* InterstitialRenderingAdUnitTest.swift */,
53514CC72D01B5F200A480C0 /* RewardedAdUnitTest.swift */,
533135C5282A869800AA1E4D /* BidTest.swift */,
);
path = Prebid;
Expand Down Expand Up @@ -3868,6 +3874,7 @@
FAC837D82321583500565051 /* CollectionExtensionTest.swift in Sources */,
922AFCE82736FAAE00732C53 /* LogToFileLock.swift in Sources */,
600CF0702208963500C95176 /* UtilsTests.swift in Sources */,
53514CC62D01B5B900A480C0 /* InterstitialRenderingAdUnitTest.swift in Sources */,
922AFD392737286D00732C53 /* PBMHTMLCreativeTest_ModalManagerDelegate.swift in Sources */,
6013E3F82215C82900FEE2B1 /* CLLocationManager+Swizzle.swift in Sources */,
925D5D722737B79D00A8A2B5 /* PBMTrackingRecordTest.swift in Sources */,
Expand Down Expand Up @@ -3997,6 +4004,7 @@
925D5D872737BAB300A8A2B5 /* PBMOpenMeasurementWrapperTest.swift in Sources */,
536A39262A84C50F00B1CCEA /* StringExtensionsTest.swift in Sources */,
925D5E782737F60100A8A2B5 /* VastEventTrackingTest.swift in Sources */,
53514CC82D01B5F900A480C0 /* RewardedAdUnitTest.swift in Sources */,
533FDF852A12030C0066ED5A /* MockPrebidJSLibraryManager.swift in Sources */,
922AFD452737298200732C53 /* PBMHTMLCreativeTest_MRAIDPlayVideo.swift in Sources */,
47D9AD2385D2A68745D1AD77 /* MockLocationManager.swift in Sources */,
Expand Down
6 changes: 6 additions & 0 deletions PrebidMobile/AdUnits/AdUnit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ public class AdUnit: NSObject, DispatcherDelegate {
set { adUnitConfig.setPbAdSlot(newValue) }
}

/// The position of the ad on the screen.
public var adPosition: AdPosition {
get { adUnitConfig.adPosition }
set { adUnitConfig.adPosition = newValue }
}

var adSizes: [CGSize] {
get { [adUnitConfig.adSize] + (adUnitConfig.additionalSizes ?? []) }
}
Expand Down
1 change: 1 addition & 0 deletions PrebidMobile/AdUnits/MultiformatAdUnit/PrebidAdUnit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public class PrebidAdUnit: NSObject {

adUnit.adUnitConfig.adConfiguration.isInterstitialAd = request.isInterstitial
adUnit.adUnitConfig.adConfiguration.isRewarded = request.isRewarded
adUnit.adUnitConfig.adPosition = request.adPosition

if request.isInterstitial || request.isRewarded {
adUnit.adUnitConfig.adPosition = .fullScreen
Expand Down
14 changes: 12 additions & 2 deletions PrebidMobile/AdUnits/MultiformatAdUnit/PrebidRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ import Foundation
@objcMembers
public class PrebidRequest: NSObject {

// MARK: - Public properties

/// The position of the ad on the screen.
public var adPosition: AdPosition = .undefined

// MARK: - Internal properties

private(set) var bannerParameters: BannerParameters?
Expand All @@ -45,8 +50,13 @@ public class PrebidRequest: NSObject {
/// - nativeParameters: The native parameters for the ad request.
/// - isInterstitial: Indicates if the request is for an interstitial ad.
/// - isRewarded: Indicates if the request is for a rewarded ad.
public init(bannerParameters: BannerParameters? = nil, videoParameters: VideoParameters? = nil,
nativeParameters: NativeParameters? = nil, isInterstitial: Bool = false, isRewarded: Bool = false) {
public init(
bannerParameters: BannerParameters? = nil,
videoParameters: VideoParameters? = nil,
nativeParameters: NativeParameters? = nil,
isInterstitial: Bool = false,
isRewarded: Bool = false
) {
self.bannerParameters = bannerParameters
self.videoParameters = videoParameters
self.nativeParameters = nativeParameters
Expand Down
17 changes: 13 additions & 4 deletions PrebidMobile/PrebidMobileRendering/AdPosition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,25 @@ import Foundation
public enum AdPosition: Int {

/// 0 Unknown
case undefined = 0
case undefined = 0

/// 1 Above the Fold
case aboveTheFold = 1

/// 2 Locked (i.e. fixed position)
case locked = 2

/// 3 Below the Fold
case belowTheFold = 3

/// 4 Header
case header = 4
case header = 4

/// 5 Footer
case footer = 5
case footer = 5

/// 6 Sidebar
case sidebar = 6
case sidebar = 6

/// 7 Full Screen
case fullScreen = 7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public class InterstitialRenderingAdUnit: NSObject, BaseInterstitialAdUnitProtoc
set { adUnitConfig.adFormats = newValue }
}

/// The position of the ad on the screen.
public var adPosition: AdPosition {
get { adUnitConfig.adPosition }
set { adUnitConfig.adPosition = newValue }
}

/// The ORTB (OpenRTB) configuration string for the ad unit.
public var ortbConfig: String? {
get { adUnitConfig.ortbConfig }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public class RewardedAdUnit: NSObject, BaseInterstitialAdUnitProtocol {
set { adUnitConfig.adFormats = newValue }
}

/// The position of the ad on the screen.
public var adPosition: AdPosition {
get { adUnitConfig.adPosition }
set { adUnitConfig.adPosition = newValue }
}

/// The ORTB (OpenRTB) configuration string for the ad unit.
public var ortbConfig: String? {
get { adUnitConfig.ortbConfig }
Expand Down Expand Up @@ -75,14 +81,17 @@ public class RewardedAdUnit: NSObject, BaseInterstitialAdUnitProtocol {
set { adUnitConfig.adConfiguration.videoControlsConfig.isSoundButtonVisible = newValue }
}

// MARK: Private properties

private let baseAdUnit: BaseRewardedAdUnit
// MARK: Internal Properties

private var adUnitConfig: AdUnitConfig {
// Note: exposed for tests
var adUnitConfig: AdUnitConfig {
baseAdUnit.adUnitConfig
}

// MARK: Private properties

private let baseAdUnit: BaseRewardedAdUnit

private var eventHandler: PBMPrimaryAdRequesterProtocol {
baseAdUnit.eventHandler
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public class MediationBaseInterstitialAdUnit : NSObject {
get { adUnitConfig.adConfiguration.videoParameters }
}

/// The position of the ad on the screen.
public var adPosition: AdPosition {
get { adUnitConfig.adPosition }
set { adUnitConfig.adPosition = newValue }
}

/// Indicates whether the video ad is muted.
public var isMuted: Bool {
get { adUnitConfig.adConfiguration.videoControlsConfig.isMuted }
Expand Down
7 changes: 5 additions & 2 deletions PrebidMobileTests/AdUnitTests/AdUnitSuccessorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AdUnitSuccessorTests: XCTestCase {
Prebid.shared.useExternalClickthroughBrowser = false
}

//MARK: - BannerAdUnit
// MARK: - BannerAdUnit

func testBannerAdUnitCreation() {
//when
Expand All @@ -51,7 +51,8 @@ class AdUnitSuccessorTests: XCTestCase {
bannerBasedAdUnits.forEach { checkBannerParametersHelper($0) }
}

//MARK: - InterstitialAdUnit
// MARK: - InterstitialAdUnit

func testInterstitialAdUnitCreation() {
//when
let adUnit = InterstitialAdUnit(configId: Constants.configID1)
Expand Down Expand Up @@ -86,6 +87,7 @@ class AdUnitSuccessorTests: XCTestCase {
}

//MARK: - VideoAdUnit

func testVideoAdUnitCreation() {
//when
let adUnit = VideoAdUnit(configId: Constants.configID1, size: CGSize(width: Constants.width1, height: Constants.height1))
Expand All @@ -95,6 +97,7 @@ class AdUnitSuccessorTests: XCTestCase {
}

//MARK: - VideoInterstitialAdUnit

func testVideoInterstitialAdUnitCreation() {
//when
let adUnit = VideoInterstitialAdUnit(configId: Constants.configID1)
Expand Down
20 changes: 20 additions & 0 deletions PrebidMobileTests/AdUnitTests/AdUnitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -702,4 +702,24 @@ class AdUnitTests: XCTestCase {
let objects2 = adUnit.getUserData()!
XCTAssertEqual(0, objects2.count)
}

func testAdUnitSetAdPosition() {
let adUnit = AdUnit(
configId: "test",
size: CGSize(width: 300, height: 250),
adFormats: [.banner, .video]
)

let adUnitConfig = adUnit.adUnitConfig

adUnit.adPosition = .header

XCTAssertEqual(adUnit.adPosition, adUnitConfig.adPosition)
XCTAssertEqual(adUnitConfig.adPosition, .header)

adUnit.adPosition = .footer

XCTAssertEqual(adUnit.adPosition, adUnitConfig.adPosition)
XCTAssertEqual(adUnitConfig.adPosition, .footer)
}
}
15 changes: 15 additions & 0 deletions PrebidMobileTests/AdUnitTests/PrebidAdUnitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -402,4 +402,19 @@ class PrebidAdUnitTests: XCTestCase {

waitForExpectations(timeout: 5, handler: nil)
}

func testSetAdPosition() {
let request = PrebidRequest(bannerParameters: BannerParameters())
request.adPosition = .header

let adUnit = PrebidAdUnit(configId: "test-config-id")
adUnit.fetchDemand(request: request, completion: { _ in })

XCTAssertEqual(adUnit.getConfiguration().adPosition, .header)

request.adPosition = .footer
adUnit.fetchDemand(request: request, completion: { _ in })

XCTAssertEqual(adUnit.getConfiguration().adPosition, .footer)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*   Copyright 2018-2024 Prebid.org, Inc.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

import XCTest
@testable import PrebidMobile

class InterstitialRenderingAdUnitTest: XCTestCase {

func testSetAdPosition() {
let adUnit = InterstitialRenderingAdUnit(configID: "test")

let adUnitConfig = adUnit.adUnitConfig

adUnit.adPosition = .header

XCTAssertEqual(adUnit.adPosition, adUnitConfig.adPosition)
XCTAssertEqual(adUnitConfig.adPosition, .header)

adUnit.adPosition = .footer

XCTAssertEqual(adUnit.adPosition, adUnitConfig.adPosition)
XCTAssertEqual(adUnitConfig.adPosition, .footer)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,22 @@ class MediationInterstitialAdUnitTest: XCTestCase {
waitForExpectations(timeout: 0.1)
}

func testSetAdPosition() {
let adUnit = MediationBaseInterstitialAdUnit(
configId: "test",
mediationDelegate: MockEmptyPrebidMediationDelegate()
)

let adUnitConfig = adUnit.adUnitConfig

adUnit.adPosition = .header

XCTAssertEqual(adUnit.adPosition, adUnitConfig.adPosition)
XCTAssertEqual(adUnitConfig.adPosition, .header)

adUnit.adPosition = .footer

XCTAssertEqual(adUnit.adPosition, adUnitConfig.adPosition)
XCTAssertEqual(adUnitConfig.adPosition, .footer)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ fileprivate let HBKeywordPrefix = "hb_"
@objc var localExtras: [AnyHashable : Any]?
}

class MockEmptyPrebidMediationDelegate: PrebidMediationDelegate {
func setUpAdObject(with values: [String : Any]) -> Bool { true }
func cleanUpAdObject() {}
func getAdView() -> UIView? { UIView(frame: .zero)}
}

class MockMediationUtils: PrebidMediationDelegate {

let adObject: MockAdObject
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*   Copyright 2018-2024 Prebid.org, Inc.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

import XCTest
@testable import PrebidMobile

class RewardedAdUnitTest: XCTestCase {

func testSetAdPosition() {
let adUnit = RewardedAdUnit(configID: "test")

let adUnitConfig = adUnit.adUnitConfig

adUnit.adPosition = .header

XCTAssertEqual(adUnit.adPosition, adUnitConfig.adPosition)
XCTAssertEqual(adUnitConfig.adPosition, .header)

adUnit.adPosition = .footer

XCTAssertEqual(adUnit.adPosition, adUnitConfig.adPosition)
XCTAssertEqual(adUnitConfig.adPosition, .footer)
}
}

0 comments on commit cb51b11

Please sign in to comment.