Skip to content

Commit

Permalink
Merge pull request #326 from PubMatic-OpenWrap/test_br_b2_20190403124840
Browse files Browse the repository at this point in the history
Prebid upgarde automate- test pull request created through git api please ignore it
  • Loading branch information
pm-shashank-jain authored Apr 3, 2019
2 parents de208cd + 083ade8 commit 220f7c7
Show file tree
Hide file tree
Showing 23 changed files with 10,925 additions and 305 deletions.
109 changes: 109 additions & 0 deletions integrationExamples/gpt/gdpr_iframe_hello_world.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<!--
This page calls a single bidder for a single ad slot. It can be considered a "hello world" example for using
Prebid with the Google Publisher Tag.
It also makes a good test page for new adapter PR submissions. Simply set your server's Bid Params object in the
bids array inside the adUnits, and it will use your adapter to load an ad.
NOTE that many ad servers won't send back an ad if the URL is localhost... so you might need to
set an alias in your /etc/hosts file so that you can load this page from a different domain.
-->

<html>
<head>
<script>
var PREBID_TIMEOUT = 700;

var adUnits = [{
code: 'div-gpt-ad-1460505748561-0',
sizes: [[300, 250], [300,600]],

// Replace this object to test a new Adapter!
bids: [{
bidder: 'appnexusAst',
params: {
placementId: '10433394'
}
}]

}];

var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];

</script>

<script type="text/javascript" src="../../build/dev/prebid.js" async></script>
<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(function() {
googletag.pubads().disableInitialLoad();
});

pbjs.que.push(function() {
pbjs.addAdUnits(adUnits);
pbjs.setConfig({
consentManagement: {
cmpApi: 'iab',
timeout: 5000,
allowAuctionWithoutConsent: false
},
pubcid: {
enable: false
},
debug: true
});
pbjs.requestBids({
bidsBackHandler: sendAdserverRequest
});
});

function sendAdserverRequest() {
if (pbjs.adserverRequestSent) return;
pbjs.adserverRequestSent = true;
googletag.cmd.push(function() {
pbjs.que.push(function() {
pbjs.setTargetingForGPTAsync();
googletag.pubads().refresh();
});
});
}

// setTimeout(function() {
// sendAdserverRequest();
// }, PREBID_TIMEOUT);

</script>

