From ced7963de73f1567b21ca2319cea811b875347c1 Mon Sep 17 00:00:00 2001 From: Mathias Methner Date: Wed, 8 May 2019 07:03:06 +0200 Subject: [PATCH] Orbidder uses onSetTargeting callback (#3804) * 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. instead of this. 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 --- modules/orbidderBidAdapter.js | 22 ++++++++------ package-lock.json | 30 ++++++++++++++------ test/spec/modules/orbidderBidAdapter_spec.js | 19 +++++++++---- 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/modules/orbidderBidAdapter.js b/modules/orbidderBidAdapter.js index fc5eecbab08f..1123cc5d50e6 100644 --- a/modules/orbidderBidAdapter.js +++ b/modules/orbidderBidAdapter.js @@ -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; @@ -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) { diff --git a/package-lock.json b/package-lock.json index c3bd739008f2..6f908eeba520 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "prebid.js", - "version": "2.13.0-pre", + "version": "2.14.0-pre", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -6093,12 +6093,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -6113,17 +6115,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -6240,7 +6245,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -6252,6 +6258,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -6266,6 +6273,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -6273,12 +6281,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -6297,6 +6307,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -6377,7 +6388,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -6389,6 +6401,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -6510,6 +6523,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", diff --git a/test/spec/modules/orbidderBidAdapter_spec.js b/test/spec/modules/orbidderBidAdapter_spec.js index bc88090095b9..3818f5029015 100644 --- a/test/spec/modules/orbidderBidAdapter_spec.js +++ b/test/spec/modules/orbidderBidAdapter_spec.js @@ -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); @@ -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', () => { @@ -146,9 +147,9 @@ describe('orbidderBidAdapter', () => { }); }); - describe('onBidWon', () => { + describe('onCallbackHandler', () => { let ajaxStub; - const winObj = { + const bidObj = { adId: 'testId', test: 1, pageUrl: 'www.someurl.de', @@ -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)); }); });