Skip to content

Commit

Permalink
Module - Size Mapping V2 (prebid#4690)
Browse files Browse the repository at this point in the history
* implement size bucket filtration logic

* finish implmenation of getFilteredMediaTypes

* implement getBids function

* log useful information to the console

* enable test workflow

* modify checkAdUnitSetup function to account for the new sizeConfig object

* remove unrelated example

* add decider function to choose between sizeMapping v1 and sizeMapping v2

* add getBidsHook for s2s bidders

* handle edge case where all mediaTypes get filtered out and the case when bidder gets filtered out

* add test examples for banner media type

* update label check to pick up the fist label operator instead of the last on incase there are multiple lables present

* added example for label checks with banner ad

* add checkAdUnit setup hook on sizeMappingV2 modules to check presence of sizeConfig property in addition to doing normal adUnit checks

* restore old hello world example

* give free pass to video mediaTypes configured with sizeConfig property, while keeping in place the essential sizeConfig checks

* fixing minor bus and enchancing bidder level sizeConfig checks

* bugfix: checkBidderSizeConfigFormat

* add more scenarios for testing sizeMapping V2

* small docs changes

* feedback1 changes

* modify logic for bailing out

* add module description

* refactor isUsingNewSizeMapping function by making it a pure function

* add unit test case for isUsingNewSizeMapping function

* made adUnit checks more robusts and fully make adUnit.mediaTypes mandatory

* remove redundancy in checAdUnitSetupHook

* add banner units test cases for checkAdUnitSetupHook function

* add video and native mediaTypes units test for checkAdUnitSetupHook function

* rewrite some of the log messages

* redefine log messages to make it simple to the end user

* code optimization done so that getFilteredMediaTypes function gets called only once per adUnit per auction

* add code comments

* code refactorization and more unit test cases

* more unit tests for getBids function

* add sizeMapping usage example

* delete sizeMappingV2 directory

* add doctype declaration

* fix LGTM alert and revert changes to pbjs_api.spec.js

* fix LGTM alerts in sizeMappingV2_spec file

* add file extension for imports
  • Loading branch information
Fawke authored and mi.chen committed Mar 31, 2020
1 parent 50fc0dd commit 8d205fc
Show file tree
Hide file tree
Showing 6 changed files with 2,315 additions and 44 deletions.
121 changes: 121 additions & 0 deletions integrationExamples/gpt/responsiveAds_sizeMappingV2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<!DOCTYPE html>
<html>

<head>
<script async src="../../../build/dev/prebid.js"></script>
<script async src="https://www.googletagservices.com/tag/js/gpt.js"></script>
<script>
const FAILSAFE_TIMEOUT = 3300;
const PREBID_TIMEOUT = 1000;

const adUnits = [{
code: 'div-gpt-ad-1460505748561-0',
mediaTypes: {
banner: {
sizeConfig: [
{ minViewPort: [0, 0], sizes: [] }, // remove if < 750px
{ minViewPort: [750, 0], sizes: [[300, 250], [300, 600]] }, // between 750px and 1199px
{ minViewPort: [1200, 0], sizes: [[970, 90], [728, 90], [300, 250]] }, // between 1200px and 1599px
{ minViewPort: [1600, 0], sizes: [[1000, 300], [970, 90], [728, 90], [300, 250]] } // greater than 1600px
]
},
video: {
context: 'instream',
sizeConfig: [
{ minViewPort: [0, 0], playerSize: [] },
{ minViewPort: [800, 0], playerSize: [640, 480] }
]
},
native: {
image: {
required: true,
sizes: [150, 50]
},

sizeConfig: [
{ minViewPort: [0, 0], active: false },
{ minViewPort: [600, 0], active: true }
]
}
},
bids: [{
bidder: 'appnexus',
params: {
placementId: 13144370
},
sizeConfig: [
{ minViewPort: [0, 0], relevantMediaTypes: ['none'] },
{ minViewPort: [850, 0], relevantMediaTypes: ['banner'] }
]
}, {
bidder: 'rubicon',
params: {
accountId: 14062,
siteId: 70608,
zoneId: 498816
},
sizeConfig: [
{ minViewPort: [0, 0], relevantMediaTypes: ['none'] },
{ minViewPort: [850, 0], relevantMediaTypes: ['native'] },
{ minViewPort: [1200, 0], relevantMediaTypes: ['none'] }
]
}]
}];
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];

</script>

<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(function () {
googletag.pubads().disableInitialLoad();
});

pbjs.que.push(function () {
pbjs.addAdUnits(adUnits);
pbjs.requestBids({
bidsBackHandler: sendAdserverRequest,
timeout: PREBID_TIMEOUT
});
});

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();
}, FAILSAFE_TIMEOUT);

</script>

<script>
googletag.cmd.push(function () {
googletag.defineSlot('/19968336/header-bid-tag-0', [728, 90], '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>
2 changes: 1 addition & 1 deletion modules/adpod.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export function checkAdUnitSetupHook(fn, adUnits) {

let errMsg = `Detected missing or incorrectly setup fields for an adpod adUnit. Please review the following fields of adUnitCode: ${adUnit.code}. This adUnit will be removed from the auction.`;

let playerSize = !!(videoConfig.playerSize && utils.isArrayOfNums(videoConfig.playerSize));
let playerSize = !!((videoConfig.playerSize && utils.isArrayOfNums(videoConfig.playerSize)) || (videoConfig.sizeConfig));
let adPodDurationSec = !!(videoConfig.adPodDurationSec && utils.isNumber(videoConfig.adPodDurationSec) && videoConfig.adPodDurationSec > 0);
let durationRangeSec = !!(videoConfig.durationRangeSec && utils.isArrayOfNums(videoConfig.durationRangeSec) && videoConfig.durationRangeSec.every(range => range > 0));

Expand Down
Loading

0 comments on commit 8d205fc

Please sign in to comment.