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 54 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
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
133 changes: 85 additions & 48 deletions modules/platformioBidAdapter.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,85 @@
# Overview

**Module Name**: Platform.io Bidder Adapter
**Module Type**: Bidder Adapter
**Maintainer**: siarhei.kasukhin@platform.io

# Description

Connects to Platform.io demand source to fetch bids.
Banner and Native formats are supported.
Please use ```platformio``` as the bidder code.

# Test Parameters
```
var adUnits = [{
code: 'banner-ad-div',
sizes: [[300, 250]],
bids: [{
bidder: 'platformio',
params: {
pubId: '29521', // required
siteId: '26047', // required
size: '250X250', // required
placementId: '123', // required
bidFloor: '0.001'
}
}]
},{
code: 'native-ad-div',
sizes: [[1, 1]],
nativeParams: {
title: { required: true, len: 75 },
image: { required: true },
body: { len: 200 },
sponsoredBy: { len: 20 },
icon: { required: false }
},
bids: [{
bidder: 'platformio',
params: {
pubId: '29521', // required
siteId: '26047', // required
placementId: '123', // required
bidFloor: '0.001'
}
}]
}];
```
# Overview

**Module Name**: Platform.io Bidder Adapter
**Module Type**: Bidder Adapter
**Maintainer**: siarhei.kasukhin@platform.io

# Description

Connects to Platform.io demand source to fetch bids.
Banner, Native, Video formats are supported.
Please use ```platformio``` as the bidder code.

