Skip to content
Merged
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
63 changes: 50 additions & 13 deletions src/main/java/org/prebid/server/bidder/yandex/YandexBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.iab.openrtb.request.Format;
import com.iab.openrtb.request.Imp;
import com.iab.openrtb.request.Site;
import com.iab.openrtb.request.Video;
import com.iab.openrtb.response.BidResponse;
import com.iab.openrtb.response.SeatBid;
import io.vertx.core.MultiMap;
Expand Down Expand Up @@ -46,6 +47,8 @@ public class YandexBidder implements Bidder<BidRequest> {

private static final String PAGE_ID_MACRO = "{{PageId}}";
private static final String IMP_ID_MACRO = "{{ImpId}}";
private static final String DISPLAY_MANAGER = "prebid.java";
private static final String DISPLAY_MANAGER_VERSION = "1.1";

private final String endpointUrl;
private final JacksonMapper mapper;
Expand Down Expand Up @@ -110,17 +113,25 @@ private ExtImpYandex parseAndValidateImpExt(ObjectNode impExtNode, final String
}

private static Imp modifyImp(Imp imp) {
if (imp.getBanner() != null) {
return imp.toBuilder().banner(modifyBanner(imp.getBanner())).build();
}
if (imp.getXNative() != null) {
return imp;
if (imp.getBanner() == null && imp.getVideo() == null && imp.getXNative() == null) {
throw new PreBidException("Imp #%s must contain at least one valid format (banner, video, or native)"
.formatted(imp.getId()));
}
throw new PreBidException("Yandex only supports banner and native types. Ignoring imp id #%s"
.formatted(imp.getId()));

return imp.toBuilder()
.displaymanager(DISPLAY_MANAGER)
.displaymanagerver(DISPLAY_MANAGER_VERSION)
.banner(modifyBanner(imp.getBanner()))
.video(modifyVideo(imp.getVideo()))
.xNative(imp.getXNative())
.build();
}

private static Banner modifyBanner(Banner banner) {
if (banner == null) {
return null;
}

final Integer weight = banner.getW();
final Integer height = banner.getH();
final List<Format> format = banner.getFormat();
Expand All @@ -134,6 +145,31 @@ private static Banner modifyBanner(Banner banner) {
return banner;
}

private static Video modifyVideo(Video video) {
if (video == null) {
return null;
}

final Integer width = video.getW();
final Integer height = video.getH();
if (width == null || height == null || width == 0 || height == 0) {
throw new PreBidException("Invalid sizes provided for Video %sx%s".formatted(width, height));
}

final Video.VideoBuilder videoBuilder = video.toBuilder();
if (video.getMinduration() == null || video.getMinduration() == 0) {
videoBuilder.minduration(1);
}
if (video.getMaxduration() == null || video.getMaxduration() == 0) {
videoBuilder.maxduration(120);
}
if (CollectionUtils.isEmpty(video.getProtocols())) {
videoBuilder.protocols(Collections.singletonList(3));
}

return videoBuilder.build();
}

private String modifyUrl(ExtImpYandex extImpYandex, String referer, String currency) {
final String resolvedUrl = endpointUrl
.replace(PAGE_ID_MACRO, HttpUtil.encodeUrl(extImpYandex.getPageId().toString()))
Expand Down Expand Up @@ -167,6 +203,10 @@ private HttpRequest<BidRequest> buildHttpRequest(BidRequest outgoingRequest, Str

private static MultiMap headers(BidRequest bidRequest) {
final MultiMap headers = HttpUtil.headers();

headers.add(HttpUtil.X_OPENRTB_VERSION_HEADER, "2.5");
HttpUtil.addHeaderIfValueIsNotEmpty(headers, HttpUtil.REFERER_HEADER, getReferer(bidRequest));

final Device device = bidRequest.getDevice();
if (device != null) {
HttpUtil.addHeaderIfValueIsNotEmpty(headers, HttpUtil.ACCEPT_LANGUAGE_HEADER, device.getLanguage());
Expand Down Expand Up @@ -217,18 +257,15 @@ private static BidType getBidType(String bidImpId, List<Imp> imps) {
}

private static BidType resolveImpType(Imp imp) {
if (imp.getVideo() != null) {
return BidType.video;
}
if (imp.getXNative() != null) {
return BidType.xNative;
}
if (imp.getBanner() != null) {
return BidType.banner;
}
if (imp.getVideo() != null) {
return BidType.video;
}
if (imp.getAudio() != null) {
return BidType.audio;
}
throw new PreBidException("Processing an invalid impression; cannot resolve impression type for imp #%s"
.formatted(imp.getId()));
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/bidder-config/yandex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ adapters:
app-media-types:
site-media-types:
- banner
- video
- native
vendor-id: 0
usersync:
cookie-family-name: yandex
redirect:
url: https://an.yandex.ru/mapuid/yandex/?ssp-id=10500&gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&location={{redirect_url}}
url: https://yandex.ru/an/mapuid/yandex/?ssp-id=10500&gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&location={{redirect_url}}
support-cors: false
uid-macro: '{YANDEXUID}'
Loading
Loading