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

LKQD: update adapter to include new parameters #6033

Merged
merged 3 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions modules/lkqdBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as utils from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { VIDEO } from '../src/mediaTypes.js';
import { config } from '../src/config.js';

const BIDDER_CODE = 'lkqd';
const BID_TTL_DEFAULT = 300;
Expand Down Expand Up @@ -148,6 +149,9 @@ function buildRequests(validBidRequests, bidderRequest) {
if (bidRequest.params.hasOwnProperty('dnt') && bidRequest.params.dnt != null) {
sspData.dnt = bidRequest.params.dnt;
}
if (config.getConfig('coppa') === true) {
sspData.coppa = 1;
}
if (bidRequest.params.hasOwnProperty('pageurl') && bidRequest.params.pageurl != null) {
sspData.pageurl = bidRequest.params.pageurl;
} else if (bidderRequest && bidderRequest.refererInfo) {
Expand Down Expand Up @@ -177,6 +181,12 @@ function buildRequests(validBidRequests, bidderRequest) {
sspData.bidWidth = playerWidth;
sspData.bidHeight = playerHeight;

for (let k = 1; k <= 40; k++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I do not think this is the most efficient way to do this. It does not seem likely that you will have all 40 or even close to that of these in each bidRequest.

I would think simply looping over each param and adding it is the right thing to do.

Object.keys(bidRequest.params).forEach(param => {
   if (/c\d{1,2}/.test(param)){
     sspData[param] = bidRequest.params[param];
   }
});

With the above code, we only loop as many times as needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do not require c numbered data to be sent in sequential order and is passed along only if it exists. Your code would also iterate over all the parameters passed in and not our selectively targeted version. My for loop only looks for c1...c40 because all other known accepted data has been picked out.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, but it is not common for a bid adapter to take in 40+ bidParams.

Looks like 2 params are required for your adapter.

So in what seems to be the usual case, it seems as though looping over the params which the pub set is more efficient on average.

Unless your bidder is unique and you make publishers set 40+ unique LKQD params each time.

Another option is to filter the params looking for the c params, then add those.

Also, regarding the logic of a bunch of if / else's for each bid param. Looks like each bid param name directly maps 1:1 to the associated SSPData name as well.

So why can we just not loop over bid params and just add them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At this time the correction of my predecessor's code regarding the if statements are out of scope and of course needs to be done. For this particular task, I have to minimize changes to the addition of coppa and c1...c40. So this is why I chose the for loop that limits the count to 40 instead of doing the generic loop, that is something that can be adopted in a future revision.

For some context on the c data, it is custom data that we allow publisher partners to put into our system and pass along. For better or worse they can put whatever string they want. Custom Parameters Doc

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok sounds good.

Not meaning to be too combative. Just wanted to double check!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries, constructive help is always welcomed and I will try to do my part and explain as best I can. This was my first encounter with this code as a result of client requests, the code base along with its companion test is now on my growing list of things to change/improve. Have a good one!

if (bidRequest.params.hasOwnProperty(`c${k}`) && bidRequest.params[`c${k}`]) {
sspData[`c${k}`] = bidRequest.params[`c${k}`];
}
}

bidRequests.push({
method: 'GET',
url: sspUrl,
Expand Down
29 changes: 27 additions & 2 deletions test/spec/modules/lkqdBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { spec } from 'modules/lkqdBidAdapter.js';
import { newBidder } from 'src/adapters/bidderFactory.js';
const { expect } = require('chai');
import { config } from 'src/config.js';
import { expect } from 'chai';

describe('LKQD Bid Adapter Test', () => {
const adapter = newBidder(spec);
Expand Down Expand Up @@ -47,7 +48,9 @@ describe('LKQD Bid Adapter Test', () => {
'bidder': 'lkqd',
'params': {
'siteId': '662921',
'placementId': '263'
'placementId': '263',
'c1': 'newWindow',
'c20': 'lkqdCustom'
},
'adUnitCode': 'lkqd',
'sizes': [[300, 250], [640, 480]],
Expand Down Expand Up @@ -75,21 +78,37 @@ describe('LKQD Bid Adapter Test', () => {
];

it('should populate available parameters', () => {
sinon.stub(config, 'getConfig')
.withArgs('coppa')
.returns(true);

const requests = spec.buildRequests(bidRequests);
expect(requests.length).to.equal(2);
const r1 = requests[0].data;
expect(r1).to.have.string('pid=263&');
expect(r1).to.have.string('&sid=662921&');
expect(r1).to.have.string('&width=300&');
expect(r1).to.have.string('&height=250&');
expect(r1).to.have.string('&coppa=1&');
expect(r1).to.have.string('&c1=newWindow&');
expect(r1).to.have.string('&c20=lkqdCustom');
const r2 = requests[1].data;
expect(r2).to.have.string('pid=263&');
expect(r2).to.have.string('&sid=662921&');
expect(r2).to.have.string('&width=640&');
expect(r2).to.have.string('&height=480&');
expect(r2).to.have.string('&coppa=1&');
expect(r2).to.have.string('&c1=newWindow&');
expect(r2).to.have.string('&c20=lkqdCustom');

config.getConfig.restore();
});

it('should not populate unspecified parameters', () => {
sinon.stub(config, 'getConfig')
.withArgs('coppa')
.returns(false);

const requests = spec.buildRequests(bidRequests);
expect(requests.length).to.equal(2);
const r1 = requests[0].data;
Expand All @@ -99,13 +118,19 @@ describe('LKQD Bid Adapter Test', () => {
expect(r1).to.not.have.string('&contentlength=');
expect(r1).to.not.have.string('&contenturl=');
expect(r1).to.not.have.string('&schain=');
expect(r1).to.not.have.string('&c10=');
expect(r1).to.not.have.string('coppa');
const r2 = requests[1].data;
expect(r2).to.not.have.string('&dnt=');
expect(r2).to.not.have.string('&contentid=');
expect(r2).to.not.have.string('&contenttitle=');
expect(r2).to.not.have.string('&contentlength=');
expect(r2).to.not.have.string('&contenturl=');
expect(r2).to.not.have.string('&schain=');
expect(r2).to.not.have.string('&c39=');
expect(r2).to.not.have.string('coppa');

config.getConfig.restore();
});

it('should handle single size request', () => {
Expand Down