Skip to content

Commit

Permalink
Orbidder uses onSetTargeting callback (prebid#3804)
Browse files Browse the repository at this point in the history
* initial orbidder version in personal github repo

* use adUnits from orbidder_example.html

* replace obsolete functions

* forgot to commit the test

* check if bidderRequest object is available

* try to fix weird safari/ie issue

* ebayK: add more params

* update orbidderBidAdapter.md

* use spec.<function> instead of this.<function> for consistency reasons

* add bidfloor parameter to params object

* fix gdpr object handling

* default to consentRequired: false when not explicitly given

* wip - use onSetTargeting callback

* add tests for onSetTargeting callback
  • Loading branch information
mmethner authored and jacekburys-quantcast committed May 15, 2019
1 parent 7522b5a commit ced7963
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 22 deletions.
22 changes: 14 additions & 8 deletions modules/orbidderBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ export const spec = {
if (bidderRequest && bidderRequest.gdprConsent) {
ret.data.gdprConsent = {
consentString: bidderRequest.gdprConsent.consentString,
consentRequired: (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean')
? bidderRequest.gdprConsent.gdprApplies
: true
consentRequired: (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') && bidderRequest.gdprConsent.gdprApplies
};
}
return ret;
Expand All @@ -72,15 +70,23 @@ export const spec = {
return bidResponses;
},

onBidWon(winObj) {
onBidWon(bid) {
this.onHandler(bid, '/win');
},

onSetTargeting (bid) {
this.onHandler(bid, '/targeting');
},

onHandler (bid, route) {
const getRefererInfo = detectReferer(window);

winObj.pageUrl = getRefererInfo().referer;
if (spec.bidParams[winObj.adId]) {
winObj.params = spec.bidParams[winObj.adId];
bid.pageUrl = getRefererInfo().referer;
if (spec.bidParams[bid.adId]) {
bid.params = spec.bidParams[bid.adId];
}

spec.ajaxCall(`${spec.orbidderHost}/win`, JSON.stringify(winObj));
spec.ajaxCall(`${spec.orbidderHost}${route}`, JSON.stringify(bid));
},

ajaxCall(endpoint, data) {
Expand Down
30 changes: 22 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions test/spec/modules/orbidderBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {expect} from 'chai';
import {spec} from 'modules/orbidderBidAdapter';
import {newBidder} from 'src/adapters/bidderFactory';
import openxAdapter from '../../../modules/openxAnalyticsAdapter';

describe('orbidderBidAdapter', () => {
const adapter = newBidder(spec);
Expand Down Expand Up @@ -107,7 +108,7 @@ describe('orbidderBidAdapter', () => {
const request = buildRequest(defaultBidRequest, {
gdprConsent: {}
});
expect(request.data.gdprConsent.consentRequired).to.be.equal(true);
expect(request.data.gdprConsent.consentRequired).to.be.equal(false);
});

it('handles non-existent gdpr object', () => {
Expand Down Expand Up @@ -146,9 +147,9 @@ describe('orbidderBidAdapter', () => {
});
});

describe('onBidWon', () => {
describe('onCallbackHandler', () => {
let ajaxStub;
const winObj = {
const bidObj = {
adId: 'testId',
test: 1,
pageUrl: 'www.someurl.de',
Expand All @@ -163,12 +164,18 @@ describe('orbidderBidAdapter', () => {
ajaxStub.restore();
});

it('calls orbidder\'s win endpoint', () => {
spec.onBidWon(winObj);
it('calls orbidder\'s callback endpoint', () => {
spec.onBidWon(bidObj);
expect(ajaxStub.calledOnce).to.equal(true);
expect(ajaxStub.firstCall.args[0].indexOf('https://')).to.equal(0);
expect(ajaxStub.firstCall.args[0]).to.equal(`${spec.orbidderHost}/win`);
expect(ajaxStub.firstCall.args[1]).to.equal(JSON.stringify(winObj));
expect(ajaxStub.firstCall.args[1]).to.equal(JSON.stringify(bidObj));

spec.onSetTargeting(bidObj);
expect(ajaxStub.calledTwice).to.equal(true);
expect(ajaxStub.secondCall.args[0].indexOf('https://')).to.equal(0);
expect(ajaxStub.secondCall.args[0]).to.equal(`${spec.orbidderHost}/targeting`);
expect(ajaxStub.secondCall.args[1]).to.equal(JSON.stringify(bidObj));
});
});

Expand Down

0 comments on commit ced7963

Please sign in to comment.