From ab93aaade4142b15af33c3748ba0014bc0ade88c Mon Sep 17 00:00:00 2001 From: "takaaki.kojima" Date: Fri, 5 Oct 2018 16:38:58 +0900 Subject: [PATCH 1/4] update AdGeneration adapter --- modules/adgenerationBidAdapter.js | 40 ++++++++++++++++++- modules/adgenerationBidAdapter.md | 1 + .../modules/adgenerationBidAdapter_spec.js | 15 ++++--- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/modules/adgenerationBidAdapter.js b/modules/adgenerationBidAdapter.js index 1753446fc67..faffae63edb 100644 --- a/modules/adgenerationBidAdapter.js +++ b/modules/adgenerationBidAdapter.js @@ -1,5 +1,4 @@ import * as utils from 'src/utils'; -// import {config} from 'src/config'; import {registerBidder} from 'src/adapters/bidderFactory'; import {BANNER, NATIVE} from 'src/mediaTypes'; const ADG_BIDDER_CODE = 'adgeneration'; @@ -15,7 +14,7 @@ export const spec = { * @return boolean True if this is a valid bid, and false otherwise. */ isBidRequestValid: function (bid) { - return !!(bid.params.id); + return !!(bid.params.id) && (isValidCurrency(bid.params.currency)); }, /** * Make a server request from the list of BidRequests. @@ -24,6 +23,7 @@ export const spec = { * @return ServerRequest Info describing the request to the server. */ buildRequests: function (validBidRequests) { + const ADGENE_PREBID_VERSION = '1.0.1'; let serverRequests = []; for (let i = 0, len = validBidRequests.length; i < len; i++) { const validReq = validBidRequests[i]; @@ -38,6 +38,12 @@ export const spec = { data = utils.tryAppendQueryString(data, 'hb', 'true'); data = utils.tryAppendQueryString(data, 't', 'json3'); data = utils.tryAppendQueryString(data, 'transactionid', validReq.transactionId); + data = utils.tryAppendQueryString(data, 'sizes', getSizes(validReq)); + data = utils.tryAppendQueryString(data, 'currency', validReq.params.currency.toUpperCase()); + data = utils.tryAppendQueryString(data, 'pbver', '$prebid.version$'); + data = utils.tryAppendQueryString(data, 'sdkname', 'prebidjs'); + data = utils.tryAppendQueryString(data, 'adapterver', ADGENE_PREBID_VERSION); + data = utils.tryAppendQueryString(data, 'tp', utils.getTopWindowUrl()); // native以外にvideo等の対応が入った場合は要修正 if (!validReq.mediaTypes || !validReq.mediaTypes.native) { @@ -198,4 +204,34 @@ function removeWrapper(ad) { return ad.substr(bodyIndex, lastBodyIndex).replace('', '').replace('', ''); } +/** + * request + * @param validReq request + * @returns {?string} 300x250,320x50... + */ +function getSizes(validReq) { + const sizes = validReq.sizes; + if (!sizes || sizes.length < 1) return null; + let sizesStr = null; + for (const i in sizes) { + const size = sizes[i]; + if (sizesStr == null) { + sizesStr = size[0] + 'x' + size[1]; + } else { + sizesStr += ',' + size[0] + 'x' + size[1]; + } + } + return sizesStr; +} + +/** + * @param {?string} currency + * @return {!boolean} + */ +function isValidCurrency(currency) { + if (!currency) return false; + const upperCurrency = currency.toUpperCase(); + return (upperCurrency === 'JPY' || upperCurrency === 'USD') +} + registerBidder(spec); diff --git a/modules/adgenerationBidAdapter.md b/modules/adgenerationBidAdapter.md index 7d8281be9b2..4a475d4d1ba 100644 --- a/modules/adgenerationBidAdapter.md +++ b/modules/adgenerationBidAdapter.md @@ -24,6 +24,7 @@ var adUnits = [ bidder: 'adg', params: { id: '58278', // banner + currency: 'JPY', } }, ] diff --git a/test/spec/modules/adgenerationBidAdapter_spec.js b/test/spec/modules/adgenerationBidAdapter_spec.js index 558303ccecb..fc24eda60a7 100644 --- a/test/spec/modules/adgenerationBidAdapter_spec.js +++ b/test/spec/modules/adgenerationBidAdapter_spec.js @@ -15,10 +15,11 @@ describe('AdgenerationAdapter', function () { }); describe('isBidRequestValid', function () { - let bid = { + const bid = { 'bidder': 'adg', 'params': { id: '58278', // banner + currency: 'JPY', } }; it('should return true when required params found', function () { @@ -39,11 +40,10 @@ describe('AdgenerationAdapter', function () { bidder: 'adg', params: { id: '58278', - width: '300', - height: '250' + currency: 'JPY', }, adUnitCode: 'adunit-code', - sizes: [[300, 250]], + sizes: [[300, 250], [320, 100]], bidId: '2f6ac468a9c15e', bidderRequestId: '14a9f773e30243', auctionId: '4aae9f05-18c6-4fcd-80cf-282708cd584a', @@ -53,8 +53,7 @@ describe('AdgenerationAdapter', function () { bidder: 'adg', params: { id: '58278', - width: '300', - height: '250' + currency: 'JPY', }, mediaTypes: { native: { @@ -88,8 +87,8 @@ describe('AdgenerationAdapter', function () { } ]; const data = { - banner: 'posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&imark=1', - native: 'posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3' + banner: `posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=300x250%2C320x100¤cy=JPY&pbver=%24prebid.version%24&sdkname=prebidjs&adapterver=1.0.1&tp=http%3A%2F%2Flocalhost%3A9876%2F&imark=1`, + native: 'posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=1x1¤cy=JPY&pbver=%24prebid.version%24&sdkname=prebidjs&adapterver=1.0.1&tp=http%3A%2F%2Flocalhost%3A9876%2F' }; it('sends bid request to ENDPOINT via GET', function () { const request = spec.buildRequests(bidRequests)[0]; From 9a774571fbee31b8e31f037d716c203e14e4970c Mon Sep 17 00:00:00 2001 From: "takaaki.kojima" Date: Thu, 25 Oct 2018 18:23:15 +0900 Subject: [PATCH 2/4] fix test spec --- modules/adgenerationBidAdapter.js | 4 +--- test/spec/modules/adgenerationBidAdapter_spec.js | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/modules/adgenerationBidAdapter.js b/modules/adgenerationBidAdapter.js index faffae63edb..d5bfe44d05a 100644 --- a/modules/adgenerationBidAdapter.js +++ b/modules/adgenerationBidAdapter.js @@ -43,13 +43,11 @@ export const spec = { data = utils.tryAppendQueryString(data, 'pbver', '$prebid.version$'); data = utils.tryAppendQueryString(data, 'sdkname', 'prebidjs'); data = utils.tryAppendQueryString(data, 'adapterver', ADGENE_PREBID_VERSION); - data = utils.tryAppendQueryString(data, 'tp', utils.getTopWindowUrl()); - // native以外にvideo等の対応が入った場合は要修正 if (!validReq.mediaTypes || !validReq.mediaTypes.native) { data = utils.tryAppendQueryString(data, 'imark', '1'); } - + data = utils.tryAppendQueryString(data, 'tp', utils.getTopWindowUrl()); // remove the trailing "&" if (data.lastIndexOf('&') === data.length - 1) { data = data.substring(0, data.length - 1); diff --git a/test/spec/modules/adgenerationBidAdapter_spec.js b/test/spec/modules/adgenerationBidAdapter_spec.js index fc24eda60a7..c2d986df224 100644 --- a/test/spec/modules/adgenerationBidAdapter_spec.js +++ b/test/spec/modules/adgenerationBidAdapter_spec.js @@ -87,8 +87,8 @@ describe('AdgenerationAdapter', function () { } ]; const data = { - banner: `posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=300x250%2C320x100¤cy=JPY&pbver=%24prebid.version%24&sdkname=prebidjs&adapterver=1.0.1&tp=http%3A%2F%2Flocalhost%3A9876%2F&imark=1`, - native: 'posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=1x1¤cy=JPY&pbver=%24prebid.version%24&sdkname=prebidjs&adapterver=1.0.1&tp=http%3A%2F%2Flocalhost%3A9876%2F' + banner: `posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=300x250%2C320x100¤cy=JPY&pbver=%24prebid.version%24&sdkname=prebidjs&adapterver=1.0.1&imark=1&tp=` + encodeURIComponent(utils.getTopWindowUrl()), + native: 'posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=1x1¤cy=JPY&pbver=%24prebid.version%24&sdkname=prebidjs&adapterver=1.0.1&tp=' + encodeURIComponent(utils.getTopWindowUrl()) }; it('sends bid request to ENDPOINT via GET', function () { const request = spec.buildRequests(bidRequests)[0]; @@ -113,7 +113,6 @@ describe('AdgenerationAdapter', function () { expect(request.data).to.equal(data.native); }); }); - describe('interpretResponse', function () { const bidRequests = { banner: { From 0bd5f0f450ce4dc75eb10a32dd36c3b3f3a236ba Mon Sep 17 00:00:00 2001 From: "takaaki.kojima" Date: Fri, 26 Oct 2018 21:45:30 +0900 Subject: [PATCH 3/4] update AdGeneration adapter --- modules/adgenerationBidAdapter.js | 34 +++++++++---------- modules/adgenerationBidAdapter.md | 1 - .../modules/adgenerationBidAdapter_spec.js | 23 ++++++------- 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/modules/adgenerationBidAdapter.js b/modules/adgenerationBidAdapter.js index d5bfe44d05a..340017c26cf 100644 --- a/modules/adgenerationBidAdapter.js +++ b/modules/adgenerationBidAdapter.js @@ -1,6 +1,7 @@ import * as utils from 'src/utils'; import {registerBidder} from 'src/adapters/bidderFactory'; import {BANNER, NATIVE} from 'src/mediaTypes'; +import { config } from 'src/config'; const ADG_BIDDER_CODE = 'adgeneration'; export const spec = { @@ -14,7 +15,7 @@ export const spec = { * @return boolean True if this is a valid bid, and false otherwise. */ isBidRequestValid: function (bid) { - return !!(bid.params.id) && (isValidCurrency(bid.params.currency)); + return !!(bid.params.id); }, /** * Make a server request from the list of BidRequests. @@ -22,7 +23,7 @@ export const spec = { * @param {validBidRequests[]} - an array of bids * @return ServerRequest Info describing the request to the server. */ - buildRequests: function (validBidRequests) { + buildRequests: function (validBidRequests, bidderRequest) { const ADGENE_PREBID_VERSION = '1.0.1'; let serverRequests = []; for (let i = 0, len = validBidRequests.length; i < len; i++) { @@ -39,7 +40,7 @@ export const spec = { data = utils.tryAppendQueryString(data, 't', 'json3'); data = utils.tryAppendQueryString(data, 'transactionid', validReq.transactionId); data = utils.tryAppendQueryString(data, 'sizes', getSizes(validReq)); - data = utils.tryAppendQueryString(data, 'currency', validReq.params.currency.toUpperCase()); + data = utils.tryAppendQueryString(data, 'currency', getCurrencyType()); data = utils.tryAppendQueryString(data, 'pbver', '$prebid.version$'); data = utils.tryAppendQueryString(data, 'sdkname', 'prebidjs'); data = utils.tryAppendQueryString(data, 'adapterver', ADGENE_PREBID_VERSION); @@ -47,7 +48,7 @@ export const spec = { if (!validReq.mediaTypes || !validReq.mediaTypes.native) { data = utils.tryAppendQueryString(data, 'imark', '1'); } - data = utils.tryAppendQueryString(data, 'tp', utils.getTopWindowUrl()); + data = utils.tryAppendQueryString(data, 'tp', bidderRequest.refererInfo.referer); // remove the trailing "&" if (data.lastIndexOf('&') === data.length - 1) { data = data.substring(0, data.length - 1); @@ -86,10 +87,9 @@ export const spec = { height: body.h ? body.h : 1, creativeId: body.creativeid || '', dealId: body.dealid || '', - currency: 'JPY', + currency: getCurrencyType(), netRevenue: true, ttl: body.ttl || 10, - referrer: utils.getTopWindowUrl(), }; if (bidRequest.mediaTypes && bidRequest.mediaTypes.native) { bidResponse.native = createNativeAd(body); @@ -210,26 +210,24 @@ function removeWrapper(ad) { function getSizes(validReq) { const sizes = validReq.sizes; if (!sizes || sizes.length < 1) return null; - let sizesStr = null; + let sizesStr = ''; for (const i in sizes) { const size = sizes[i]; - if (sizesStr == null) { - sizesStr = size[0] + 'x' + size[1]; - } else { - sizesStr += ',' + size[0] + 'x' + size[1]; - } + if (size.length !== 2) return null; + sizesStr += `${size[0]}x${size[1]},`; + } + if (sizesStr || sizesStr.lastIndexOf(',') === sizesStr.length - 1) { + sizesStr = sizesStr.substring(0, sizesStr.length - 1); } return sizesStr; } /** - * @param {?string} currency - * @return {!boolean} + * @return {?string} USD or JPY */ -function isValidCurrency(currency) { - if (!currency) return false; - const upperCurrency = currency.toUpperCase(); - return (upperCurrency === 'JPY' || upperCurrency === 'USD') +function getCurrencyType() { + if (config.getConfig('currency.adServerCurrency') && config.getConfig('currency.adServerCurrency').toUpperCase() === 'USD') return 'USD'; + return 'JPY'; } registerBidder(spec); diff --git a/modules/adgenerationBidAdapter.md b/modules/adgenerationBidAdapter.md index 4a475d4d1ba..7d8281be9b2 100644 --- a/modules/adgenerationBidAdapter.md +++ b/modules/adgenerationBidAdapter.md @@ -24,7 +24,6 @@ var adUnits = [ bidder: 'adg', params: { id: '58278', // banner - currency: 'JPY', } }, ] diff --git a/test/spec/modules/adgenerationBidAdapter_spec.js b/test/spec/modules/adgenerationBidAdapter_spec.js index c2d986df224..bfc4a207a5a 100644 --- a/test/spec/modules/adgenerationBidAdapter_spec.js +++ b/test/spec/modules/adgenerationBidAdapter_spec.js @@ -1,5 +1,4 @@ import {expect} from 'chai'; -import * as utils from 'src/utils'; import {spec} from 'modules/adgenerationBidAdapter'; import {newBidder} from 'src/adapters/bidderFactory'; import {NATIVE} from 'src/mediaTypes'; @@ -19,7 +18,6 @@ describe('AdgenerationAdapter', function () { 'bidder': 'adg', 'params': { id: '58278', // banner - currency: 'JPY', } }; it('should return true when required params found', function () { @@ -86,30 +84,35 @@ describe('AdgenerationAdapter', function () { transactionTd: 'f76f6dfd-d64f-4645-a29f-682bac7f431a' } ]; + const bidderRequest = { + refererInfo: { + referer: 'http://example.com' + } + }; const data = { - banner: `posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=300x250%2C320x100¤cy=JPY&pbver=%24prebid.version%24&sdkname=prebidjs&adapterver=1.0.1&imark=1&tp=` + encodeURIComponent(utils.getTopWindowUrl()), - native: 'posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=1x1¤cy=JPY&pbver=%24prebid.version%24&sdkname=prebidjs&adapterver=1.0.1&tp=' + encodeURIComponent(utils.getTopWindowUrl()) + banner: `posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=300x250%2C320x100¤cy=JPY&pbver=%24prebid.version%24&sdkname=prebidjs&adapterver=1.0.1&imark=1&tp=http%3A%2F%2Fexample.com`, + native: 'posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=1x1¤cy=JPY&pbver=%24prebid.version%24&sdkname=prebidjs&adapterver=1.0.1&tp=http%3A%2F%2Fexample.com' }; it('sends bid request to ENDPOINT via GET', function () { - const request = spec.buildRequests(bidRequests)[0]; + const request = spec.buildRequests(bidRequests, bidderRequest)[0]; expect(request.url).to.equal(ENDPOINT[1]); expect(request.method).to.equal('GET'); }); it('sends bid request to debug ENDPOINT via GET', function () { bidRequests[0].params.debug = true; - const request = spec.buildRequests(bidRequests)[0]; + const request = spec.buildRequests(bidRequests, bidderRequest)[0]; expect(request.url).to.equal(ENDPOINT[0]); expect(request.method).to.equal('GET'); }); it('should attache params to the banner request', function () { - const request = spec.buildRequests(bidRequests)[0]; + const request = spec.buildRequests(bidRequests, bidderRequest)[0]; expect(request.data).to.equal(data.banner); }); it('should attache params to the native request', function () { - const request = spec.buildRequests(bidRequests)[1]; + const request = spec.buildRequests(bidRequests, bidderRequest)[1]; expect(request.data).to.equal(data.native); }); }); @@ -296,7 +299,6 @@ describe('AdgenerationAdapter', function () { currency: 'JPY', netRevenue: true, ttl: 1000, - referrer: utils.getTopWindowUrl(), ad: '
', }, native: { @@ -309,7 +311,6 @@ describe('AdgenerationAdapter', function () { currency: 'JPY', netRevenue: true, ttl: 1000, - referrer: utils.getTopWindowUrl(), ad: '↵
', native: { title: 'Title', @@ -349,7 +350,6 @@ describe('AdgenerationAdapter', function () { expect(result.currency).to.equal(bidResponses.banner.currency); expect(result.netRevenue).to.equal(bidResponses.banner.netRevenue); expect(result.ttl).to.equal(bidResponses.banner.ttl); - expect(result.referrer).to.equal(bidResponses.banner.referrer); expect(result.ad).to.equal(bidResponses.banner.ad); }); @@ -363,7 +363,6 @@ describe('AdgenerationAdapter', function () { expect(result.currency).to.equal(bidResponses.native.currency); expect(result.netRevenue).to.equal(bidResponses.native.netRevenue); expect(result.ttl).to.equal(bidResponses.native.ttl); - expect(result.referrer).to.equal(bidResponses.native.referrer); expect(result.native.title).to.equal(bidResponses.native.native.title); expect(result.native.image.url).to.equal(bidResponses.native.native.image.url); expect(result.native.image.height).to.equal(bidResponses.native.native.image.height); From 5c68c7c9d4278fb2a19d0d673c1529b82a96ed33 Mon Sep 17 00:00:00 2001 From: "takaaki.kojima" Date: Mon, 5 Nov 2018 21:24:41 +0900 Subject: [PATCH 4/4] update AdGeneration adapter - Adding UnitTest for setCurrency --- .../modules/adgenerationBidAdapter_spec.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/spec/modules/adgenerationBidAdapter_spec.js b/test/spec/modules/adgenerationBidAdapter_spec.js index bfc4a207a5a..2cd810d7fb4 100644 --- a/test/spec/modules/adgenerationBidAdapter_spec.js +++ b/test/spec/modules/adgenerationBidAdapter_spec.js @@ -2,6 +2,7 @@ import {expect} from 'chai'; import {spec} from 'modules/adgenerationBidAdapter'; import {newBidder} from 'src/adapters/bidderFactory'; import {NATIVE} from 'src/mediaTypes'; +import {config} from 'src/config'; describe('AdgenerationAdapter', function () { const adapter = newBidder(spec); @@ -91,6 +92,7 @@ describe('AdgenerationAdapter', function () { }; const data = { banner: `posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=300x250%2C320x100¤cy=JPY&pbver=%24prebid.version%24&sdkname=prebidjs&adapterver=1.0.1&imark=1&tp=http%3A%2F%2Fexample.com`, + bannerUSD: `posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=300x250%2C320x100¤cy=USD&pbver=%24prebid.version%24&sdkname=prebidjs&adapterver=1.0.1&imark=1&tp=http%3A%2F%2Fexample.com`, native: 'posall=SSPLOC&id=58278&sdktype=0&hb=true&t=json3&sizes=1x1¤cy=JPY&pbver=%24prebid.version%24&sdkname=prebidjs&adapterver=1.0.1&tp=http%3A%2F%2Fexample.com' }; it('sends bid request to ENDPOINT via GET', function () { @@ -115,6 +117,26 @@ describe('AdgenerationAdapter', function () { const request = spec.buildRequests(bidRequests, bidderRequest)[1]; expect(request.data).to.equal(data.native); }); + it('allows setConfig to set bidder currency for JPY', function () { + config.setConfig({ + currency: { + adServerCurrency: 'JPY' + } + }); + const request = spec.buildRequests(bidRequests, bidderRequest)[0]; + expect(request.data).to.equal(data.banner); + config.resetConfig(); + }); + it('allows setConfig to set bidder currency for USD', function () { + config.setConfig({ + currency: { + adServerCurrency: 'USD' + } + }); + const request = spec.buildRequests(bidRequests, bidderRequest)[0]; + expect(request.data).to.equal(data.bannerUSD); + config.resetConfig(); + }); }); describe('interpretResponse', function () { const bidRequests = {