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

Initial Consumable Bidder Adapter commit #2381

Merged
merged 4 commits into from
Apr 26, 2018
Merged

Initial Consumable Bidder Adapter commit #2381

merged 4 commits into from
Apr 26, 2018

Conversation

naffis
Copy link
Contributor

@naffis naffis commented Apr 11, 2018

Type of change

  • [x ] New bidder adapter

Description of change

Adding Consumable's bidder adapter for Prebid.js.

  • test parameters for validating bids
{
  bidder: 'consumable',
  params: {
    placement: '1234567',
    network: '9599.1',
    unitId: '987654',
    unitName: 'unitname',
    zoneId: '9599.1',
  }
}

Be sure to test the integration with your adserver using the Hello World sample page.

Other information

@mkendall07
Copy link
Member

This pull request introduces 1 alert when merging 218076e into cea9243 - view on lgtm.com

new alerts:

  • 1 for Identical operands

Comment posted by lgtm.com

@mkendall07
Copy link
Member

This pull request introduces 1 alert when merging 5c2f90a into cea9243 - view on lgtm.com

new alerts:

  • 1 for Identical operands

Comment posted by lgtm.com

let tagName = item.match(tagNameRegExp)[0];
let url = item.match(srcRegExp)[2];

if (tagName && tagName) {
Copy link
Member

Choose a reason for hiding this comment

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

believe this should be if (tagName && url)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this. Fixed.

buildRequests: function (bids) {
return bids.map(bid => {
return formatBidRequest(bid);
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd remove the extra function call, these three lines are equivalent to return bids.map(formatBidRequest);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed


return pubapiTemplate({
host: server,
network: params.network,
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't mutate the params object, just network: params.network || '10947.1' here should work. Same with bidRequest.network below. Might want to use a named constant rather than a magic number if doing more than once.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback. Now using a constant and no longer mutating the params object as suggested.

});
return result.join('');
};
}
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 lot of code for a simple templated function. May I suggest something like

const pubapiTemplate = ({host, network, placement, alias}) => `//${host}/pubapi/3.0/${network}/${placement}/0/0/ADTECH;v=2;cmd=bid;cors=yes;alias=${alias};misc=${new Date().getTime()}`

which could replace template, isInteger, and pubapiTemplate above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. Simplified based on your suggestions.

}

function parsePixelItems(pixels) {
let itemsRegExp = /(img|iframe)[\s\S]*?src\s*=\s*("|')(.*?)\2/gi;
Copy link
Collaborator

Choose a reason for hiding this comment

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

[\s\S] is all whitespace and all non-whitespace, which i'm pretty sure is equivalent to .

that's going to give you more than you're hoping for, like for the test string you have below <script>document.write('<img src="img.org"></iframe><iframe src="pixels1.org"></iframe>');</script> gives you iframe><iframe src="pixels1.org" as a match which is obviously not correct including the previous tag (and whatever might be between) and could cause errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue turned out to be matching on the tag name without the opening bracket. The regex should work now for the example given and other test cases.

return pubapiTemplate({
host: server,
network: params.network,
placement: parseInt(params.placement),
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should always specify the radix when using parseInt, or use parseFloat if applicable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Radix is now supplied.

host: server,
network: params.network,
placement: parseInt(params.placement),
misc: new Date().getTime() // cache busting
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should just be handled by your templating function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to the templating function.

bidRequest = {
url: _buildConsumableUrl(bid),
method: 'GET',
ttl: CONSUMABLE_TTL
Copy link
Collaborator

Choose a reason for hiding this comment

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

there's no reason to return this for the bid request, the bidderFactory won't use it. I see you use it in interpretResponse but you can just use CONSUMABLE_TTL directly as it's a constant and you don't seem to be modifying it in the body of interpretResponse

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed and using the constant directly as suggested.

'catch(e){continue;}' +
'}}</script>';
},
_parseBidResponse: function (response, bidRequest) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You shouldn't expose this, it's a private method. Also, using a private method (regular function scoped to this module, in this case) allows the minify to mangle the name resulting in smaller code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved this method so it's no longer exposed.

}
}
},
_formatPixels: function (pixels) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should not be exposed either. You can test it as part of interpretResponse

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved this method so it's no longer exposed.

_parseBidResponse: function (response, bidRequest) {
let bidData;
try {
bidData = response.seatbid[0].bid[0];
Copy link
Collaborator

Choose a reason for hiding this comment

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

If your endpoint is returning arrays (which it appears to be by this code) I suggest handling the responses as arrays w/ forEach or map (if you're returning the results directly) rather than picking off the first bid and bailing early if not present. interpretResponse allows you to return multiple bids. Even if you only want to return one bid for now, a forEach or map implementation will still behave correctly (as you have here) but will also be forward compatible should you decide to do multiple bids in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion. I'd like to wait on this to roll it into a larger refactor. It should work fine as-is as we're only concerned with the first bid in the array returned.

@mkendall07
Copy link
Member

This pull request introduces 1 alert when merging 5fd65d7 into 2e27a33 - view on lgtm.com

new alerts:

  • 1 for Identical operands

Comment posted by lgtm.com

@naffis
Copy link
Contributor Author

naffis commented Apr 19, 2018

Please let me know if everything looks ok now after the latest round of edits based on the reviews. We have a number of publishers who are eager for the adapter. Thank you.

@naffis
Copy link
Contributor Author

naffis commented Apr 24, 2018

Checking in again. Any updates on this?

Copy link
Collaborator

@snapwich snapwich left a comment

Choose a reason for hiding this comment

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

LGTM

@snapwich snapwich merged commit bb9bc18 into prebid:master Apr 26, 2018
@naffis naffis deleted the consumable-adapter branch April 26, 2018 16:30
dluxemburg pushed a commit to Genius/Prebid.js that referenced this pull request Jul 17, 2018
* Initial Consumable Bidder Adapter commit

* fix tests and lint errors for Consumable bidder adapter and specs

* changes based on reviews by @snapwich and @mkendall07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants