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 Adapter: Video Instream capabilities #8631

Merged
merged 14 commits into from
Jul 12, 2022
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
34 changes: 26 additions & 8 deletions modules/adnuntiusBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER } from '../src/mediaTypes.js';
import { isStr, deepAccess } from '../src/utils.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { isStr, deepAccess, logInfo } from '../src/utils.js';
import { config } from '../src/config.js';
import { getStorageManager } from '../src/storageManager.js';

const BIDDER_CODE = 'adnuntius';
const ENDPOINT_URL = 'https://ads.adnuntius.delivery/i';
const GVLID = 855;
const DEFAULT_VAST_VERSION = 'vast4'

const checkSegment = function (segment) {
if (isStr(segment)) return segment;
Expand All @@ -27,7 +28,7 @@ const getSegmentsFromOrtb = function (ortb2) {
}

const handleMeta = function () {
const storage = getStorageManager({gvlid: GVLID, bidderCode: BIDDER_CODE})
const storage = getStorageManager({ gvlid: GVLID, bidderCode: BIDDER_CODE })
let adnMeta = null
if (storage.localStorageIsEnabled()) {
adnMeta = JSON.parse(storage.getDataFromLocalStorage('adn.metaData'))
Expand All @@ -45,7 +46,7 @@ const getUsi = function (meta, ortb2, bidderRequest) {
export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
supportedMediaTypes: [BANNER],
supportedMediaTypes: [BANNER, VIDEO],
isBidRequestValid: function (bid) {
return !!(bid.bidId || (bid.params.member && bid.params.invCode));
},
Expand All @@ -67,15 +68,20 @@ export const spec = {

request.push('tzo=' + tzo)
request.push('format=json')

if (gdprApplies !== undefined) request.push('consentString=' + consentString);
if (segments.length > 0) request.push('segments=' + segments.join(','));
if (usi) request.push('userId=' + usi);
if (bidderConfig.useCookie === false) request.push('noCookies=true')
for (var i = 0; i < validBidRequests.length; i++) {
const bid = validBidRequests[i]
const network = bid.params.network || 'network';
let network = bid.params.network || 'network';
const targeting = bid.params.targeting || {};

if (bid.mediaTypes && bid.mediaTypes.video && bid.mediaTypes.video.context !== 'outstream') {
network += '_video'
}

bidRequests[network] = bidRequests[network] || [];
bidRequests[network].push(bid);

Expand All @@ -89,9 +95,11 @@ export const spec = {
const networkKeys = Object.keys(networks)
for (var j = 0; j < networkKeys.length; j++) {
const network = networkKeys[j];
const networkRequest = [...request]
if (network.indexOf('_video') > -1) { networkRequest.push('tt=' + DEFAULT_VAST_VERSION) }
requests.push({
method: 'POST',
url: ENDPOINT_URL + '?' + request.join('&'),
url: ENDPOINT_URL + '?' + networkRequest.join('&'),
data: JSON.stringify(networks[network]),
bid: bidRequests[network]
});
Expand All @@ -106,7 +114,7 @@ export const spec = {
if (adUnit.matchedAdCount >= 1) {
const ad = adUnit.ads[0];
const effectiveCpm = (ad.bid) ? ad.bid.amount * 1000 : 0;
return {
const adResponse = {
...response,
[adUnit.targetId]: {
requestId: adUnit.targetId,
Expand All @@ -122,9 +130,19 @@ export const spec = {
},
netRevenue: false,
ttl: 360,
ad: adUnit.html
}
}

if (adUnit.vastXml) {
adResponse[adUnit.targetId].vastXml = adUnit.vastXml
adResponse[adUnit.targetId].mediaType = 'video'
} else {
adResponse[adUnit.targetId].ad = adUnit.html
}

logInfo('BID', adResponse)

return adResponse
} else return response
}, {});

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

140 changes: 126 additions & 14 deletions test/spec/modules/adnuntiusBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('adnuntiusBidAdapter', function () {
const GVLID = 855;
const usi = utils.generateUUID()
const meta = [{ key: 'usi', value: usi }]
const storage = getStorageManager({gvlid: GVLID, moduleName: 'adnuntius'})
const storage = getStorageManager({ gvlid: GVLID, moduleName: 'adnuntius' })
storage.setDataInLocalStorage('adn.metaData', JSON.stringify(meta))

beforeEach(function () {
Expand All @@ -29,12 +29,13 @@ describe('adnuntiusBidAdapter', function () {

const tzo = new Date().getTimezoneOffset();
const ENDPOINT_URL = `${URL}${tzo}&format=json&userId=${usi}`;
const ENDPOINT_URL_VIDEO = `${URL}${tzo}&format=json&userId=${usi}&tt=vast4`;
const ENDPOINT_URL_NOCOOKIE = `${URL}${tzo}&format=json&userId=${usi}&noCookies=true`;
const ENDPOINT_URL_SEGMENTS = `${URL}${tzo}&format=json&segments=segment1,segment2,segment3&userId=${usi}`;
const ENDPOINT_URL_CONSENT = `${URL}${tzo}&format=json&consentString=consentString&userId=${usi}`;
const adapter = newBidder(spec);

const bidRequests = [
const bidderRequests = [
{
bidId: '123',
bidder: 'adnuntius',
Expand All @@ -46,6 +47,23 @@ describe('adnuntiusBidAdapter', function () {
}
]

const videoBidderRequest = [
{
bidId: '123',
bidder: 'adnuntius',
params: {
auId: '8b6bc',
network: 'adnuntius',
},
mediaTypes: {
video: {
playerSize: [640, 480],
context: 'instream'
}
},
}
]

const singleBidRequest = {
bid: [
{
Expand All @@ -54,6 +72,10 @@ describe('adnuntiusBidAdapter', function () {
]
}

const videoBidRequest = {
bid: videoBidderRequest
}

const serverResponse = {
body: {
'adUnits': [
Expand Down Expand Up @@ -117,6 +139,69 @@ describe('adnuntiusBidAdapter', function () {
]
}
}
const serverVideoResponse = {
body: {
'adUnits': [
{
'auId': '000000000008b6bc',
'targetId': '123',
'html': '<h1>hi!</h1>',
'matchedAdCount': 1,
'responseId': 'adn-rsp-1460129238',
'ads': [
{
'destinationUrlEsc': 'https%3A%2F%2Fdelivery.adnuntius.com%2Fc%2F52AHNuxCqxB_Y9ZP9ERWkMBPCOha4zuV3aKn5cog5jsAAAAQCtjQz9kbGWD4nuZy3q6HaHGLB4-k_fySWECIOOmHKY6iokgHNFH-U57ew_-1QHlKnFr2NT8y4QK1oU5HxnDLbYPz-GmQ3C2JyxLGpKmIb-P-3bm7HYPEreNjPdhjRG51A8NGuc4huUhns7nEUejHuOjOHE5sV1zfYxCRWRx9wPDN9EUCC7KN%3Fct%3D2501%26r%3Dhttp%253A%252F%252Fgoogle.com',
'assets': {
'image': {
'cdnId': 'https://assets.adnuntius.com/oEmZa5uYjxENfA1R692FVn6qIveFpO8wUbpyF2xSOCc.jpg',
'width': '980',
'height': '120'
}
},
'clickUrl': 'https://delivery.adnuntius.com/c/52AHNuxCqxB_Y9ZP9ERWkMBPCOha4zuV3aKn5cog5jsAAAAQCtjQz9kbGWD4nuZy3q6HaHGLB4-k_fySWECIOOmHKY6iokgHNFH-U57ew_-1QHlKnFr2NT8y4QK1oU5HxnDLbYPz-GmQ3C2JyxLGpKmIb-P-3bm7HYPEreNjPdhjRG51A8NGuc4huUhns7nEUejHuOjOHE5sV1zfYxCRWRx9wPDN9EUCC7KN',
'urls': {
'destination': 'https://delivery.adnuntius.com/c/52AHNuxCqxB_Y9ZP9ERWkMBPCOha4zuV3aKn5cog5jsAAAAQCtjQz9kbGWD4nuZy3q6HaHGLB4-k_fySWECIOOmHKY6iokgHNFH-U57ew_-1QHlKnFr2NT8y4QK1oU5HxnDLbYPz-GmQ3C2JyxLGpKmIb-P-3bm7HYPEreNjPdhjRG51A8NGuc4huUhns7nEUejHuOjOHE5sV1zfYxCRWRx9wPDN9EUCC7KN?ct=2501&r=http%3A%2F%2Fgoogle.com'
},
'urlsEsc': {
'destination': 'https%3A%2F%2Fdelivery.adnuntius.com%2Fc%2F52AHNuxCqxB_Y9ZP9ERWkMBPCOha4zuV3aKn5cog5jsAAAAQCtjQz9kbGWD4nuZy3q6HaHGLB4-k_fySWECIOOmHKY6iokgHNFH-U57ew_-1QHlKnFr2NT8y4QK1oU5HxnDLbYPz-GmQ3C2JyxLGpKmIb-P-3bm7HYPEreNjPdhjRG51A8NGuc4huUhns7nEUejHuOjOHE5sV1zfYxCRWRx9wPDN9EUCC7KN%3Fct%3D2501%26r%3Dhttp%253A%252F%252Fgoogle.com'
},
'destinationUrls': {
'destination': 'http://google.com'
},
'cpm': { 'amount': 5.0, 'currency': 'NOK' },
'bid': { 'amount': 0.005, 'currency': 'NOK' },
'cost': { 'amount': 0.005, 'currency': 'NOK' },
'impressionTrackingUrls': [],
'impressionTrackingUrlsEsc': [],
'adId': 'adn-id-1347343135',
'selectedColumn': '0',
'selectedColumnPosition': '0',
'renderedPixel': 'https://delivery.adnuntius.com/b/52AHNuxCqxB_Y9ZP9ERWkMBPCOha4zuV3aKn5cog5jsAAAAQCtjQz9kbGWD4nuZy3q6HaHGLB4-k_fySWECIOOmHKY6iokgHNFH-U57ew_-1QHlKnFr2NT8y4QK1oU5HxnDLbYPz-GmQ3C2JyxLGpKmIb-P-3bm7HYPEreNjPdhjRG51A8NGuc4huUhns7nEUejHuOjOHE5sV1zfYxCRWRx9wPDN9EUCC7KN.html',
'renderedPixelEsc': 'https%3A%2F%2Fdelivery.adnuntius.com%2Fb%2F52AHNuxCqxB_Y9ZP9ERWkMBPCOha4zuV3aKn5cog5jsAAAAQCtjQz9kbGWD4nuZy3q6HaHGLB4-k_fySWECIOOmHKY6iokgHNFH-U57ew_-1QHlKnFr2NT8y4QK1oU5HxnDLbYPz-GmQ3C2JyxLGpKmIb-P-3bm7HYPEreNjPdhjRG51A8NGuc4huUhns7nEUejHuOjOHE5sV1zfYxCRWRx9wPDN9EUCC7KN.html',
'visibleUrl': 'https://delivery.adnuntius.com/s?rt=52AHNuxCqxB_Y9ZP9ERWkMBPCOha4zuV3aKn5cog5jsAAAAQCtjQz9kbGWD4nuZy3q6HaHGLB4-k_fySWECIOOmHKY6iokgHNFH-U57ew_-1QHlKnFr2NT8y4QK1oU5HxnDLbYPz-GmQ3C2JyxLGpKmIb-P-3bm7HYPEreNjPdhjRG51A8NGuc4huUhns7nEUejHuOjOHE5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Rx9wPDN9EUCC7KN',
'creativeWidth': '980',
'creativeHeight': '120',
'creativeId': 'wgkq587vgtpchsx1',
'lineItemId': 'scyjdyv3mzgdsnpf',
'layoutId': 'sw6gtws2rdj1kwby',
'layoutName': 'Responsive image'
},

]
},
{
'auId': '000000000008b6bc',
'targetId': '456',
'matchedAdCount': 0,
'responseId': 'adn-rsp-1460129238',
}
]
}
}

describe('inherited functions', function () {
it('exists and is a function', function () {
Expand All @@ -126,13 +211,13 @@ describe('adnuntiusBidAdapter', function () {

describe('isBidRequestValid', function () {
it('should return true when required params found', function () {
expect(spec.isBidRequestValid(bidRequests[0])).to.equal(true);
expect(spec.isBidRequestValid(bidderRequests[0])).to.equal(true);
});
});

describe('buildRequests', function () {
it('Test requests', function () {
const request = spec.buildRequests(bidRequests, {});
const request = spec.buildRequests(bidderRequests, {});
expect(request.length).to.equal(1);
expect(request[0]).to.have.property('bid');
const bid = request[0].bid[0]
Expand All @@ -143,6 +228,16 @@ describe('adnuntiusBidAdapter', function () {
expect(request[0].data).to.equal('{\"adUnits\":[{\"auId\":\"8b6bc\",\"targetId\":\"123\"}],\"metaData\":{\"usi\":\"' + usi + '\"}}');
});

it('Test Video requests', function () {
const request = spec.buildRequests(videoBidderRequest, {});
expect(request.length).to.equal(1);
expect(request[0]).to.have.property('bid');
const bid = request[0].bid[0]
expect(bid).to.have.property('bidId');
expect(request[0]).to.have.property('url');
expect(request[0].url).to.equal(ENDPOINT_URL_VIDEO);
});

it('should pass segments if available in config', function () {
const ortb2 = {
user: {
Expand All @@ -157,7 +252,7 @@ describe('adnuntiusBidAdapter', function () {
}
};

const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidRequests, {ortb2}));
const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, { ortb2 }));
expect(request.length).to.equal(1);
expect(request[0]).to.have.property('url')
expect(request[0].url).to.equal(ENDPOINT_URL_SEGMENTS);
Expand All @@ -179,7 +274,7 @@ describe('adnuntiusBidAdapter', function () {
}
};

const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidRequests, {ortb2}));
const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, { ortb2 }));
expect(request.length).to.equal(1);
expect(request[0]).to.have.property('url')
expect(request[0].url).to.equal(ENDPOINT_URL_SEGMENTS);
Expand All @@ -188,14 +283,14 @@ describe('adnuntiusBidAdapter', function () {

describe('user privacy', function () {
it('should send GDPR Consent data if gdprApplies', function () {
let request = spec.buildRequests(bidRequests, { gdprConsent: { gdprApplies: true, consentString: 'consentString' } });
let request = spec.buildRequests(bidderRequests, { gdprConsent: { gdprApplies: true, consentString: 'consentString' } });
expect(request.length).to.equal(1);
expect(request[0]).to.have.property('url')
expect(request[0].url).to.equal(ENDPOINT_URL_CONSENT);
});

it('should not send GDPR Consent data if gdprApplies equals undefined', function () {
let request = spec.buildRequests(bidRequests, { gdprConsent: { gdprApplies: undefined, consentString: 'consentString' } });
let request = spec.buildRequests(bidderRequests, { gdprConsent: { gdprApplies: undefined, consentString: 'consentString' } });
expect(request.length).to.equal(1);
expect(request[0]).to.have.property('url')
expect(request[0].url).to.equal(ENDPOINT_URL);
Expand All @@ -215,7 +310,7 @@ describe('adnuntiusBidAdapter', function () {
}
}

const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidRequests, {ortb2}));
const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, { ortb2 }));
expect(request.length).to.equal(1);
expect(request[0]).to.have.property('url')
expect(request[0].url).to.equal(ENDPOINT_URL_SEGMENTS);
Expand All @@ -237,7 +332,7 @@ describe('adnuntiusBidAdapter', function () {
}
};

const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidRequests, {ortb2}));
const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, { ortb2 }));
expect(request.length).to.equal(1);
expect(request[0]).to.have.property('url')
expect(request[0].url).to.equal(ENDPOINT_URL_SEGMENTS);
Expand All @@ -250,7 +345,7 @@ describe('adnuntiusBidAdapter', function () {
}
};

const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidRequests, {ortb2}));
const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, { ortb2 }));
expect(request.length).to.equal(1);
expect(request[0]).to.have.property('url')
expect(request[0].url).to.equal(ENDPOINT_URL);
Expand All @@ -259,14 +354,14 @@ describe('adnuntiusBidAdapter', function () {

describe('user privacy', function () {
it('should send GDPR Consent data if gdprApplies', function () {
let request = spec.buildRequests(bidRequests, { gdprConsent: { gdprApplies: true, consentString: 'consentString' } });
let request = spec.buildRequests(bidderRequests, { gdprConsent: { gdprApplies: true, consentString: 'consentString' } });
expect(request.length).to.equal(1);
expect(request[0]).to.have.property('url')
expect(request[0].url).to.equal(ENDPOINT_URL_CONSENT);
});

it('should not send GDPR Consent data if gdprApplies equals undefined', function () {
let request = spec.buildRequests(bidRequests, { gdprConsent: { gdprApplies: undefined, consentString: 'consentString' } });
let request = spec.buildRequests(bidderRequests, { gdprConsent: { gdprApplies: undefined, consentString: 'consentString' } });
expect(request.length).to.equal(1);
expect(request[0]).to.have.property('url')
expect(request[0].url).to.equal(ENDPOINT_URL);
Expand All @@ -282,7 +377,7 @@ describe('adnuntiusBidAdapter', function () {
}
});

const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidRequests, {}));
const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, {}));
expect(request.length).to.equal(1);
expect(request[0]).to.have.property('url')
expect(request[0].url).to.equal(ENDPOINT_URL_NOCOOKIE);
Expand All @@ -307,4 +402,21 @@ describe('adnuntiusBidAdapter', function () {
expect(interpretedResponse[0].ttl).to.equal(360);
});
});
describe('interpretVideoResponse', function () {
it('should return valid response when passed valid server response', function () {
const interpretedResponse = spec.interpretResponse(serverVideoResponse, videoBidRequest);
const ad = serverVideoResponse.body.adUnits[0].ads[0]
expect(interpretedResponse).to.have.lengthOf(1);
expect(interpretedResponse[0].cpm).to.equal(ad.cpm.amount);
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);
expect(interpretedResponse[0].currency).to.equal(ad.bid.currency);
expect(interpretedResponse[0].netRevenue).to.equal(false);
expect(interpretedResponse[0].meta).to.have.property('advertiserDomains');
expect(interpretedResponse[0].meta.advertiserDomains).to.have.lengthOf(1);
expect(interpretedResponse[0].meta.advertiserDomains[0]).to.equal('google.com');
expect(interpretedResponse[0].vastXml).to.equal(serverVideoResponse.body.adUnits[0].vastXml);
});
});
});