Skip to content

Commit

Permalink
Adyoulike bid adapter - improvements on Native case (#6831)
Browse files Browse the repository at this point in the history
* add required clickurl in every native adrequest

* allows the native response to be given as is to prebid if possible

* add unit tests on new Native case
  • Loading branch information
guiann authored May 27, 2021
1 parent 9013e55 commit 3cbdf86
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 84 deletions.
101 changes: 52 additions & 49 deletions modules/adyoulikeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export const spec = {
if (nativeReq.type === 'image') {
nativeReq = Object.assign({}, NATIVE_IMAGE, nativeReq);
}
// click url is always mandatory even if not specified by publisher
nativeReq.clickUrl = {
required: true
};
accumulator[bidReq.bidId].Native = nativeReq;
}
if (mediatype === VIDEO) {
Expand Down Expand Up @@ -329,6 +333,9 @@ function getVideoAd(response) {
}

function getNativeAssets(response, nativeConfig) {
if (typeof response.Native === 'object') {
return response.Native;
}
const native = {};

var adJson = {};
Expand Down Expand Up @@ -362,59 +369,55 @@ function getNativeAssets(response, nativeConfig) {
}

Object.keys(nativeConfig).map(function(key, index) {
if (typeof response.Native === 'object') {
native[key] = response.Native[key];
} else {
switch (key) {
case 'title':
native[key] = textsJson.TITLE;
break;
case 'body':
native[key] = textsJson.DESCRIPTION;
break;
case 'cta':
native[key] = textsJson.CALLTOACTION;
break;
case 'sponsoredBy':
native[key] = adJson.Content.Preview.Sponsor.Name;
break;
case 'image':
// main image requested size
const imgSize = nativeConfig.image.sizes || [];
if (!imgSize.length) {
imgSize[0] = response.Width || 300;
imgSize[1] = response.Height || 250;
switch (key) {
case 'title':
native[key] = textsJson.TITLE;
break;
case 'body':
native[key] = textsJson.DESCRIPTION;
break;
case 'cta':
native[key] = textsJson.CALLTOACTION;
break;
case 'sponsoredBy':
native[key] = adJson.Content.Preview.Sponsor.Name;
break;
case 'image':
// main image requested size
const imgSize = nativeConfig.image.sizes || [];
if (!imgSize.length) {
imgSize[0] = response.Width || 300;
imgSize[1] = response.Height || 250;
}

native[key] = {
url: getImageUrl(adJson, adJson.Content.Preview.Thumbnail.Image, imgSize[0], imgSize[1]),
width: imgSize[0],
height: imgSize[1]
};
break;
case 'icon':
if (adJson.HasSponsorImage) {
// icon requested size
const iconSize = nativeConfig.icon.sizes || [];
if (!iconSize.length) {
iconSize[0] = 50;
iconSize[1] = 50;
}

native[key] = {
url: getImageUrl(adJson, adJson.Content.Preview.Thumbnail.Image, imgSize[0], imgSize[1]),
width: imgSize[0],
height: imgSize[1]
url: getImageUrl(adJson, adJson.Content.Preview.Sponsor.Logo.Resource, iconSize[0], iconSize[1]),
width: iconSize[0],
height: iconSize[1]
};
break;
case 'icon':
if (adJson.HasSponsorImage) {
// icon requested size
const iconSize = nativeConfig.icon.sizes || [];
if (!iconSize.length) {
iconSize[0] = 50;
iconSize[1] = 50;
}

native[key] = {
url: getImageUrl(adJson, adJson.Content.Preview.Sponsor.Logo.Resource, iconSize[0], iconSize[1]),
width: iconSize[0],
height: iconSize[1]
};
}
break;
case 'privacyIcon':
native[key] = getImageUrl(adJson, adJson.Content.Preview.Credit.Logo.Resource, 25, 25);
break;
case 'privacyLink':
native[key] = adJson.Content.Preview.Credit.Url;
break;
}
}
break;
case 'privacyIcon':
native[key] = getImageUrl(adJson, adJson.Content.Preview.Credit.Logo.Resource, 25, 25);
break;
case 'privacyLink':
native[key] = adJson.Content.Preview.Credit.Url;
break;
}
});

Expand Down
113 changes: 78 additions & 35 deletions test/spec/modules/adyoulikeBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,74 @@ describe('Adyoulike Adapter', function () {
'Height': 600,
}
];

const responseWithSingleNative = [{
'BidID': 'bid_id_0',
'Placement': 'placement_0',
'Native': {
'body': 'Considérant l\'extrémité conjoncturelle, il serait bon d\'anticiper toutes les voies de bon sens.',
'cta': 'Click here to learn more',
'clickUrl': 'https://tracking.omnitagjs.com/tracking/ar?event_kind=CLICK&attempt=a11a121205932e75e622af275681965d&campaign=f1c80d4bb5643c222ae8de75e9b2f991&url=https%3A%2F%2Fwww.w3.org%2FPeople%2Fmimasa%2Ftest%2Fxhtml%2Fentities%2Fentities-11.xhtml%23lat1',
'image': {
'height': 600,
'url': 'https://blobs.omnitagjs.com/blobs/f1/f1c80d4bb5643c22/fd4362d35bb174d6f1c80d4bb5643c22',
'width': 300
},
'privacyIcon': 'https://fo-static.omnitagjs.com/fo-static/native/images/info-ayl.png',
'privacyLink': 'https://blobs.omnitagjs.com/adchoice/',
'sponsoredBy': 'QA Team',
'title': 'Adserver Traffic Redirect Internal',
'impressionTrackers': [
'https://testPixelIMP.com/fake',
'https://tracking.omnitagjs.com/tracking/pixel?event_kind=IMPRESSION&attempt=a11a121205932e75e622af275681965d&campaign=f1c80d4bb5643c222ae8de75e9b2f991',
'https://tracking.omnitagjs.com/tracking/pixel?event_kind=INSERTION&attempt=a11a121205932e75e622af275681965d&campaign=f1c80d4bb5643c222ae8de75e9b2f991',
],
'javascriptTrackers': [
'https://testJsIMP.com/fake.js'
],
'clickTrackers': [
'https://testPixelCLICK.com/fake'
]
},
'Price': 0.5,
'Height': 600,
}];

const nativeResult = [{
cpm: 0.5,
creativeId: undefined,
currency: 'USD',
netRevenue: true,
requestId: 'bid_id_0',
ttl: 3600,
mediaType: 'native',
native: {
body: 'Considérant l\'extrémité conjoncturelle, il serait bon d\'anticiper toutes les voies de bon sens.',
clickTrackers: [
'https://testPixelCLICK.com/fake'
],
clickUrl: 'https://tracking.omnitagjs.com/tracking/ar?event_kind=CLICK&attempt=a11a121205932e75e622af275681965d&campaign=f1c80d4bb5643c222ae8de75e9b2f991&url=https%3A%2F%2Fwww.w3.org%2FPeople%2Fmimasa%2Ftest%2Fxhtml%2Fentities%2Fentities-11.xhtml%23lat1',
cta: 'Click here to learn more',
image: {
height: 600,
url: 'https://blobs.omnitagjs.com/blobs/f1/f1c80d4bb5643c22/fd4362d35bb174d6f1c80d4bb5643c22',
width: 300,
},
impressionTrackers: [
'https://testPixelIMP.com/fake',
'https://tracking.omnitagjs.com/tracking/pixel?event_kind=IMPRESSION&attempt=a11a121205932e75e622af275681965d&campaign=f1c80d4bb5643c222ae8de75e9b2f991',
'https://tracking.omnitagjs.com/tracking/pixel?event_kind=INSERTION&attempt=a11a121205932e75e622af275681965d&campaign=f1c80d4bb5643c222ae8de75e9b2f991'
],
javascriptTrackers: [
'https://testJsIMP.com/fake.js'
],
privacyIcon: 'https://fo-static.omnitagjs.com/fo-static/native/images/info-ayl.png',
privacyLink: 'https://blobs.omnitagjs.com/adchoice/',
sponsoredBy: 'QA Team',
title: 'Adserver Traffic Redirect Internal',
}
}];

const responseWithMultiplePlacements = [
{
'BidID': 'bid_id_0',
Expand Down Expand Up @@ -569,46 +637,21 @@ describe('Adyoulike Adapter', function () {
});

it('receive reponse with Native ad', function () {
serverResponse.body = responseWithSinglePlacement;
serverResponse.body = responseWithSingleNative;
let result = spec.interpretResponse(serverResponse, {data: '{"Bids":' + JSON.stringify(sentBidNative) + '}'});

expect(result.length).to.equal(1);

expect(result).to.deep.equal([{
cpm: 0.5,
creativeId: undefined,
currency: 'USD',
netRevenue: true,
requestId: 'bid_id_0',
ttl: 3600,
mediaType: 'native',
native: {
body: 'Considérant l\'extrémité conjoncturelle, il serait bon d\'anticiper toutes les voies de bon sens.',
clickTrackers: [
'https://testPixelCLICK.com/fake'
],
clickUrl: 'https://tracking.omnitagjs.com/tracking/ar?event_kind=CLICK&attempt=a11a121205932e75e622af275681965d&campaign=f1c80d4bb5643c222ae8de75e9b2f991&url=https%3A%2F%2Fwww.w3.org%2FPeople%2Fmimasa%2Ftest%2Fxhtml%2Fentities%2Fentities-11.xhtml%23lat1',
cta: 'Click here to learn more',
image: {
height: 600,
url: 'https://blobs.omnitagjs.com/blobs/f1/f1c80d4bb5643c22/fd4362d35bb174d6f1c80d4bb5643c22',
width: 300,
},
impressionTrackers: [
'https://testPixelIMP.com/fake',
'https://tracking.omnitagjs.com/tracking/pixel?event_kind=IMPRESSION&attempt=a11a121205932e75e622af275681965d&campaign=f1c80d4bb5643c222ae8de75e9b2f991',
'https://tracking.omnitagjs.com/tracking/pixel?event_kind=INSERTION&attempt=a11a121205932e75e622af275681965d&campaign=f1c80d4bb5643c222ae8de75e9b2f991'
],
javascriptTrackers: [
'https://testJsIMP.com/fake.js'
],
privacyIcon: 'https://fo-static.omnitagjs.com/fo-static/native/images/info-ayl.png',
privacyLink: 'https://blobs.omnitagjs.com/adchoice/',
sponsoredBy: 'QA Team',
title: 'Adserver Traffic Redirect Internal',
}
expect(result).to.deep.equal(nativeResult);
});

it('receive reponse with Native from ad markup', function () {
serverResponse.body = responseWithSinglePlacement;
let result = spec.interpretResponse(serverResponse, {data: '{"Bids":' + JSON.stringify(sentBidNative) + '}'});

expect(result.length).to.equal(1);

}]);
expect(result).to.deep.equal(nativeResult);
});
});
});

0 comments on commit 3cbdf86

Please sign in to comment.