<script>
(function () {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>

<script>
googletag.cmd.push(function () {
googletag.defineSlot('/19968336/header-bid-tag-0', [[300, 250], [300, 600]], 'div-gpt-ad-1460505748561-0').addService(googletag.pubads());

googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>
</head>

<body>
<h2>Prebid.js Test</h2>
<h5>Div-1</h5>
<div id='div-gpt-ad-1460505748561-0'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1460505748561-0'); });
</script>
</div>
</body>
</html>
10 changes: 10 additions & 0 deletions integrationExamples/gpt/gdpr_iframe_test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<script>window.__cmp = {config: {logging: 'debug'}}</script>
<script src="//acdn.adnxs.com/cmp/cmp.complete.bundle.js" async></script>
</head>

<body>
<iframe src="../../integrationExamples/gpt/gdpr_iframe_hello_world.html" style="height:800px; width:800px" id="myId"/>
</body>
</html>
2 changes: 1 addition & 1 deletion modules.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["appnexusBidAdapter","consentManagement","sekindoUMBidAdapter","pulsepointBidAdapter","audienceNetworkBidAdapter","openxBidAdapter","rubiconBidAdapter","sovrnBidAdapter","pubmaticBidAdapter","adgenerationBidAdapter","pubmaticServerBidAdapter","ixBidAdapter","criteoBidAdapter"]
["appnexusBidAdapter","consentManagement","sekindoUMBidAdapter","pulsepointBidAdapter","audienceNetworkBidAdapter","openxBidAdapter","rubiconBidAdapter","sovrnBidAdapter","pubmaticBidAdapter","adgenerationBidAdapter","pubmaticServerBidAdapter","ixBidAdapter","criteoBidAdapter"]
3 changes: 1 addition & 2 deletions modules/audienceNetworkBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ const hbBidder = 'fan';
const ttl = 600;
const videoTtl = 3600;
const platver = '$prebid.version$';
const platform = '241394079772386';
const platform = '2078522619030089';
const adapterver = '1.3.0';

/**
* Does this bid request contain valid parameters?
* @param {Object} bid
Expand Down
3 changes: 3 additions & 0 deletions modules/ixBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ function isValidBidFloorParams(bidFloor, bidFloorCur) {
export const spec = {

code: BIDDER_CODE,

aliases: ['indexExchange'],

supportedMediaTypes: SUPPORTED_AD_TYPES,

/**
Expand Down
133 changes: 80 additions & 53 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,37 +208,36 @@ function _parseAdSlot(bid) {
bid.params.adUnitIndex = '0';
bid.params.width = 0;
bid.params.height = 0;
var sizesArrayExists = (bid.hasOwnProperty('sizes') && utils.isArray(bid.sizes) && bid.sizes.length >= 1);
var sizesArrayExists = (bid.hasOwnProperty('sizes') && utils.isArray(bid.sizes) && bid.sizes.length >= 1) || (bid.hasOwnProperty('mediaTypes') && bid.mediaTypes.hasOwnProperty('banner') && bid.mediaTypes.banner.hasOwnProperty('sizes') && bid.mediaTypes.banner.sizes.length >= 1);
bid.params.adSlot = _cleanSlot(bid.params.adSlot);

var slot = bid.params.adSlot;
var splits = slot.split(':');

slot = splits[0];
if (splits.length == 2) {
bid.params.adUnitIndex = splits[1];
}
// check if size is mentioned in sizes array. in that case do not check for @ in adslot
splits = slot.split('@');
if (splits.length != 2) {
if (!(sizesArrayExists)) {
utils.logWarn(LOG_WARN_PREFIX + 'AdSlot Error: adSlot not in required format');
return;
}
}
bid.params.adUnit = splits[0];
if (splits.length > 1) { // i.e size is specified in adslot, so consider that and ignore sizes array
splits = splits[1].split('x');
if (splits.length != 2) {
utils.logWarn(LOG_WARN_PREFIX + 'AdSlot Error: adSlot not in required format');
return;
try {
var splits = slot.split('@');
// check if size is mentioned in sizes array. in that case do not check for @ in adslot
slot = splits[0];
if (splits.length == 2) {
bid.params.adUnitIndex = splits[1].split(':').length == 2 ? splits[1].split(':')[1] : '0';
splits = splits[1].split(':')[0].split('x');
if (splits.length != 2) {
utils.logWarn('AdSlot Error: adSlot not in required format');
return;
}
bid.params.width = parseInt(splits[0]);
bid.params.height = parseInt(splits[1]);
// delete bid.sizes;
} else {
if (!(sizesArrayExists)) {
utils.logWarn('AdSlot Error: adSlot not in required format');
return;
}
bid.params.width = parseInt(bid.sizes[0][0]);
bid.params.height = parseInt(bid.sizes[0][1]);
bid.params.adUnitIndex = slot.split(':').length > 1 ? slot.split(':')[slot.split(':').length - 1] : '0';
}
bid.params.width = parseInt(splits[0]);
bid.params.height = parseInt(splits[1]);
delete bid.sizes;
} else if (sizesArrayExists) {
bid.params.width = parseInt(bid.sizes[0][0]);
bid.params.height = parseInt(bid.sizes[0][1]);
bid.params.adUnit = slot;
} catch (e) {
utils.logWarn('AdSlot Error: adSlot not in required format');
}
}

Expand Down Expand Up @@ -389,6 +388,7 @@ function _createNativeRequest(params) {
type: NATIVE_ASSET_IMAGE_TYPE.ICON,
w: params[key].w || params[key].width || (params[key].sizes ? params[key].sizes[0] : undefined),
h: params[key].h || params[key].height || (params[key].sizes ? params[key].sizes[1] : undefined),
ext: params[key].ext
}
};
} else {
Expand Down Expand Up @@ -444,7 +444,8 @@ function _createNativeRequest(params) {
img: {
type: NATIVE_ASSET_IMAGE_TYPE.LOGO,
w: params[key].w || params[key].width || (params[key].sizes ? params[key].sizes[0] : undefined),
h: params[key].h || params[key].height || (params[key].sizes ? params[key].sizes[1] : undefined)
h: params[key].h || params[key].height || (params[key].sizes ? params[key].sizes[1] : undefined),
ext: params[key].ext
}
};
break;
Expand Down Expand Up @@ -591,8 +592,8 @@ function _createImpressionObject(bid, conf) {
var impObj = {};
var bannerObj = {};
var videoObj = {};
var sizes = bid.hasOwnProperty('sizes') ? bid.sizes : [];

// var sizes = bid.hasOwnProperty('sizes') ? bid.sizes : [];
var sizes = bid.hasOwnProperty('sizes') ? bid.sizes : bid.hasOwnProperty('mediaTypes') && bid.mediaTypes.hasOwnProperty('banner') && bid.mediaTypes.banner.hasOwnProperty('sizes') ? bid.mediaTypes.banner.sizes : [];
impObj = {
id: bid.bidId,
tagid: bid.params.adUnit,
Expand Down Expand Up @@ -919,6 +920,9 @@ export const spec = {
} else {
utils.logWarn(LOG_WARN_PREFIX + 'dctr value not found in 1st adunit, ignoring values from subsequent adunits');
}
} else {
// Commenting out for prebid 1.21 release. Needs to be uncommented and changes from Prebid PR2941 to be pulled in.
// utils.logWarn(BIDDER_CODE + ': dctr value not found in 1st adunit, ignoring values from subsequent adunits');
}

_handleEids(payload);
Expand All @@ -939,37 +943,60 @@ export const spec = {
const bidResponses = [];
var respCur = DEFAULT_CURRENCY;
try {
let requestData = JSON.parse(request.data);
if (requestData && requestData.imp && requestData.imp.length > 0) {
requestData.imp.forEach(impData => {
bidResponses.push({
requestId: impData.id,
width: 0,
height: 0,
ttl: 300,
ad: '',
creativeId: 0,
netRevenue: NET_REVENUE,
cpm: 0,
currency: respCur,
referrer: requestData.site && requestData.site.ref ? requestData.site.ref : '',
})
});
}
if (response.body && response.body.seatbid && utils.isArray(response.body.seatbid)) {
// Supporting multiple bid responses for same adSize
respCur = response.body.cur || respCur;
response.body.seatbid.forEach(seatbidder => {
seatbidder.bid &&
utils.isArray(seatbidder.bid) &&
seatbidder.bid.forEach(bid => {
let parsedRequest = JSON.parse(request.data);
let newBid = {
requestId: bid.impid,
cpm: (parseFloat(bid.price) || 0).toFixed(2),
width: bid.w,
height: bid.h,
creativeId: bid.crid || bid.id,
dealId: bid.dealid,
currency: respCur,
netRevenue: NET_REVENUE,
ttl: 300,
referrer: parsedRequest.site && parsedRequest.site.ref ? parsedRequest.site.ref : '',
ad: bid.adm
};
if (parsedRequest.imp && parsedRequest.imp.length > 0) {
parsedRequest.imp.forEach(req => {
if (bid.impid === req.id && req.hasOwnProperty('video')) {
newBid.mediaType = 'video';
newBid.width = bid.hasOwnProperty('w') ? bid.w : req.video.w;
newBid.height = bid.hasOwnProperty('h') ? bid.h : req.video.h;
newBid.vastXml = bid.adm;
bidResponses.forEach(br => {
if (br.requestId == bid.impid) {
// br = {
br.requestId = bid.impid;
br.cpm = (parseFloat(bid.price) || 0).toFixed(2);
br.width = bid.w;
br.height = bid.h;
br.creativeId = bid.crid || bid.id;
br.dealId = bid.dealid;
br.currency = respCur;
br.netRevenue = NET_REVENUE;
br.ttl = 300;
br.referrer = requestData.site && requestData.site.ref ? requestData.site.ref : '';
br.ad = bid.adm;
// };
if (requestData.imp && requestData.imp.length > 0) {
requestData.imp.forEach(req => {
if (bid.impid === req.id && req.hasOwnProperty('video')) {
br.mediaType = 'video';
br.width = bid.hasOwnProperty('w') ? bid.w : req.video.w;
br.height = bid.hasOwnProperty('h') ? bid.h : req.video.h;
br.vastXml = bid.adm;
}
if (bid.impid === req.id && req.hasOwnProperty('native')) {
_parseNativeResponse(bid, br);
}
});
}
if (bid.impid === req.id && req.hasOwnProperty('native')) {
_parseNativeResponse(bid, newBid);
if (bid.ext && bid.ext.deal_channel) {
br['dealChannel'] = dealChannelValues[bid.ext.deal_channel] || null;
}
});
}
Expand Down
Loading

0 comments on commit 220f7c7

Please sign in to comment.