Skip to content
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 @@ -264,6 +264,7 @@ private static BidderInfo bidderInfo(OrtbVersion ortbVersion) {
true,
ortbVersion,
false,
false,
null,
null,
null,
Expand Down
35 changes: 27 additions & 8 deletions src/main/java/org/prebid/server/auction/BidResponseCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,6 @@ private Bid toBid(BidInfo bidInfo,
final TargetingInfo targetingInfo = bidInfo.getTargetingInfo();
final BidType bidType = bidInfo.getBidType();
final Bid bid = bidInfo.getBid();

final CacheInfo cacheInfo = bidInfo.getCacheInfo();
final String cacheId = cacheInfo != null ? cacheInfo.getCacheId() : null;
final String videoCacheId = cacheInfo != null ? cacheInfo.getVideoCacheId() : null;
Expand All @@ -1562,9 +1561,10 @@ private Bid toBid(BidInfo bidInfo,
final boolean isWinningBid = targetingInfo.isWinningBid();
final String seat = targetingInfo.getSeat();
final String categoryDuration = bidInfo.getCategory();
final Integer bidDuration = prepareBidDuration(bid, targeting);
targetingKeywords = keywordsCreator != null
? keywordsCreator.makeFor(
bid, seat, isWinningBid, cacheId, bidType.getName(), videoCacheId, categoryDuration, account)
? keywordsCreator.makeFor(bid, seat, isWinningBid, cacheId,
bidType.getName(), videoCacheId, categoryDuration, account, bidDuration)
: null;
} else {
targetingKeywords = null;
Expand All @@ -1573,10 +1573,8 @@ private Bid toBid(BidInfo bidInfo,
final CacheAsset bids = cacheId != null ? toCacheAsset(cacheId) : null;
final CacheAsset vastXml = videoCacheId != null ? toCacheAsset(videoCacheId) : null;
final ExtResponseCache cache = bids != null || vastXml != null ? ExtResponseCache.of(bids, vastXml) : null;

final ObjectNode originalBidExt = bid.getExt();
final Boolean dealsTierSatisfied = bidInfo.getSatisfiedPriority();

final boolean bidRankingEnabled = isBidRankingEnabled(account);

final ExtBidPrebid updatedExtBidPrebid =
Expand Down Expand Up @@ -1625,6 +1623,30 @@ private static boolean isBidRankingEnabled(Account account) {
.orElse(false);
}

private Integer prepareBidDuration(Bid bid, ExtRequestTargeting targeting) {
final List<Integer> durationRangePerSec = targeting.getDurationrangesec();
if (CollectionUtils.isEmpty(durationRangePerSec)) {
return null;
}

final Integer duration = ObjectUtils.firstNonNull(bid.getDur(), getBidMetaDuration(bid));
return durationRangePerSec.stream()
.sorted()
.filter(bucket -> bucket >= duration)
.findFirst()
// should never occur. See ResponseBidValidator
.orElseThrow();
}

private Integer getBidMetaDuration(Bid bid) {
return Optional.ofNullable(bid.getExt())
.filter(ext -> ext.hasNonNull("prebid"))
.map(ext -> convertValue(ext, "prebid", ExtBidPrebid.class))
.map(ExtBidPrebid::getMeta)
.map(ExtBidPrebidMeta::getDur)
.orElse(null);
}

private String createNativeMarkup(String bidAdm, Imp correspondingImp) {
final Response nativeMarkup;
try {
Expand Down Expand Up @@ -1717,9 +1739,7 @@ private static boolean eventsEnabledForChannel(AuctionContext auctionContext) {
.map(AccountAnalyticsConfig::getAuctionEvents)
.map(AccountAuctionEventConfig::getEvents)
.orElseGet(AccountAnalyticsConfig::fallbackAuctionEvents);

final String channelFromRequest = channelFromRequest(auctionContext.getBidRequest());

return channelConfig.entrySet().stream()
.filter(entry -> StringUtils.equalsIgnoreCase(channelFromRequest, entry.getKey()))
.findFirst()
Expand All @@ -1731,7 +1751,6 @@ private static String channelFromRequest(BidRequest bidRequest) {
final ExtRequest ext = bidRequest.getExt();
final ExtRequestPrebid prebid = ext != null ? ext.getPrebid() : null;
final ExtRequestPrebidChannel channel = prebid != null ? prebid.getChannel() : null;

return channel != null ? recogniseChannelName(channel.getName()) : null;
}

Expand Down
12 changes: 10 additions & 2 deletions src/main/java/org/prebid/server/auction/BidsAdjuster.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.response.Bid;
import org.prebid.server.auction.adpodding.AdPoddingBidDeduplicationService;
import org.prebid.server.auction.aliases.BidderAliases;
import org.prebid.server.auction.model.AuctionContext;
import org.prebid.server.auction.model.AuctionParticipation;
Expand All @@ -27,16 +28,19 @@ public class BidsAdjuster {
private final PriceFloorEnforcer priceFloorEnforcer;
private final BidAdjustmentsProcessor bidAdjustmentsProcessor;
private final DsaEnforcer dsaEnforcer;
private final AdPoddingBidDeduplicationService bidDeduplicationService;

public BidsAdjuster(ResponseBidValidator responseBidValidator,
PriceFloorEnforcer priceFloorEnforcer,
BidAdjustmentsProcessor bidAdjustmentsProcessor,
DsaEnforcer dsaEnforcer) {
DsaEnforcer dsaEnforcer,
AdPoddingBidDeduplicationService bidDeduplicationService) {

this.responseBidValidator = Objects.requireNonNull(responseBidValidator);
this.priceFloorEnforcer = Objects.requireNonNull(priceFloorEnforcer);
this.bidAdjustmentsProcessor = Objects.requireNonNull(bidAdjustmentsProcessor);
this.dsaEnforcer = Objects.requireNonNull(dsaEnforcer);
this.bidDeduplicationService = Objects.requireNonNull(bidDeduplicationService);
}

public List<AuctionParticipation> validateAndAdjustBids(List<AuctionParticipation> auctionParticipations,
Expand All @@ -49,7 +53,11 @@ public List<AuctionParticipation> validateAndAdjustBids(List<AuctionParticipatio
.map(auctionParticipation -> bidAdjustmentsProcessor.enrichWithAdjustedBids(
auctionParticipation,
bidRequest))

.map(auctionParticipation -> bidDeduplicationService.deduplicate(
auctionContext.getBidRequest(),
auctionParticipation,
auctionContext.getAccount(),
auctionContext.getBidRejectionTrackers().get(auctionParticipation.getBidder())))
.map(auctionParticipation -> priceFloorEnforcer.enforce(
bidRequest,
auctionParticipation,
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/prebid/server/auction/ExchangeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.prebid.server.activity.infrastructure.payload.ActivityInvocationPayload;
import org.prebid.server.activity.infrastructure.payload.impl.ActivityInvocationPayloadImpl;
import org.prebid.server.activity.infrastructure.payload.impl.BidRequestActivityInvocationPayload;
import org.prebid.server.auction.adpodding.AdPoddingImpDowngradingService;
import org.prebid.server.auction.aliases.AlternateBidderCodesConfig;
import org.prebid.server.auction.aliases.BidderAliases;
import org.prebid.server.auction.mediatypeprocessor.MediaTypeProcessingResult;
Expand Down Expand Up @@ -156,6 +157,7 @@ public class ExchangeService {
private final PriceFloorAdjuster priceFloorAdjuster;
private final PriceFloorProcessor priceFloorProcessor;
private final BidsAdjuster bidsAdjuster;
private final AdPoddingImpDowngradingService impDowngradingService;
private final Metrics metrics;
private final Clock clock;
private final JacksonMapper mapper;
Expand Down Expand Up @@ -183,6 +185,7 @@ public ExchangeService(double logSamplingRate,
PriceFloorAdjuster priceFloorAdjuster,
PriceFloorProcessor priceFloorProcessor,
BidsAdjuster bidsAdjuster,
AdPoddingImpDowngradingService impDowngradingService,
Metrics metrics,
Clock clock,
JacksonMapper mapper,
Expand Down Expand Up @@ -210,6 +213,7 @@ public ExchangeService(double logSamplingRate,
this.priceFloorAdjuster = Objects.requireNonNull(priceFloorAdjuster);
this.priceFloorProcessor = Objects.requireNonNull(priceFloorProcessor);
this.bidsAdjuster = Objects.requireNonNull(bidsAdjuster);
this.impDowngradingService = Objects.requireNonNull(impDowngradingService);
this.metrics = Objects.requireNonNull(metrics);
this.clock = Objects.requireNonNull(clock);
this.mapper = Objects.requireNonNull(mapper);
Expand Down Expand Up @@ -887,6 +891,7 @@ private List<Imp> prepareImps(String bidder,
.map(imp -> imp.toBuilder().ext(imp.getExt().deepCopy()).build())
.map(imp -> impAdjuster.adjust(imp, bidder, bidderAliases, debugWarnings))
.map(imp -> prepareImp(imp, bidder, bidRequest, transmitTid, useFirstPartyData, account, debugWarnings))
.flatMap(imp -> impDowngradingService.downgrade(imp, bidder, bidderAliases).stream())
.toList();
}

Expand Down Expand Up @@ -919,6 +924,7 @@ private ObjectNode prepareImpExt(String bidder,
ObjectNode impExt,
boolean transmitTid,
boolean useFirstPartyData) {

final JsonNode bidderNode = bidderParamsFromImpExt(impExt).get(bidder);
final JsonNode impExtPrebid = cleanUpImpExtPrebid(impExt.get(PREBID_EXT));
Optional.ofNullable(impExtPrebid).ifPresentOrElse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -72,6 +71,11 @@ public class TargetingKeywordsCreator {
*/
private static final String CATEGORY_DURATION_KEY = "_pb_cat_dur";

/**
* Stores bid's duration
*/
private static final String BID_DURATION_KEY = "_dur";

/**
* Stores bid's format. For example "video" or "banner".
*/
Expand Down Expand Up @@ -154,7 +158,8 @@ Map<String, String> makeFor(Bid bid,
String format,
String vastCacheId,
String categoryDuration,
Account account) {
Account account,
Integer bidDuration) {

final Map<String, String> keywords = makeFor(
bidder,
Expand All @@ -167,7 +172,8 @@ Map<String, String> makeFor(Bid bid,
categoryDuration,
format,
bid.getDealid(),
account);
account,
bidDuration);

if (resolver == null) {
return truncateKeys(keywords);
Expand All @@ -192,15 +198,16 @@ private Map<String, String> makeFor(String bidder,
String categoryDuration,
String format,
String dealId,
Account account) {
Account account,
Integer bidDuration) {

final boolean includeDealBid = alwaysIncludeDeals && StringUtils.isNotEmpty(dealId);
final KeywordMap keywordMap = new KeywordMap(
bidder,
winningBid,
includeWinners,
includeBidderKeys || includeDealBid,
Collections.emptySet());
Set.of(this.keyPrefix + BID_DURATION_KEY));

final String roundedCpm = isPriceGranularityValid()
? CpmRange.fromCpm(price, priceGranularity, account)
Expand Down Expand Up @@ -239,6 +246,9 @@ private Map<String, String> makeFor(String bidder,
if (StringUtils.isNotBlank(categoryDuration)) {
keywordMap.put(this.keyPrefix + CATEGORY_DURATION_KEY, categoryDuration);
}
if (bidDuration != null) {
keywordMap.put(this.keyPrefix + BID_DURATION_KEY, bidDuration.toString());
}

return keywordMap.asMap();
}
Expand Down
Loading
Loading