Skip to content

Commit

Permalink
admarkup html wrapping removed (prebid#3432)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckbo3hrk authored and Pedro López Jiménez committed Mar 18, 2019
1 parent 442a2e7 commit e72dfee
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 86 deletions.
39 changes: 21 additions & 18 deletions modules/adkernelAdnBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ import * as utils from '../src/utils';
import {registerBidder} from '../src/adapters/bidderFactory';
import {BANNER, VIDEO} from '../src/mediaTypes';
import includes from 'core-js/library/fn/array/includes';
import {parse as parseUrl} from '../src/url';

const DEFAULT_ADKERNEL_DSP_DOMAIN = 'tag.adkernel.com';
const VIDEO_TARGETING = ['mimes', 'protocols', 'api'];
const DEFAULT_MIMES = ['video/mp4', 'video/webm', 'application/x-shockwave-flash', 'application/javascript'];
const DEFAULT_PROTOCOLS = [2, 3, 5, 6];
const DEFAULT_APIS = [1, 2];

function isRtbDebugEnabled() {
return utils.getTopWindowLocation().href.indexOf('adk_debug=true') !== -1;
function isRtbDebugEnabled(refInfo) {
return refInfo.referer.indexOf('adk_debug=true') !== -1;
}

function buildImp(bidRequest) {
let imp = {
id: bidRequest.bidId,
tagid: bidRequest.adUnitCode
};
if (bidRequest.mediaType === BANNER || utils.deepAccess(bidRequest, `mediaTypes.banner`) ||
(bidRequest.mediaTypes === undefined && bidRequest.mediaType === undefined)) {
let sizes = canonicalizeSizesArray(bidRequest.sizes);
if (utils.deepAccess(bidRequest, `mediaTypes.banner`)) {
let sizes = canonicalizeSizesArray(bidRequest.mediaTypes.banner.sizes);
imp.banner = {
format: utils.parseSizesInput(sizes)
}
} else if (bidRequest.mediaType === VIDEO || utils.deepAccess(bidRequest, `mediaTypes.video`)) {
let size = canonicalizeSizesArray(bidRequest.sizes)[0];
} else if (utils.deepAccess(bidRequest, `mediaTypes.video`)) {
let size = canonicalizeSizesArray(bidRequest.mediaTypes.video.playerSize)[0];
imp.video = {
w: size[0],
h: size[1],
Expand Down Expand Up @@ -54,11 +54,11 @@ function canonicalizeSizesArray(sizes) {
return sizes;
}

function buildRequestParams(tags, auctionId, transactionId, gdprConsent) {
function buildRequestParams(tags, auctionId, transactionId, gdprConsent, refInfo) {
let req = {
id: auctionId,
tid: transactionId,
site: buildSite(),
site: buildSite(refInfo),
imp: tags
};

Expand All @@ -74,13 +74,15 @@ function buildRequestParams(tags, auctionId, transactionId, gdprConsent) {
return req;
}

function buildSite() {
let loc = utils.getTopWindowLocation();
function buildSite(refInfo) {
let loc = parseUrl(refInfo.referer);
let result = {
page: loc.href,
ref: utils.getTopWindowReferrer(),
secure: ~~(loc.protocol === 'https:')
page: `${loc.protocol}://${loc.hostname}${loc.pathname}`,
secure: ~~(loc.protocol === 'https')
};
if (self === top && document.referrer) {
result.ref = document.referrer;
}
let keywords = document.getElementsByTagName('meta')['keywords'];
if (keywords && keywords.content) {
result.keywords = keywords.content;
Expand All @@ -101,7 +103,7 @@ function buildBid(tag) {
netRevenue: true
};
if (tag.tag) {
bid.ad = `<!DOCTYPE html><html><head><title></title><body style='margin:0px;padding:0px;'>${tag.tag}</body></head>`;
bid.ad = tag.tag;
bid.mediaType = BANNER;
} else if (tag.vast_url) {
bid.vastUrl = tag.vast_url;
Expand All @@ -117,7 +119,7 @@ export const spec = {

isBidRequestValid: function(bidRequest) {
return 'params' in bidRequest && (typeof bidRequest.params.host === 'undefined' || typeof bidRequest.params.host === 'string') &&
typeof bidRequest.params.pubId === 'number';
typeof bidRequest.params.pubId === 'number' && 'mediaTypes' in bidRequest && ('banner' in bidRequest.mediaTypes || 'video' in bidRequest.mediaTypes);
},

buildRequests: function(bidRequests, bidderRequest) {
Expand All @@ -134,13 +136,14 @@ export const spec = {
let auctionId = bidderRequest.auctionId;
let gdprConsent = bidderRequest.gdprConsent;
let transactionId = bidderRequest.transactionId;
let refererInfo = bidderRequest.refererInfo;
let requests = [];
Object.keys(dispatch).forEach(host => {
Object.keys(dispatch[host]).forEach(pubId => {
let request = buildRequestParams(dispatch[host][pubId], auctionId, transactionId, gdprConsent);
let request = buildRequestParams(dispatch[host][pubId], auctionId, transactionId, gdprConsent, refererInfo);
requests.push({
method: 'POST',
url: `//${host}/tag?account=${pubId}&pb=1${isRtbDebugEnabled() ? '&debug=1' : ''}`,
url: `//${host}/tag?account=${pubId}&pb=1${isRtbDebugEnabled(refererInfo) ? '&debug=1' : ''}`,
data: JSON.stringify(request)
})
});
Expand Down
31 changes: 13 additions & 18 deletions modules/adkernelBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BANNER, VIDEO } from '../src/mediaTypes';
import {registerBidder} from '../src/adapters/bidderFactory';
import find from 'core-js/library/fn/array/find';
import includes from 'core-js/library/fn/array/includes';
import {parse as parseUrl} from '../src/url'
import {parse as parseUrl} from '../src/url';

const VIDEO_TARGETING = ['mimes', 'minduration', 'maxduration', 'protocols',
'startdelay', 'linearity', 'boxingallowed', 'playbackmethod', 'delivery',
Expand All @@ -20,7 +20,8 @@ export const spec = {
supportedMediaTypes: [BANNER, VIDEO],
isBidRequestValid: function(bidRequest) {
return 'params' in bidRequest && typeof bidRequest.params.host !== 'undefined' &&
'zoneId' in bidRequest.params && !isNaN(Number(bidRequest.params.zoneId));
'zoneId' in bidRequest.params && !isNaN(Number(bidRequest.params.zoneId)) &&
bidRequest.mediaTypes && (bidRequest.mediaTypes.banner || bidRequest.mediaTypes.video);
},
buildRequests: function(bidRequests, bidderRequest) {
let impDispatch = dispatchImps(bidRequests, bidderRequest.refererInfo);
Expand All @@ -31,14 +32,9 @@ export const spec = {
Object.keys(impDispatch[host]).forEach(zoneId => {
const request = buildRtbRequest(impDispatch[host][zoneId], auctionId, gdprConsent, bidderRequest.refererInfo);
requests.push({
method: 'GET',
url: `${window.location.protocol}//${host}/rtbg`,
data: {
zone: Number(zoneId),
ad_type: 'rtb',
v: VERSION,
r: JSON.stringify(request)
}
method: 'POST',
url: `${window.location.protocol}//${host}/hb?zone=${Number(zoneId)}&v=${VERSION}`,
data: JSON.stringify(request)
});
});
});
Expand All @@ -50,7 +46,7 @@ export const spec = {
return [];
}

let rtbRequest = JSON.parse(request.data.r);
let rtbRequest = JSON.parse(request.data);
let rtbImps = rtbRequest.imp;
let rtbBids = response.seatbid
.map(seatbid => seatbid.bid)
Expand Down Expand Up @@ -120,15 +116,14 @@ function buildImp(bidRequest, secure) {
'tagid': bidRequest.adUnitCode
};

if (bidRequest.mediaType === BANNER || utils.deepAccess(bidRequest, `mediaTypes.banner`) ||
(bidRequest.mediaTypes === undefined && bidRequest.mediaType === undefined)) {
let sizes = canonicalizeSizesArray(bidRequest.sizes);
if (utils.deepAccess(bidRequest, `mediaTypes.banner`)) {
let sizes = canonicalizeSizesArray(bidRequest.mediaTypes.banner.sizes);
imp.banner = {
format: sizes.map(s => ({'w': s[0], 'h': s[1]})),
topframe: 0
};
} else if (bidRequest.mediaType === VIDEO || utils.deepAccess(bidRequest, 'mediaTypes.video')) {
let size = canonicalizeSizesArray(bidRequest.sizes)[0];
} else if (utils.deepAccess(bidRequest, 'mediaTypes.video')) {
let size = canonicalizeSizesArray(bidRequest.mediaTypes.video.playerSize)[0];
imp.video = {
w: size[0],
h: size[1]
Expand Down Expand Up @@ -222,9 +217,9 @@ function createSite(refInfo) {
* @param bid rtb Bid object
*/
function formatAdMarkup(bid) {
var adm = bid.adm;
let adm = bid.adm;
if ('nurl' in bid) {
adm += utils.createTrackPixelHtml(`${bid.nurl}&px=1`);
}
return `<!DOCTYPE html><html><head><title></title><body style='margin:0px;padding:0px;'>${adm}</body></head>`;
return adm;
}
Loading

0 comments on commit e72dfee

Please sign in to comment.