Skip to content

Commit

Permalink
adagioBidAdapter: add Native support (#6368)
Browse files Browse the repository at this point in the history
  • Loading branch information
osazos committed Mar 9, 2021
1 parent 9b2d3c0 commit a2282be
Show file tree
Hide file tree
Showing 3 changed files with 340 additions and 9 deletions.
116 changes: 113 additions & 3 deletions modules/adagioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import sha256 from 'crypto-js/sha256.js';
import { getStorageManager } from '../src/storageManager.js';
import { getRefererInfo } from '../src/refererDetection.js';
import { createEidsArray } from './userId/eids.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import { Renderer } from '../src/Renderer.js';
import { OUTSTREAM } from '../src/video.js';

export const BIDDER_CODE = 'adagio';
export const LOG_PREFIX = 'Adagio:';
export const VERSION = '2.6.0';
export const VERSION = '2.7.0';
export const FEATURES_VERSION = '1';
export const ENDPOINT = 'https://mp.4dex.io/prebid';
export const SUPPORTED_MEDIA_TYPES = [BANNER, VIDEO];
export const SUPPORTED_MEDIA_TYPES = [BANNER, NATIVE, VIDEO];
export const ADAGIO_TAG_URL = 'https://script.4dex.io/localstore.js';
export const ADAGIO_LOCALSTORAGE_KEY = 'adagioScript';
export const GVLID = 617;
Expand Down Expand Up @@ -687,6 +687,112 @@ function _renderer(bid) {
});
}

function _parseNativeBidResponse(bid) {
if (!bid.admNative || !Array.isArray(bid.admNative.assets)) {
utils.logError(`${LOG_PREFIX} Invalid native response`);
return;
}

const native = {}

function addAssetDataValue(data) {
const map = {
1: 'sponsoredBy', // sponsored
2: 'body', // desc
3: 'rating',
4: 'likes',
5: 'downloads',
6: 'price',
7: 'salePrice',
8: 'phone',
9: 'address',
10: 'body2', // desc2
11: 'displayUrl',
12: 'cta'
}
if (map.hasOwnProperty(data.type) && typeof data.value === 'string') {
native[map[data.type]] = data.value;
}
}

// assets
bid.admNative.assets.forEach(asset => {
if (asset.title) {
native.title = asset.title.text
} else if (asset.data) {
addAssetDataValue(asset.data)
} else if (asset.img) {
switch (asset.img.type) {
case 1:
native.icon = {
url: asset.img.url,
width: asset.img.w,
height: asset.img.h
};
break;
default:
native.image = {
url: asset.img.url,
width: asset.img.w,
height: asset.img.h
};
break;
}
}
});

if (bid.admNative.link) {
if (bid.admNative.link.url) {
native.clickUrl = bid.admNative.link.url;
}
if (Array.isArray(bid.admNative.link.clickTrackers)) {
native.clickTrackers = bid.admNative.link.clickTrackers
}
}

if (Array.isArray(bid.admNative.eventtrackers)) {
native.impressionTrackers = [];
bid.admNative.eventtrackers.forEach(tracker => {
// Only Impression events are supported. Prebid does not support Viewability events yet.
if (tracker.event !== 1) {
return;
}

// methods:
// 1: image
// 2: js
// note: javascriptTrackers is a string. If there's more than one JS tracker in bid response, the last script will be used.
switch (tracker.method) {
case 1:
native.impressionTrackers.push(tracker.url);
break;
case 2:
native.javascriptTrackers = `<script src=\"${tracker.url}\"></script>`;
break;
}
});
} else {
native.impressionTrackers = Array.isArray(bid.admNative.imptrackers) ? bid.admNative.imptrackers : [];
if (bid.admNative.jstracker) {
native.javascriptTrackers = bid.admNative.jstracker;
}
}

if (bid.admNative.privacy) {
native.privacyLink = bid.admNative.privacy;
}

if (bid.admNative.ext) {
native.ext = {}

if (bid.admNative.ext.bvw) {
native.ext.adagio_bvw = bid.admNative.ext.bvw;
}
}

bid.native = native
}

export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
Expand Down Expand Up @@ -873,6 +979,10 @@ export const spec = {
}
}

