Skip to content

Commit

Permalink
Smaato Bid Adapter: Native support (#9089)
Browse files Browse the repository at this point in the history
* PREB-36	[Prebid.js] Native support

* PREB-36	[Prebid.js] Native support
- update to ortb native

Co-authored-by: Ruslan Sibgatullin <ruslan.sibgatullin@smaato.com>
Co-authored-by: Bernhard Pickenbrock <bernhard.pickenbrock@smaato.com>
  • Loading branch information
3 people authored Oct 19, 2022
1 parent e459b91 commit 5885682
Show file tree
Hide file tree
Showing 3 changed files with 439 additions and 41 deletions.
59 changes: 54 additions & 5 deletions modules/smaatoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { deepAccess, getDNT, deepSetValue, logInfo, logError, isEmpty, getAdUnitSizes, fill, chunk, getMaxValueFromArray, getMinValueFromArray } from '../src/utils.js';
import { deepAccess, isNumber, getDNT, deepSetValue, logInfo, logError, isEmpty, getAdUnitSizes, fill, chunk, getMaxValueFromArray, getMinValueFromArray } from '../src/utils.js';
import {find} from '../src/polyfill.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {config} from '../src/config.js';
import {ADPOD, BANNER, VIDEO} from '../src/mediaTypes.js';
import {ADPOD, BANNER, VIDEO, NATIVE} from '../src/mediaTypes.js';
import CONSTANTS from '../src/constants.json';

const { NATIVE_IMAGE_TYPES } = CONSTANTS;
const BIDDER_CODE = 'smaato';
const SMAATO_ENDPOINT = 'https://prebid.ad.smaato.net/oapi/prebid';
const SMAATO_CLIENT = 'prebid_js_$prebid.version$_1.6'
const SMAATO_CLIENT = 'prebid_js_$prebid.version$_1.7'
const CURRENCY = 'USD';

const buildOpenRtbBidRequest = (bidRequest, bidderRequest) => {
Expand Down Expand Up @@ -91,6 +94,12 @@ const buildOpenRtbBidRequest = (bidRequest, bidderRequest) => {
}
}

const nativeOrtbRequest = bidRequest.nativeOrtbRequest;
if (nativeOrtbRequest) {
const nativeRequest = Object.assign({}, requestTemplate, createNativeImp(bidRequest, nativeOrtbRequest));
requests.push(nativeRequest);
}

return requests;
}

Expand All @@ -109,11 +118,11 @@ const buildServerRequest = (validBidRequest, data) => {

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO],
supportedMediaTypes: [BANNER, VIDEO, NATIVE],
gvlid: 82,

/**
* Determines whether or not the given bid request is valid.
* Determines whether the given bid request is valid.
*
* @param {BidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
Expand Down Expand Up @@ -171,6 +180,7 @@ export const spec = {
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @param {BidRequest} bidRequest
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: (serverResponse, bidRequest) => {
Expand Down Expand Up @@ -239,6 +249,11 @@ export const spec = {
resultingBid.mediaType = VIDEO;
bids.push(resultingBid);
break;
case 'Native':
resultingBid.native = createNativeAd(bid.adm);
resultingBid.mediaType = NATIVE;
bids.push(resultingBid);
break;
default:
logInfo('[SMAATO] Invalid ad type:', smtAdType);
}
Expand Down Expand Up @@ -297,6 +312,13 @@ const createRichmediaAd = (adm) => {
return markup + '</div>';
};

const createNativeAd = (adm) => {
const nativeResponse = JSON.parse(adm).native;
return {
ortb: nativeResponse
}
};

function createBannerImp(bidRequest) {
const adUnitSizes = getAdUnitSizes(bidRequest);
const sizes = adUnitSizes.map((size) => ({w: size[0], h: size[1]}));
Expand Down Expand Up @@ -342,6 +364,33 @@ function createVideoImp(bidRequest, videoMediaType) {
};
}

function createNativeImp(bidRequest, nativeRequest) {
return {
imp: [{
id: bidRequest.bidId,
tagid: deepAccess(bidRequest, 'params.adspaceId'),
bidfloor: getBidFloor(bidRequest, NATIVE, getNativeMainImageSize(nativeRequest)),
native: {
request: JSON.stringify(nativeRequest),
ver: '1.2'
}
}]
};
}

function getNativeMainImageSize(nativeRequest) {
const mainImage = find(nativeRequest.assets, asset => asset.hasOwnProperty('img') && asset.img.type === NATIVE_IMAGE_TYPES.MAIN)
if (mainImage) {
if (isNumber(mainImage.img.w) && isNumber(mainImage.img.h)) {
return [[mainImage.img.w, mainImage.img.h]]
}
if (isNumber(mainImage.img.wmin) && isNumber(mainImage.img.hmin)) {
return [[mainImage.img.wmin, mainImage.img.hmin]]
}
}
return []
}

function createAdPodImp(bidRequest, videoMediaType) {
const tagid = deepAccess(bidRequest, 'params.adbreakId')
const bce = config.getConfig('adpod.brandCategoryExclusion')
Expand Down
78 changes: 78 additions & 0 deletions modules/smaatoBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,84 @@ var adUnits = [{
}];
```

For native adunits:

```
var adUnits = [{
"code": "native unit",
"mediaTypes": {
native: {
ortb: {
ver: "1.2",
assets: [
{
id: 1,
required: 1,
img: {
type: 3,
w: 150,
h: 50,
}
},
{
id: 2,
required: 1,
img: {
type: 2,
w: 50,
h: 50
}
},
{
id: 3,
required: 1,
title: {
len: 80
}
},
{
id: 4,
required: 1,
data: {
type: 1
}
},
{
id: 5,
required: 1,
data: {
type: 2
}
},
{
id: 6,
required: 0,
data: {
type: 3
}
},
{
id: 7,
required: 0,
data: {
type: 12
}
}
]
},
sendTargetingKeys: false,
}
},
"bids": [{
"bidder": "smaato",
"params": {
"publisherId": "1100042525",
"adspaceId": "130563103"
}
}]
}];
```

For adpod adunits:

```
Expand Down
Loading

0 comments on commit 5885682

Please sign in to comment.