Skip to content
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

Adagio Analytics Adapter: handle bid cache usecases #10699

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
38 changes: 33 additions & 5 deletions modules/adagioAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ const cache = {
...this.auctions[auctionId][adUnitCode],
...values
};
},

// Map prebid auction id to adagio auction id
auctionIdReferences: {},
addPrebidAuctionIdRef(auctionId, adagioAuctionId) {
this.auctionIdReferences[auctionId] = adagioAuctionId;
},
getAdagioAuctionId(auctionId) {
return this.auctionIdReferences[auctionId];
}
};
const enc = window.encodeURIComponent;
Expand Down Expand Up @@ -125,6 +134,10 @@ function sendNewBeacon(auctionId, adUnitCode) {
sendRequest(cache.getAuction(auctionId, adUnitCode));
};

function getTargetedAuctionId(bid) {
return deepAccess(bid, 'latestTargetedAuctionId') || deepAccess(bid, 'auctionId');
}

/**
* END UTILS FUNCTIONS
*/
Expand Down Expand Up @@ -196,6 +209,9 @@ function handlerAuctionInit(event) {
// We assume that all Adagio bids for a same adunit have the same params.
const params = adagioAdUnitBids[0].params;

const adagioAuctionId = params.adagioAuctionId;
cache.addPrebidAuctionIdRef(prebidAuctionId, adagioAuctionId);

// Get all media types requested for Adagio.
const adagioMediaTypes = removeDuplicates(
adagioAdUnitBids.map(bid => Object.keys(bid.mediaTypes)).flat(),
Expand All @@ -208,7 +224,7 @@ function handlerAuctionInit(event) {
org_id: params.organizationId,
site: params.site,
pv_id: params.pageviewId,
auct_id: params.adagioAuctionId,
auct_id: adagioAuctionId,
adu_code: adUnitCode,
url_dmn: w.location.hostname,
dvc: params.environment,
Expand Down Expand Up @@ -247,7 +263,9 @@ function handlerBidResponse(event) {
};

function handlerBidWon(event) {
if (!guard.bidTracked(event.auctionId, event.adUnitCode)) {
let auctionId = getTargetedAuctionId(event);

if (!guard.bidTracked(auctionId, event.adUnitCode)) {
return;
}

Expand All @@ -266,7 +284,12 @@ function handlerBidWon(event) {
logError('Error on Adagio Analytics Adapter - handlerBidWon', error);
}

cache.updateAuction(event.auctionId, event.adUnitCode, {
const adagioAuctionCacheId = (
(event.latestTargetedAuctionId && event.latestTargetedAuctionId !== event.auctionId)
? cache.getAdagioAuctionId(event.auctionId)
: null);

cache.updateAuction(auctionId, event.adUnitCode, {
win_bdr: getAdapterNameForAlias(event.bidder),
win_mt: getMediaTypeAlias(event.mediaType),
win_ban_sz: event.mediaType === BANNER ? `${event.width}x${event.height}` : null,
Expand All @@ -280,12 +303,17 @@ function handlerBidWon(event) {
og_cpm: event.originalCpm,
og_cur: event.originalCurrency,
og_cur_rate: ogCurRateToUSD,

// cache bid id
auct_id_c: adagioAuctionCacheId,
});
sendNewBeacon(event.auctionId, event.adUnitCode);
sendNewBeacon(auctionId, event.adUnitCode);
};

function handlerAdRender(event, isSuccess) {
const { auctionId, adUnitCode } = event.bid;
const { adUnitCode } = event.bid;
let auctionId = getTargetedAuctionId(event.bid);

if (!guard.bidTracked(auctionId, adUnitCode)) {
return;
}
Expand Down
Loading