if (bidObj.mediaType === NATIVE) {
_parseNativeBidResponse(bidObj);
}

bidObj.site = bidReq.params.site;
bidObj.placement = bidReq.params.placement;
bidObj.pagetype = bidReq.params.pagetype;
Expand Down
60 changes: 56 additions & 4 deletions modules/adagioBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ Connects to Adagio demand source to fetch bids.
category: 'sport', // Recommended. Category of the content displayed in the page.
subcategory: 'handball', // Optional. Subcategory of the content displayed in the page.
postBid: false, // Optional. Use it in case of Post-bid integration only.
useAdUnitCodeAsAdUnitElementId: false // Optional. Use it by-pass adUnitElementId and use the adUnit code as value
useAdUnitCodeAsPlacement: false // Optional. Use it to by-pass placement and use the adUnit code as value
useAdUnitCodeAsAdUnitElementId: false, // Optional. Use it by-pass adUnitElementId and use the adUnit code as value
useAdUnitCodeAsPlacement: false, // Optional. Use it to by-pass placement and use the adUnit code as value
// Optional debug mode, used to get a bid response with expected cpm.
debug: {
enabled: true,
Expand Down Expand Up @@ -78,8 +78,8 @@ Connects to Adagio demand source to fetch bids.
category: 'sport', // Recommended. Category of the content displayed in the page.
subcategory: 'handball', // Optional. Subcategory of the content displayed in the page.
postBid: false, // Optional. Use it in case of Post-bid integration only.
useAdUnitCodeAsAdUnitElementId: false // Optional. Use it by-pass adUnitElementId and use the adUnit code as value
useAdUnitCodeAsPlacement: false // Optional. Use it to by-pass placement and use the adUnit code as value
useAdUnitCodeAsAdUnitElementId: false, // Optional. Use it by-pass adUnitElementId and use the adUnit code as value
useAdUnitCodeAsPlacement: false, // Optional. Use it to by-pass placement and use the adUnit code as value
video: {
skip: 0
// OpenRTB 2.5 video options defined here override ones defined in mediaTypes.
Expand All @@ -91,6 +91,58 @@ Connects to Adagio demand source to fetch bids.
}
}
}]
},
{
code: 'article_native',
mediaTypes: {
native: {
// generic Prebid options
title: {
required: true,
len: 80
},
//
// Custom Adagio data assets
ext: {
adagio_bvw: {
required: false
}
}
}
},
bids: [{
bidder: 'adagio', // Required
params: {
organizationId: '1002', // Required - Organization ID provided by Adagio.
site: 'adagio-io', // Required - Site Name provided by Adagio.
placement: 'in_article', // Required. Refers to the placement of an adunit in a page. Must not contain any information about the type of device. Other example: `mpu_btf'.
adUnitElementId: 'article_native', // Required - AdUnit element id. Refers to the adunit id in a page. Usually equals to the adunit code above.

// The following params are limited to 30 characters,
// and can only contain the following characters:
// - alphanumeric (A-Z+a-z+0-9, case-insensitive)
// - dashes `-`
// - underscores `_`
// Also, each param can have at most 50 unique active values (case-insensitive).
pagetype: 'article', // Highly recommended. The pagetype describes what kind of content will be present in the page.
environment: 'mobile', // Recommended. Environment where the page is displayed.
category: 'sport', // Recommended. Category of the content displayed in the page.
subcategory: 'handball', // Optional. Subcategory of the content displayed in the page.
postBid: false, // Optional. Use it in case of Post-bid integration only.
useAdUnitCodeAsAdUnitElementId: false, // Optional. Use it by-pass adUnitElementId and use the adUnit code as value
useAdUnitCodeAsPlacement: false, // Optional. Use it to by-pass placement and use the adUnit code as value
// Optional OpenRTB Native 1.2 request object. Only `context`, `plcmttype` fields are supported.
native: {
context: 1,
plcmttype: 2
},
// Optional debug mode, used to get a bid response with expected cpm.
debug: {
enabled: true,
cpm: 3.00 // default to 1.00
}
}
}]
}
];

Expand Down
Loading

0 comments on commit a2282be

Please sign in to comment.