# Test Parameters
```
var adUnits = [{
code: 'dfp-native-div',
mediaType: 'native',
mediaTypes: {
native: {
title: {
required: true,
len: 75
},
image: {
required: true
},
body: {
len: 200
},
icon: {
required: false
}
}
},
bids: [{
bidder: 'platformio',
params: {
pubId: '29521',
siteId: '26048',
placementId: '123',
}
}]
},
{
code: 'dfp-banner-div',
mediaTypes: {
banner: {
sizes: [
[300, 250]
],
}
},
bids: [{
bidder: 'platformio',
params: {
pubId: '29521',
siteId: '26049',
size: '300X250',
placementId: '123',
}
}]
},
{
code: 'dfp-video-div',
sizes: [640, 480],
mediaTypes: {
video: {
context: "instream"
}
},
bids: [{
bidder: 'platformio',
params: {
pubId: '29521',
siteId: '26049',
size: '640X480',
placementId: '123',
video: {
skippable: true,
}
}
}]
}
];
```
76 changes: 73 additions & 3 deletions test/spec/modules/platformioBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import {expect} from 'chai';
import {spec} from 'modules/platformioBidAdapter';
import {getTopWindowLocation} from 'src/utils';
Expand All @@ -8,6 +7,7 @@ describe('Platform.io Adapter Tests', () => {
const slotConfigs = [{
placementCode: '/DfpAccount1/slot1',
bidId: 'bid12345',
mediaType: 'banner',
params: {
pubId: '29521',
siteId: '26047',
Expand All @@ -18,6 +18,7 @@ describe('Platform.io Adapter Tests', () => {
}, {
placementCode: '/DfpAccount2/slot2',
bidId: 'bid23456',
mediaType: 'banner',
params: {
pubId: '29521',
siteId: '26047',
Expand All @@ -29,6 +30,7 @@ describe('Platform.io Adapter Tests', () => {
const nativeSlotConfig = [{
placementCode: '/DfpAccount1/slot3',
bidId: 'bid12345',
mediaType: 'native',
nativeParams: {
title: { required: true, len: 200 },
body: {},
Expand All @@ -42,6 +44,20 @@ describe('Platform.io Adapter Tests', () => {
siteId: '26047'
}
}];
const videoSlotConfig = [{
placementCode: '/DfpAccount1/slot4',
bidId: 'bid12345678',
mediaType: 'video',
video: {
skippable: true
},
params: {
pubId: '29521',
placementId: '1234567',
siteId: '26047',
size: '640x480'
}
}];

it('Verify build request', () => {
const request = spec.buildRequests(slotConfigs);
Expand Down Expand Up @@ -111,7 +127,7 @@ describe('Platform.io Adapter Tests', () => {
expect(request.url).to.equal('//piohbdisp.hb.adx1.com/');
expect(request.method).to.equal('POST');
const ortbRequest = JSON.parse(request.data);
// // native impression
// native impression
expect(ortbRequest.imp[0].tagid).to.equal('123');
const nativePart = ortbRequest.imp[0]['native'];
expect(nativePart).to.not.equal(null);
Expand Down Expand Up @@ -194,18 +210,72 @@ describe('Platform.io Adapter Tests', () => {
expect(nativeBid.impressionTrackers[0]).to.equal('http://rtb.adx1.com/log');
});

it('Verify Video request', () => {
const request = spec.buildRequests(videoSlotConfig);
expect(request.url).to.equal('//piohbdisp.hb.adx1.com/');
expect(request.method).to.equal('POST');
const videoRequest = JSON.parse(request.data);
// site object
expect(videoRequest.site).to.not.equal(null);
expect(videoRequest.site.publisher.id).to.equal('29521');
expect(videoRequest.site.ref).to.equal(window.top.document.referrer);
expect(videoRequest.site.page).to.equal(getTopWindowLocation().href);
// device object
expect(videoRequest.device).to.not.equal(null);
expect(videoRequest.device.ua).to.equal(navigator.userAgent);
// slot 1
expect(videoRequest.imp[0].tagid).to.equal('1234567');
expect(videoRequest.imp[0].video).to.not.equal(null);
expect(videoRequest.imp[0].video.w).to.equal(640);
expect(videoRequest.imp[0].video.h).to.equal(480);
expect(videoRequest.imp[0].banner).to.equal(null);
expect(videoRequest.imp[0].native).to.equal(null);
});

it('Verify parse video response', () => {
const request = spec.buildRequests(videoSlotConfig);
const videoRequest = JSON.parse(request.data);
const videoResponse = {
seatbid: [{
bid: [{
impid: videoRequest.imp[0].id,
price: 1.90,
adm: 'http://vid.example.com/9876',
crid: '510511_754567308'
}]
}],
cur: 'USD'
};
const bids = spec.interpretResponse({ body: videoResponse }, request);
expect(bids).to.have.lengthOf(1);
// verify first bid
const bid = bids[0];
expect(bid.cpm).to.equal(1.90);
expect(bid.vastUrl).to.equal('http://vid.example.com/9876');
expect(bid.crid).to.equal('510511_754567308');
expect(bid.width).to.equal(640);
expect(bid.height).to.equal(480);
expect(bid.adId).to.equal('bid12345678');
expect(bid.netRevenue).to.equal(true);
expect(bid.currency).to.equal('USD');
expect(bid.ttl).to.equal(360);
});

it('Verifies bidder code', () => {
expect(spec.code).to.equal('platformio');
});

it('Verifies supported media types', () => {
expect(spec.supportedMediaTypes).to.have.lengthOf(2);
expect(spec.supportedMediaTypes).to.have.lengthOf(3);
expect(spec.supportedMediaTypes[0]).to.equal('banner');
expect(spec.supportedMediaTypes[1]).to.equal('native');
expect(spec.supportedMediaTypes[2]).to.equal('video');
});

it('Verifies if bid request valid', () => {
expect(spec.isBidRequestValid(slotConfigs[0])).to.equal(true);
expect(spec.isBidRequestValid(slotConfigs[1])).to.equal(true);
expect(spec.isBidRequestValid(nativeSlotConfig[0])).to.equal(true);
expect(spec.isBidRequestValid(videoSlotConfig[0])).to.equal(true);
});
});