Skip to content

Equativ: SmartAdserver alias with update to use mtype #3678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ private static Publisher modifyPublisher(Publisher publisher, Integer networkId)
public Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequest bidRequest) {
try {
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class);
return extractBids(httpCall.getRequest().getPayload(), bidResponse);
return extractBids(bidResponse);
} catch (DecodeException | PreBidException e) {
return Result.withError(BidderError.badServerResponse(e.getMessage()));
}
}

private Result<List<BidderBid>> extractBids(BidRequest bidRequest, BidResponse bidResponse) {
private Result<List<BidderBid>> extractBids(BidResponse bidResponse) {
if (bidResponse == null || CollectionUtils.isEmpty(bidResponse.getSeatbid())) {
return Result.empty();
}
Expand All @@ -128,19 +128,21 @@ private Result<List<BidderBid>> extractBids(BidRequest bidRequest, BidResponse b
.map(SeatBid::getBid)
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.map(bid -> BidderBid.of(bid, getBidType(bid.getImpid(), bidRequest.getImp()), bidResponse.getCur()))
.map(bid -> BidderBid.of(bid, getBidTypeFromMarkupType(bid.getMtype()), bidResponse.getCur()))
.toList();
return Result.of(bidderBids, errors);
}

private static BidType getBidType(String impId, List<Imp> imps) {
for (Imp imp : imps) {
if (imp.getId().equals(impId)) {
return imp.getVideo() != null
? BidType.video
: (imp.getXNative() != null ? BidType.xNative : BidType.banner);
}
private static BidType getBidTypeFromMarkupType(Integer markupType) {
if (markupType == null) {
return BidType.banner;
}
return BidType.banner;
return switch (markupType) {
case 1 -> BidType.banner;
case 2 -> BidType.video;
case 3 -> BidType.audio;
case 4 -> BidType.xNative;
default -> BidType.banner;
Comment on lines +136 to +145
Copy link
Contributor Author

@EmilNadimanov EmilNadimanov Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as FYI: Taking into account this Go code, a response body that is missing mType in PBS-Go will be parsed to 0 by default and to null in PBS-Java. So I had to account for nullability of the Integer and added a test case for both unhappy cases: null and out-of-bounds (default -> BidType.banner).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EmilNadimanov You can simplify it like this:

switch (...) {
  ...
  case null, default -> BidType.banner;
}

};
}
}
5 changes: 5 additions & 0 deletions src/main/resources/bidder-config/smartadserver.yaml
Copy link
Contributor Author

@EmilNadimanov EmilNadimanov Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: I have a question here. The original PR adds gpp support: https://github.com/prebid/prebid-server/pull/4045/files#diff-aaf548993679435ffc95fdfea42cf46f7d38b55e91c34ea6d874379c6aa5e878R25-R26

All i've been able to find in regard to GPP in PBS-Java was gpp={{gpp}}&gpp_sid={{gpp_sid}} in the query string under adapters.<BIDDER>.usersync.redirect.url. In PBS-Go no changes were made to the URL when gpp-support was declared in the config. Should I do anything here to port this change as well?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I see from the GO logic is simply a way for the adapter to indicate that there is no need to "move" properties from GPP to old locations.

If you want to reproduce this logic, the only way to do it is to remove these properties if GPP is present.
(regs.ext.us_privacy and regs.ext.gdpr, user.ext.consent)

Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
adapters:
smartadserver:
endpoint: https://ssb-global.smartadserver.com
endpoint-compression: gzip
aliases:
equativ: ~
Copy link
Contributor Author

@EmilNadimanov EmilNadimanov Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Also not sure whether I should write something here or just leave a tilde. As reference, the corresponding change in the original PR: https://github.com/prebid/prebid-server/pull/4045/files#diff-91570c852a44292f55ba1a3c722b2c26d76eacc0c87a41a527a84bdf7b021e36R1

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add enabled: false so that in case smartadserver is enabled, equativ won't be enabled unless specified

meta-info:
maintainer-email: [email protected]
app-media-types:
- banner
- video
- native
- audio
site-media-types:
- banner
- video
- native
- audio
supported-vendors:
vendor-id: 45
usersync:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.iab.openrtb.request.Banner;
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.request.Native;
import com.iab.openrtb.request.Publisher;
import com.iab.openrtb.request.Site;
import com.iab.openrtb.request.Video;
Expand All @@ -27,8 +26,10 @@
import java.util.function.Function;

import static java.util.Collections.singletonList;
import static java.util.function.UnaryOperator.identity;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.prebid.server.proto.openrtb.ext.response.BidType.audio;
import static org.prebid.server.proto.openrtb.ext.response.BidType.banner;
import static org.prebid.server.proto.openrtb.ext.response.BidType.video;
import static org.prebid.server.proto.openrtb.ext.response.BidType.xNative;
Expand Down Expand Up @@ -66,7 +67,7 @@ public void makeHttpRequestsShouldReturnErrorIfImpExtCouldNotBeParsed() {
public void makeHttpRequestsShouldCreateCorrectURL() {
// given
final BidRequest bidRequest = BidRequest.builder()
.imp(singletonList(givenImp(Function.identity())))
.imp(singletonList(givenImp(identity())))
.build();

// when
Expand All @@ -83,7 +84,7 @@ public void makeHttpRequestsShouldCreateCorrectURL() {
public void makeHttpRequestsShouldUpdateSiteObjectIfPresent() {
// given
final BidRequest bidRequest = BidRequest.builder()
.imp(singletonList(givenImp(Function.identity())))
.imp(singletonList(givenImp(identity())))
.site(Site.builder()
.domain("www.foo.com")
.publisher(Publisher.builder().domain("foo.com").build())
Expand All @@ -110,7 +111,7 @@ public void makeHttpRequestsShouldUpdateSiteObjectIfPresent() {
public void makeHttpRequestsShouldCreateRequestForEveryValidImp() {
// given
final BidRequest bidRequest = BidRequest.builder()
.imp(Arrays.asList(givenImp(Function.identity()),
.imp(Arrays.asList(givenImp(identity()),
givenImp(impBuilder -> impBuilder.id("456"))
))
.build();
Expand Down Expand Up @@ -196,33 +197,46 @@ public void makeBidsShouldReturnEmptyListIfBidResponseSeatBidIsNull() throws Jso
}

@Test
public void makeBidsShouldReturnBannerBidIfBannerIsPresent() throws JsonProcessingException {
public void makeBidsShouldReturnBannerBidIfMarkupTypeIsBanner() throws JsonProcessingException {
// given
final BidderCall<BidRequest> httpCall = givenHttpCall(
BidRequest.builder()
.imp(singletonList(Imp.builder().id("123").banner(Banner.builder().build()).build()))
.build(),
BidRequest.builder().build(),
mapper.writeValueAsString(
givenBidResponse(bidBuilder -> bidBuilder.impid("123"))));
givenBidResponse(bidBuilder -> bidBuilder.mtype(1))));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, null);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.containsOnly(BidderBid.of(Bid.builder().impid("123").build(), banner, "EUR"));
.containsOnly(BidderBid.of(Bid.builder().mtype(1).build(), banner, "EUR"));
}

@Test
public void makeBidsShouldReturnBannerBidByDefault() throws JsonProcessingException {
public void makeBidsShouldReturnAudioBidIfMarkupTypeIsAudio() throws JsonProcessingException {
// given
final BidderCall<BidRequest> httpCall = givenHttpCall(
BidRequest.builder()
.imp(singletonList(Imp.builder().id("123").banner(Banner.builder().build()).build()))
.build(),
BidRequest.builder().build(),
mapper.writeValueAsString(
givenBidResponse(Function.identity())));
givenBidResponse(bidBuilder -> bidBuilder.mtype(3))));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, null);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.containsOnly(BidderBid.of(Bid.builder().mtype(3).build(), audio, "EUR"));
}

@Test
public void makeBidsShouldReturnBannerBidIfMarkupTypeIsNull() throws JsonProcessingException {
// given
final BidderCall<BidRequest> httpCall = givenHttpCall(
BidRequest.builder().build(),
mapper.writeValueAsString(
givenBidResponse(identity())));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, null);
Expand All @@ -234,41 +248,54 @@ public void makeBidsShouldReturnBannerBidByDefault() throws JsonProcessingExcept
}

@Test
public void makeBidsShouldReturnVideoBidIfVideoIsPresent() throws JsonProcessingException {
public void makeBidsShouldReturnBannerBidIfMarkupTypeOutOfBounds() throws JsonProcessingException {
// given
final BidderCall<BidRequest> httpCall = givenHttpCall(
BidRequest.builder().build(),
mapper.writeValueAsString(
givenBidResponse(bidBuilder -> bidBuilder.mtype(5))));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, null);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.containsOnly(BidderBid.of(Bid.builder().mtype(5).build(), banner, "EUR"));
}

@Test
public void makeBidsShouldReturnVideoBidIfMarkupTypeIsVideo() throws JsonProcessingException {
// given
final BidderCall<BidRequest> httpCall = givenHttpCall(
BidRequest.builder()
.imp(singletonList(Imp.builder().id("123").video(Video.builder().build()).build()))
.build(),
BidRequest.builder().build(),
mapper.writeValueAsString(
givenBidResponse(bidBuilder -> bidBuilder.impid("123"))));
givenBidResponse(bidBuilder -> bidBuilder.mtype(2))));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, null);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.containsOnly(BidderBid.of(Bid.builder().impid("123").build(), video, "EUR"));
.containsOnly(BidderBid.of(Bid.builder().mtype(2).build(), video, "EUR"));
}

@Test
public void makeBidsShouldReturnNativeBidIfNativeIsPresent() throws JsonProcessingException {
public void makeBidsShouldReturnNativeBidIfMarkupTypeIsNative() throws JsonProcessingException {
// given
final BidderCall<BidRequest> httpCall = givenHttpCall(
BidRequest.builder()
.imp(singletonList(Imp.builder().id("123").xNative(Native.builder().build()).build()))
.build(),
BidRequest.builder().build(),
mapper.writeValueAsString(
givenBidResponse(bidBuilder -> bidBuilder.impid("123"))));
givenBidResponse(bidBuilder -> bidBuilder.mtype(4))));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, null);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.containsOnly(BidderBid.of(Bid.builder().impid("123").build(), xNative, "EUR"));
.containsOnly(BidderBid.of(Bid.builder().mtype(4).build(), xNative, "EUR"));
}

private static Imp givenImp(Function<Imp.ImpBuilder, Imp.ImpBuilder> impCustomizer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"type": "banner"
},
"origbidcpm": 0.5
}
},
"mtype": 1
}
],
"seat": "smartadserver",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"cid": "cid",
"crid": "crid",
"h": 576,
"w": 1024
"w": 1024,
"mtype": 1
}
]
}
Expand Down
Loading