Skip to content

Commit fe93361

Browse files
osazosseergiioo6
authored andcommitted
adagioBidAdapter: add Native support (prebid#6368)
1 parent e089f70 commit fe93361

File tree

3 files changed

+340
-9
lines changed

3 files changed

+340
-9
lines changed

modules/adagioBidAdapter.js

Lines changed: 113 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import sha256 from 'crypto-js/sha256.js';
88
import { getStorageManager } from '../src/storageManager.js';
99
import { getRefererInfo } from '../src/refererDetection.js';
1010
import { createEidsArray } from './userId/eids.js';
11-
import { BANNER, VIDEO } from '../src/mediaTypes.js';
11+
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
1212
import { Renderer } from '../src/Renderer.js';
1313
import { OUTSTREAM } from '../src/video.js';
1414

1515
export const BIDDER_CODE = 'adagio';
1616
export const LOG_PREFIX = 'Adagio:';
17-
export const VERSION = '2.6.0';
17+
export const VERSION = '2.7.0';
1818
export const FEATURES_VERSION = '1';
1919
export const ENDPOINT = 'https://mp.4dex.io/prebid';
20-
export const SUPPORTED_MEDIA_TYPES = [BANNER, VIDEO];
20+
export const SUPPORTED_MEDIA_TYPES = [BANNER, NATIVE, VIDEO];
2121
export const ADAGIO_TAG_URL = 'https://script.4dex.io/localstore.js';
2222
export const ADAGIO_LOCALSTORAGE_KEY = 'adagioScript';
2323
export const GVLID = 617;
@@ -687,6 +687,112 @@ function _renderer(bid) {
687687
});
688688
}
689689

690+
function _parseNativeBidResponse(bid) {
691+
if (!bid.admNative || !Array.isArray(bid.admNative.assets)) {
692+
utils.logError(`${LOG_PREFIX} Invalid native response`);
693+
return;
694+
}
695+
696+
const native = {}
697+
698+
function addAssetDataValue(data) {
699+
const map = {
700+
1: 'sponsoredBy', // sponsored
701+
2: 'body', // desc
702+
3: 'rating',
703+
4: 'likes',
704+
5: 'downloads',
705+
6: 'price',
706+
7: 'salePrice',
707+
8: 'phone',
708+
9: 'address',
709+
10: 'body2', // desc2
710+
11: 'displayUrl',
711+
12: 'cta'
712+
}
713+
if (map.hasOwnProperty(data.type) && typeof data.value === 'string') {
714+
native[map[data.type]] = data.value;
715+
}
716+
}
717+
718+
// assets
719+
bid.admNative.assets.forEach(asset => {
720+
if (asset.title) {
721+
native.title = asset.title.text
722+
} else if (asset.data) {
723+
addAssetDataValue(asset.data)
724+
} else if (asset.img) {
725+
switch (asset.img.type) {
726+
case 1:
727+
native.icon = {
728+
url: asset.img.url,
729+
width: asset.img.w,
730+
height: asset.img.h
731+
};
732+
break;
733+
default:
734+
native.image = {
735+
url: asset.img.url,
736+
width: asset.img.w,
737+
height: asset.img.h
738+
};
739+
break;
740+
}
741+
}
742+
});
743+
744+
if (bid.admNative.link) {
745+
if (bid.admNative.link.url) {
746+
native.clickUrl = bid.admNative.link.url;
747+
}
748+
if (Array.isArray(bid.admNative.link.clickTrackers)) {
749+
native.clickTrackers = bid.admNative.link.clickTrackers
750+
}
751+
}
752+
753+
if (Array.isArray(bid.admNative.eventtrackers)) {
754+
native.impressionTrackers = [];
755+
bid.admNative.eventtrackers.forEach(tracker => {
756+
// Only Impression events are supported. Prebid does not support Viewability events yet.
757+
if (tracker.event !== 1) {
758+
return;
759+
}
760+
761+
// methods:
762+
// 1: image
763+
// 2: js
764+
// note: javascriptTrackers is a string. If there's more than one JS tracker in bid response, the last script will be used.
765+
switch (tracker.method) {
766+
case 1:
767+
native.impressionTrackers.push(tracker.url);
768+
break;
769+
case 2:
770+
native.javascriptTrackers = `<script src=\"${tracker.url}\"></script>`;
771+
break;
772+
}
773+
});
774+
} else {
775+
native.impressionTrackers = Array.isArray(bid.admNative.imptrackers) ? bid.admNative.imptrackers : [];
776+
if (bid.admNative.jstracker) {
777+
native.javascriptTrackers = bid.admNative.jstracker;
778+
}
779+
}
780+
781+
if (bid.admNative.privacy) {
782+
native.privacyLink = bid.admNative.privacy;
783+
}
784+
785+
if (bid.admNative.ext) {
786+
native.ext = {}
787+
788+
if (bid.admNative.ext.bvw) {
789+
native.ext.adagio_bvw = bid.admNative.ext.bvw;
790+
}
791+
}
792+
793+
bid.native = native
794+
}
795+
690796
export const spec = {
691797
code: BIDDER_CODE,
692798
gvlid: GVLID,
@@ -873,6 +979,10 @@ export const spec = {
873979
}
874980
}
875981

