Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Platform.io video support #2318

Merged
merged 58 commits into from
Mar 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
2cc71fb
Add PlatformioBidAdapter
varashellov Aug 1, 2017
6801ca1
Update platformioBidAdapter.js
varashellov Aug 2, 2017
9bdcd7e
Add files via upload
varashellov Aug 2, 2017
06c04ce
Update hello_world.html
varashellov Aug 2, 2017
3e11a2a
Update platformioBidAdapter.js
varashellov Aug 2, 2017
e3d049e
Update platformioBidAdapter_spec.js
varashellov Aug 2, 2017
c09d8ae
Update hello_world.html
varashellov Aug 2, 2017
e0be49c
Update platformioBidAdapter_spec.js
varashellov Aug 7, 2017
eedbd3e
Update platformioBidAdapter.js
varashellov Aug 14, 2017
faa9963
Update hello_world.html
varashellov Aug 14, 2017
946d081
Add files via upload
varashellov Aug 14, 2017
69b4f57
Update platformioBidAdapter
varashellov Aug 16, 2017
659562a
Update platformioBidAdapter
varashellov Aug 16, 2017
66a3f7f
Update platformioBidAdapter
varashellov Aug 16, 2017
225b798
Merge pull request #1 from varashellov/varashellov-patch-1
varashellov Aug 16, 2017
cd21b96
Add files via upload
varashellov Oct 17, 2017
e426d54
Add files via upload
varashellov Oct 17, 2017
4ac6786
Add files via upload
varashellov Oct 17, 2017
6cc3ec1
Merge branch 'master' into master
varashellov Oct 18, 2017
ccdfd49
Update platformioBidAdapter.js
varashellov Oct 19, 2017
3947c83
Update platformioBidAdapter_spec.js
varashellov Oct 19, 2017
6451e5b
Update platformioBidAdapter_spec.js
varashellov Oct 19, 2017
9282871
Update platformioBidAdapter_spec.js
varashellov Oct 19, 2017
7b60d11
Update platformioBidAdapter.js
varashellov Oct 19, 2017
1124da8
Update platformioBidAdapter.js
varashellov Oct 19, 2017
176c633
Update platformioBidAdapter_spec.js
varashellov Oct 19, 2017
96245d6
Add files via upload
varashellov Oct 20, 2017
380be34
Add files via upload
varashellov Oct 20, 2017
ffcfb29
Add files via upload
varashellov Oct 20, 2017
6d9cff3
Add files via upload
varashellov Nov 9, 2017
8ea886d
Add files via upload
varashellov Nov 9, 2017
0896c99
Add files via upload
varashellov Nov 9, 2017
764034a
Merge branch 'master' into master
varashellov Nov 9, 2017
af7b0c4
Update platformioBidAdapter.js
varashellov Nov 13, 2017
c1c9a48
Update platformioBidAdapter_spec.js
varashellov Nov 13, 2017
8da6491
Add files via upload
varashellov Jan 3, 2018
fa0d7b5
Add files via upload
varashellov Jan 3, 2018
dd6b0ef
Merge branch 'master' into master
varashellov Jan 3, 2018
ea0a5a0
Merge branch 'master' into master
varashellov Jan 3, 2018
02d65be
Add files via upload
varashellov Mar 7, 2018
8c279c0
Add files via upload
varashellov Mar 7, 2018
2ee61f6
Merge branch 'master' into master
varashellov Mar 7, 2018
b45d144
Update platformioBidAdapter_spec.js
varashellov Mar 7, 2018
d78f613
Update platformioBidAdapter.js
varashellov Mar 7, 2018
0bd73d1
Update platformioBidAdapter.md
varashellov Mar 10, 2018
c3cb234
Add files via upload
varashellov Mar 26, 2018
1dd1462
Add files via upload
varashellov Mar 26, 2018
f0eb8ac
Add files via upload
varashellov Mar 26, 2018
110384f
Merge branch 'master' into master
varashellov Mar 26, 2018
445ff71
Update platformioBidAdapter.md
varashellov Mar 28, 2018
70b7193
Update platformioBidAdapter.md
varashellov Mar 28, 2018
3bf9cbc
Update platformioBidAdapter.js
varashellov Mar 28, 2018
d61713c
Update platformioBidAdapter_spec.js
varashellov Mar 28, 2018
36b8d65
Update platformioBidAdapter.md
varashellov Mar 28, 2018
6653030
Add files via upload
varashellov Mar 28, 2018
6e4a678
Add files via upload
varashellov Mar 28, 2018
795381b
Delete hello_world.html
varashellov Mar 29, 2018
8eecd2d
Add files via upload
varashellov Mar 29, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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