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

Update Platformio Adapter #2468

Merged
merged 62 commits into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 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
bc1cabc
Add files via upload
varashellov Apr 29, 2018
84e8163
Add files via upload
varashellov Apr 29, 2018
bbad3a2
Merge branch 'master' into master
varashellov Apr 29, 2018
d1327cb
Add files via upload
varashellov May 3, 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
69 changes: 54 additions & 15 deletions modules/platformioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const NATIVE_DEFAULTS = {
IMG_MIN: 150,
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];
Expand All @@ -22,15 +21,16 @@ export const spec = {
supportedMediaTypes: [BANNER, NATIVE, VIDEO],

isBidRequestValid: bid => (
!!(bid && bid.params && bid.params.pubId && bid.params.siteId)
!!(bid && bid.params && bid.params.pubId && bid.params.placementId)
),
buildRequests: bidRequests => {
const request = {
id: bidRequests[0].bidderRequestId,
at: 2,
imp: bidRequests.map(slot => impression(slot)),
site: site(bidRequests),
device: device(),
app: app(bidRequests),
device: device(bidRequests),
};
return {
method: 'POST',
Expand Down Expand Up @@ -101,6 +101,7 @@ function bidResponseAvailable(bidRequest, bidResponse) {
function impression(slot) {
return {
id: slot.bidId,
secure: window.location.protocol === 'https:' ? 1 : 0,
'banner': banner(slot),
'native': nativeImpression(slot),
'video': videoImpression(slot),
Expand All @@ -110,10 +111,16 @@ function impression(slot) {
}

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

Expand Down Expand Up @@ -207,25 +214,57 @@ function dataAsset(id, params, type, defaultLen) {
function site(bidderRequest) {
const pubId = bidderRequest && bidderRequest.length > 0 ? bidderRequest[0].params.pubId : '0';
const siteId = bidderRequest && bidderRequest.length > 0 ? bidderRequest[0].params.siteId : '0';
return {
publisher: {
id: pubId.toString(),
domain: utils.getTopWindowLocation().hostname,
},
id: siteId.toString(),
ref: utils.getTopWindowReferrer(),
page: utils.getTopWindowLocation().href,
const appParams = bidderRequest[0].params.app;
if (!appParams) {
return {
publisher: {
id: pubId.toString(),
domain: utils.getTopWindowLocation().hostname,
},
id: siteId.toString(),
ref: utils.getTopWindowReferrer(),
page: utils.getTopWindowLocation().href,
}
}
return null;
}

function app(bidderRequest) {
const pubId = bidderRequest && bidderRequest.length > 0 ? bidderRequest[0].params.pubId : '0';
const appParams = bidderRequest[0].params.app;
if (appParams) {
return {
publisher: {
id: pubId.toString(),
},
id: appParams.id,
name: appParams.name,
bundle: appParams.bundle,
storeurl: appParams.storeUrl,
domain: appParams.domain,
}
}
return null;
}

function device() {
function device(bidderRequest) {
const lat = bidderRequest && bidderRequest.length > 0 ? bidderRequest[0].params.latitude : '';
const lon = bidderRequest && bidderRequest.length > 0 ? bidderRequest[0].params.longitude : '';
const ifa = bidderRequest && bidderRequest.length > 0 ? bidderRequest[0].params.ifa : '';
return {
dnt: utils.getDNT() ? 1 : 0,
ua: navigator.userAgent,
language: (navigator.language || navigator.browserLanguage || navigator.userLanguage || navigator.systemLanguage),
w: (window.screen.width || window.innerWidth),
h: (window.screen.height || window.innerHeigh),
geo: {
lat: lat,
lon: lon,
},
ifa: ifa,
};
}

function parse(rawResponse) {
try {
if (rawResponse) {
Expand Down
6 changes: 5 additions & 1 deletion modules/platformioBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Please use ```platformio``` as the bidder code.
pubId: '29521',
siteId: '26048',
placementId: '123',
bidFloor: '0.001', // optional
ifa: 'XXX-XXX', // optional
latitude: '40.712775', // optional
longitude: '-74.005973', // optional
}
}]
},
Expand Down Expand Up @@ -76,7 +80,7 @@ Please use ```platformio``` as the bidder code.
size: '640X480',
placementId: '123',
video: {
skippable: true,
skipppable: true,
}
}
}]
Expand Down
39 changes: 37 additions & 2 deletions test/spec/modules/platformioBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ describe('Platform.io Adapter Tests', () => {
siteId: '26047',
placementId: '123',
size: '300x250',
bidFloor: '0.001'
bidFloor: '0.001',
ifa: 'IFA',
latitude: '40.712775',
longitude: '-74.005973'
}
}, {
placementCode: '/DfpAccount2/slot2',
Expand All @@ -24,7 +27,7 @@ describe('Platform.io Adapter Tests', () => {
siteId: '26047',
placementId: '1234',
size: '728x90',
bidFloor: '0.000001'
bidFloor: '0.000001',
}
}];
const nativeSlotConfig = [{
Expand Down Expand Up @@ -58,6 +61,21 @@ describe('Platform.io Adapter Tests', () => {
size: '640x480'
}
}];
const appSlotConfig = [{
placementCode: '/DfpAccount1/slot5',
bidId: 'bid12345',
params: {
pubId: '29521',
placementId: '1234',
app: {
id: '1111',
name: 'app name',
bundle: 'io.platform.apps',
storeUrl: 'http://platform.io/apps',
domain: 'platform.io'
}
}
}];

it('Verify build request', () => {
const request = spec.buildRequests(slotConfigs);
Expand All @@ -74,6 +92,9 @@ describe('Platform.io Adapter Tests', () => {
// device object
expect(ortbRequest.device).to.not.equal(null);
expect(ortbRequest.device.ua).to.equal(navigator.userAgent);
expect(ortbRequest.device.ifa).to.equal('IFA');
expect(ortbRequest.device.geo.lat).to.equal('40.712775');
expect(ortbRequest.device.geo.lon).to.equal('-74.005973');
// slot 1
expect(ortbRequest.imp[0].tagid).to.equal('123');
expect(ortbRequest.imp[0].banner).to.not.equal(null);
Expand Down Expand Up @@ -278,4 +299,18 @@ describe('Platform.io Adapter Tests', () => {
expect(spec.isBidRequestValid(nativeSlotConfig[0])).to.equal(true);
expect(spec.isBidRequestValid(videoSlotConfig[0])).to.equal(true);
});

it('Verify app requests', () => {
const request = spec.buildRequests(appSlotConfig);
const ortbRequest = JSON.parse(request.data);
expect(ortbRequest.site).to.equal(null);
expect(ortbRequest.app).to.not.be.null;
expect(ortbRequest.app.publisher).to.not.equal(null);
expect(ortbRequest.app.publisher.id).to.equal('29521');
expect(ortbRequest.app.id).to.equal('1111');
expect(ortbRequest.app.name).to.equal('app name');
expect(ortbRequest.app.bundle).to.equal('io.platform.apps');
expect(ortbRequest.app.storeurl).to.equal('http://platform.io/apps');
expect(ortbRequest.app.domain).to.equal('platform.io');
});
});