Skip to content

Commit

Permalink
Smaato: Change server response type (#11450)
Browse files Browse the repository at this point in the history
  • Loading branch information
Enigo committed May 8, 2024
1 parent 3870124 commit 5438945
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 102 deletions.
46 changes: 11 additions & 35 deletions modules/smaatoBidAdapter.js
Expand Up @@ -19,7 +19,7 @@ import {ortbConverter} from '../libraries/ortbConverter/converter.js';

const BIDDER_CODE = 'smaato';
const SMAATO_ENDPOINT = 'https://prebid.ad.smaato.net/oapi/prebid';
const SMAATO_CLIENT = 'prebid_js_$prebid.version$_2.0'
const SMAATO_CLIENT = 'prebid_js_$prebid.version$_3.0'
const TTL = 300;
const CURRENCY = 'USD';
const SUPPORTED_MEDIA_TYPES = [BANNER, VIDEO, NATIVE];
Expand Down Expand Up @@ -160,12 +160,8 @@ export const spec = {
} else {
switch (smtAdType) {
case 'Img':
resultingBid.ad = createImgAd(bid.adm);
resultingBid.mediaType = BANNER;
bids.push(resultingBid);
break;
case 'Richmedia':
resultingBid.ad = createRichmediaAd(bid.adm);
resultingBid.ad = createBannerAd(bid);
resultingBid.mediaType = BANNER;
bids.push(resultingBid);
break;
Expand Down Expand Up @@ -370,37 +366,17 @@ const converter = ortbConverter({
}
});

const createImgAd = (adm) => {
const image = JSON.parse(adm).image;

const createBannerAd = (bid) => {
let clickEvent = '';
image.clicktrackers.forEach(src => {
clickEvent += `fetch(decodeURIComponent('${encodeURIComponent(src)}'), {cache: 'no-cache'});`;
})

let markup = `<div style="cursor:pointer" onclick="${clickEvent};window.open(decodeURIComponent('${encodeURIComponent(image.img.ctaurl)}'));"><img src="${image.img.url}" width="${image.img.w}" height="${image.img.h}"/>`;

image.impressiontrackers.forEach(src => {
markup += `<img src="${src}" alt="" width="0" height="0"/>`;
});

return markup + '</div>';
};

const createRichmediaAd = (adm) => {
const rich = JSON.parse(adm).richmedia;
let clickEvent = '';
rich.clicktrackers.forEach(src => {
clickEvent += `fetch(decodeURIComponent('${encodeURIComponent(src)}'), {cache: 'no-cache'});`;
})

let markup = `<div onclick="${clickEvent}">${rich.mediadata.content}`;

rich.impressiontrackers.forEach(src => {
markup += `<img src="${src}" alt="" width="0" height="0"/>`;
});
if (bid.ext && bid.ext.curls) {
let clicks = ''
bid.ext.curls.forEach(src => {
clicks += `fetch(decodeURIComponent('${encodeURIComponent(src)}'), {cache: 'no-cache'});`;
})
clickEvent = `onclick="${clicks}"`
}

return markup + '</div>';
return `<div style="cursor:pointer" ${clickEvent}>${bid.adm}</div>`;
};

const createNativeAd = (adm) => {
Expand Down
74 changes: 7 additions & 67 deletions test/spec/modules/smaatoBidAdapter_spec.js
Expand Up @@ -13,7 +13,6 @@ import 'modules/consentManagementUsp.js';
import 'modules/schain.js';

const ADTYPE_IMG = 'Img';
const ADTYPE_RICHMEDIA = 'Richmedia';
const ADTYPE_VIDEO = 'Video';
const ADTYPE_NATIVE = 'Native';

Expand Down Expand Up @@ -1300,43 +1299,7 @@ describe('smaatoBidAdapterTest', () => {

switch (adType) {
case ADTYPE_IMG:
adm = JSON.stringify(
{
image: {
img: {
url: 'https://prebid/static/ad.jpg',
w: 320,
h: 50,
ctaurl: 'https://prebid/track/ctaurl'
},
impressiontrackers: [
'https://prebid/track/imp/1',
'https://prebid/track/imp/2'
],
clicktrackers: [
'https://prebid/track/click/1'
]
}
});
break;
case ADTYPE_RICHMEDIA:
adm = JSON.stringify(
{
richmedia: {
mediadata: {
content: '<div><h3>RICHMEDIA CONTENT</h3></div>',
w: 800,
h: 600
},
impressiontrackers: [
'https://prebid/track/imp/1',
'https://prebid/track/imp/2'
],
clicktrackers: [
'https://prebid/track/click/1'
]
}
});
adm = '<a rel="nofollow" href="https://prebid.net/click"><img src="https://prebid.net/images/image.png" alt="" width="480" height="320" /></a>'
break;
case ADTYPE_VIDEO:
adm = '<VAST version="2.0"></VAST>';
Expand Down Expand Up @@ -1372,7 +1335,10 @@ describe('smaatoBidAdapterTest', () => {
'nurl': 'https://prebid/nurl',
'price': 0.01,
'w': 350,
'h': 50
'h': 50,
'ext': {
curls: ['https://prebid/track/click/1']
}
}
],
seat: 'CM6523'
Expand All @@ -1398,7 +1364,7 @@ describe('smaatoBidAdapterTest', () => {
});

describe('non ad pod', () => {
it('single image response', () => {
it('single banner response', () => {
const bids = spec.interpretResponse(buildOpenRtbBidResponse(ADTYPE_IMG), buildBidRequest());

expect(bids).to.deep.equal([
Expand All @@ -1407,33 +1373,7 @@ describe('smaatoBidAdapterTest', () => {
cpm: 0.01,
width: 350,
height: 50,
ad: '<div style="cursor:pointer" onclick="fetch(decodeURIComponent(\'https%3A%2F%2Fprebid%2Ftrack%2Fclick%2F1\'), {cache: \'no-cache\'});;window.open(decodeURIComponent(\'https%3A%2F%2Fprebid%2Ftrack%2Fctaurl\'));"><img src="https://prebid/static/ad.jpg" width="320" height="50"/><img src="https://prebid/track/imp/1" alt="" width="0" height="0"/><img src="https://prebid/track/imp/2" alt="" width="0" height="0"/></div>',
ttl: 300,
creativeId: 'CR69381',
dealId: '12345',
netRevenue: true,
currency: 'USD',
mediaType: 'banner',
meta: {
advertiserDomains: ['smaato.com'],
agencyId: 'CM6523',
networkName: 'smaato',
mediaType: 'banner'
}
}
]);
});

it('single richmedia response', () => {
const bids = spec.interpretResponse(buildOpenRtbBidResponse(ADTYPE_RICHMEDIA), buildBidRequest());

expect(bids).to.deep.equal([
{
requestId: '226416e6e6bf41',
cpm: 0.01,
width: 350,
height: 50,
ad: '<div onclick="fetch(decodeURIComponent(\'https%3A%2F%2Fprebid%2Ftrack%2Fclick%2F1\'), {cache: \'no-cache\'});"><div><h3>RICHMEDIA CONTENT</h3></div><img src="https://prebid/track/imp/1" alt="" width="0" height="0"/><img src="https://prebid/track/imp/2" alt="" width="0" height="0"/></div>',
ad: '<div style="cursor:pointer" onclick="fetch(decodeURIComponent(\'https%3A%2F%2Fprebid%2Ftrack%2Fclick%2F1\'), {cache: \'no-cache\'});"><a rel="nofollow" href="https://prebid.net/click"><img src="https://prebid.net/images/image.png" alt="" width="480" height="320" /></a></div>',
ttl: 300,
creativeId: 'CR69381',
dealId: '12345',
Expand Down

0 comments on commit 5438945

Please sign in to comment.