Skip to content

Commit

Permalink
Yieldlab: Support for Ad Unit Sizes (prebid#3494)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoxaAntoxic authored and sergseven committed Dec 23, 2024
1 parent a6216d6 commit 95d67b2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@
import java.time.Clock;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class YieldlabBidder implements Bidder<Void> {

Expand Down Expand Up @@ -166,6 +168,12 @@ private String makeUrl(ExtImpYieldlab extImpYieldlab, BidRequest request) {
.addParameter("ts", timestamp)
.addParameter("t", getTargetingValues(extImpYieldlab));

final String formats = makeFormats(request, extImpYieldlab);

if (formats != null) {
uriBuilder.addParameter("sizes", formats);
}

final User user = request.getUser();
if (user != null && StringUtils.isNotBlank(user.getBuyeruid())) {
uriBuilder.addParameter("ids", String.join("ylid:", user.getBuyeruid()));
Expand Down Expand Up @@ -209,6 +217,24 @@ private String makeUrl(ExtImpYieldlab extImpYieldlab, BidRequest request) {
return uriBuilder.toString();
}

private String makeFormats(BidRequest request, ExtImpYieldlab extImp) {
final List<String> formats = new ArrayList<>();
for (Imp imp: request.getImp()) {
if (isBanner(imp)) {
Stream.ofNullable(imp.getBanner().getFormat())
.flatMap(Collection::stream)
.map(format -> "%s:%d|%d".formatted(extImp.getAdslotId(), format.getW(), format.getH()))
.forEach(formats::add);
}
}

return formats.isEmpty() ? null : String.join(",", formats);
}

private boolean isBanner(Imp imp) {
return imp.getBanner() != null && imp.getXNative() == null && imp.getVideo() == null && imp.getAudio() == null;
}

/**
* Determines debug flag from {@link BidRequest} or {@link ExtRequest}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

import java.util.Map;

/**
* Defines the contract for bidrequest.imp[i].ext.yieldlab
*/
@Builder
@Value
public class ExtImpYieldlab {
Expand All @@ -19,9 +16,6 @@ public class ExtImpYieldlab {
@JsonProperty("supplyId")
String supplyId;

@JsonProperty("adSize")
String adSize;

Map<String, String> targeting;

@JsonProperty("extId")
Expand Down
7 changes: 1 addition & 6 deletions src/main/resources/static/bidder-params/yieldlab.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
"type": "string",
"description": "Yieldlab ID of the supply"
},
"adSize": {
"type": "string",
"description": "Size of the adslot in pixel, e.g. 200x50"
},
"extId": {
"type": "string",
"description": "External ID used for reporting"
Expand All @@ -27,7 +23,6 @@
},
"required": [
"adslotId",
"supplyId",
"adSize"
"supplyId"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.iab.openrtb.request.Banner;
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Device;
import com.iab.openrtb.request.Format;
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.request.Regs;
import com.iab.openrtb.request.Site;
Expand All @@ -25,9 +26,9 @@
import org.prebid.server.bidder.yieldlab.model.YieldlabDigitalServicesActResponse;
import org.prebid.server.bidder.yieldlab.model.YieldlabResponse;
import org.prebid.server.proto.openrtb.ext.ExtPrebid;
import org.prebid.server.proto.openrtb.ext.request.DsaTransparency;
import org.prebid.server.proto.openrtb.ext.request.ExtRegs;
import org.prebid.server.proto.openrtb.ext.request.ExtRegsDsa;
import org.prebid.server.proto.openrtb.ext.request.DsaTransparency;
import org.prebid.server.proto.openrtb.ext.request.ExtUser;
import org.prebid.server.proto.openrtb.ext.request.yieldlab.ExtImpYieldlab;
import org.prebid.server.proto.openrtb.ext.response.BidType;
Expand Down Expand Up @@ -100,12 +101,15 @@ public void makeHttpRequestsShouldSendRequestToModifiedUrlWithHeaders() {
targeting.put("key2", "value2");
final BidRequest bidRequest = BidRequest.builder()
.imp(singletonList(Imp.builder()
.banner(Banner.builder().w(1).h(1).build())
.banner(Banner.builder()
.format(List.of(
Format.builder().w(1).h(1).build(),
Format.builder().w(2).h(2).build()))
.build())
.ext(mapper.valueToTree(ExtPrebid.of(null,
ExtImpYieldlab.builder()
.adslotId("1")
.supplyId("2")
.adSize("adSize")
.targeting(targeting)
.extId("extId")
.build())))
Expand All @@ -127,8 +131,8 @@ public void makeHttpRequestsShouldSendRequestToModifiedUrlWithHeaders() {
.extracting(HttpRequest::getUri)
.allSatisfy(uri -> {
assertThat(uri).startsWith("https://test.endpoint.com/1?content=json&pvid=true&ts=");
assertThat(uri).endsWith("&t=key1%3Dvalue1%26key2%3Dvalue2&ids=buyeruid&yl_rtb_ifa&"
+ "yl_rtb_devicetype=1&gdpr=1&consent=consent");
assertThat(uri).endsWith("&t=key1%3Dvalue1%26key2%3Dvalue2&sizes=1%3A1%7C1%2C1%3A2%7C2&"
+ "ids=buyeruid&yl_rtb_ifa&yl_rtb_devicetype=1&gdpr=1&consent=consent");
final String ts = uri.substring(54, uri.indexOf("&t="));
assertThat(Long.parseLong(ts)).isEqualTo(expectedTime);
});
Expand Down Expand Up @@ -157,7 +161,6 @@ public void constructExtImpShouldWorkWithDuplicateKeysTargeting() {
ExtImpYieldlab.builder()
.adslotId("1")
.supplyId("2")
.adSize("adSize")
.targeting(targeting)
.extId("extId")
.build())))
Expand All @@ -168,7 +171,6 @@ public void constructExtImpShouldWorkWithDuplicateKeysTargeting() {
ExtImpYieldlab.builder()
.adslotId("2")
.supplyId("2")
.adSize("adSize")
.targeting(targeting)
.extId("extId")
.build())))
Expand Down Expand Up @@ -220,7 +222,6 @@ public void makeBidsShouldReturnCorrectBidderBid() throws JsonProcessingExceptio
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpYieldlab.builder()
.adslotId("1")
.supplyId("2")
.adSize("adSize")
.targeting(singletonMap("key", "value"))
.extId("extId")
.build())))
Expand Down Expand Up @@ -272,7 +273,6 @@ public void makeBidsShouldReturnCorrectAdm() throws JsonProcessingException {
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpYieldlab.builder()
.adslotId("12345")
.supplyId("123456789")
.adSize("728x90")
.extId("abc")
.build())))
.video(Video.builder().build())
Expand Down Expand Up @@ -452,7 +452,6 @@ public void makeBidsShouldAddDsaParamsWhenDsaIsPresentInResponse() throws JsonPr
.ext(mapper.valueToTree(ExtPrebid.of(null, ExtImpYieldlab.builder()
.adslotId("1")
.supplyId("2")
.adSize("adSize")
.targeting(singletonMap("key", "value"))
.extId("extId")
.build())))
Expand Down

0 comments on commit 95d67b2

Please sign in to comment.