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 AdGeneration adapter #3228

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
42 changes: 38 additions & 4 deletions modules/adgenerationBidAdapter.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend against adding this adapter-specific bids.params.currency. The standard way that the publisher is supposed to specify currency is by calling setConfig with currency.adServerCurrency. All modules should be reading this value rather than making the publisher specify the currency in each adapter's params.

pbjs.setConfig({
    "priceGranularity": "low",
    "currency": {
       "adServerCurrency": "JPY",
       "granularityMultiplier": 108
       "defaultRates": { "USD": { "JPY": 110 }}
    }
});

For the full picture see http://prebid.org/dev-docs/modules/currency.html

},
/**
* Make a server request from the list of BidRequests.
Expand All @@ -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];
Expand All @@ -38,12 +38,16 @@ 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);
// native以外にvideo等の対応が入った場合は要修正
if (!validReq.mediaTypes || !validReq.mediaTypes.native) {
data = utils.tryAppendQueryString(data, 'imark', '1');
}

data = utils.tryAppendQueryString(data, 'tp', utils.getTopWindowUrl());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a deprecated function. Please pull the referrer out of bidRequest.refererInfo. See http://prebid.org/dev-docs/bidder-adaptor.html#referrers

// remove the trailing "&"
if (data.lastIndexOf('&') === data.length - 1) {
data = data.substring(0, data.length - 1);
Expand Down Expand Up @@ -198,4 +202,34 @@ function removeWrapper(ad) {
return ad.substr(bodyIndex, lastBodyIndex).replace('<body>', '').replace('</body>', '');
}

/**
* request
* @param validReq request
* @returns {?string} 300x250,320x50...
*/
function getSizes(validReq) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function assumes valid formatting of the sizes input and will crash on invalid size formatting. Since there are try/catch blocks around the adapter, this isn't necessarily something that needs to get fixed, just pointing it out.

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);
1 change: 1 addition & 0 deletions modules/adgenerationBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var adUnits = [
bidder: 'adg',
params: {
id: '58278', // banner
currency: 'JPY',
}
},
]
Expand Down
16 changes: 7 additions & 9 deletions test/spec/modules/adgenerationBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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',
Expand All @@ -53,8 +53,7 @@ describe('AdgenerationAdapter', function () {
bidder: 'adg',
params: {
id: '58278',
width: '300',
height: '250'
currency: 'JPY',
},
mediaTypes: {
native: {
Expand Down Expand Up @@ -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&currency=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&currency=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];
Expand All @@ -114,7 +113,6 @@ describe('AdgenerationAdapter', function () {
expect(request.data).to.equal(data.native);
});
});

describe('interpretResponse', function () {
const bidRequests = {
banner: {
Expand Down