Skip to content

Commit ad37434

Browse files
authored
Yandex Bid Adapter : add support for video ads (#4004)
1 parent 355bb5a commit ad37434

File tree

4 files changed

+301
-61
lines changed

4 files changed

+301
-61
lines changed

src/main/java/org/prebid/server/bidder/yandex/YandexBidder.java

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.iab.openrtb.request.Format;
99
import com.iab.openrtb.request.Imp;
1010
import com.iab.openrtb.request.Site;
11+
import com.iab.openrtb.request.Video;
1112
import com.iab.openrtb.response.BidResponse;
1213
import com.iab.openrtb.response.SeatBid;
1314
import io.vertx.core.MultiMap;
@@ -46,6 +47,8 @@ public class YandexBidder implements Bidder<BidRequest> {
4647

4748
private static final String PAGE_ID_MACRO = "{{PageId}}";
4849
private static final String IMP_ID_MACRO = "{{ImpId}}";
50+
private static final String DISPLAY_MANAGER = "prebid.java";
51+
private static final String DISPLAY_MANAGER_VERSION = "1.1";
4952

5053
private final String endpointUrl;
5154
private final JacksonMapper mapper;
@@ -110,17 +113,25 @@ private ExtImpYandex parseAndValidateImpExt(ObjectNode impExtNode, final String
110113
}
111114

112115
private static Imp modifyImp(Imp imp) {
113-
if (imp.getBanner() != null) {
114-
return imp.toBuilder().banner(modifyBanner(imp.getBanner())).build();
115-
}
116-
if (imp.getXNative() != null) {
117-
return imp;
116+
if (imp.getBanner() == null && imp.getVideo() == null && imp.getXNative() == null) {
117+
throw new PreBidException("Imp #%s must contain at least one valid format (banner, video, or native)"
118+
.formatted(imp.getId()));
118119
}
119-
throw new PreBidException("Yandex only supports banner and native types. Ignoring imp id #%s"
120-
.formatted(imp.getId()));
120+
121+
return imp.toBuilder()
122+
.displaymanager(DISPLAY_MANAGER)
123+
.displaymanagerver(DISPLAY_MANAGER_VERSION)
124+
.banner(modifyBanner(imp.getBanner()))
125+
.video(modifyVideo(imp.getVideo()))
126+
.xNative(imp.getXNative())
127+
.build();
121128
}
122129

123130
private static Banner modifyBanner(Banner banner) {
131+
if (banner == null) {
132+
return null;
133+
}
134+
124135
final Integer weight = banner.getW();
125136
final Integer height = banner.getH();
126137
final List<Format> format = banner.getFormat();
@@ -134,6 +145,31 @@ private static Banner modifyBanner(Banner banner) {
134145
return banner;
135146
}
136147

148+
private static Video modifyVideo(Video video) {
149+
if (video == null) {
150+
return null;
151+
}
152+
153+
final Integer width = video.getW();
154+
final Integer height = video.getH();
155+
if (width == null || height == null || width == 0 || height == 0) {
156+
throw new PreBidException("Invalid sizes provided for Video %sx%s".formatted(width, height));
157+
}
158+
159+
final Video.VideoBuilder videoBuilder = video.toBuilder();
160+
if (video.getMinduration() == null || video.getMinduration() == 0) {
161+
videoBuilder.minduration(1);
162+
}
163+
if (video.getMaxduration() == null || video.getMaxduration() == 0) {
164+
videoBuilder.maxduration(120);
165+
}
166+
if (CollectionUtils.isEmpty(video.getProtocols())) {
167+
videoBuilder.protocols(Collections.singletonList(3));
168+
}
169+
170+
return videoBuilder.build();
171+
}
172+
137173
private String modifyUrl(ExtImpYandex extImpYandex, String referer, String currency) {
138174
final String resolvedUrl = endpointUrl
139175
.replace(PAGE_ID_MACRO, HttpUtil.encodeUrl(extImpYandex.getPageId().toString()))
@@ -167,6 +203,10 @@ private HttpRequest<BidRequest> buildHttpRequest(BidRequest outgoingRequest, Str
167203

168204
private static MultiMap headers(BidRequest bidRequest) {
169205
final MultiMap headers = HttpUtil.headers();
206+
207+
headers.add(HttpUtil.X_OPENRTB_VERSION_HEADER, "2.5");
208+
HttpUtil.addHeaderIfValueIsNotEmpty(headers, HttpUtil.REFERER_HEADER, getReferer(bidRequest));
209+
170210
final Device device = bidRequest.getDevice();
171211
if (device != null) {
172212
HttpUtil.addHeaderIfValueIsNotEmpty(headers, HttpUtil.ACCEPT_LANGUAGE_HEADER, device.getLanguage());
@@ -217,18 +257,15 @@ private static BidType getBidType(String bidImpId, List<Imp> imps) {
217257
}
218258

219259
private static BidType resolveImpType(Imp imp) {
260+
if (imp.getVideo() != null) {
261+
return BidType.video;
262+
}
220263
if (imp.getXNative() != null) {
221264
return BidType.xNative;
222265
}
223266
if (imp.getBanner() != null) {
224267
return BidType.banner;
225268
}
226-
if (imp.getVideo() != null) {
227-
return BidType.video;
228-
}
229-
if (imp.getAudio() != null) {
230-
return BidType.audio;
231-
}
232269
throw new PreBidException("Processing an invalid impression; cannot resolve impression type for imp #%s"
233270
.formatted(imp.getId()));
234271
}

src/main/resources/bidder-config/yandex.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ adapters:
77
app-media-types:
88
site-media-types:
99
- banner
10+
- video
1011
- native
1112
vendor-id: 0
1213
usersync:
1314
cookie-family-name: yandex
1415
redirect:
15-
url: https://an.yandex.ru/mapuid/yandex/?ssp-id=10500&gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&location={{redirect_url}}
16+
url: https://yandex.ru/an/mapuid/yandex/?ssp-id=10500&gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&location={{redirect_url}}
1617
support-cors: false
1718
uid-macro: '{YANDEXUID}'

0 commit comments

Comments
 (0)