-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathbanner.js
40 lines (36 loc) · 1.25 KB
/
banner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import {createTrackPixelHtml, deepAccess, inIframe, mergeDeep} from '../../../src/utils.js';
import {BANNER} from '../../../src/mediaTypes.js';
import {sizesToFormat} from '../lib/sizes.js';
/**
* fill in a request `imp` with banner parameters from `bidRequest`.
*/
export function fillBannerImp(imp, bidRequest, context) {
if (context.mediaType && context.mediaType !== BANNER) return;
const bannerParams = deepAccess(bidRequest, 'mediaTypes.banner');
if (bannerParams) {
const banner = {
topframe: inIframe() === true ? 0 : 1
};
if (bannerParams.sizes) {
banner.format = sizesToFormat(bannerParams.sizes);
}
if (bannerParams.hasOwnProperty('pos')) {
banner.pos = bannerParams.pos;
}
imp.banner = mergeDeep(banner, imp.banner);
}
}
export function bannerResponseProcessor({createPixel = (url) => createTrackPixelHtml(decodeURIComponent(url))} = {}) {
return function fillBannerResponse(bidResponse, bid) {
if (bidResponse.mediaType === BANNER) {
if (bid.adm && bid.nurl) {
bidResponse.ad = bid.adm;
bidResponse.ad += createPixel(bid.nurl);
} else if (bid.adm) {
bidResponse.ad = bid.adm;
} else if (bid.nurl) {
bidResponse.adUrl = bid.nurl;
}
}
};
}