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

Adnuntius Bid Adaptor: Enable choosing bidType for cpm bid #10446

Merged
merged 1 commit into from
Sep 13, 2023
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
95 changes: 95 additions & 0 deletions integrationExamples/gpt/adnuntius_example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<html>
<head>
<script async src="https://www.googletagservices.com/tag/js/gpt.js"></script>
<script async src="../../build/dev/prebid.js"></script>
<script>
var FAILSAFE_TIMEOUT = 3000;

var adUnits = [
{
code: 'div-gpt-ad-1683695049516-0',
mediaTypes: {
banner: {
sizes: [[320, 320]]
}
},
bids: [{
bidder: 'adnuntius',
params: {
auId: "201208",
network: "adnuntius",
bidType: 'netBid'
}
}]
},
];
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(function() {
googletag.pubads().disableInitialLoad();
});

var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];

pbjs.que.push(function() {
pbjs.setConfig({
enableSendAllBids: true,
targetingControls: {
alwaysIncludeDeals: true
},
userSync: {
syncEnabled: false
}
});

pbjs.setBidderConfig({
bidders: ['adnuntius'],
config: {
bidType: 'netBid'
}
});

pbjs.addAdUnits(adUnits);
pbjs.requestBids({bidsBackHandler: initAdserver});
});

function initAdserver() {
if (pbjs.initAdserverSet) return;
pbjs.initAdserverSet = true;
googletag.cmd.push(function() {
pbjs.que.push(function() {
pbjs.setTargetingForGPTAsync('div-gpt-ad-1683695049516-0');
googletag.pubads().refresh();
});
});
}

// in case PBJS doesn't load
setTimeout(function() {
initAdserver();
}, FAILSAFE_TIMEOUT);

window.googletag = window.googletag || {cmd: []};
googletag.cmd.push(function() {
googletag.defineSlot('/19660636/320x320', [320, 320], 'div-gpt-ad-1683695049516-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
</head>
<body>
<h2>Adnuntius Prebid Adaptor Test</h2>
<h5>Ad Slot 1</h5>

<!-- /19660636/320x320 -->
<div id='div-gpt-ad-1683695049516-0' style='min-width: 320px; min-height: 320px;'>
<script>
googletag.cmd.push(function() {
googletag.display('div-gpt-ad-1683695049516-0');
});
</script>
</div>

</body>
</html>
16 changes: 15 additions & 1 deletion modules/adnuntiusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const ENDPOINT_URL_EUROPE = 'https://europe.delivery.adnuntius.com/i';
const GVLID = 855;
const DEFAULT_VAST_VERSION = 'vast4'
const MAXIMUM_DEALS_LIMIT = 5;
const VALID_BID_TYPES = ['netBid', 'grossBid'];

const checkSegment = function (segment) {
if (isStr(segment)) return segment;
Expand Down Expand Up @@ -48,6 +49,10 @@ const getUsi = function (meta, ortb2, bidderRequest) {
return usi
}

const validateBidType = function(bidTypeOption) {
return VALID_BID_TYPES.indexOf(bidTypeOption || '') > -1 ? bidTypeOption : 'bid';
}

const AU_ID_REGEX = new RegExp('^[0-9A-Fa-f]{1,20}$');

export const spec = {
Expand Down Expand Up @@ -126,6 +131,15 @@ export const spec = {
interpretResponse: function (serverResponse, bidRequest) {
const adUnits = serverResponse.body.adUnits;

let validatedBidType = validateBidType(config.getConfig().bidType);
if (bidRequest.bid) {
bidRequest.bid.forEach(b => {
if (b.params && b.params.bidType) {
validatedBidType = validateBidType(b.params.bidType);
}
});
}

function buildAdResponse(bidderCode, ad, adUnit, dealCount) {
const destinationUrls = ad.destinationUrls || {};
const advertiserDomains = [];
Expand All @@ -135,7 +149,7 @@ export const spec = {
const adResponse = {
bidderCode: bidderCode,
requestId: adUnit.targetId,
cpm: (ad.bid) ? ad.bid.amount * 1000 : 0,
cpm: ad[validatedBidType] ? ad[validatedBidType].amount * 1000 : 0,
width: Number(ad.creativeWidth),
height: Number(ad.creativeHeight),
creativeId: ad.creativeId,
Expand Down
24 changes: 19 additions & 5 deletions test/spec/modules/adnuntiusBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ describe('adnuntiusBidAdapter', function() {

const videoBidRequest = {
bid: videoBidderRequest,
bidder: 'adnuntius'
bidder: 'adnuntius',
params: {
bidType: 'justsomestuff-error-handling'
}
}

const deals = [
Expand Down Expand Up @@ -749,12 +752,20 @@ describe('adnuntiusBidAdapter', function() {

describe('interpretResponse', function() {
it('should return valid response when passed valid server response', function() {
const interpretedResponse = spec.interpretResponse(serverResponse, singleBidRequest);
config.setBidderConfig({
bidders: ['adnuntius'],
config: {
bidType: 'netBid',
maxDeals: 1
}
});

const interpretedResponse = config.runWithBidder('adnuntius', () => spec.interpretResponse(serverResponse, singleBidRequest));
expect(interpretedResponse).to.have.lengthOf(2);

const deal = serverResponse.body.adUnits[0].deals[0];
expect(interpretedResponse[0].bidderCode).to.equal('adnuntius');
expect(interpretedResponse[0].cpm).to.equal(deal.bid.amount * 1000);
expect(interpretedResponse[0].cpm).to.equal(deal.netBid.amount * 1000);
expect(interpretedResponse[0].width).to.equal(Number(deal.creativeWidth));
expect(interpretedResponse[0].height).to.equal(Number(deal.creativeHeight));
expect(interpretedResponse[0].creativeId).to.equal(deal.creativeId);
Expand All @@ -770,7 +781,7 @@ describe('adnuntiusBidAdapter', function() {

const ad = serverResponse.body.adUnits[0].ads[0];
expect(interpretedResponse[1].bidderCode).to.equal('adnuntius');
expect(interpretedResponse[1].cpm).to.equal(ad.bid.amount * 1000);
expect(interpretedResponse[1].cpm).to.equal(ad.netBid.amount * 1000);
expect(interpretedResponse[1].width).to.equal(Number(ad.creativeWidth));
expect(interpretedResponse[1].height).to.equal(Number(ad.creativeHeight));
expect(interpretedResponse[1].creativeId).to.equal(ad.creativeId);
Expand Down Expand Up @@ -808,6 +819,9 @@ describe('adnuntiusBidAdapter', function() {
{
bidder: 'adn-alt',
bidId: 'adn-0000000000000551',
params: {
bidType: 'netBid'
}
}
]
};
Expand All @@ -818,7 +832,7 @@ describe('adnuntiusBidAdapter', function() {

const ad = serverResponse.body.adUnits[0].ads[0];
expect(interpretedResponse[0].bidderCode).to.equal('adn-alt');
expect(interpretedResponse[0].cpm).to.equal(ad.bid.amount * 1000);
expect(interpretedResponse[0].cpm).to.equal(ad.netBid.amount * 1000);
expect(interpretedResponse[0].width).to.equal(Number(ad.creativeWidth));
expect(interpretedResponse[0].height).to.equal(Number(ad.creativeHeight));
expect(interpretedResponse[0].creativeId).to.equal(ad.creativeId);
Expand Down