982+
if (bidObj.mediaType === NATIVE) {
983+
_parseNativeBidResponse(bidObj);
984+
}
985+
876986
bidObj.site = bidReq.params.site;
877987
bidObj.placement = bidReq.params.placement;
878988
bidObj.pagetype = bidReq.params.pagetype;

modules/adagioBidAdapter.md

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ Connects to Adagio demand source to fetch bids.
3838
category: 'sport', // Recommended. Category of the content displayed in the page.
3939
subcategory: 'handball', // Optional. Subcategory of the content displayed in the page.
4040
postBid: false, // Optional. Use it in case of Post-bid integration only.
41-
useAdUnitCodeAsAdUnitElementId: false // Optional. Use it by-pass adUnitElementId and use the adUnit code as value
42-
useAdUnitCodeAsPlacement: false // Optional. Use it to by-pass placement and use the adUnit code as value
41+
useAdUnitCodeAsAdUnitElementId: false, // Optional. Use it by-pass adUnitElementId and use the adUnit code as value
42+
useAdUnitCodeAsPlacement: false, // Optional. Use it to by-pass placement and use the adUnit code as value
4343
// Optional debug mode, used to get a bid response with expected cpm.
4444
debug: {
4545
enabled: true,
@@ -78,8 +78,8 @@ Connects to Adagio demand source to fetch bids.
7878
category: 'sport', // Recommended. Category of the content displayed in the page.
7979
subcategory: 'handball', // Optional. Subcategory of the content displayed in the page.
8080
postBid: false, // Optional. Use it in case of Post-bid integration only.
81-
useAdUnitCodeAsAdUnitElementId: false // Optional. Use it by-pass adUnitElementId and use the adUnit code as value
82-
useAdUnitCodeAsPlacement: false // Optional. Use it to by-pass placement and use the adUnit code as value
81+
useAdUnitCodeAsAdUnitElementId: false, // Optional. Use it by-pass adUnitElementId and use the adUnit code as value
82+
useAdUnitCodeAsPlacement: false, // Optional. Use it to by-pass placement and use the adUnit code as value
8383
video: {
8484
skip: 0
8585
// OpenRTB 2.5 video options defined here override ones defined in mediaTypes.
@@ -91,6 +91,58 @@ Connects to Adagio demand source to fetch bids.
9191
}
9292
}
9393
}]
94+
},
95+
{
96+
code: 'article_native',
97+
mediaTypes: {
98+
native: {
99+
// generic Prebid options
100+
title: {
101+
required: true,
102+
len: 80
103+
},
104+
//
105+
// Custom Adagio data assets
106+
ext: {
107+
adagio_bvw: {
108+
required: false
109+
}
110+
}
111+
}
112+
},
113+
bids: [{
114+
bidder: 'adagio', // Required
115+
params: {
116+
organizationId: '1002', // Required - Organization ID provided by Adagio.
117+
site: 'adagio-io', // Required - Site Name provided by Adagio.
118+
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'.
119+
adUnitElementId: 'article_native', // Required - AdUnit element id. Refers to the adunit id in a page. Usually equals to the adunit code above.
120+
121+
// The following params are limited to 30 characters,
122+
// and can only contain the following characters:
123+
// - alphanumeric (A-Z+a-z+0-9, case-insensitive)
124+
// - dashes `-`
125+
// - underscores `_`
126+
// Also, each param can have at most 50 unique active values (case-insensitive).
127+
pagetype: 'article', // Highly recommended. The pagetype describes what kind of content will be present in the page.
128+
environment: 'mobile', // Recommended. Environment where the page is displayed.
129+
category: 'sport', // Recommended. Category of the content displayed in the page.
130+
subcategory: 'handball', // Optional. Subcategory of the content displayed in the page.
131+
postBid: false, // Optional. Use it in case of Post-bid integration only.
132+
useAdUnitCodeAsAdUnitElementId: false, // Optional. Use it by-pass adUnitElementId and use the adUnit code as value
133+
useAdUnitCodeAsPlacement: false, // Optional. Use it to by-pass placement and use the adUnit code as value
134+
// Optional OpenRTB Native 1.2 request object. Only `context`, `plcmttype` fields are supported.
135+
native: {
136+
context: 1,
137+
plcmttype: 2
138+
},
139+
// Optional debug mode, used to get a bid response with expected cpm.
140+
debug: {
141+
enabled: true,
142+
cpm: 3.00 // default to 1.00
143+
}
144+
}
145+
}]
94146
}
95147
];
96148

0 commit comments

Comments
 (0)