Skip to content

Commit

Permalink
Sharethrough Bid Adapter: support Fledge + refine video-placement req…
Browse files Browse the repository at this point in the history
… logic (#11048)

* Modify value-setting logic for video-placement reqs

* Updating value-setting logic in `buildRequests()` method so that `placement` property in video requests does not possibly get overridden to 1 as a value if `plcmt` is also present as a property.  (Current logic sets `placement` at 1 if `context` is "instream".)

* Support for Fledge

* Adding updates to our unit tests and the relevant methods in our bid adapter to make it ready, eventually, for Fledge auctions.
  • Loading branch information
jefftmahoney authored Feb 7, 2024
1 parent 88b7477 commit 36906f7
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
30 changes: 27 additions & 3 deletions modules/sharethroughBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { deepAccess, generateUUID, inIframe } from '../src/utils.js';
import { deepAccess, generateUUID, inIframe, mergeDeep } from '../src/utils.js';

const VERSION = '4.3.0';
const BIDDER_CODE = 'sharethrough';
Expand Down Expand Up @@ -104,6 +104,10 @@ export const sharethroughAdapterSpec = {

const videoRequest = deepAccess(bidReq, 'mediaTypes.video');

if (bidderRequest.fledgeEnabled && bidReq.mediaTypes.banner) {
mergeDeep(impression, { ext: { ae: 1 } }); // ae = auction environment; if this is 1, ad server knows we have a fledge auction
}

if (videoRequest) {
// default playerSize, only change this if we know width and height are properly defined in the request
let [w, h] = [640, 360];
Expand All @@ -116,6 +120,14 @@ export const sharethroughAdapterSpec = {
[w, h] = videoRequest.playerSize[0];
}

const getVideoPlacementValue = (vidReq) => {
if (vidReq.plcmt) {
return vidReq.placement;
} else {
return vidReq.context === 'instream' ? 1 : +deepAccess(vidReq, 'placement', 4);
}
};

impression.video = {
pos: nullish(videoRequest.pos, 0),
topframe: inIframe() ? 0 : 1,
Expand All @@ -132,7 +144,8 @@ export const sharethroughAdapterSpec = {
startdelay: nullish(videoRequest.startdelay, 0),
skipmin: nullish(videoRequest.skipmin, 0),
skipafter: nullish(videoRequest.skipafter, 0),
placement: videoRequest.context === 'instream' ? 1 : +deepAccess(videoRequest, 'placement', 4),
placement: getVideoPlacementValue(videoRequest),
plcmt: videoRequest.plcmt ? videoRequest.plcmt : null,
};

if (videoRequest.delivery) impression.video.delivery = videoRequest.delivery;
Expand Down Expand Up @@ -179,7 +192,9 @@ export const sharethroughAdapterSpec = {
return [];
}

return body.seatbid[0].bid.map((bid) => {
const fledgeAuctionEnabled = body.ext?.auctionConfigs;

const bidsFromExchange = body.seatbid[0].bid.map((bid) => {
// Spec: https://docs.prebid.org/dev-docs/bidder-adaptor.html#interpreting-the-response
const response = {
requestId: bid.impid,
Expand Down Expand Up @@ -219,6 +234,15 @@ export const sharethroughAdapterSpec = {

return response;
});

if (fledgeAuctionEnabled) {
return {
bids: bidsFromExchange,
fledgeAuctionConfigs: body.ext?.auctionConfigs || {},
};
} else {
return bidsFromExchange;
}
},

getUserSyncs: (syncOptions, serverResponses) => {
Expand Down
37 changes: 37 additions & 0 deletions test/spec/modules/sharethroughBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,27 @@ describe('sharethrough adapter spec', function () {

expect(videoImp.placement).to.equal(4);
});

it('should not override "placement" value if "plcmt" prop is present', () => {
// ASSEMBLE
const ARBITRARY_PLACEMENT_VALUE = 99;
const ARBITRARY_PLCMT_VALUE = 100;

bidRequests[1].mediaTypes.video.context = 'instream';
bidRequests[1].mediaTypes.video.placement = ARBITRARY_PLACEMENT_VALUE;

// adding "plcmt" property - this should prevent "placement" prop
// from getting overridden to 1
bidRequests[1].mediaTypes.video['plcmt'] = ARBITRARY_PLCMT_VALUE;

// ACT
const builtRequest = spec.buildRequests(bidRequests, bidderRequest)[1];
const videoImp = builtRequest.data.imp[0].video;

// ASSERT
expect(videoImp.placement).to.equal(ARBITRARY_PLACEMENT_VALUE);
expect(videoImp.plcmt).to.equal(ARBITRARY_PLCMT_VALUE);
});
});
});

Expand Down Expand Up @@ -692,6 +713,22 @@ describe('sharethrough adapter spec', function () {
expect(openRtbReq.regs.ext.gpp_sid).to.equal(firstPartyData.regs.gpp_sid);
});
});

describe('fledge', () => {
it('should attach "ae" as a property to the request if 1) fledge auctions are enabled, and 2) request is display (only supporting display for now)', () => {
// ASSEMBLE
const EXPECTED_AE_VALUE = 1;

// ACT
bidderRequest['fledgeEnabled'] = true;
const builtRequests = spec.buildRequests(bidRequests, bidderRequest);
const ACTUAL_AE_VALUE = builtRequests[0].data.imp[0].ext.ae;

// ASSERT
expect(ACTUAL_AE_VALUE).to.equal(EXPECTED_AE_VALUE);
expect(builtRequests[1].data.imp[0].ext.ae).to.be.undefined;
});
});
});

describe('interpretResponse', function () {
Expand Down

0 comments on commit 36906f7

Please sign in to comment.