Skip to content

Commit

Permalink
Adnuntius Bid Adapter: native added (prebid#9330)
Browse files Browse the repository at this point in the history
* package lock fix.

* Add dimensions to prebid.

* Adnuntius Bid Adapter. Added native as a media type.
  • Loading branch information
mikael-lundin authored and jorgeluisrocha committed May 18, 2023
1 parent 937c876 commit 952a83d
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 3 deletions.
41 changes: 38 additions & 3 deletions modules/adnuntiusBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { BANNER, VIDEO, NATIVE } from '../src/mediaTypes.js';
import { isStr, deepAccess, logInfo } from '../src/utils.js';
import { config } from '../src/config.js';
import { getStorageManager } from '../src/storageManager.js';
Expand All @@ -8,6 +8,7 @@ const BIDDER_CODE = 'adnuntius';
const ENDPOINT_URL = 'https://ads.adnuntius.delivery/i';
const GVLID = 855;
const DEFAULT_VAST_VERSION = 'vast4'
const DEFAULT_NATIVE = 'native'

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

function createNative(ad) {
const native = {};
const assets = ad.assets
native.title = ad.text.title.content;
native.image = {
url: assets.image.cdnId,
height: assets.image.height,
width: assets.image.width,
};
if (assets.icon) {
native.icon = {
url: assets.icon.cdnId,
height: assets.icon.height,
width: assets.icon.width,
};
}

native.sponsoredBy = ad.text.sponsoredBy?.content || '';
native.body = ad.text.body?.content || '';
native.cta = ad.text.cta?.content || '';
native.clickUrl = ad.destinationUrls.destination || '';
native.impressionTrackers = ad.impressionTrackingUrls || [ad.renderedPixel];

return native;
}

const handleMeta = function () {
const storage = getStorageManager({ gvlid: GVLID, bidderCode: BIDDER_CODE })
let adnMeta = null
Expand All @@ -46,7 +73,7 @@ const getUsi = function (meta, ortb2, bidderRequest) {
export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
supportedMediaTypes: [BANNER, VIDEO],
supportedMediaTypes: [BANNER, VIDEO, NATIVE],
isBidRequestValid: function (bid) {
return !!(bid.bidId || (bid.params.member && bid.params.invCode));
},
Expand Down Expand Up @@ -82,6 +109,10 @@ export const spec = {
network += '_video'
}

if (bid.mediaTypes && bid.mediaTypes.native) {
network += '_native'
}

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

Expand All @@ -99,6 +130,7 @@ export const spec = {
const network = networkKeys[j];
const networkRequest = [...request]
if (network.indexOf('_video') > -1) { networkRequest.push('tt=' + DEFAULT_VAST_VERSION) }
if (network.indexOf('_native') > -1) { networkRequest.push('tt=' + DEFAULT_NATIVE) }
requests.push({
method: 'POST',
url: ENDPOINT_URL + '?' + networkRequest.join('&'),
Expand Down Expand Up @@ -137,7 +169,10 @@ export const spec = {

if (adUnit.vastXml) {
adResponse[adUnit.targetId].vastXml = adUnit.vastXml
adResponse[adUnit.targetId].mediaType = 'video'
adResponse[adUnit.targetId].mediaType = VIDEO
} else if (ad.assets && ad.assets.image && ad.text && ad.text.title && ad.text.body && ad.destinationUrls && ad.destinationUrls.destination) {
adResponse[adUnit.targetId].native = createNative(ad);
adResponse[adUnit.targetId].mediaType = NATIVE;
} else {
adResponse[adUnit.targetId].ad = adUnit.html
}
Expand Down
122 changes: 122 additions & 0 deletions test/spec/modules/adnuntiusBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,30 @@ describe('adnuntiusBidAdapter', function () {
}
]

const nativeBidderRequest = [
{
bidId: '123',
bidder: 'adnuntius',
params: {
auId: '8b6bc',
network: 'adnuntius',
},
mediaTypes: {
native: {
title: {
required: true
},
image: {
required: true
},
body: {
required: true
}
}
},
}
]

const singleBidRequest = {
bid: [
{
Expand All @@ -83,6 +107,10 @@ describe('adnuntiusBidAdapter', function () {
bid: videoBidderRequest
}

const nativeBidRequest = {
bid: nativeBidderRequest
}

const serverResponse = {
body: {
'adUnits': [
Expand Down Expand Up @@ -209,6 +237,83 @@ describe('adnuntiusBidAdapter', function () {
]
}
}
const serverNativeResponse = {
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/K9rfXC6wJvgVuy4Fbt5P8oEEGXme9ZaP8BNDzz3OMGQ.jpg',
'width': '300',
'height': '250'
}
},
'text': {
'body': {
'content': 'Testing Native ad from Adnuntius',
'length': '32',
'minLength': '0',
'maxLength': '100'
},
'title': {
'content': 'Native Ad',
'length': '9',
'minLength': '5',
'maxLength': '100'
}
},
'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-3bm7HYPEreNjPdhjRG51A8NGuc4huUhns7nEUejHuOjOHE5sV1zfYxCRWRx9wPDN9EUCC7KN',
'visibleUrlEsc': 'https%3A%2F%2Fdelivery.adnuntius.com%2Fs%3Frt%3D52AHNuxCqxB_Y9ZP9ERWkMBPCOha4zuV3aKn5cog5jsAAAAQCtjQz9kbGWD4nuZy3q6HaHGLB4-k_fySWECIOOmHKY6iokgHNFH-U57ew_-1QHlKnFr2NT8y4QK1oU5HxnDLbYPz-GmQ3C2JyxLGpKmIb-P-3bm7HYPEreNjPdhjRG51A8NGuc4huUhns7nEUejHuOjOHE5sV1zfYxCRWRx9wPDN9EUCC7KN',
'viewUrl': 'https://delivery.adnuntius.com/v?rt=52AHNuxCqxB_Y9ZP9ERWkMBPCOha4zuV3aKn5cog5jsAAAAQCtjQz9kbGWD4nuZy3q6HaHGLB4-k_fySWECIOOmHKY6iokgHNFH-U57ew_-1QHlKnFr2NT8y4QK1oU5HxnDLbYPz-GmQ3C2JyxLGpKmIb-P-3bm7HYPEreNjPdhjRG51A8NGuc4huUhns7nEUejHuOjOHE5sV1zfYxCRWRx9wPDN9EUCC7KN',
'viewUrlEsc': 'https%3A%2F%2Fdelivery.adnuntius.com%2Fv%3Frt%3D52AHNuxCqxB_Y9ZP9ERWkMBPCOha4zuV3aKn5cog5jsAAAAQCtjQz9kbGWD4nuZy3q6HaHGLB4-k_fySWECIOOmHKY6iokgHNFH-U57ew_-1QHlKnFr2NT8y4QK1oU5HxnDLbYPz-GmQ3C2JyxLGpKmIb-P-3bm7HYPEreNjPdhjRG51A8NGuc4huUhns7nEUejHuOjOHE5sV1zfYxCRWRx9wPDN9EUCC7KN',
'rt': '52AHNuxCqxB_Y9ZP9ERWkMBPCOha4zuV3aKn5cog5jsAAAAQCtjQz9kbGWD4nuZy3q6HaHGLB4-k_fySWECIOOmHKY6iokgHNFH-U57ew_-1QHlKnFr2NT8y4QK1oU5HxnDLbYPz-GmQ3C2JyxLGpKmIb-P-3bm7HYPEreNjPdhjRG51A8NGuc4huUhns7nEUejHuOjOHE5sV1zfYxCRWRx9wPDN9EUCC7KN',
'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 Down Expand Up @@ -426,4 +531,21 @@ describe('adnuntiusBidAdapter', function () {
expect(interpretedResponse[0].vastXml).to.equal(serverVideoResponse.body.adUnits[0].vastXml);
});
});
describe('interpretNativeResponse', function () {
it('should return valid response when passed valid server response', function () {
const interpretedResponse = spec.interpretResponse(serverNativeResponse, nativeBidRequest);
const ad = serverNativeResponse.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].native.body).to.equal(serverNativeResponse.body.adUnits[0].ads[0].text.body.content);
});
});
});

0 comments on commit 952a83d

Please sign in to comment.