Skip to content

Commit

Permalink
Platform.io video support (#2318)
Browse files Browse the repository at this point in the history
* Add PlatformioBidAdapter

* Update platformioBidAdapter.js

* Add files via upload

* Update hello_world.html

* Update platformioBidAdapter.js

* Update platformioBidAdapter_spec.js

* Update hello_world.html

* Update platformioBidAdapter_spec.js

* Update platformioBidAdapter.js

* Update hello_world.html

* Add files via upload

* Update platformioBidAdapter

## Type of change
- [x] Other

## Description of change
1. RequestURL changes
2. Add placementCode to request params

* Update platformioBidAdapter

* Update platformioBidAdapter

## Type of change
- [x] Other

## Description of change
1. RequestURL changes
2. Add placementCode to request params

* Add files via upload

* Add files via upload

* Add files via upload

* Update platformioBidAdapter.js

Endpoint URL change

* Update platformioBidAdapter_spec.js

Endpoint URL change

* Update platformioBidAdapter_spec.js

* Update platformioBidAdapter_spec.js

* Update platformioBidAdapter.js

* Update platformioBidAdapter.js

* Update platformioBidAdapter_spec.js

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Update platformioBidAdapter.js

* Update platformioBidAdapter_spec.js

* Add files via upload

* Add files via upload

* Add files via upload

* Add files via upload

* Update platformioBidAdapter_spec.js

* Update platformioBidAdapter.js

* Update platformioBidAdapter.md

* Add files via upload

* Add files via upload

* Add files via upload

* Update platformioBidAdapter.md

* Update platformioBidAdapter.md

* Update platformioBidAdapter.js

* Update platformioBidAdapter_spec.js

* Update platformioBidAdapter.md

* Add files via upload

* Add files via upload

* Delete hello_world.html

* Add files via upload
  • Loading branch information
varashellov authored and jsnellbaker committed Mar 30, 2018
1 parent a34dbe2 commit 7407a44
Show file tree
Hide file tree
Showing 4 changed files with 312 additions and 164 deletions.
194 changes: 97 additions & 97 deletions integrationExamples/gpt/hello_world.html
Original file line number Diff line number Diff line change
@@ -1,98 +1,98 @@
<!--
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.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>
<!--
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.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>
73 changes: 57 additions & 16 deletions modules/platformioBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import {logError, getTopWindowLocation, getTopWindowReferrer} from 'src/utils';
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';
import { BANNER, NATIVE, VIDEO } from 'src/mediaTypes';
import includes from 'core-js/library/fn/array/includes';

const NATIVE_DEFAULTS = {
TITLE_LEN: 100,
Expand All @@ -10,10 +11,15 @@ const NATIVE_DEFAULTS = {
ICON_MIN: 50,
};

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

export const spec = {

code: 'platformio',
supportedMediaTypes: ['banner', 'native'],
supportedMediaTypes: [BANNER, NATIVE, VIDEO],

isBidRequestValid: bid => (
!!(bid && bid.params && bid.params.pubId && bid.params.siteId)
Expand Down Expand Up @@ -69,7 +75,14 @@ function bidResponseAvailable(bidRequest, bidResponse) {
nurl = nurl.replace(/\$(%7B|\{)AUCTION_BID_ID(%7D|\})/gi, bidResponse.bidid);
bid['native']['impressionTrackers'] = [nurl];
bid.mediaType = 'native';
} else {
} else if (idToImpMap[id]['video']) {
bid.vastUrl = idToBidMap[id].adm;
bid.vastUrl = bid.vastUrl.replace(/\$(%7B|\{)AUCTION_PRICE(%7D|\})/gi, idToBidMap[id].price);
bid.crid = idToBidMap[id].crid;
bid.width = idToImpMap[id].video.w;
bid.height = idToImpMap[id].video.h;
bid.mediaType = 'video';
} else if (idToImpMap[id]['banner']) {
bid.ad = idToBidMap[id].adm;
bid.ad = bid.ad.replace(/\$(%7B|\{)AUCTION_IMP_ID(%7D|\})/gi, idToBidMap[id].impid);
bid.ad = bid.ad.replace(/\$(%7B|\{)AUCTION_AD_ID(%7D|\})/gi, idToBidMap[id].adid);
Expand All @@ -78,6 +91,7 @@ function bidResponseAvailable(bidRequest, bidResponse) {
bid.ad = bid.ad.replace(/\$(%7B|\{)AUCTION_BID_ID(%7D|\})/gi, bidResponse.bidid);
bid.width = idToImpMap[id].banner.w;
bid.height = idToImpMap[id].banner.h;
bid.mediaType = 'banner';
}
bids.push(bid);
}
Expand All @@ -87,26 +101,53 @@ function bidResponseAvailable(bidRequest, bidResponse) {
function impression(slot) {
return {
id: slot.bidId,
banner: banner(slot),
'banner': banner(slot),
'native': nativeImpression(slot),
'video': videoImpression(slot),
bidfloor: slot.params.bidFloor || '0.000001',
tagid: slot.params.placementId.toString(),
};
}

function getSizes(slot) {
const size = slot.params.size.toUpperCase().split('X');
return {
width: parseInt(size[0]),
height: parseInt(size[1]),
};
}

function banner(slot) {
if (!slot.nativeParams) {
const size = slot.params.size.toUpperCase().split('X');
const width = parseInt(size[0]);
const height = parseInt(size[1]);
if (slot.mediaType === 'banner' || utils.deepAccess(slot, 'mediaTypes.banner')) {
const sizes = getSizes(slot);
return {
w: width,
h: height,
w: sizes.width,
h: sizes.height,
};
};
}
return null;
}

function videoImpression(slot) {
if (slot.mediaType === 'video' || utils.deepAccess(slot, 'mediaTypes.video')) {
const sizes = getSizes(slot);
const video = {
w: sizes.width,
h: sizes.height,
mimes: DEFAULT_MIMES,
protocols: DEFAULT_PROTOCOLS,
api: DEFAULT_APIS,
};
if (slot.params.video) {
Object.keys(slot.params.video).filter(param => includes(VIDEO_TARGETING, param)).forEach(param => video[param] = slot.params.video[param]);
}
return video;
}
return null;
}

function nativeImpression(slot) {
if (slot.nativeParams) {
if (slot.mediaType === 'native' || utils.deepAccess(slot, 'mediaTypes.native')) {
const assets = [];
addAsset(assets, titleAsset(1, slot.nativeParams.title, NATIVE_DEFAULTS.TITLE_LEN));
addAsset(assets, dataAsset(2, slot.nativeParams.body, 2, NATIVE_DEFAULTS.DESCR_LEN));
Expand Down Expand Up @@ -169,11 +210,11 @@ function site(bidderRequest) {
return {
publisher: {
id: pubId.toString(),
domain: getTopWindowLocation().hostname,
domain: utils.getTopWindowLocation().hostname,
},
id: siteId.toString(),
ref: getTopWindowReferrer(),
page: getTopWindowLocation().href,
ref: utils.getTopWindowReferrer(),
page: utils.getTopWindowLocation().href,
}
}

Expand Down
Loading

0 comments on commit 7407a44

Please sign in to comment.