From 1beaa7caa30639fd50b7dd8b32e71e3adba805cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Tue, 25 Sep 2018 15:29:05 +0200 Subject: [PATCH 01/35] Livewrapped bid and analytics adapter --- modules/livewrappedAnalyticsAdapter.js | 214 +++++++ modules/livewrappedBidAdapter.js | 186 ++++++ modules/livewrappedBidAdapter.md | 28 + .../livewrappedAnalyticsAdapter_spec.js | 265 ++++++++ .../modules/livewrappedBidAdapter_spec.js | 591 ++++++++++++++++++ 5 files changed, 1284 insertions(+) create mode 100644 modules/livewrappedAnalyticsAdapter.js create mode 100644 modules/livewrappedBidAdapter.js create mode 100644 modules/livewrappedBidAdapter.md create mode 100644 test/spec/modules/livewrappedAnalyticsAdapter_spec.js create mode 100644 test/spec/modules/livewrappedBidAdapter_spec.js diff --git a/modules/livewrappedAnalyticsAdapter.js b/modules/livewrappedAnalyticsAdapter.js new file mode 100644 index 00000000000..ede79f164f0 --- /dev/null +++ b/modules/livewrappedAnalyticsAdapter.js @@ -0,0 +1,214 @@ +import * as utils from 'src/utils'; +import {ajax} from 'src/ajax'; +import adapter from 'src/AnalyticsAdapter'; +import CONSTANTS from 'src/constants.json'; +import adaptermanager from 'src/adaptermanager'; + +const ANALYTICSTYPE = 'endpoint'; +const URL = '//lwadm.com/analytics/10'; +const EMPTYURL = ''; +const REQUESTSENT = 1; +const RESPONSESENT = 2; +const WINSENT = 4; +const TIMEOUTSENT = 8; + +let initOptions; +export const BID_WON_TIMEOUT = 500; + +const cache = { + auctions: {}, +}; + +let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE}), { + track({eventType, args}) { + utils.logInfo('"LIVEWRAPPED_EVENT:', [eventType, args]); + + switch (eventType) { + case CONSTANTS.EVENTS.AUCTION_INIT: + utils.logInfo('LIVEWRAPPED_AUCTION_INIT:', args); + cache.auctions[args.auctionId] = {bids: {}}; + break; + case CONSTANTS.EVENTS.BID_REQUESTED: + utils.logInfo('LIVEWRAPPED_BID_REQUESTED:', args); + + args.bids.forEach(function(bidRequest) { + cache.auctions[args.auctionId].timeStamp = args.start; + cache.auctions[args.auctionId].bids[bidRequest.bidId] = { + bidder: bidRequest.bidder, + adUnit: bidRequest.adUnitCode, + isBid: false, + won: false, + timeout: false, + sendStatus: 0 + } + + utils.logInfo(bidRequest); + }) + utils.logInfo(livewrappedAnalyticsAdapter.requestEvents); + break; + case CONSTANTS.EVENTS.BID_RESPONSE: + utils.logInfo('LIVEWRAPPED_BID_RESPONSE:', args); + + let bidResponse = cache.auctions[args.auctionId].bids[args.adId]; + bidResponse.isBid = args.getStatusCode() === CONSTANTS.STATUS.GOOD; + bidResponse.width = args.width; + bidResponse.height = args.height; + bidResponse.cpm = args.cpm; + bidResponse.ttr = args.timeToRespond; + break; + case CONSTANTS.EVENTS.BIDDER_DONE: + utils.logInfo('LIVEWRAPPED_BIDDER_DONE:', args); + args.bids.forEach(doneBid => { + let bid = cache.auctions[doneBid.auctionId].bids[doneBid.bidId]; + if (!bid.ttr) { + bid.ttr = Date.now() - args.auctionStart; + } + }); + break; + case CONSTANTS.EVENTS.BID_WON: + utils.logInfo('LIVEWRAPPED_BID_WON:', args); + let wonBid = cache.auctions[args.auctionId].bids[args.adId]; + wonBid.won = true; + if (wonBid.sendStatus != 0) { + livewrappedAnalyticsAdapter.sendEvents(); + } + break; + case CONSTANTS.EVENTS.BID_TIMEOUT: + utils.logInfo('LIVEWRAPPED_BID_TIMEOUT:', args); + args.forEach(timeout => { + cache.auctions[timeout.auctionId].bids[timeout.bidId].timeout = true; + }); + break; + case CONSTANTS.EVENTS.AUCTION_END: + utils.logInfo('LIVEWRAPPED_AUCTION_END:', args); + setTimeout(() => { + livewrappedAnalyticsAdapter.sendEvents(); + }, BID_WON_TIMEOUT); + break; + } + } +}); + +// save the base class function +livewrappedAnalyticsAdapter.originEnableAnalytics = livewrappedAnalyticsAdapter.enableAnalytics; +livewrappedAnalyticsAdapter.allRequestEvents = []; + +// override enableAnalytics so we can get access to the config passed in from the page +livewrappedAnalyticsAdapter.enableAnalytics = function (config) { + initOptions = config.options; + livewrappedAnalyticsAdapter.originEnableAnalytics(config); +}; + +livewrappedAnalyticsAdapter.sendEvents = function() { + var events = { + publisherId: initOptions.publisherId, + requests: getSentRequests(), + responses: getResponses(), + wins: getWins(), + timeouts: getTimeouts() + }; + + if (events.requests.length == 0 && + events.responses.length == 0 && + events.wins.length == 0 && + events.timeouts.length == 0) { + return; + } + + ajax(URL, undefined, JSON.stringify(events), {method: 'POST'}); +} + +function getSentRequests() { + var sentRequests = []; + + Object.values(cache.auctions).forEach(auction => { + Object.values(auction.bids).forEach(bid => { + if (!(bid.sendStatus & REQUESTSENT)) { + bid.sendStatus |= REQUESTSENT; + + sentRequests.push({ + timeStamp: auction.timeStamp, + adUnit: bid.adUnit, + bidder: bid.bidder + }); + } + }); + }); + + return sentRequests; +} + +function getResponses() { + var responses = []; + + Object.values(cache.auctions).forEach(auction => { + Object.values(auction.bids).forEach(bid => { + if (!(bid.sendStatus & RESPONSESENT) && !bid.timeout) { + bid.sendStatus |= RESPONSESENT; + + responses.push({ + timeStamp: auction.timeStamp, + adUnit: bid.adUnit, + bidder: bid.bidder, + width: bid.width, + height: bid.height, + cpm: bid.cpm, + ttr: bid.ttr, + IsBid: bid.isBid + }); + } + }); + }); + + return responses; +} + +function getWins() { + var wins = []; + + Object.values(cache.auctions).forEach(auction => { + Object.values(auction.bids).forEach(bid => { + if (!(bid.sendStatus & WINSENT) && bid.won) { + bid.sendStatus |= WINSENT; + + wins.push({ + timeStamp: auction.timeStamp, + adUnit: bid.adUnit, + bidder: bid.bidder, + width: bid.width, + height: bid.height, + cpm: bid.cpm, + }); + } + }); + }); + + return wins; +} + +function getTimeouts() { + var timeouts = []; + + Object.values(cache.auctions).forEach(auction => { + Object.values(auction.bids).forEach(bid => { + if (!(bid.sendStatus & TIMEOUTSENT) && bid.timeout) { + bid.sendStatus |= TIMEOUTSENT; + + timeouts.push({ + bidder: bid.bidder, + adUnit: bid.adUnit, + timeStamp: auction.timeStamp + }); + } + }); + }); + + return timeouts; +} + +adaptermanager.registerAnalyticsAdapter({ + adapter: livewrappedAnalyticsAdapter, + code: 'livewrappedAnalytics' +}); + +export default livewrappedAnalyticsAdapter; diff --git a/modules/livewrappedBidAdapter.js b/modules/livewrappedBidAdapter.js new file mode 100644 index 00000000000..53f19f84b63 --- /dev/null +++ b/modules/livewrappedBidAdapter.js @@ -0,0 +1,186 @@ +import * as utils from 'src/utils'; +import { registerBidder } from 'src/adapters/bidderFactory'; +import { config } from 'src/config'; + +const BIDDER_CODE = 'livewrapped'; +export const URL = 'https://lwadm.com/ad'; +const VERSION = '1.1'; + +export const spec = { + code: BIDDER_CODE, + + /** + * Determines whether or not the given bid request is valid. + * + * Parameters should be + * + * adUnitId: LiveWrapped's id of the ad unit. Optional. A guid identifying the ad unit. + * adUnitName: LiveWrapped's name of the ad unit Optional. (Prebid's ad unit code will be used otherwise.) + * publisherId: Publisher id. Required if adUnitName is used or both adUnitName and adUnitId is omitted, otherwise optional. + * userId: A persistent user id if available. Optional. + * url: Page url Optional. Use if page url cannot be determined due to use of iframes. + * bidUrl: Bidding endpoint Optional. + * seats: List of bidders and seats Optional. {"bidder name": ["seat 1", "seat 2"], ...} + * deviceId: Device id if available Optional. + * ifa: Advertising ID Optional. + * + * @param {BidRequest} bid The bid params to validate. + * @return boolean True if this is a valid bid, and false otherwise. + */ + isBidRequestValid: function(bid) { + return (bid.params.adUnitId || ((bid.params.adUnitName || bid.adUnitCode || bid.placementCode) && bid.params.publisherId)) !== undefined; + }, + + /** + * Make a server request from the list of BidRequests. + * + * @param {BidRequest[]} bidRequests A non-empty list of bid requests which should be sent to the Server. + * @return ServerRequest Info describing the request to the server. + */ + buildRequests: function(bidRequests, bidderRequest) { + const userId = bidRequests.find(hasUserId); + const publisherId = bidRequests.find(hasPublisherId); + const auctionId = bidRequests.find(hasAuctionId); + let bidUrl = bidRequests.find(hasBidUrl); + let url = bidRequests.find(hasUrl); + let test = bidRequests.find(hasTestParam); + let seats = bidRequests.find(hasSeatsParam); + let deviceId = bidRequests.find(hasDeviceIdParam); + let ifa = bidRequests.find(hasIfaParam); + let tid = bidRequests.find(hasTidParam); + bidUrl = bidUrl ? bidUrl.params.bidUrl : URL; + url = url ? url.params.url : (config.getConfig('pageUrl') || utils.getTopWindowUrl()); + test = test ? test.params.test : undefined; + var adRequests = bidRequests.map(bidToAdRequest); + + const payload = { + auctionId: auctionId ? auctionId.auctionId : undefined, + publisherId: publisherId ? publisherId.params.publisherId : undefined, + userId: userId ? userId.params.userId : undefined, + url: url, + test: test, + seats: seats ? seats.params.seats : undefined, + deviceId: deviceId ? deviceId.params.deviceId : undefined, + ifa: ifa ? ifa.params.ifa : undefined, + tid: tid ? tid.params.tid : undefined, + version: VERSION, + gdprApplies: bidderRequest.gdprConsent ? bidderRequest.gdprConsent.gdprApplies : false, + gdprConsent: bidderRequest.gdprConsent ? bidderRequest.gdprConsent.consentString : undefined, + cookieSupport: !utils.isSafariBrowser() && utils.cookiesAreEnabled(), + adRequests: [...adRequests] + }; + const payloadString = JSON.stringify(payload); + return { + method: 'POST', + url: bidUrl, + data: payloadString, + }; + }, + + /** + * Unpack the response from the server into a list of bids. + * + * @param {*} serverResponse A successful response from the server. + * @return {Bid[]} An array of bids which were nested inside the server. + */ + interpretResponse: function(serverResponse) { + const bidResponses = []; + + serverResponse.body.ads.forEach(function(ad) { + let bidResponse = { + requestId: ad.bidId, + bidderCode: BIDDER_CODE, + cpm: ad.cpmBid, + width: ad.width, + height: ad.height, + ad: ad.tag, + ttl: ad.ttl, + creativeId: ad.creativeId, + netRevenue: true, + currency: serverResponse.body.currency + }; + + bidResponses.push(bidResponse); + }); + + return bidResponses; + }, + + getUserSyncs: function(syncOptions, serverResponses) { + if (serverResponses.length == 0) return []; + + let syncList = []; + let userSync = serverResponses[0].body.pixels || []; + + userSync.forEach(function(sync) { + if (syncOptions.pixelEnabled && sync.type == 'Redirect') { + syncList.push({type: 'image', url: sync.url}); + } + + if (syncOptions.iframeEnabled && sync.type == 'Iframe') { + syncList.push({type: 'iframe', url: sync.url}); + } + }); + + return syncList; + } +} + +function hasUserId(bid) { + return !!bid.params.userId; +} + +function hasPublisherId(bid) { + return !!bid.params.publisherId; +} + +function hasUrl(bid) { + return !!bid.params.url; +} + +function hasBidUrl(bid) { + return !!bid.params.bidUrl; +} + +function hasAuctionId(bid) { + return !!bid.auctionId; +} + +function hasTestParam(bid) { + return !!bid.params.test; +} + +function hasSeatsParam(bid) { + return !!bid.params.seats; +} + +function hasDeviceIdParam(bid) { + return !!bid.params.deviceId; +} + +function hasIfaParam(bid) { + return !!bid.params.ifa; +} + +function hasTidParam(bid) { + return !!bid.params.tid; +} + +function bidToAdRequest(bid) { + return { + adUnitId: bid.params.adUnitId, + callerAdUnitId: bid.params.adUnitName || bid.adUnitCode || bid.placementCode, + bidId: bid.bidId, + transactionId: bid.transactionId, + formats: bid.sizes.map(sizeToFormat) + }; +} + +function sizeToFormat(size) { + return { + width: size[0], + height: size[1] + } +} + +registerBidder(spec); diff --git a/modules/livewrappedBidAdapter.md b/modules/livewrappedBidAdapter.md new file mode 100644 index 00000000000..15e3e8d533a --- /dev/null +++ b/modules/livewrappedBidAdapter.md @@ -0,0 +1,28 @@ +# Overview + +**Module Name**: Livewrapped Bid Adapter +**Module Type**: Bidder Adapter +**Maintainer**: info@livewrapped.com + +# Description + +Connects to Livewrapped Header Bidding wrapper for bids. + +Livewrapped supports banner. + +# Test Parameters + +``` +var adUnits = [ + { + code: 'banner-div', + sizes: [[300, 250], [300,600]], + bids: [{ + bidder: 'livewrapped', + params: { + adUnitId: '6A32352E-BC17-4B94-B2A7-5BF1724417D7' + } + }] + } +]; +``` diff --git a/test/spec/modules/livewrappedAnalyticsAdapter_spec.js b/test/spec/modules/livewrappedAnalyticsAdapter_spec.js new file mode 100644 index 00000000000..a44312430ba --- /dev/null +++ b/test/spec/modules/livewrappedAnalyticsAdapter_spec.js @@ -0,0 +1,265 @@ +import livewrappedAnalyticsAdapter, { BID_WON_TIMEOUT } from 'modules/livewrappedAnalyticsAdapter'; +import CONSTANTS from 'src/constants.json'; +import { config } from 'src/config'; + +let events = require('src/events'); +let adaptermanager = require('src/adaptermanager'); + +const { + EVENTS: { + AUCTION_INIT, + AUCTION_END, + BID_REQUESTED, + BID_RESPONSE, + BIDDER_DONE, + BID_WON, + BID_TIMEOUT, + SET_TARGETING + }, + STATUS: { + GOOD + } +} = CONSTANTS; + +const BID1 = { + width: 980, + height: 240, + cpm: 1.1, + timeToRespond: 200, + bidId: '2ecff0db240757', + adId: '2ecff0db240757', + auctionId: '25c6d7f5-699a-4bfc-87c9-996f915341fa', + getStatusCode() { + return CONSTANTS.STATUS.GOOD; + } +}; + +const BID2 = Object.assign({}, BID1, { + width: 300, + height: 250, + cpm: 2.2, + timeToRespond: 300, + bidId: '3ecff0db240757', + adId: '3ecff0db240757', +}); + +const MOCK = { + AUCTION_INIT: { + 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa', + }, + BID_REQUESTED: { + 'bidder': 'livewrapped', + 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa', + 'bidderRequestId': '1be65d7958826a', + 'bids': [ + { + 'bidder': 'livewrapped', + 'adUnitCode': 'panorama_d_1', + 'bidId': '2ecff0db240757', + }, + { + 'bidder': 'livewrapped', + 'adUnitCode': 'box_d_1', + 'bidId': '3ecff0db240757', + } + ], + 'start': 1519149562216 + }, + BID_RESPONSE: [ + BID1, + BID2 + ], + AUCTION_END: { + }, + BID_WON: [ + Object.assign({}, BID1, { + 'status': 'rendered' + }), + Object.assign({}, BID2, { + 'status': 'rendered' + }) + ], + BIDDER_DONE: { + 'bidderCode': 'livewrapped', + 'bids': [ + BID1, + BID2 + ] + }, + BID_TIMEOUT: [ + { + 'bidId': '2ecff0db240757', + 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa' + } + ] +}; + +const ANALYTICS_MESSAGE = { + publisherId: 'CC411485-42BC-4F92-8389-42C503EE38D7', + requests: [ + { + adUnit: 'panorama_d_1', + bidder: 'livewrapped', + timeStamp: 1519149562216 + }, + { + adUnit: 'box_d_1', + bidder: 'livewrapped', + timeStamp: 1519149562216 + } + ], + responses: [ + { + timeStamp: 1519149562216, + adUnit: 'panorama_d_1', + bidder: 'livewrapped', + width: 980, + height: 240, + cpm: 1.1, + ttr: 200, + IsBid: true + }, + { + timeStamp: 1519149562216, + adUnit: 'box_d_1', + bidder: 'livewrapped', + width: 300, + height: 250, + cpm: 2.2, + ttr: 300, + IsBid: true + } + ], + timeouts: [], + wins: [ + { + timeStamp: 1519149562216, + adUnit: 'panorama_d_1', + bidder: 'livewrapped', + width: 980, + height: 240, + cpm: 1.1 + }, + { + timeStamp: 1519149562216, + adUnit: 'box_d_1', + bidder: 'livewrapped', + width: 300, + height: 250, + cpm: 2.2 + } + ] +}; + +function performStandardAuction() { + events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); + events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); + events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); + events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[1]); + events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); + events.emit(AUCTION_END, MOCK.AUCTION_END); + events.emit(SET_TARGETING, MOCK.SET_TARGETING); + events.emit(BID_WON, MOCK.BID_WON[0]); + events.emit(BID_WON, MOCK.BID_WON[1]); +} + +describe('Livewrapped analytics adapter', function () { + let sandbox; + let xhr; + let requests; + let clock; + + beforeEach(function () { + sandbox = sinon.sandbox.create(); + + xhr = sandbox.useFakeXMLHttpRequest(); + requests = []; + xhr.onCreate = request => requests.push(request); + + sandbox.stub(events, 'getEvents').returns([]); + + clock = sandbox.useFakeTimers(1519767013781); + }); + + afterEach(function () { + sandbox.restore(); + config.resetConfig(); + }); + + describe('when handling events', function () { + adaptermanager.registerAnalyticsAdapter({ + code: 'livewrappedAnalytics', + adapter: livewrappedAnalyticsAdapter + }); + + beforeEach(function () { + adaptermanager.enableAnalytics({ + provider: 'livewrappedAnalytics', + options: { + publisherId: 'CC411485-42BC-4F92-8389-42C503EE38D7' + } + }); + }); + + afterEach(function () { + livewrappedAnalyticsAdapter.disableAnalytics(); + }); + + it('should build a batched message from prebid events', function () { + performStandardAuction(); + + clock.tick(BID_WON_TIMEOUT + 1000); + + expect(requests.length).to.equal(1); + let request = requests[0]; + + expect(request.url).to.equal('//lwadm.com/analytics/10'); + + let message = JSON.parse(request.requestBody); + + expect(message).to.deep.equal(ANALYTICS_MESSAGE); + }); + + it('should send batched message without BID_WON if necessary and further BID_WON events individually', function () { + events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); + events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); + events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); + events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[1]); + events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); + events.emit(AUCTION_END, MOCK.AUCTION_END); + events.emit(SET_TARGETING, MOCK.SET_TARGETING); + events.emit(BID_WON, MOCK.BID_WON[0]); + + clock.tick(BID_WON_TIMEOUT + 1000); + + events.emit(BID_WON, MOCK.BID_WON[1]); + + expect(requests.length).to.equal(2); + + let message = JSON.parse(requests[0].requestBody); + expect(message.wins.length).to.equal(1); + expect(message.requests).to.deep.equal(ANALYTICS_MESSAGE.requests); + expect(message.wins[0]).to.deep.equal(ANALYTICS_MESSAGE.wins[0]); + + message = JSON.parse(requests[1].requestBody); + expect(message.wins.length).to.equal(1); + expect(message.wins[0]).to.deep.equal(ANALYTICS_MESSAGE.wins[1]); + }); + + it('should properly mark bids as timed out', function () { + events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); + events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); + events.emit(BID_TIMEOUT, MOCK.BID_TIMEOUT); + events.emit(AUCTION_END, MOCK.AUCTION_END); + + clock.tick(BID_WON_TIMEOUT + 1000); + + expect(requests.length).to.equal(1); + + let message = JSON.parse(requests[0].requestBody); + expect(message.timeouts.length).to.equal(1); + expect(message.timeouts[0].bidder).to.equal('livewrapped'); + expect(message.timeouts[0].adUnit).to.equal('panorama_d_1'); + }); + }); +}); diff --git a/test/spec/modules/livewrappedBidAdapter_spec.js b/test/spec/modules/livewrappedBidAdapter_spec.js new file mode 100644 index 00000000000..0b01656f16f --- /dev/null +++ b/test/spec/modules/livewrappedBidAdapter_spec.js @@ -0,0 +1,591 @@ +import {expect} from 'chai'; +import {spec} from 'modules/livewrappedBidAdapter'; +import {config} from 'src/config'; +import * as utils from 'src/utils'; + +describe('Livewrapped adapter tests', function () { + let sandbox, + bidderRequest; + + beforeEach(function () { + sandbox = sinon.sandbox.create(); + + bidderRequest = { + bidderCode: 'livewrapped', + auctionId: 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a', + bidderRequestId: '178e34bad3658f', + bids: [ + { + bidder: 'livewrapped', + params: { + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']} + }, + adUnitCode: 'panorama_d_1', + sizes: [[980, 240], [980, 120]], + bidId: '2ffb201a808da7', + bidderRequestId: '178e34bad3658f', + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D' + } + ], + start: 1472239426002, + auctionStart: 1472239426000, + timeout: 5000 + }; + }); + + afterEach(function () { + sandbox.restore(); + }); + + describe('isBidRequestValid', function() { + it('should accept a request with id only as valid', function() { + let bid = {params: {adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37'}}; + + let result = spec.isBidRequestValid(bid); + + expect(result).to.be.true; + }); + + it('should accept a request with adUnitName and PublisherId as valid', function() { + let bid = {params: {adUnitName: 'panorama_d_1', publisherId: '26947112-2289-405D-88C1-A7340C57E63E'}}; + + let result = spec.isBidRequestValid(bid); + + expect(result).to.be.true; + }); + + it('should accept a request with adUnitCode and PublisherId as valid', function() { + let bid = {adUnitCode: 'panorama_d_1', params: {publisherId: '26947112-2289-405D-88C1-A7340C57E63E'}}; + + let result = spec.isBidRequestValid(bid); + + expect(result).to.be.true; + }); + + it('should accept a request with placementCode and PublisherId as valid', function() { + let bid = {placementCode: 'panorama_d_1', params: {publisherId: '26947112-2289-405D-88C1-A7340C57E63E'}}; + + let result = spec.isBidRequestValid(bid); + + expect(result).to.be.true; + }); + + it('should not accept a request with adUnitName, adUnitCode, placementCode but no PublisherId as valid', function() { + let bid = {placementCode: 'panorama_d_1', adUnitCode: 'panorama_d_1', params: {adUnitName: 'panorama_d_1'}}; + + let result = spec.isBidRequestValid(bid); + + expect(result).to.be.false; + }); + }); + + describe('buildRequests', function() { + it('should make a well-formed single request object', function() { + let result = spec.buildRequests(bidderRequest.bids, bidderRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: true, + gdprApplies: false, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed multiple request object', function() { + let multiplebidRequest = clone(bidderRequest); + multiplebidRequest.bids.push(clone(bidderRequest.bids[0])); + multiplebidRequest.bids[1].adUnitCode = 'box_d_1'; + multiplebidRequest.bids[1].sizes = [[300, 250]]; + multiplebidRequest.bids[1].bidId = '3ffb201a808da7'; + delete multiplebidRequest.bids[1].params.adUnitId; + + let result = spec.buildRequests(multiplebidRequest.bids, multiplebidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: true, + gdprApplies: false, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }, { + callerAdUnitId: 'box_d_1', + bidId: '3ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 300, height: 250}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed single request object with AdUnitName', function() { + let testbidRequest = clone(bidderRequest); + testbidRequest.bids[0].params.adUnitName = 'caller id 1'; + delete testbidRequest.bids[0].params.adUnitId; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: true, + gdprApplies: false, + adRequests: [{ + callerAdUnitId: 'caller id 1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed single request object with less parameters', function() { + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + delete testbidRequest.bids[0].params.seats; + delete testbidRequest.bids[0].params.adUnitId; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + url: 'http://www.domain.com', + version: '1.1', + cookieSupport: true, + gdprApplies: false, + adRequests: [{ + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed single request object with less parameters, no publisherId', function() { + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + delete testbidRequest.bids[0].params.seats; + delete testbidRequest.bids[0].params.publisherId; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + url: 'http://www.domain.com', + version: '1.1', + cookieSupport: true, + gdprApplies: false, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed single request object with app parameters', function() { + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + delete testbidRequest.bids[0].params.seats; + delete testbidRequest.bids[0].params.adUnitId; + testbidRequest.bids[0].params.deviceId = 'deviceid'; + testbidRequest.bids[0].params.ifa = 'ifa'; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + url: 'http://www.domain.com', + version: '1.1', + deviceId: 'deviceid', + ifa: 'ifa', + cookieSupport: true, + gdprApplies: false, + adRequests: [{ + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed single request object with debug parameters', function() { + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + delete testbidRequest.bids[0].params.seats; + delete testbidRequest.bids[0].params.adUnitId; + testbidRequest.bids[0].params.tid = 'tracking id'; + testbidRequest.bids[0].params.test = true; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + url: 'http://www.domain.com', + version: '1.1', + tid: 'tracking id', + test: true, + cookieSupport: true, + gdprApplies: false, + adRequests: [{ + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should pass gdpr parameters', function() { + let testRequest = clone(bidderRequest); + testRequest.gdprConsent = { + gdprApplies: true, + consentString: 'test' + }; + let result = spec.buildRequests(testRequest.bids, testRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: true, + gdprApplies: true, + gdprConsent: 'test', + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should pass no cookie support', function() { + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => false); + let result = spec.buildRequests(bidderRequest.bids, bidderRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + gdprApplies: false, + cookieSupport: false, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should pass no cookie support Safari', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => true); + let result = spec.buildRequests(bidderRequest.bids, bidderRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + gdprApplies: false, + cookieSupport: false, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should use params.url, then config pageUrl, then getTopWindowUrl', function() { + let testRequest = clone(bidderRequest); + sandbox.stub(utils, 'getTopWindowUrl').callsFake(() => 'http://www.topurl.com'); + + let result = spec.buildRequests(testRequest.bids, testRequest); + let data = JSON.parse(result.data); + + expect(data.url).to.equal('http://www.domain.com'); + + delete testRequest.bids[0].params.url; + + result = spec.buildRequests(testRequest.bids, testRequest); + data = JSON.parse(result.data); + + expect(data.url).to.equal('http://www.topurl.com'); + + let origGetConfig = config.getConfig; + sandbox.stub(config, 'getConfig').callsFake(function (key) { + if (key === 'pageUrl') { + return 'http://www.configurl.com'; + } + return origGetConfig.apply(config, arguments); + }); + + result = spec.buildRequests(testRequest.bids, testRequest); + data = JSON.parse(result.data); + + expect(data.url).to.equal('http://www.configurl.com'); + }); + }); + + describe('interpretResponse', function () { + it('should handle single success response', function() { + let lwResponse = { + ads: [ + { + id: '28e5ddf4-3c01-11e8-86a7-0a44794250d4', + callerId: 'site_outsider_0', + tag: 'ad', + width: 300, + height: 250, + cpmBid: 2.565917, + bidId: '32e50fad901ae89', + auctionId: '13e674db-d4d8-4e19-9d28-ff38177db8bf', + creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', + ttl: 120 + } + ], + currency: 'USD' + }; + + let expectedResponse = [{ + requestId: '32e50fad901ae89', + bidderCode: 'livewrapped', + cpm: 2.565917, + width: 300, + height: 250, + ad: 'ad', + ttl: 120, + creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', + netRevenue: true, + currency: 'USD' + }]; + + let bids = spec.interpretResponse({body: lwResponse}); + + expect(bids).to.deep.equal(expectedResponse); + }) + + it('should handle multiple success response', function() { + let lwResponse = { + ads: [ + { + id: '28e5ddf4-3c01-11e8-86a7-0a44794250d4', + callerId: 'site_outsider_0', + tag: 'ad1', + width: 300, + height: 250, + cpmBid: 2.565917, + bidId: '32e50fad901ae89', + auctionId: '13e674db-d4d8-4e19-9d28-ff38177db8bf', + creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', + ttl: 120 + }, + { + id: '38e5ddf4-3c01-11e8-86a7-0a44794250d4', + callerId: 'site_outsider_1', + tag: 'ad2', + width: 980, + height: 240, + cpmBid: 3.565917, + bidId: '42e50fad901ae89', + auctionId: '13e674db-d4d8-4e19-9d28-ff38177db8bf', + creativeId: '62cbd598-2715-4c43-a06f-229fc170f945:427077', + ttl: 120 + } + ], + currency: 'USD' + }; + + let expectedResponse = [{ + requestId: '32e50fad901ae89', + bidderCode: 'livewrapped', + cpm: 2.565917, + width: 300, + height: 250, + ad: 'ad1', + ttl: 120, + creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', + netRevenue: true, + currency: 'USD' + }, { + requestId: '42e50fad901ae89', + bidderCode: 'livewrapped', + cpm: 3.565917, + width: 980, + height: 240, + ad: 'ad2', + ttl: 120, + creativeId: '62cbd598-2715-4c43-a06f-229fc170f945:427077', + netRevenue: true, + currency: 'USD' + }]; + + let bids = spec.interpretResponse({body: lwResponse}); + + expect(bids).to.deep.equal(expectedResponse); + }) + }); + + describe('user sync', function () { + let serverResponses; + + beforeEach(function () { + serverResponses = [{ + body: { + pixels: [ + {type: 'Redirect', url: 'http://pixelsync'}, + {type: 'Iframe', url: 'http://iframesync'} + ] + } + }]; + }); + + it('should return empty if no server responses', function() { + let syncs = spec.getUserSyncs({ + pixelEnabled: true, + iframeEnabled: true + }, []); + + let expectedResponse = []; + + expect(syncs).to.deep.equal(expectedResponse) + }); + + it('should return empty if no user sync', function() { + let syncs = spec.getUserSyncs({ + pixelEnabled: true, + iframeEnabled: true + }, [{body: {}}]); + + let expectedResponse = []; + + expect(syncs).to.deep.equal(expectedResponse) + }); + + it('should returns pixel and iframe user sync', function() { + let syncs = spec.getUserSyncs({ + pixelEnabled: true, + iframeEnabled: true + }, serverResponses); + + let expectedResponse = [{type: 'image', url: 'http://pixelsync'}, {type: 'iframe', url: 'http://iframesync'}]; + + expect(syncs).to.deep.equal(expectedResponse) + }); + + it('should returns pixel only if iframe not supported user sync', function() { + let syncs = spec.getUserSyncs({ + pixelEnabled: true, + iframeEnabled: false + }, serverResponses); + + let expectedResponse = [{type: 'image', url: 'http://pixelsync'}]; + + expect(syncs).to.deep.equal(expectedResponse) + }); + + it('should returns iframe only if pixel not supported user sync', function() { + let syncs = spec.getUserSyncs({ + pixelEnabled: false, + iframeEnabled: true + }, serverResponses); + + let expectedResponse = [{type: 'iframe', url: 'http://iframesync'}]; + + expect(syncs).to.deep.equal(expectedResponse) + }); + }); +}); + +function clone(obj) { + return JSON.parse(JSON.stringify(obj)); +} From c47dd606404013e058f5160f302e54e106179992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Thu, 4 Oct 2018 09:56:18 +0200 Subject: [PATCH 02/35] Fixed some tests for browser compatibility --- modules/livewrappedAnalyticsAdapter.js | 24 ++++++++++++++++-------- modules/livewrappedBidAdapter.js | 21 +++++++++++---------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/modules/livewrappedAnalyticsAdapter.js b/modules/livewrappedAnalyticsAdapter.js index ede79f164f0..c6a1167c783 100644 --- a/modules/livewrappedAnalyticsAdapter.js +++ b/modules/livewrappedAnalyticsAdapter.js @@ -121,8 +121,10 @@ livewrappedAnalyticsAdapter.sendEvents = function() { function getSentRequests() { var sentRequests = []; - Object.values(cache.auctions).forEach(auction => { - Object.values(auction.bids).forEach(bid => { + Object.keys(cache.auctions).forEach(auctionId => { + Object.keys(cache.auctions[auctionId].bids).forEach(bidId => { + let auction = cache.auctions[auctionId]; + let bid = auction.bids[bidId]; if (!(bid.sendStatus & REQUESTSENT)) { bid.sendStatus |= REQUESTSENT; @@ -141,8 +143,10 @@ function getSentRequests() { function getResponses() { var responses = []; - Object.values(cache.auctions).forEach(auction => { - Object.values(auction.bids).forEach(bid => { + Object.keys(cache.auctions).forEach(auctionId => { + Object.keys(cache.auctions[auctionId].bids).forEach(bidId => { + let auction = cache.auctions[auctionId]; + let bid = auction.bids[bidId]; if (!(bid.sendStatus & RESPONSESENT) && !bid.timeout) { bid.sendStatus |= RESPONSESENT; @@ -166,8 +170,10 @@ function getResponses() { function getWins() { var wins = []; - Object.values(cache.auctions).forEach(auction => { - Object.values(auction.bids).forEach(bid => { + Object.keys(cache.auctions).forEach(auctionId => { + Object.keys(cache.auctions[auctionId].bids).forEach(bidId => { + let auction = cache.auctions[auctionId]; + let bid = auction.bids[bidId]; if (!(bid.sendStatus & WINSENT) && bid.won) { bid.sendStatus |= WINSENT; @@ -189,8 +195,10 @@ function getWins() { function getTimeouts() { var timeouts = []; - Object.values(cache.auctions).forEach(auction => { - Object.values(auction.bids).forEach(bid => { + Object.keys(cache.auctions).forEach(auctionId => { + Object.keys(cache.auctions[auctionId].bids).forEach(bidId => { + let auction = cache.auctions[auctionId]; + let bid = auction.bids[bidId]; if (!(bid.sendStatus & TIMEOUTSENT) && bid.timeout) { bid.sendStatus |= TIMEOUTSENT; diff --git a/modules/livewrappedBidAdapter.js b/modules/livewrappedBidAdapter.js index 53f19f84b63..ebfe4aad2d4 100644 --- a/modules/livewrappedBidAdapter.js +++ b/modules/livewrappedBidAdapter.js @@ -1,6 +1,7 @@ import * as utils from 'src/utils'; import { registerBidder } from 'src/adapters/bidderFactory'; import { config } from 'src/config'; +import find from 'core-js/library/fn/array/find'; const BIDDER_CODE = 'livewrapped'; export const URL = 'https://lwadm.com/ad'; @@ -38,16 +39,16 @@ export const spec = { * @return ServerRequest Info describing the request to the server. */ buildRequests: function(bidRequests, bidderRequest) { - const userId = bidRequests.find(hasUserId); - const publisherId = bidRequests.find(hasPublisherId); - const auctionId = bidRequests.find(hasAuctionId); - let bidUrl = bidRequests.find(hasBidUrl); - let url = bidRequests.find(hasUrl); - let test = bidRequests.find(hasTestParam); - let seats = bidRequests.find(hasSeatsParam); - let deviceId = bidRequests.find(hasDeviceIdParam); - let ifa = bidRequests.find(hasIfaParam); - let tid = bidRequests.find(hasTidParam); + const userId = find(bidRequests, hasUserId); + const publisherId = find(bidRequests, hasPublisherId); + const auctionId = find(bidRequests, hasAuctionId); + let bidUrl = find(bidRequests, hasBidUrl); + let url = find(bidRequests, hasUrl); + let test = find(bidRequests, hasTestParam); + let seats = find(bidRequests, hasSeatsParam); + let deviceId = find(bidRequests, hasDeviceIdParam); + let ifa = find(bidRequests, hasIfaParam); + let tid = find(bidRequests, hasTidParam); bidUrl = bidUrl ? bidUrl.params.bidUrl : URL; url = url ? url.params.url : (config.getConfig('pageUrl') || utils.getTopWindowUrl()); test = test ? test.params.test : undefined; From 5c0a3545d0c60c9c91f1c75d666d4bf472d6afdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Thu, 4 Oct 2018 10:11:42 +0200 Subject: [PATCH 03/35] Fixed some tests for browser compatibility --- .../spec/modules/livewrappedBidAdapter_spec.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/spec/modules/livewrappedBidAdapter_spec.js b/test/spec/modules/livewrappedBidAdapter_spec.js index 0b01656f16f..64a70b946ef 100644 --- a/test/spec/modules/livewrappedBidAdapter_spec.js +++ b/test/spec/modules/livewrappedBidAdapter_spec.js @@ -86,6 +86,8 @@ describe('Livewrapped adapter tests', function () { describe('buildRequests', function() { it('should make a well-formed single request object', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); let result = spec.buildRequests(bidderRequest.bids, bidderRequest); let data = JSON.parse(result.data); @@ -113,6 +115,8 @@ describe('Livewrapped adapter tests', function () { }); it('should make a well-formed multiple request object', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); let multiplebidRequest = clone(bidderRequest); multiplebidRequest.bids.push(clone(bidderRequest.bids[0])); multiplebidRequest.bids[1].adUnitCode = 'box_d_1'; @@ -152,6 +156,8 @@ describe('Livewrapped adapter tests', function () { }); it('should make a well-formed single request object with AdUnitName', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); let testbidRequest = clone(bidderRequest); testbidRequest.bids[0].params.adUnitName = 'caller id 1'; delete testbidRequest.bids[0].params.adUnitId; @@ -181,6 +187,8 @@ describe('Livewrapped adapter tests', function () { }); it('should make a well-formed single request object with less parameters', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); let testbidRequest = clone(bidderRequest); delete testbidRequest.bids[0].params.userId; delete testbidRequest.bids[0].params.seats; @@ -209,6 +217,8 @@ describe('Livewrapped adapter tests', function () { }); it('should make a well-formed single request object with less parameters, no publisherId', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); let testbidRequest = clone(bidderRequest); delete testbidRequest.bids[0].params.userId; delete testbidRequest.bids[0].params.seats; @@ -237,6 +247,8 @@ describe('Livewrapped adapter tests', function () { }); it('should make a well-formed single request object with app parameters', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); let testbidRequest = clone(bidderRequest); delete testbidRequest.bids[0].params.userId; delete testbidRequest.bids[0].params.seats; @@ -267,6 +279,8 @@ describe('Livewrapped adapter tests', function () { }); it('should make a well-formed single request object with debug parameters', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); let testbidRequest = clone(bidderRequest); delete testbidRequest.bids[0].params.userId; delete testbidRequest.bids[0].params.seats; @@ -297,6 +311,8 @@ describe('Livewrapped adapter tests', function () { }); it('should pass gdpr parameters', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); let testRequest = clone(bidderRequest); testRequest.gdprConsent = { gdprApplies: true, @@ -331,6 +347,7 @@ describe('Livewrapped adapter tests', function () { it('should pass no cookie support', function() { sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => false); + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); let result = spec.buildRequests(bidderRequest.bids, bidderRequest); let data = JSON.parse(result.data); @@ -358,6 +375,7 @@ describe('Livewrapped adapter tests', function () { }); it('should pass no cookie support Safari', function() { + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); sandbox.stub(utils, 'isSafariBrowser').callsFake(() => true); let result = spec.buildRequests(bidderRequest.bids, bidderRequest); let data = JSON.parse(result.data); From f02ada19a3843541c3acaddabd7c0a873bae89d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Fri, 5 Oct 2018 09:09:10 +0200 Subject: [PATCH 04/35] Changed analytics adapter code name --- modules/livewrappedAnalyticsAdapter.js | 2 +- test/spec/modules/livewrappedAnalyticsAdapter_spec.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/livewrappedAnalyticsAdapter.js b/modules/livewrappedAnalyticsAdapter.js index c6a1167c783..ecbb630e7d9 100644 --- a/modules/livewrappedAnalyticsAdapter.js +++ b/modules/livewrappedAnalyticsAdapter.js @@ -216,7 +216,7 @@ function getTimeouts() { adaptermanager.registerAnalyticsAdapter({ adapter: livewrappedAnalyticsAdapter, - code: 'livewrappedAnalytics' + code: 'livewrapped' }); export default livewrappedAnalyticsAdapter; diff --git a/test/spec/modules/livewrappedAnalyticsAdapter_spec.js b/test/spec/modules/livewrappedAnalyticsAdapter_spec.js index a44312430ba..f7de9cd8101 100644 --- a/test/spec/modules/livewrappedAnalyticsAdapter_spec.js +++ b/test/spec/modules/livewrappedAnalyticsAdapter_spec.js @@ -188,13 +188,13 @@ describe('Livewrapped analytics adapter', function () { describe('when handling events', function () { adaptermanager.registerAnalyticsAdapter({ - code: 'livewrappedAnalytics', + code: 'livewrapped', adapter: livewrappedAnalyticsAdapter }); beforeEach(function () { adaptermanager.enableAnalytics({ - provider: 'livewrappedAnalytics', + provider: 'livewrapped', options: { publisherId: 'CC411485-42BC-4F92-8389-42C503EE38D7' } From 47922452e52ffbd1e9239f12eaac21d61b709415 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Tue, 9 Oct 2018 16:30:49 +0200 Subject: [PATCH 05/35] Fix double quote in debug message --- modules/livewrappedAnalyticsAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/livewrappedAnalyticsAdapter.js b/modules/livewrappedAnalyticsAdapter.js index ecbb630e7d9..21c0bc73ec4 100644 --- a/modules/livewrappedAnalyticsAdapter.js +++ b/modules/livewrappedAnalyticsAdapter.js @@ -21,7 +21,7 @@ const cache = { let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE}), { track({eventType, args}) { - utils.logInfo('"LIVEWRAPPED_EVENT:', [eventType, args]); + utils.logInfo('LIVEWRAPPED_EVENT:', [eventType, args]); switch (eventType) { case CONSTANTS.EVENTS.AUCTION_INIT: From 02a6e5a8ed5cb4ce7e6020ed149439e905c89879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Fri, 2 Nov 2018 15:20:02 +0100 Subject: [PATCH 06/35] modified how gdpr is being passed --- modules/livewrappedBidAdapter.js | 4 +- .../modules/livewrappedBidAdapter_spec.js | 60 +++++++++++++------ 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/modules/livewrappedBidAdapter.js b/modules/livewrappedBidAdapter.js index ebfe4aad2d4..110a9567364 100644 --- a/modules/livewrappedBidAdapter.js +++ b/modules/livewrappedBidAdapter.js @@ -4,7 +4,7 @@ import { config } from 'src/config'; import find from 'core-js/library/fn/array/find'; const BIDDER_CODE = 'livewrapped'; -export const URL = 'https://lwadm.com/ad'; +export const URL = '//lwadm.com/ad'; const VERSION = '1.1'; export const spec = { @@ -65,7 +65,7 @@ export const spec = { ifa: ifa ? ifa.params.ifa : undefined, tid: tid ? tid.params.tid : undefined, version: VERSION, - gdprApplies: bidderRequest.gdprConsent ? bidderRequest.gdprConsent.gdprApplies : false, + gdprApplies: bidderRequest.gdprConsent ? bidderRequest.gdprConsent.gdprApplies : undefined, gdprConsent: bidderRequest.gdprConsent ? bidderRequest.gdprConsent.consentString : undefined, cookieSupport: !utils.isSafariBrowser() && utils.cookiesAreEnabled(), adRequests: [...adRequests] diff --git a/test/spec/modules/livewrappedBidAdapter_spec.js b/test/spec/modules/livewrappedBidAdapter_spec.js index 64a70b946ef..072d374ac72 100644 --- a/test/spec/modules/livewrappedBidAdapter_spec.js +++ b/test/spec/modules/livewrappedBidAdapter_spec.js @@ -91,7 +91,7 @@ describe('Livewrapped adapter tests', function () { let result = spec.buildRequests(bidderRequest.bids, bidderRequest); let data = JSON.parse(result.data); - expect(result.url).to.equal('https://lwadm.com/ad'); + expect(result.url).to.equal('//lwadm.com/ad'); let expectedQuery = { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', @@ -101,7 +101,6 @@ describe('Livewrapped adapter tests', function () { seats: {'dsp': ['seat 1']}, version: '1.1', cookieSupport: true, - gdprApplies: false, adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -127,7 +126,7 @@ describe('Livewrapped adapter tests', function () { let result = spec.buildRequests(multiplebidRequest.bids, multiplebidRequest); let data = JSON.parse(result.data); - expect(result.url).to.equal('https://lwadm.com/ad'); + expect(result.url).to.equal('//lwadm.com/ad'); let expectedQuery = { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', @@ -137,7 +136,6 @@ describe('Livewrapped adapter tests', function () { seats: {'dsp': ['seat 1']}, version: '1.1', cookieSupport: true, - gdprApplies: false, adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -164,7 +162,7 @@ describe('Livewrapped adapter tests', function () { let result = spec.buildRequests(testbidRequest.bids, testbidRequest); let data = JSON.parse(result.data); - expect(result.url).to.equal('https://lwadm.com/ad'); + expect(result.url).to.equal('//lwadm.com/ad'); let expectedQuery = { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', @@ -174,7 +172,6 @@ describe('Livewrapped adapter tests', function () { seats: {'dsp': ['seat 1']}, version: '1.1', cookieSupport: true, - gdprApplies: false, adRequests: [{ callerAdUnitId: 'caller id 1', bidId: '2ffb201a808da7', @@ -196,7 +193,7 @@ describe('Livewrapped adapter tests', function () { let result = spec.buildRequests(testbidRequest.bids, testbidRequest); let data = JSON.parse(result.data); - expect(result.url).to.equal('https://lwadm.com/ad'); + expect(result.url).to.equal('//lwadm.com/ad'); let expectedQuery = { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', @@ -204,7 +201,6 @@ describe('Livewrapped adapter tests', function () { url: 'http://www.domain.com', version: '1.1', cookieSupport: true, - gdprApplies: false, adRequests: [{ callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', @@ -226,14 +222,13 @@ describe('Livewrapped adapter tests', function () { let result = spec.buildRequests(testbidRequest.bids, testbidRequest); let data = JSON.parse(result.data); - expect(result.url).to.equal('https://lwadm.com/ad'); + expect(result.url).to.equal('//lwadm.com/ad'); let expectedQuery = { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', url: 'http://www.domain.com', version: '1.1', cookieSupport: true, - gdprApplies: false, adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', callerAdUnitId: 'panorama_d_1', @@ -266,7 +261,6 @@ describe('Livewrapped adapter tests', function () { deviceId: 'deviceid', ifa: 'ifa', cookieSupport: true, - gdprApplies: false, adRequests: [{ callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', @@ -298,7 +292,6 @@ describe('Livewrapped adapter tests', function () { tid: 'tracking id', test: true, cookieSupport: true, - gdprApplies: false, adRequests: [{ callerAdUnitId: 'panorama_d_1', bidId: '2ffb201a808da7', @@ -310,7 +303,7 @@ describe('Livewrapped adapter tests', function () { expect(data).to.deep.equal(expectedQuery); }); - it('should pass gdpr parameters', function() { + it('should pass gdpr true parameters', function() { sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); let testRequest = clone(bidderRequest); @@ -321,7 +314,7 @@ describe('Livewrapped adapter tests', function () { let result = spec.buildRequests(testRequest.bids, testRequest); let data = JSON.parse(result.data); - expect(result.url).to.equal('https://lwadm.com/ad'); + expect(result.url).to.equal('//lwadm.com/ad'); let expectedQuery = { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', @@ -345,13 +338,46 @@ describe('Livewrapped adapter tests', function () { expect(data).to.deep.equal(expectedQuery); }); + it('should pass gdpr false parameters', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testRequest = clone(bidderRequest); + testRequest.gdprConsent = { + gdprApplies: false + }; + let result = spec.buildRequests(testRequest.bids, testRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('//lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: true, + gdprApplies: false, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + it('should pass no cookie support', function() { sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => false); sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); let result = spec.buildRequests(bidderRequest.bids, bidderRequest); let data = JSON.parse(result.data); - expect(result.url).to.equal('https://lwadm.com/ad'); + expect(result.url).to.equal('//lwadm.com/ad'); let expectedQuery = { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', @@ -360,7 +386,6 @@ describe('Livewrapped adapter tests', function () { url: 'http://www.domain.com', seats: {'dsp': ['seat 1']}, version: '1.1', - gdprApplies: false, cookieSupport: false, adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', @@ -380,7 +405,7 @@ describe('Livewrapped adapter tests', function () { let result = spec.buildRequests(bidderRequest.bids, bidderRequest); let data = JSON.parse(result.data); - expect(result.url).to.equal('https://lwadm.com/ad'); + expect(result.url).to.equal('//lwadm.com/ad'); let expectedQuery = { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', @@ -389,7 +414,6 @@ describe('Livewrapped adapter tests', function () { url: 'http://www.domain.com', seats: {'dsp': ['seat 1']}, version: '1.1', - gdprApplies: false, cookieSupport: false, adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', From 176ea08f8e2fd8d477fc172c97d742bdb9969916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Thu, 17 Jan 2019 08:58:58 +0100 Subject: [PATCH 07/35] Added support for Publisher Common ID Module --- modules/livewrappedBidAdapter.js | 15 +++-- .../modules/livewrappedBidAdapter_spec.js | 61 +++++++++++++++++++ 2 files changed, 71 insertions(+), 5 deletions(-) diff --git a/modules/livewrappedBidAdapter.js b/modules/livewrappedBidAdapter.js index 7affdb34dd9..69a89421a32 100644 --- a/modules/livewrappedBidAdapter.js +++ b/modules/livewrappedBidAdapter.js @@ -40,15 +40,16 @@ export const spec = { */ buildRequests: function(bidRequests, bidderRequest) { const userId = find(bidRequests, hasUserId); + const pubcid = find(bidRequests, hasPubcid); const publisherId = find(bidRequests, hasPublisherId); const auctionId = find(bidRequests, hasAuctionId); let bidUrl = find(bidRequests, hasBidUrl); let url = find(bidRequests, hasUrl); let test = find(bidRequests, hasTestParam); - let seats = find(bidRequests, hasSeatsParam); - let deviceId = find(bidRequests, hasDeviceIdParam); - let ifa = find(bidRequests, hasIfaParam); - let tid = find(bidRequests, hasTidParam); + const seats = find(bidRequests, hasSeatsParam); + const deviceId = find(bidRequests, hasDeviceIdParam); + const ifa = find(bidRequests, hasIfaParam); + const tid = find(bidRequests, hasTidParam); bidUrl = bidUrl ? bidUrl.params.bidUrl : URL; url = url ? url.params.url : (config.getConfig('pageUrl') || utils.getTopWindowUrl()); test = test ? test.params.test : undefined; @@ -57,7 +58,7 @@ export const spec = { const payload = { auctionId: auctionId ? auctionId.auctionId : undefined, publisherId: publisherId ? publisherId.params.publisherId : undefined, - userId: userId ? userId.params.userId : undefined, + userId: userId ? userId.params.userId : (pubcid ? pubcid.crumbs.pubcid : undefined), url: url, test: test, seats: seats ? seats.params.seats : undefined, @@ -167,6 +168,10 @@ function hasTidParam(bid) { return !!bid.params.tid; } +function hasPubcid(bid) { + return !!bid.crumbs && !!bid.crumbs.pubcid; +} + function bidToAdRequest(bid) { return { adUnitId: bid.params.adUnitId, diff --git a/test/spec/modules/livewrappedBidAdapter_spec.js b/test/spec/modules/livewrappedBidAdapter_spec.js index 072d374ac72..b12ff56c075 100644 --- a/test/spec/modules/livewrappedBidAdapter_spec.js +++ b/test/spec/modules/livewrappedBidAdapter_spec.js @@ -456,6 +456,67 @@ describe('Livewrapped adapter tests', function () { expect(data.url).to.equal('http://www.configurl.com'); }); + + it('should make use of pubcid if available', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + testbidRequest.bids[0].crumbs = {pubcid: 'pubcid 123'}; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('//lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'pubcid 123', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: true, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make userId take precedence over pubcid', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + testbidRequest.bids[0].crumbs = {pubcid: 'pubcid 123'}; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('//lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: true, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); }); describe('interpretResponse', function () { From 5f1951ae4d18d2f8e1a4d0e5da77cf48daf4534c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Mon, 18 Feb 2019 17:13:56 +0100 Subject: [PATCH 08/35] Corrections for ttr in analytics --- modules/livewrappedAnalyticsAdapter.js | 21 ++++++++---- .../livewrappedAnalyticsAdapter_spec.js | 32 ++++++++++++++++++- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/modules/livewrappedAnalyticsAdapter.js b/modules/livewrappedAnalyticsAdapter.js index 272ccadfbcf..03a797e901a 100644 --- a/modules/livewrappedAnalyticsAdapter.js +++ b/modules/livewrappedAnalyticsAdapter.js @@ -21,25 +21,27 @@ const cache = { let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE}), { track({eventType, args}) { + const time = utils.timestamp(); utils.logInfo('LIVEWRAPPED_EVENT:', [eventType, args]); switch (eventType) { case CONSTANTS.EVENTS.AUCTION_INIT: utils.logInfo('LIVEWRAPPED_AUCTION_INIT:', args); - cache.auctions[args.auctionId] = {bids: {}}; + cache.auctions[args.auctionId] = {bids: {}, timeStamp: args.timestamp}; break; case CONSTANTS.EVENTS.BID_REQUESTED: utils.logInfo('LIVEWRAPPED_BID_REQUESTED:', args); args.bids.forEach(function(bidRequest) { - cache.auctions[args.auctionId].timeStamp = args.start; cache.auctions[args.auctionId].bids[bidRequest.bidId] = { bidder: bidRequest.bidder, adUnit: bidRequest.adUnitCode, isBid: false, won: false, timeout: false, - sendStatus: 0 + sendStatus: 0, + readyToSend: 0, + start: args.start } utils.logInfo(bidRequest); @@ -49,20 +51,25 @@ let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE case CONSTANTS.EVENTS.BID_RESPONSE: utils.logInfo('LIVEWRAPPED_BID_RESPONSE:', args); - let bidResponse = cache.auctions[args.auctionId].bids[args.adId]; + let bidResponse = cache.auctions[args.auctionId].bids[args.adId || args.requestId]; bidResponse.isBid = args.getStatusCode() === CONSTANTS.STATUS.GOOD; bidResponse.width = args.width; bidResponse.height = args.height; bidResponse.cpm = args.cpm; bidResponse.ttr = args.timeToRespond; + bidResponse.readyToSend = 1; + if (!bidResponse.ttr) { + bidResponse.ttr = time - bidResponse.start; + } break; case CONSTANTS.EVENTS.BIDDER_DONE: utils.logInfo('LIVEWRAPPED_BIDDER_DONE:', args); args.bids.forEach(doneBid => { - let bid = cache.auctions[doneBid.auctionId].bids[doneBid.bidId]; + let bid = cache.auctions[doneBid.auctionId].bids[doneBid.bidId || doneBid.requestId]; if (!bid.ttr) { - bid.ttr = Date.now() - args.auctionStart; + bid.ttr = time - bid.start; } + bid.readyToSend = 1; }); break; case CONSTANTS.EVENTS.BID_WON: @@ -147,7 +154,7 @@ function getResponses() { Object.keys(cache.auctions[auctionId].bids).forEach(bidId => { let auction = cache.auctions[auctionId]; let bid = auction.bids[bidId]; - if (!(bid.sendStatus & RESPONSESENT) && !bid.timeout) { + if (bid.readyToSend && !(bid.sendStatus & RESPONSESENT) && !bid.timeout) { bid.sendStatus |= RESPONSESENT; responses.push({ diff --git a/test/spec/modules/livewrappedAnalyticsAdapter_spec.js b/test/spec/modules/livewrappedAnalyticsAdapter_spec.js index 60fc9bdc1ec..e2bb58c7488 100644 --- a/test/spec/modules/livewrappedAnalyticsAdapter_spec.js +++ b/test/spec/modules/livewrappedAnalyticsAdapter_spec.js @@ -3,6 +3,7 @@ import CONSTANTS from 'src/constants.json'; import { config } from 'src/config'; let events = require('src/events'); +let utils = require('src/utils'); let adapterManager = require('src/adapterManager').default; const { @@ -43,9 +44,19 @@ const BID2 = Object.assign({}, BID1, { adId: '3ecff0db240757', }); +const BID3 = { + bidId: '4ecff0db240757', + adId: '4ecff0db240757', + auctionId: '25c6d7f5-699a-4bfc-87c9-996f915341fa', + getStatusCode() { + return CONSTANTS.STATUS.NO_BID; + } +}; + const MOCK = { AUCTION_INIT: { 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa', + 'timestamp': 1519149562216 }, BID_REQUESTED: { 'bidder': 'livewrapped', @@ -61,6 +72,11 @@ const MOCK = { 'bidder': 'livewrapped', 'adUnitCode': 'box_d_1', 'bidId': '3ecff0db240757', + }, + { + 'bidder': 'livewrapped', + 'adUnitCode': 'box_d_2', + 'bidId': '4ecff0db240757', } ], 'start': 1519149562216 @@ -83,7 +99,8 @@ const MOCK = { 'bidderCode': 'livewrapped', 'bids': [ BID1, - BID2 + BID2, + BID3 ] }, BID_TIMEOUT: [ @@ -106,6 +123,11 @@ const ANALYTICS_MESSAGE = { adUnit: 'box_d_1', bidder: 'livewrapped', timeStamp: 1519149562216 + }, + { + adUnit: 'box_d_2', + bidder: 'livewrapped', + timeStamp: 1519149562216 } ], responses: [ @@ -128,6 +150,13 @@ const ANALYTICS_MESSAGE = { cpm: 2.2, ttr: 300, IsBid: true + }, + { + timeStamp: 1519149562216, + adUnit: 'box_d_2', + bidder: 'livewrapped', + ttr: 200, + IsBid: false } ], timeouts: [], @@ -177,6 +206,7 @@ describe('Livewrapped analytics adapter', function () { xhr.onCreate = request => requests.push(request); sandbox.stub(events, 'getEvents').returns([]); + sandbox.stub(utils, 'timestamp').returns(1519149562416); clock = sandbox.useFakeTimers(1519767013781); }); From e959425c9e7f74ca1d41398743cdf8fbf478bd97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Mon, 18 Feb 2019 18:48:11 +0100 Subject: [PATCH 09/35] ANalytics updates --- modules/livewrappedAnalyticsAdapter.js | 4 ++-- test/spec/modules/livewrappedAnalyticsAdapter_spec.js | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/livewrappedAnalyticsAdapter.js b/modules/livewrappedAnalyticsAdapter.js index 03a797e901a..3ba501d2642 100644 --- a/modules/livewrappedAnalyticsAdapter.js +++ b/modules/livewrappedAnalyticsAdapter.js @@ -51,7 +51,7 @@ let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE case CONSTANTS.EVENTS.BID_RESPONSE: utils.logInfo('LIVEWRAPPED_BID_RESPONSE:', args); - let bidResponse = cache.auctions[args.auctionId].bids[args.adId || args.requestId]; + let bidResponse = cache.auctions[args.auctionId].bids[args.requestId]; bidResponse.isBid = args.getStatusCode() === CONSTANTS.STATUS.GOOD; bidResponse.width = args.width; bidResponse.height = args.height; @@ -74,7 +74,7 @@ let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE break; case CONSTANTS.EVENTS.BID_WON: utils.logInfo('LIVEWRAPPED_BID_WON:', args); - let wonBid = cache.auctions[args.auctionId].bids[args.adId]; + let wonBid = cache.auctions[args.auctionId].bids[args.requestId]; wonBid.won = true; if (wonBid.sendStatus != 0) { livewrappedAnalyticsAdapter.sendEvents(); diff --git a/test/spec/modules/livewrappedAnalyticsAdapter_spec.js b/test/spec/modules/livewrappedAnalyticsAdapter_spec.js index e2bb58c7488..639cbbb08e6 100644 --- a/test/spec/modules/livewrappedAnalyticsAdapter_spec.js +++ b/test/spec/modules/livewrappedAnalyticsAdapter_spec.js @@ -28,6 +28,7 @@ const BID1 = { cpm: 1.1, timeToRespond: 200, bidId: '2ecff0db240757', + requestId: '2ecff0db240757', adId: '2ecff0db240757', auctionId: '25c6d7f5-699a-4bfc-87c9-996f915341fa', getStatusCode() { @@ -41,11 +42,13 @@ const BID2 = Object.assign({}, BID1, { cpm: 2.2, timeToRespond: 300, bidId: '3ecff0db240757', + requestId: '3ecff0db240757', adId: '3ecff0db240757', }); const BID3 = { bidId: '4ecff0db240757', + requestId: '4ecff0db240757', adId: '4ecff0db240757', auctionId: '25c6d7f5-699a-4bfc-87c9-996f915341fa', getStatusCode() { @@ -89,10 +92,12 @@ const MOCK = { }, BID_WON: [ Object.assign({}, BID1, { - 'status': 'rendered' + 'status': 'rendered', + 'requestId': '2ecff0db240757' }), Object.assign({}, BID2, { - 'status': 'rendered' + 'status': 'rendered', + 'requestId': '3ecff0db240757' }) ], BIDDER_DONE: { From 43f2f07c73bda901e7d4a9510a31d77ceece02a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Fri, 22 Feb 2019 10:59:13 +0100 Subject: [PATCH 10/35] Auction start time stamp changed --- modules/livewrappedAnalyticsAdapter.js | 3 ++- test/spec/modules/livewrappedAnalyticsAdapter_spec.js | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/livewrappedAnalyticsAdapter.js b/modules/livewrappedAnalyticsAdapter.js index 3ba501d2642..7f3dba1e4e8 100644 --- a/modules/livewrappedAnalyticsAdapter.js +++ b/modules/livewrappedAnalyticsAdapter.js @@ -27,10 +27,11 @@ let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE switch (eventType) { case CONSTANTS.EVENTS.AUCTION_INIT: utils.logInfo('LIVEWRAPPED_AUCTION_INIT:', args); - cache.auctions[args.auctionId] = {bids: {}, timeStamp: args.timestamp}; + cache.auctions[args.auctionId] = {bids: {}}; break; case CONSTANTS.EVENTS.BID_REQUESTED: utils.logInfo('LIVEWRAPPED_BID_REQUESTED:', args); + cache.auctions[args.auctionId].timeStamp = args.start; args.bids.forEach(function(bidRequest) { cache.auctions[args.auctionId].bids[bidRequest.bidId] = { diff --git a/test/spec/modules/livewrappedAnalyticsAdapter_spec.js b/test/spec/modules/livewrappedAnalyticsAdapter_spec.js index 639cbbb08e6..908adc0601c 100644 --- a/test/spec/modules/livewrappedAnalyticsAdapter_spec.js +++ b/test/spec/modules/livewrappedAnalyticsAdapter_spec.js @@ -59,7 +59,6 @@ const BID3 = { const MOCK = { AUCTION_INIT: { 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa', - 'timestamp': 1519149562216 }, BID_REQUESTED: { 'bidder': 'livewrapped', From 87ebc8b7b4b68ecd1375d4dd0e514a7db972a7f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Mon, 15 Apr 2019 14:21:03 +0200 Subject: [PATCH 11/35] Detect recovered ad blocked requests Make it possible to pass dynamic parameters to adapter --- modules/livewrappedAnalyticsAdapter.js | 9 ++- modules/livewrappedBidAdapter.js | 11 +++- .../livewrappedAnalyticsAdapter_spec.js | 15 +++++ .../modules/livewrappedBidAdapter_spec.js | 58 +++++++++++++++++++ 4 files changed, 91 insertions(+), 2 deletions(-) diff --git a/modules/livewrappedAnalyticsAdapter.js b/modules/livewrappedAnalyticsAdapter.js index 7f3dba1e4e8..ec0ddb6fd54 100644 --- a/modules/livewrappedAnalyticsAdapter.js +++ b/modules/livewrappedAnalyticsAdapter.js @@ -113,7 +113,8 @@ livewrappedAnalyticsAdapter.sendEvents = function() { requests: getSentRequests(), responses: getResponses(), wins: getWins(), - timeouts: getTimeouts() + timeouts: getTimeouts(), + rcv: getAdblockerRecovered() }; if (events.requests.length == 0 && @@ -126,6 +127,12 @@ livewrappedAnalyticsAdapter.sendEvents = function() { ajax(URL, undefined, JSON.stringify(events), {method: 'POST'}); } +function getAdblockerRecovered() { + try { + return utils.getWindowTop().I12C && utils.getWindowTop().I12C.Morph === 1; + } catch (e) {} +} + function getSentRequests() { var sentRequests = []; diff --git a/modules/livewrappedBidAdapter.js b/modules/livewrappedBidAdapter.js index 69a89421a32..1ad18cb15eb 100644 --- a/modules/livewrappedBidAdapter.js +++ b/modules/livewrappedBidAdapter.js @@ -24,6 +24,7 @@ export const spec = { * seats: List of bidders and seats Optional. {"bidder name": ["seat 1", "seat 2"], ...} * deviceId: Device id if available Optional. * ifa: Advertising ID Optional. + * options Dynamic data Optional. Optional data to send into adapter. * * @param {BidRequest} bid The bid params to validate. * @return boolean True if this is a valid bid, and false otherwise. @@ -69,6 +70,7 @@ export const spec = { gdprApplies: bidderRequest.gdprConsent ? bidderRequest.gdprConsent.gdprApplies : undefined, gdprConsent: bidderRequest.gdprConsent ? bidderRequest.gdprConsent.consentString : undefined, cookieSupport: !utils.isSafariBrowser() && utils.cookiesAreEnabled(), + rcv: getAdblockerRecovered(), adRequests: [...adRequests] }; const payloadString = JSON.stringify(payload); @@ -178,7 +180,8 @@ function bidToAdRequest(bid) { callerAdUnitId: bid.params.adUnitName || bid.adUnitCode || bid.placementCode, bidId: bid.bidId, transactionId: bid.transactionId, - formats: bid.sizes.map(sizeToFormat) + formats: bid.sizes.map(sizeToFormat), + options: bid.params.options }; } @@ -189,4 +192,10 @@ function sizeToFormat(size) { } } +function getAdblockerRecovered() { + try { + return utils.getWindowTop().I12C && utils.getWindowTop().I12C.Morph === 1; + } catch (e) {} +} + registerBidder(spec); diff --git a/test/spec/modules/livewrappedAnalyticsAdapter_spec.js b/test/spec/modules/livewrappedAnalyticsAdapter_spec.js index 908adc0601c..92c1c4d3ab3 100644 --- a/test/spec/modules/livewrappedAnalyticsAdapter_spec.js +++ b/test/spec/modules/livewrappedAnalyticsAdapter_spec.js @@ -240,6 +240,7 @@ describe('Livewrapped analytics adapter', function () { }); it('should build a batched message from prebid events', function () { + sandbox.stub(utils, 'getWindowTop').returns({}); performStandardAuction(); clock.tick(BID_WON_TIMEOUT + 1000); @@ -295,5 +296,19 @@ describe('Livewrapped analytics adapter', function () { expect(message.timeouts[0].bidder).to.equal('livewrapped'); expect(message.timeouts[0].adUnit).to.equal('panorama_d_1'); }); + + it('should detect adblocker recovered request', function () { + sandbox.stub(utils, 'getWindowTop').returns({ I12C: { Morph: 1 } }); + performStandardAuction(); + + clock.tick(BID_WON_TIMEOUT + 1000); + + expect(requests.length).to.equal(1); + let request = requests[0]; + + let message = JSON.parse(request.requestBody); + + expect(message.rcv).to.equal(true); + }); }); }); diff --git a/test/spec/modules/livewrappedBidAdapter_spec.js b/test/spec/modules/livewrappedBidAdapter_spec.js index b12ff56c075..855eb2ee3f9 100644 --- a/test/spec/modules/livewrappedBidAdapter_spec.js +++ b/test/spec/modules/livewrappedBidAdapter_spec.js @@ -303,6 +303,64 @@ describe('Livewrapped adapter tests', function () { expect(data).to.deep.equal(expectedQuery); }); + it('should make a well-formed single request object with optional parameters', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + delete testbidRequest.bids[0].params.seats; + delete testbidRequest.bids[0].params.adUnitId; + testbidRequest.bids[0].params.options = {keyvalues: [{key: 'key', value: 'value'}]}; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + url: 'http://www.domain.com', + version: '1.1', + cookieSupport: true, + adRequests: [{ + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}], + options: {keyvalues: [{key: 'key', value: 'value'}]} + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed single request object with ad blocker revovered parameter', function() { + sandbox.stub(utils, 'getWindowTop').returns({ I12C: { Morph: 1 } }); + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + delete testbidRequest.bids[0].params.seats; + delete testbidRequest.bids[0].params.adUnitId; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + url: 'http://www.domain.com', + version: '1.1', + cookieSupport: true, + rcv: true, + adRequests: [{ + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + it('should pass gdpr true parameters', function() { sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); From 332b500499fd14f948b4a066a96206cb1ae31f29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Fri, 16 Aug 2019 16:04:27 +0200 Subject: [PATCH 12/35] Collect info on ad units receiving any valid bid --- modules/livewrappedAnalyticsAdapter.js | 23 +++++++++++++++++++ .../livewrappedAnalyticsAdapter_spec.js | 10 ++++++++ 2 files changed, 33 insertions(+) diff --git a/modules/livewrappedAnalyticsAdapter.js b/modules/livewrappedAnalyticsAdapter.js index ec0ddb6fd54..72c46de744d 100644 --- a/modules/livewrappedAnalyticsAdapter.js +++ b/modules/livewrappedAnalyticsAdapter.js @@ -17,6 +17,7 @@ export const BID_WON_TIMEOUT = 500; const cache = { auctions: {}, + bidAdUnits: {} }; let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE}), { @@ -62,6 +63,9 @@ let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE if (!bidResponse.ttr) { bidResponse.ttr = time - bidResponse.start; } + if (!cache.bidAdUnits[bidResponse.adUnit]) { + cache.bidAdUnits[bidResponse.adUnit] = {sent: 0, timeStamp: cache.auctions[args.auctionId].timeStamp}; + } break; case CONSTANTS.EVENTS.BIDDER_DONE: utils.logInfo('LIVEWRAPPED_BIDDER_DONE:', args); @@ -114,6 +118,7 @@ livewrappedAnalyticsAdapter.sendEvents = function() { responses: getResponses(), wins: getWins(), timeouts: getTimeouts(), + bidAdUnits: getbidAdUnits(), rcv: getAdblockerRecovered() }; @@ -229,6 +234,24 @@ function getTimeouts() { return timeouts; } +function getbidAdUnits() { + var bidAdUnits = []; + + Object.keys(cache.bidAdUnits).forEach(adUnit => { + let bidAdUnit = cache.bidAdUnits[adUnit]; + if (!bidAdUnit.sent) { + bidAdUnit.sent = 1; + + bidAdUnits.push({ + adUnit: adUnit, + timeStamp: bidAdUnit.timeStamp + }); + } + }); + + return bidAdUnits; +} + adapterManager.registerAnalyticsAdapter({ adapter: livewrappedAnalyticsAdapter, code: 'livewrapped' diff --git a/test/spec/modules/livewrappedAnalyticsAdapter_spec.js b/test/spec/modules/livewrappedAnalyticsAdapter_spec.js index 92c1c4d3ab3..611ff95a036 100644 --- a/test/spec/modules/livewrappedAnalyticsAdapter_spec.js +++ b/test/spec/modules/livewrappedAnalyticsAdapter_spec.js @@ -117,6 +117,16 @@ const MOCK = { const ANALYTICS_MESSAGE = { publisherId: 'CC411485-42BC-4F92-8389-42C503EE38D7', + bidAdUnits: [ + { + adUnit: 'panorama_d_1', + timeStamp: 1519149562216 + }, + { + adUnit: 'box_d_1', + timeStamp: 1519149562216 + } + ], requests: [ { adUnit: 'panorama_d_1', From 5f09e2a87deb63321b57d3c7084a71abf0240335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Tue, 22 Oct 2019 07:04:09 +0200 Subject: [PATCH 13/35] Support for ID5 Pass metadata from adapter --- modules/livewrappedBidAdapter.js | 38 +++++++- .../modules/livewrappedBidAdapter_spec.js | 93 ++++++++++++++++++- 2 files changed, 124 insertions(+), 7 deletions(-) diff --git a/modules/livewrappedBidAdapter.js b/modules/livewrappedBidAdapter.js index 1ad18cb15eb..96f55fab917 100644 --- a/modules/livewrappedBidAdapter.js +++ b/modules/livewrappedBidAdapter.js @@ -71,7 +71,8 @@ export const spec = { gdprConsent: bidderRequest.gdprConsent ? bidderRequest.gdprConsent.consentString : undefined, cookieSupport: !utils.isSafariBrowser() && utils.cookiesAreEnabled(), rcv: getAdblockerRecovered(), - adRequests: [...adRequests] + adRequests: [...adRequests], + rtbData: HandleEids(bidRequests) }; const payloadString = JSON.stringify(payload); return { @@ -101,7 +102,8 @@ export const spec = { ttl: ad.ttl, creativeId: ad.creativeId, netRevenue: true, - currency: serverResponse.body.currency + currency: serverResponse.body.currency, + meta: ad.meta }; bidResponses.push(bidResponse); @@ -198,4 +200,36 @@ function getAdblockerRecovered() { } catch (e) {} } +function AddExternalUserId(eids, value, source, atype, rtiPartner) { + if (utils.isStr(value)) { + var eid = { + source, + uids: [{ + id: value, + atype + }] + }; + + if (rtiPartner) { + eid.uids[0] = {ext: {rtiPartner}}; + } + + eids.push(eid); + } +} + +function HandleEids(bidRequests) { + let eids = []; + const bidRequest = bidRequests[0]; + if (bidRequest && bidRequest.userId) { + AddExternalUserId(eids, utils.deepAccess(bidRequest, `userId.pubcid`), 'pubcommon', 1); // Also add this to eids + AddExternalUserId(eids, utils.deepAccess(bidRequest, `userId.id5id`), 'id5-sync.com', 1); + } + if (eids.length > 0) { + return {user: {ext: eids}}; + } + + return undefined; +} + registerBidder(spec); diff --git a/test/spec/modules/livewrappedBidAdapter_spec.js b/test/spec/modules/livewrappedBidAdapter_spec.js index 855eb2ee3f9..416c9b2ce61 100644 --- a/test/spec/modules/livewrappedBidAdapter_spec.js +++ b/test/spec/modules/livewrappedBidAdapter_spec.js @@ -577,6 +577,44 @@ describe('Livewrapped adapter tests', function () { }); }); + it('should make use of Id5-Id if available', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + testbidRequest.bids[0].userId = {}; + testbidRequest.bids[0].userId.id5id = 'id5-user-id'; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(data.rtbData.user.ext).to.deep.equal([{ + 'source': 'id5-sync.com', + 'uids': [{ + 'id': 'id5-user-id', + 'atype': 1 + }] + }]); + }); + + it('should make use of publisher common Id if available', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + testbidRequest.bids[0].userId = {}; + testbidRequest.bids[0].userId.pubcid = 'publisher-common-id'; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(data.rtbData.user.ext).to.deep.equal([{ + 'source': 'pubcommon', + 'uids': [{ + 'id': 'publisher-common-id', + 'atype': 1 + }] + }]); + }); + describe('interpretResponse', function () { it('should handle single success response', function() { let lwResponse = { @@ -591,7 +629,8 @@ describe('Livewrapped adapter tests', function () { bidId: '32e50fad901ae89', auctionId: '13e674db-d4d8-4e19-9d28-ff38177db8bf', creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', - ttl: 120 + ttl: 120, + meta: undefined } ], currency: 'USD' @@ -607,7 +646,8 @@ describe('Livewrapped adapter tests', function () { ttl: 120, creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', netRevenue: true, - currency: 'USD' + currency: 'USD', + meta: undefined }]; let bids = spec.interpretResponse({body: lwResponse}); @@ -628,7 +668,8 @@ describe('Livewrapped adapter tests', function () { bidId: '32e50fad901ae89', auctionId: '13e674db-d4d8-4e19-9d28-ff38177db8bf', creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', - ttl: 120 + ttl: 120, + meta: undefined }, { id: '38e5ddf4-3c01-11e8-86a7-0a44794250d4', @@ -640,7 +681,8 @@ describe('Livewrapped adapter tests', function () { bidId: '42e50fad901ae89', auctionId: '13e674db-d4d8-4e19-9d28-ff38177db8bf', creativeId: '62cbd598-2715-4c43-a06f-229fc170f945:427077', - ttl: 120 + ttl: 120, + meta: undefined } ], currency: 'USD' @@ -656,7 +698,8 @@ describe('Livewrapped adapter tests', function () { ttl: 120, creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', netRevenue: true, - currency: 'USD' + currency: 'USD', + meta: undefined }, { requestId: '42e50fad901ae89', bidderCode: 'livewrapped', @@ -667,7 +710,47 @@ describe('Livewrapped adapter tests', function () { ttl: 120, creativeId: '62cbd598-2715-4c43-a06f-229fc170f945:427077', netRevenue: true, + currency: 'USD', + meta: undefined + }]; + + let bids = spec.interpretResponse({body: lwResponse}); + + expect(bids).to.deep.equal(expectedResponse); + }) + + it('should return meta-data', function() { + let lwResponse = { + ads: [ + { + id: '28e5ddf4-3c01-11e8-86a7-0a44794250d4', + callerId: 'site_outsider_0', + tag: 'ad', + width: 300, + height: 250, + cpmBid: 2.565917, + bidId: '32e50fad901ae89', + auctionId: '13e674db-d4d8-4e19-9d28-ff38177db8bf', + creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', + ttl: 120, + meta: {metadata: "metadata"} + } + ], currency: 'USD' + }; + + let expectedResponse = [{ + requestId: '32e50fad901ae89', + bidderCode: 'livewrapped', + cpm: 2.565917, + width: 300, + height: 250, + ad: 'ad', + ttl: 120, + creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', + netRevenue: true, + currency: 'USD', + meta: {metadata: "metadata"} }]; let bids = spec.interpretResponse({body: lwResponse}); From 728be386cdc065f9a0c64a5a5939b67fbeb2fe26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Tue, 22 Oct 2019 09:08:41 +0200 Subject: [PATCH 14/35] Typo in test + eids on wrong level --- modules/livewrappedBidAdapter.js | 2 +- test/spec/modules/livewrappedBidAdapter_spec.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/livewrappedBidAdapter.js b/modules/livewrappedBidAdapter.js index 96f55fab917..5006a513454 100644 --- a/modules/livewrappedBidAdapter.js +++ b/modules/livewrappedBidAdapter.js @@ -226,7 +226,7 @@ function HandleEids(bidRequests) { AddExternalUserId(eids, utils.deepAccess(bidRequest, `userId.id5id`), 'id5-sync.com', 1); } if (eids.length > 0) { - return {user: {ext: eids}}; + return {user: {ext: {eids}}}; } return undefined; diff --git a/test/spec/modules/livewrappedBidAdapter_spec.js b/test/spec/modules/livewrappedBidAdapter_spec.js index 416c9b2ce61..6db8bff4c3d 100644 --- a/test/spec/modules/livewrappedBidAdapter_spec.js +++ b/test/spec/modules/livewrappedBidAdapter_spec.js @@ -587,7 +587,7 @@ describe('Livewrapped adapter tests', function () { let result = spec.buildRequests(testbidRequest.bids, testbidRequest); let data = JSON.parse(result.data); - expect(data.rtbData.user.ext).to.deep.equal([{ + expect(data.rtbData.user.ext.eids).to.deep.equal([{ 'source': 'id5-sync.com', 'uids': [{ 'id': 'id5-user-id', @@ -606,7 +606,7 @@ describe('Livewrapped adapter tests', function () { let result = spec.buildRequests(testbidRequest.bids, testbidRequest); let data = JSON.parse(result.data); - expect(data.rtbData.user.ext).to.deep.equal([{ + expect(data.rtbData.user.ext.eids).to.deep.equal([{ 'source': 'pubcommon', 'uids': [{ 'id': 'publisher-common-id', @@ -733,7 +733,7 @@ describe('Livewrapped adapter tests', function () { auctionId: '13e674db-d4d8-4e19-9d28-ff38177db8bf', creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', ttl: 120, - meta: {metadata: "metadata"} + meta: {metadata: 'metadata'} } ], currency: 'USD' @@ -750,7 +750,7 @@ describe('Livewrapped adapter tests', function () { creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', netRevenue: true, currency: 'USD', - meta: {metadata: "metadata"} + meta: {metadata: 'metadata'} }]; let bids = spec.interpretResponse({body: lwResponse}); From 531365e3b76ace504d93f5107409200ae1506e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Thu, 12 Dec 2019 15:02:22 +0100 Subject: [PATCH 15/35] Fix for Prebid 3.0 --- modules/livewrappedBidAdapter.js | 241 +++++ .../modules/livewrappedBidAdapter_spec.js | 835 ++++++++++++++++++ 2 files changed, 1076 insertions(+) create mode 100644 modules/livewrappedBidAdapter.js create mode 100644 test/spec/modules/livewrappedBidAdapter_spec.js diff --git a/modules/livewrappedBidAdapter.js b/modules/livewrappedBidAdapter.js new file mode 100644 index 00000000000..e773baf5f17 --- /dev/null +++ b/modules/livewrappedBidAdapter.js @@ -0,0 +1,241 @@ +import * as utils from '../src/utils'; +import { registerBidder } from '../src/adapters/bidderFactory'; +import { config } from '../src/config'; +import { parse as parseUrl } from '../src/url'; +import find from 'core-js/library/fn/array/find'; + +const BIDDER_CODE = 'livewrapped'; +export const URL = 'https://lwadm.com/ad'; +const VERSION = '1.1'; + +export const spec = { + code: BIDDER_CODE, + + /** + * Determines whether or not the given bid request is valid. + * + * Parameters should be + * + * adUnitId: LiveWrapped's id of the ad unit. Optional. A guid identifying the ad unit. + * adUnitName: LiveWrapped's name of the ad unit Optional. (Prebid's ad unit code will be used otherwise.) + * publisherId: Publisher id. Required if adUnitName is used or both adUnitName and adUnitId is omitted, otherwise optional. + * userId: A persistent user id if available. Optional. + * url: Page url Optional. Use if page url cannot be determined due to use of iframes. + * bidUrl: Bidding endpoint Optional. + * seats: List of bidders and seats Optional. {"bidder name": ["seat 1", "seat 2"], ...} + * deviceId: Device id if available Optional. + * ifa: Advertising ID Optional. + * options Dynamic data Optional. Optional data to send into adapter. + * + * @param {BidRequest} bid The bid params to validate. + * @return boolean True if this is a valid bid, and false otherwise. + */ + isBidRequestValid: function(bid) { + return (bid.params.adUnitId || ((bid.params.adUnitName || bid.adUnitCode || bid.placementCode) && bid.params.publisherId)) !== undefined; + }, + + /** + * Make a server request from the list of BidRequests. + * + * @param {BidRequest[]} bidRequests A non-empty list of bid requests which should be sent to the Server. + * @return ServerRequest Info describing the request to the server. + */ + buildRequests: function(bidRequests, bidderRequest) { + const userId = find(bidRequests, hasUserId); + const pubcid = find(bidRequests, hasPubcid); + const publisherId = find(bidRequests, hasPublisherId); + const auctionId = find(bidRequests, hasAuctionId); + let bidUrl = find(bidRequests, hasBidUrl); + let url = find(bidRequests, hasUrl); + let test = find(bidRequests, hasTestParam); + const seats = find(bidRequests, hasSeatsParam); + const deviceId = find(bidRequests, hasDeviceIdParam); + const ifa = find(bidRequests, hasIfaParam); + const tid = find(bidRequests, hasTidParam); + bidUrl = bidUrl ? bidUrl.params.bidUrl : URL; + url = url ? url.params.url : (getTopWindowLocation(bidderRequest)); + test = test ? test.params.test : undefined; + var adRequests = bidRequests.map(bidToAdRequest); + + const payload = { + auctionId: auctionId ? auctionId.auctionId : undefined, + publisherId: publisherId ? publisherId.params.publisherId : undefined, + userId: userId ? userId.params.userId : (pubcid ? pubcid.crumbs.pubcid : undefined), + url: url, + test: test, + seats: seats ? seats.params.seats : undefined, + deviceId: deviceId ? deviceId.params.deviceId : undefined, + ifa: ifa ? ifa.params.ifa : undefined, + tid: tid ? tid.params.tid : undefined, + version: VERSION, + gdprApplies: bidderRequest.gdprConsent ? bidderRequest.gdprConsent.gdprApplies : undefined, + gdprConsent: bidderRequest.gdprConsent ? bidderRequest.gdprConsent.consentString : undefined, + cookieSupport: !utils.isSafariBrowser() && utils.cookiesAreEnabled(), + rcv: getAdblockerRecovered(), + adRequests: [...adRequests], + rtbData: handleEids(bidRequests) + }; + const payloadString = JSON.stringify(payload); + return { + method: 'POST', + url: bidUrl, + data: payloadString, + }; + }, + + /** + * Unpack the response from the server into a list of bids. + * + * @param {*} serverResponse A successful response from the server. + * @return {Bid[]} An array of bids which were nested inside the server. + */ + interpretResponse: function(serverResponse) { + const bidResponses = []; + + serverResponse.body.ads.forEach(function(ad) { + let bidResponse = { + requestId: ad.bidId, + bidderCode: BIDDER_CODE, + cpm: ad.cpmBid, + width: ad.width, + height: ad.height, + ad: ad.tag, + ttl: ad.ttl, + creativeId: ad.creativeId, + netRevenue: true, + currency: serverResponse.body.currency, + meta: ad.meta + }; + + bidResponses.push(bidResponse); + }); + + return bidResponses; + }, + + getUserSyncs: function(syncOptions, serverResponses) { + if (serverResponses.length == 0) return []; + + let syncList = []; + let userSync = serverResponses[0].body.pixels || []; + + userSync.forEach(function(sync) { + if (syncOptions.pixelEnabled && sync.type == 'Redirect') { + syncList.push({type: 'image', url: sync.url}); + } + + if (syncOptions.iframeEnabled && sync.type == 'Iframe') { + syncList.push({type: 'iframe', url: sync.url}); + } + }); + + return syncList; + } +} + +function hasUserId(bid) { + return !!bid.params.userId; +} + +function hasPublisherId(bid) { + return !!bid.params.publisherId; +} + +function hasUrl(bid) { + return !!bid.params.url; +} + +function hasBidUrl(bid) { + return !!bid.params.bidUrl; +} + +function hasAuctionId(bid) { + return !!bid.auctionId; +} + +function hasTestParam(bid) { + return !!bid.params.test; +} + +function hasSeatsParam(bid) { + return !!bid.params.seats; +} + +function hasDeviceIdParam(bid) { + return !!bid.params.deviceId; +} + +function hasIfaParam(bid) { + return !!bid.params.ifa; +} + +function hasTidParam(bid) { + return !!bid.params.tid; +} + +function hasPubcid(bid) { + return !!bid.crumbs && !!bid.crumbs.pubcid; +} + +function bidToAdRequest(bid) { + return { + adUnitId: bid.params.adUnitId, + callerAdUnitId: bid.params.adUnitName || bid.adUnitCode || bid.placementCode, + bidId: bid.bidId, + transactionId: bid.transactionId, + formats: bid.sizes.map(sizeToFormat), + options: bid.params.options + }; +} + +function sizeToFormat(size) { + return { + width: size[0], + height: size[1] + } +} + +function getAdblockerRecovered() { + try { + return utils.getWindowTop().I12C && utils.getWindowTop().I12C.Morph === 1; + } catch (e) {} +} + +function AddExternalUserId(eids, value, source, atype, rtiPartner) { + if (utils.isStr(value)) { + var eid = { + source, + uids: [{ + id: value, + atype + }] + }; + + if (rtiPartner) { + eid.uids[0] = {ext: {rtiPartner}}; + } + + eids.push(eid); + } +} + +function handleEids(bidRequests) { + let eids = []; + const bidRequest = bidRequests[0]; + if (bidRequest && bidRequest.userId) { + AddExternalUserId(eids, utils.deepAccess(bidRequest, `userId.pubcid`), 'pubcommon', 1); // Also add this to eids + AddExternalUserId(eids, utils.deepAccess(bidRequest, `userId.id5id`), 'id5-sync.com', 1); + } + if (eids.length > 0) { + return {user: {ext: {eids}}}; + } + + return undefined; +} + +function getTopWindowLocation(bidderRequest) { + let url = bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer; + return parseUrl(config.getConfig('pageUrl') || url, { decodeSearchAsString: true }); +} + +registerBidder(spec); diff --git a/test/spec/modules/livewrappedBidAdapter_spec.js b/test/spec/modules/livewrappedBidAdapter_spec.js new file mode 100644 index 00000000000..6f2afda56a5 --- /dev/null +++ b/test/spec/modules/livewrappedBidAdapter_spec.js @@ -0,0 +1,835 @@ +import {expect} from 'chai'; +import {spec} from 'modules/livewrappedBidAdapter'; +import {config} from 'src/config'; +import * as utils from 'src/utils'; + +describe('Livewrapped adapter tests', function () { + let sandbox, + bidderRequest; + + beforeEach(function () { + sandbox = sinon.sandbox.create(); + + bidderRequest = { + bidderCode: 'livewrapped', + auctionId: 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a', + bidderRequestId: '178e34bad3658f', + bids: [ + { + bidder: 'livewrapped', + params: { + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']} + }, + adUnitCode: 'panorama_d_1', + sizes: [[980, 240], [980, 120]], + bidId: '2ffb201a808da7', + bidderRequestId: '178e34bad3658f', + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D' + } + ], + start: 1472239426002, + auctionStart: 1472239426000, + timeout: 5000 + }; + }); + + afterEach(function () { + sandbox.restore(); + }); + + describe('isBidRequestValid', function() { + it('should accept a request with id only as valid', function() { + let bid = {params: {adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37'}}; + + let result = spec.isBidRequestValid(bid); + + expect(result).to.be.true; + }); + + it('should accept a request with adUnitName and PublisherId as valid', function() { + let bid = {params: {adUnitName: 'panorama_d_1', publisherId: '26947112-2289-405D-88C1-A7340C57E63E'}}; + + let result = spec.isBidRequestValid(bid); + + expect(result).to.be.true; + }); + + it('should accept a request with adUnitCode and PublisherId as valid', function() { + let bid = {adUnitCode: 'panorama_d_1', params: {publisherId: '26947112-2289-405D-88C1-A7340C57E63E'}}; + + let result = spec.isBidRequestValid(bid); + + expect(result).to.be.true; + }); + + it('should accept a request with placementCode and PublisherId as valid', function() { + let bid = {placementCode: 'panorama_d_1', params: {publisherId: '26947112-2289-405D-88C1-A7340C57E63E'}}; + + let result = spec.isBidRequestValid(bid); + + expect(result).to.be.true; + }); + + it('should not accept a request with adUnitName, adUnitCode, placementCode but no PublisherId as valid', function() { + let bid = {placementCode: 'panorama_d_1', adUnitCode: 'panorama_d_1', params: {adUnitName: 'panorama_d_1'}}; + + let result = spec.isBidRequestValid(bid); + + expect(result).to.be.false; + }); + }); + + describe('buildRequests', function() { + it('should make a well-formed single request object', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let result = spec.buildRequests(bidderRequest.bids, bidderRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: true, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed multiple request object', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let multiplebidRequest = clone(bidderRequest); + multiplebidRequest.bids.push(clone(bidderRequest.bids[0])); + multiplebidRequest.bids[1].adUnitCode = 'box_d_1'; + multiplebidRequest.bids[1].sizes = [[300, 250]]; + multiplebidRequest.bids[1].bidId = '3ffb201a808da7'; + delete multiplebidRequest.bids[1].params.adUnitId; + + let result = spec.buildRequests(multiplebidRequest.bids, multiplebidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: true, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }, { + callerAdUnitId: 'box_d_1', + bidId: '3ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 300, height: 250}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed single request object with AdUnitName', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + testbidRequest.bids[0].params.adUnitName = 'caller id 1'; + delete testbidRequest.bids[0].params.adUnitId; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: true, + adRequests: [{ + callerAdUnitId: 'caller id 1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed single request object with less parameters', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + delete testbidRequest.bids[0].params.seats; + delete testbidRequest.bids[0].params.adUnitId; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + url: 'http://www.domain.com', + version: '1.1', + cookieSupport: true, + adRequests: [{ + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed single request object with less parameters, no publisherId', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + delete testbidRequest.bids[0].params.seats; + delete testbidRequest.bids[0].params.publisherId; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + url: 'http://www.domain.com', + version: '1.1', + cookieSupport: true, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed single request object with app parameters', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + delete testbidRequest.bids[0].params.seats; + delete testbidRequest.bids[0].params.adUnitId; + testbidRequest.bids[0].params.deviceId = 'deviceid'; + testbidRequest.bids[0].params.ifa = 'ifa'; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + url: 'http://www.domain.com', + version: '1.1', + deviceId: 'deviceid', + ifa: 'ifa', + cookieSupport: true, + adRequests: [{ + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed single request object with debug parameters', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + delete testbidRequest.bids[0].params.seats; + delete testbidRequest.bids[0].params.adUnitId; + testbidRequest.bids[0].params.tid = 'tracking id'; + testbidRequest.bids[0].params.test = true; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + url: 'http://www.domain.com', + version: '1.1', + tid: 'tracking id', + test: true, + cookieSupport: true, + adRequests: [{ + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed single request object with optional parameters', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + delete testbidRequest.bids[0].params.seats; + delete testbidRequest.bids[0].params.adUnitId; + testbidRequest.bids[0].params.options = {keyvalues: [{key: 'key', value: 'value'}]}; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + url: 'http://www.domain.com', + version: '1.1', + cookieSupport: true, + adRequests: [{ + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}], + options: {keyvalues: [{key: 'key', value: 'value'}]} + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed single request object with ad blocker revovered parameter', function() { + sandbox.stub(utils, 'getWindowTop').returns({ I12C: { Morph: 1 } }); + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + delete testbidRequest.bids[0].params.seats; + delete testbidRequest.bids[0].params.adUnitId; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + url: 'http://www.domain.com', + version: '1.1', + cookieSupport: true, + rcv: true, + adRequests: [{ + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should pass gdpr true parameters', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testRequest = clone(bidderRequest); + testRequest.gdprConsent = { + gdprApplies: true, + consentString: 'test' + }; + let result = spec.buildRequests(testRequest.bids, testRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: true, + gdprApplies: true, + gdprConsent: 'test', + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should pass gdpr false parameters', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testRequest = clone(bidderRequest); + testRequest.gdprConsent = { + gdprApplies: false + }; + let result = spec.buildRequests(testRequest.bids, testRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: true, + gdprApplies: false, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should pass no cookie support', function() { + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => false); + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + let result = spec.buildRequests(bidderRequest.bids, bidderRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: false, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should pass no cookie support Safari', function() { + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => true); + let result = spec.buildRequests(bidderRequest.bids, bidderRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: false, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should use params.url, then config pageUrl, then bidderRequest.refererInfo.referer', function() { + let testRequest = clone(bidderRequest); + testRequest.refererInfo = {referer: 'http://www.topurl.com'}; + + let result = spec.buildRequests(testRequest.bids, testRequest); + let data = JSON.parse(result.data); + + expect(data.url).to.equal('http://www.domain.com'); + + delete testRequest.bids[0].params.url; + + result = spec.buildRequests(testRequest.bids, testRequest); + data = JSON.parse(result.data); + + expect(data.url).to.equal('http://www.topurl.com'); + + let origGetConfig = config.getConfig; + sandbox.stub(config, 'getConfig').callsFake(function (key) { + if (key === 'pageUrl') { + return 'http://www.configurl.com'; + } + return origGetConfig.apply(config, arguments); + }); + + result = spec.buildRequests(testRequest.bids, testRequest); + data = JSON.parse(result.data); + + expect(data.url).to.equal('http://www.configurl.com'); + }); + + it('should make use of pubcid if available', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + testbidRequest.bids[0].crumbs = {pubcid: 'pubcid 123'}; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'pubcid 123', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: true, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make userId take precedence over pubcid', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + testbidRequest.bids[0].crumbs = {pubcid: 'pubcid 123'}; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(result.url).to.equal('https://lwadm.com/ad'); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + userId: 'user id', + url: 'http://www.domain.com', + seats: {'dsp': ['seat 1']}, + version: '1.1', + cookieSupport: true, + adRequests: [{ + adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + }); + + it('should make use of Id5-Id if available', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + testbidRequest.bids[0].userId = {}; + testbidRequest.bids[0].userId.id5id = 'id5-user-id'; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(data.rtbData.user.ext.eids).to.deep.equal([{ + 'source': 'id5-sync.com', + 'uids': [{ + 'id': 'id5-user-id', + 'atype': 1 + }] + }]); + }); + + it('should make use of publisher common Id if available', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + testbidRequest.bids[0].userId = {}; + testbidRequest.bids[0].userId.pubcid = 'publisher-common-id'; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + expect(data.rtbData.user.ext.eids).to.deep.equal([{ + 'source': 'pubcommon', + 'uids': [{ + 'id': 'publisher-common-id', + 'atype': 1 + }] + }]); + }); + + describe('interpretResponse', function () { + it('should handle single success response', function() { + let lwResponse = { + ads: [ + { + id: '28e5ddf4-3c01-11e8-86a7-0a44794250d4', + callerId: 'site_outsider_0', + tag: 'ad', + width: 300, + height: 250, + cpmBid: 2.565917, + bidId: '32e50fad901ae89', + auctionId: '13e674db-d4d8-4e19-9d28-ff38177db8bf', + creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', + ttl: 120, + meta: undefined + } + ], + currency: 'USD' + }; + + let expectedResponse = [{ + requestId: '32e50fad901ae89', + bidderCode: 'livewrapped', + cpm: 2.565917, + width: 300, + height: 250, + ad: 'ad', + ttl: 120, + creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', + netRevenue: true, + currency: 'USD', + meta: undefined + }]; + + let bids = spec.interpretResponse({body: lwResponse}); + + expect(bids).to.deep.equal(expectedResponse); + }) + + it('should handle multiple success response', function() { + let lwResponse = { + ads: [ + { + id: '28e5ddf4-3c01-11e8-86a7-0a44794250d4', + callerId: 'site_outsider_0', + tag: 'ad1', + width: 300, + height: 250, + cpmBid: 2.565917, + bidId: '32e50fad901ae89', + auctionId: '13e674db-d4d8-4e19-9d28-ff38177db8bf', + creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', + ttl: 120, + meta: undefined + }, + { + id: '38e5ddf4-3c01-11e8-86a7-0a44794250d4', + callerId: 'site_outsider_1', + tag: 'ad2', + width: 980, + height: 240, + cpmBid: 3.565917, + bidId: '42e50fad901ae89', + auctionId: '13e674db-d4d8-4e19-9d28-ff38177db8bf', + creativeId: '62cbd598-2715-4c43-a06f-229fc170f945:427077', + ttl: 120, + meta: undefined + } + ], + currency: 'USD' + }; + + let expectedResponse = [{ + requestId: '32e50fad901ae89', + bidderCode: 'livewrapped', + cpm: 2.565917, + width: 300, + height: 250, + ad: 'ad1', + ttl: 120, + creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', + netRevenue: true, + currency: 'USD', + meta: undefined + }, { + requestId: '42e50fad901ae89', + bidderCode: 'livewrapped', + cpm: 3.565917, + width: 980, + height: 240, + ad: 'ad2', + ttl: 120, + creativeId: '62cbd598-2715-4c43-a06f-229fc170f945:427077', + netRevenue: true, + currency: 'USD', + meta: undefined + }]; + + let bids = spec.interpretResponse({body: lwResponse}); + + expect(bids).to.deep.equal(expectedResponse); + }) + + it('should return meta-data', function() { + let lwResponse = { + ads: [ + { + id: '28e5ddf4-3c01-11e8-86a7-0a44794250d4', + callerId: 'site_outsider_0', + tag: 'ad', + width: 300, + height: 250, + cpmBid: 2.565917, + bidId: '32e50fad901ae89', + auctionId: '13e674db-d4d8-4e19-9d28-ff38177db8bf', + creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', + ttl: 120, + meta: {metadata: 'metadata'} + } + ], + currency: 'USD' + }; + + let expectedResponse = [{ + requestId: '32e50fad901ae89', + bidderCode: 'livewrapped', + cpm: 2.565917, + width: 300, + height: 250, + ad: 'ad', + ttl: 120, + creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', + netRevenue: true, + currency: 'USD', + meta: {metadata: 'metadata'} + }]; + + let bids = spec.interpretResponse({body: lwResponse}); + + expect(bids).to.deep.equal(expectedResponse); + }) + }); + + describe('user sync', function () { + let serverResponses; + + beforeEach(function () { + serverResponses = [{ + body: { + pixels: [ + {type: 'Redirect', url: 'http://pixelsync'}, + {type: 'Iframe', url: 'http://iframesync'} + ] + } + }]; + }); + + it('should return empty if no server responses', function() { + let syncs = spec.getUserSyncs({ + pixelEnabled: true, + iframeEnabled: true + }, []); + + let expectedResponse = []; + + expect(syncs).to.deep.equal(expectedResponse) + }); + + it('should return empty if no user sync', function() { + let syncs = spec.getUserSyncs({ + pixelEnabled: true, + iframeEnabled: true + }, [{body: {}}]); + + let expectedResponse = []; + + expect(syncs).to.deep.equal(expectedResponse) + }); + + it('should returns pixel and iframe user sync', function() { + let syncs = spec.getUserSyncs({ + pixelEnabled: true, + iframeEnabled: true + }, serverResponses); + + let expectedResponse = [{type: 'image', url: 'http://pixelsync'}, {type: 'iframe', url: 'http://iframesync'}]; + + expect(syncs).to.deep.equal(expectedResponse) + }); + + it('should returns pixel only if iframe not supported user sync', function() { + let syncs = spec.getUserSyncs({ + pixelEnabled: true, + iframeEnabled: false + }, serverResponses); + + let expectedResponse = [{type: 'image', url: 'http://pixelsync'}]; + + expect(syncs).to.deep.equal(expectedResponse) + }); + + it('should returns iframe only if pixel not supported user sync', function() { + let syncs = spec.getUserSyncs({ + pixelEnabled: false, + iframeEnabled: true + }, serverResponses); + + let expectedResponse = [{type: 'iframe', url: 'http://iframesync'}]; + + expect(syncs).to.deep.equal(expectedResponse) + }); + }); +}); + +function clone(obj) { + return JSON.parse(JSON.stringify(obj)); +} From 6603c59c2b7a8af3256206abd7550e456382b799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Thu, 12 Dec 2019 17:38:33 +0100 Subject: [PATCH 16/35] Fix get referer --- modules/livewrappedBidAdapter.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/livewrappedBidAdapter.js b/modules/livewrappedBidAdapter.js index e773baf5f17..fa2d6809d93 100644 --- a/modules/livewrappedBidAdapter.js +++ b/modules/livewrappedBidAdapter.js @@ -1,7 +1,6 @@ import * as utils from '../src/utils'; import { registerBidder } from '../src/adapters/bidderFactory'; import { config } from '../src/config'; -import { parse as parseUrl } from '../src/url'; import find from 'core-js/library/fn/array/find'; const BIDDER_CODE = 'livewrapped'; @@ -53,7 +52,7 @@ export const spec = { const ifa = find(bidRequests, hasIfaParam); const tid = find(bidRequests, hasTidParam); bidUrl = bidUrl ? bidUrl.params.bidUrl : URL; - url = url ? url.params.url : (getTopWindowLocation(bidderRequest)); + url = url ? url.params.url : getTopWindowLocation(bidderRequest); test = test ? test.params.test : undefined; var adRequests = bidRequests.map(bidToAdRequest); @@ -235,7 +234,7 @@ function handleEids(bidRequests) { function getTopWindowLocation(bidderRequest) { let url = bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer; - return parseUrl(config.getConfig('pageUrl') || url, { decodeSearchAsString: true }); + return config.getConfig('pageUrl') || url; } registerBidder(spec); From 0ea76e4bac52f26b2a522f4d7292c9d7e1833b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Wed, 18 Dec 2019 13:54:03 +0100 Subject: [PATCH 17/35] http -> https in tests --- .../modules/livewrappedBidAdapter_spec.js | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/test/spec/modules/livewrappedBidAdapter_spec.js b/test/spec/modules/livewrappedBidAdapter_spec.js index 6f2afda56a5..ccab9765c4b 100644 --- a/test/spec/modules/livewrappedBidAdapter_spec.js +++ b/test/spec/modules/livewrappedBidAdapter_spec.js @@ -21,7 +21,7 @@ describe('Livewrapped adapter tests', function () { adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', publisherId: '26947112-2289-405D-88C1-A7340C57E63E', userId: 'user id', - url: 'http://www.domain.com', + url: 'https://www.domain.com', seats: {'dsp': ['seat 1']} }, adUnitCode: 'panorama_d_1', @@ -97,7 +97,7 @@ describe('Livewrapped adapter tests', function () { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', publisherId: '26947112-2289-405D-88C1-A7340C57E63E', userId: 'user id', - url: 'http://www.domain.com', + url: 'https://www.domain.com', seats: {'dsp': ['seat 1']}, version: '1.1', cookieSupport: true, @@ -132,7 +132,7 @@ describe('Livewrapped adapter tests', function () { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', publisherId: '26947112-2289-405D-88C1-A7340C57E63E', userId: 'user id', - url: 'http://www.domain.com', + url: 'https://www.domain.com', seats: {'dsp': ['seat 1']}, version: '1.1', cookieSupport: true, @@ -168,7 +168,7 @@ describe('Livewrapped adapter tests', function () { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', publisherId: '26947112-2289-405D-88C1-A7340C57E63E', userId: 'user id', - url: 'http://www.domain.com', + url: 'https://www.domain.com', seats: {'dsp': ['seat 1']}, version: '1.1', cookieSupport: true, @@ -198,7 +198,7 @@ describe('Livewrapped adapter tests', function () { let expectedQuery = { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', publisherId: '26947112-2289-405D-88C1-A7340C57E63E', - url: 'http://www.domain.com', + url: 'https://www.domain.com', version: '1.1', cookieSupport: true, adRequests: [{ @@ -226,7 +226,7 @@ describe('Livewrapped adapter tests', function () { let expectedQuery = { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', - url: 'http://www.domain.com', + url: 'https://www.domain.com', version: '1.1', cookieSupport: true, adRequests: [{ @@ -256,7 +256,7 @@ describe('Livewrapped adapter tests', function () { let expectedQuery = { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', publisherId: '26947112-2289-405D-88C1-A7340C57E63E', - url: 'http://www.domain.com', + url: 'https://www.domain.com', version: '1.1', deviceId: 'deviceid', ifa: 'ifa', @@ -287,7 +287,7 @@ describe('Livewrapped adapter tests', function () { let expectedQuery = { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', publisherId: '26947112-2289-405D-88C1-A7340C57E63E', - url: 'http://www.domain.com', + url: 'https://www.domain.com', version: '1.1', tid: 'tracking id', test: true, @@ -317,7 +317,7 @@ describe('Livewrapped adapter tests', function () { let expectedQuery = { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', publisherId: '26947112-2289-405D-88C1-A7340C57E63E', - url: 'http://www.domain.com', + url: 'https://www.domain.com', version: '1.1', cookieSupport: true, adRequests: [{ @@ -346,7 +346,7 @@ describe('Livewrapped adapter tests', function () { let expectedQuery = { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', publisherId: '26947112-2289-405D-88C1-A7340C57E63E', - url: 'http://www.domain.com', + url: 'https://www.domain.com', version: '1.1', cookieSupport: true, rcv: true, @@ -378,7 +378,7 @@ describe('Livewrapped adapter tests', function () { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', publisherId: '26947112-2289-405D-88C1-A7340C57E63E', userId: 'user id', - url: 'http://www.domain.com', + url: 'https://www.domain.com', seats: {'dsp': ['seat 1']}, version: '1.1', cookieSupport: true, @@ -412,7 +412,7 @@ describe('Livewrapped adapter tests', function () { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', publisherId: '26947112-2289-405D-88C1-A7340C57E63E', userId: 'user id', - url: 'http://www.domain.com', + url: 'https://www.domain.com', seats: {'dsp': ['seat 1']}, version: '1.1', cookieSupport: true, @@ -441,7 +441,7 @@ describe('Livewrapped adapter tests', function () { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', publisherId: '26947112-2289-405D-88C1-A7340C57E63E', userId: 'user id', - url: 'http://www.domain.com', + url: 'https://www.domain.com', seats: {'dsp': ['seat 1']}, version: '1.1', cookieSupport: false, @@ -469,7 +469,7 @@ describe('Livewrapped adapter tests', function () { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', publisherId: '26947112-2289-405D-88C1-A7340C57E63E', userId: 'user id', - url: 'http://www.domain.com', + url: 'https://www.domain.com', seats: {'dsp': ['seat 1']}, version: '1.1', cookieSupport: false, @@ -487,24 +487,24 @@ describe('Livewrapped adapter tests', function () { it('should use params.url, then config pageUrl, then bidderRequest.refererInfo.referer', function() { let testRequest = clone(bidderRequest); - testRequest.refererInfo = {referer: 'http://www.topurl.com'}; + testRequest.refererInfo = {referer: 'https://www.topurl.com'}; let result = spec.buildRequests(testRequest.bids, testRequest); let data = JSON.parse(result.data); - expect(data.url).to.equal('http://www.domain.com'); + expect(data.url).to.equal('https://www.domain.com'); delete testRequest.bids[0].params.url; result = spec.buildRequests(testRequest.bids, testRequest); data = JSON.parse(result.data); - expect(data.url).to.equal('http://www.topurl.com'); + expect(data.url).to.equal('https://www.topurl.com'); let origGetConfig = config.getConfig; sandbox.stub(config, 'getConfig').callsFake(function (key) { if (key === 'pageUrl') { - return 'http://www.configurl.com'; + return 'https://www.configurl.com'; } return origGetConfig.apply(config, arguments); }); @@ -512,7 +512,7 @@ describe('Livewrapped adapter tests', function () { result = spec.buildRequests(testRequest.bids, testRequest); data = JSON.parse(result.data); - expect(data.url).to.equal('http://www.configurl.com'); + expect(data.url).to.equal('https://www.configurl.com'); }); it('should make use of pubcid if available', function() { @@ -530,7 +530,7 @@ describe('Livewrapped adapter tests', function () { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', publisherId: '26947112-2289-405D-88C1-A7340C57E63E', userId: 'pubcid 123', - url: 'http://www.domain.com', + url: 'https://www.domain.com', seats: {'dsp': ['seat 1']}, version: '1.1', cookieSupport: true, @@ -560,7 +560,7 @@ describe('Livewrapped adapter tests', function () { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', publisherId: '26947112-2289-405D-88C1-A7340C57E63E', userId: 'user id', - url: 'http://www.domain.com', + url: 'https://www.domain.com', seats: {'dsp': ['seat 1']}, version: '1.1', cookieSupport: true, @@ -766,8 +766,8 @@ describe('Livewrapped adapter tests', function () { serverResponses = [{ body: { pixels: [ - {type: 'Redirect', url: 'http://pixelsync'}, - {type: 'Iframe', url: 'http://iframesync'} + {type: 'Redirect', url: 'https://pixelsync'}, + {type: 'Iframe', url: 'https://iframesync'} ] } }]; @@ -801,7 +801,7 @@ describe('Livewrapped adapter tests', function () { iframeEnabled: true }, serverResponses); - let expectedResponse = [{type: 'image', url: 'http://pixelsync'}, {type: 'iframe', url: 'http://iframesync'}]; + let expectedResponse = [{type: 'image', url: 'https://pixelsync'}, {type: 'iframe', url: 'https://iframesync'}]; expect(syncs).to.deep.equal(expectedResponse) }); @@ -812,7 +812,7 @@ describe('Livewrapped adapter tests', function () { iframeEnabled: false }, serverResponses); - let expectedResponse = [{type: 'image', url: 'http://pixelsync'}]; + let expectedResponse = [{type: 'image', url: 'https://pixelsync'}]; expect(syncs).to.deep.equal(expectedResponse) }); @@ -823,7 +823,7 @@ describe('Livewrapped adapter tests', function () { iframeEnabled: true }, serverResponses); - let expectedResponse = [{type: 'iframe', url: 'http://iframesync'}]; + let expectedResponse = [{type: 'iframe', url: 'https://iframesync'}]; expect(syncs).to.deep.equal(expectedResponse) }); From aa1a01dec9f0a388c197f3620a6afccded245f90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Sun, 22 Dec 2019 11:27:09 +0100 Subject: [PATCH 18/35] Native support --- modules/livewrappedBidAdapter.js | 23 ++- .../modules/livewrappedBidAdapter_spec.js | 132 ++++++++++++++++-- 2 files changed, 137 insertions(+), 18 deletions(-) diff --git a/modules/livewrappedBidAdapter.js b/modules/livewrappedBidAdapter.js index fa2d6809d93..776fc9b9f55 100644 --- a/modules/livewrappedBidAdapter.js +++ b/modules/livewrappedBidAdapter.js @@ -2,13 +2,15 @@ import * as utils from '../src/utils'; import { registerBidder } from '../src/adapters/bidderFactory'; import { config } from '../src/config'; import find from 'core-js/library/fn/array/find'; +import { BANNER, NATIVE } from '../src/mediaTypes'; const BIDDER_CODE = 'livewrapped'; export const URL = 'https://lwadm.com/ad'; -const VERSION = '1.1'; +const VERSION = '1.2'; export const spec = { code: BIDDER_CODE, + supportedMediaTypes: [BANNER, NATIVE], /** * Determines whether or not the given bid request is valid. @@ -92,7 +94,7 @@ export const spec = { const bidResponses = []; serverResponse.body.ads.forEach(function(ad) { - let bidResponse = { + var bidResponse = { requestId: ad.bidId, bidderCode: BIDDER_CODE, cpm: ad.cpmBid, @@ -106,6 +108,11 @@ export const spec = { meta: ad.meta }; + if (ad.native) { + bidResponse.native = ad.native; + bidResponse.mediaType = NATIVE + } + bidResponses.push(bidResponse); }); @@ -177,7 +184,7 @@ function hasPubcid(bid) { } function bidToAdRequest(bid) { - return { + var adRequest = { adUnitId: bid.params.adUnitId, callerAdUnitId: bid.params.adUnitName || bid.adUnitCode || bid.placementCode, bidId: bid.bidId, @@ -185,6 +192,16 @@ function bidToAdRequest(bid) { formats: bid.sizes.map(sizeToFormat), options: bid.params.options }; + + if (bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.native) { + adRequest.banner = true; + } + + if (bid.mediaTypes && bid.mediaTypes.native) { + adRequest.native = bid.mediaTypes.native; + } + + return adRequest; } function sizeToFormat(size) { diff --git a/test/spec/modules/livewrappedBidAdapter_spec.js b/test/spec/modules/livewrappedBidAdapter_spec.js index ccab9765c4b..8037c0f0c8b 100644 --- a/test/spec/modules/livewrappedBidAdapter_spec.js +++ b/test/spec/modules/livewrappedBidAdapter_spec.js @@ -2,6 +2,7 @@ import {expect} from 'chai'; import {spec} from 'modules/livewrappedBidAdapter'; import {config} from 'src/config'; import * as utils from 'src/utils'; +import { BANNER, NATIVE } from 'src/mediaTypes'; describe('Livewrapped adapter tests', function () { let sandbox, @@ -99,7 +100,7 @@ describe('Livewrapped adapter tests', function () { userId: 'user id', url: 'https://www.domain.com', seats: {'dsp': ['seat 1']}, - version: '1.1', + version: '1.2', cookieSupport: true, adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', @@ -134,7 +135,7 @@ describe('Livewrapped adapter tests', function () { userId: 'user id', url: 'https://www.domain.com', seats: {'dsp': ['seat 1']}, - version: '1.1', + version: '1.2', cookieSupport: true, adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', @@ -170,7 +171,7 @@ describe('Livewrapped adapter tests', function () { userId: 'user id', url: 'https://www.domain.com', seats: {'dsp': ['seat 1']}, - version: '1.1', + version: '1.2', cookieSupport: true, adRequests: [{ callerAdUnitId: 'caller id 1', @@ -199,7 +200,7 @@ describe('Livewrapped adapter tests', function () { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', publisherId: '26947112-2289-405D-88C1-A7340C57E63E', url: 'https://www.domain.com', - version: '1.1', + version: '1.2', cookieSupport: true, adRequests: [{ callerAdUnitId: 'panorama_d_1', @@ -227,7 +228,7 @@ describe('Livewrapped adapter tests', function () { let expectedQuery = { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', url: 'https://www.domain.com', - version: '1.1', + version: '1.2', cookieSupport: true, adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', @@ -257,7 +258,7 @@ describe('Livewrapped adapter tests', function () { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', publisherId: '26947112-2289-405D-88C1-A7340C57E63E', url: 'https://www.domain.com', - version: '1.1', + version: '1.2', deviceId: 'deviceid', ifa: 'ifa', cookieSupport: true, @@ -288,7 +289,7 @@ describe('Livewrapped adapter tests', function () { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', publisherId: '26947112-2289-405D-88C1-A7340C57E63E', url: 'https://www.domain.com', - version: '1.1', + version: '1.2', tid: 'tracking id', test: true, cookieSupport: true, @@ -318,7 +319,7 @@ describe('Livewrapped adapter tests', function () { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', publisherId: '26947112-2289-405D-88C1-A7340C57E63E', url: 'https://www.domain.com', - version: '1.1', + version: '1.2', cookieSupport: true, adRequests: [{ callerAdUnitId: 'panorama_d_1', @@ -347,7 +348,7 @@ describe('Livewrapped adapter tests', function () { auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', publisherId: '26947112-2289-405D-88C1-A7340C57E63E', url: 'https://www.domain.com', - version: '1.1', + version: '1.2', cookieSupport: true, rcv: true, adRequests: [{ @@ -361,6 +362,65 @@ describe('Livewrapped adapter tests', function () { expect(data).to.deep.equal(expectedQuery); }); + it('should make a well-formed single request object with native only parameters', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + delete testbidRequest.bids[0].params.seats; + delete testbidRequest.bids[0].params.adUnitId; + testbidRequest.bids[0].mediaTypes = {'native': {'nativedata': 'content parsed serverside only'}}; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + url: 'https://www.domain.com', + version: '1.2', + cookieSupport: true, + adRequests: [{ + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}], + native: {'nativedata': 'content parsed serverside only'} + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + + it('should make a well-formed single request object with native and banner parameters', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + delete testbidRequest.bids[0].params.seats; + delete testbidRequest.bids[0].params.adUnitId; + testbidRequest.bids[0].mediaTypes = {'native': {'nativedata': 'content parsed serverside only'},'banner': {'sizes': [[980, 240], [980, 120]]}}; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + url: 'https://www.domain.com', + version: '1.2', + cookieSupport: true, + adRequests: [{ + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 980, height: 240}, {width: 980, height: 120}], + native: {'nativedata': 'content parsed serverside only'}, + banner: true + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + it('should pass gdpr true parameters', function() { sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); @@ -380,7 +440,7 @@ describe('Livewrapped adapter tests', function () { userId: 'user id', url: 'https://www.domain.com', seats: {'dsp': ['seat 1']}, - version: '1.1', + version: '1.2', cookieSupport: true, gdprApplies: true, gdprConsent: 'test', @@ -414,7 +474,7 @@ describe('Livewrapped adapter tests', function () { userId: 'user id', url: 'https://www.domain.com', seats: {'dsp': ['seat 1']}, - version: '1.1', + version: '1.2', cookieSupport: true, gdprApplies: false, adRequests: [{ @@ -443,7 +503,7 @@ describe('Livewrapped adapter tests', function () { userId: 'user id', url: 'https://www.domain.com', seats: {'dsp': ['seat 1']}, - version: '1.1', + version: '1.2', cookieSupport: false, adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', @@ -471,7 +531,7 @@ describe('Livewrapped adapter tests', function () { userId: 'user id', url: 'https://www.domain.com', seats: {'dsp': ['seat 1']}, - version: '1.1', + version: '1.2', cookieSupport: false, adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', @@ -532,7 +592,7 @@ describe('Livewrapped adapter tests', function () { userId: 'pubcid 123', url: 'https://www.domain.com', seats: {'dsp': ['seat 1']}, - version: '1.1', + version: '1.2', cookieSupport: true, adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', @@ -562,7 +622,7 @@ describe('Livewrapped adapter tests', function () { userId: 'user id', url: 'https://www.domain.com', seats: {'dsp': ['seat 1']}, - version: '1.1', + version: '1.2', cookieSupport: true, adRequests: [{ adUnitId: '9E153CED-61BC-479E-98DF-24DC0D01BA37', @@ -655,6 +715,48 @@ describe('Livewrapped adapter tests', function () { expect(bids).to.deep.equal(expectedResponse); }) + it('should handle single native success response', function() { + let lwResponse = { + ads: [ + { + id: '28e5ddf4-3c01-11e8-86a7-0a44794250d4', + callerId: 'site_outsider_0', + tag: '{\'native\':\'native\'}', + width: 300, + height: 250, + cpmBid: 2.565917, + bidId: '32e50fad901ae89', + auctionId: '13e674db-d4d8-4e19-9d28-ff38177db8bf', + creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', + native: {'native': 'native'}, + ttl: 120, + meta: undefined + } + ], + currency: 'USD' + }; + + let expectedResponse = [{ + requestId: '32e50fad901ae89', + bidderCode: 'livewrapped', + cpm: 2.565917, + width: 300, + height: 250, + ad: '{\'native\':\'native\'}', + ttl: 120, + creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077', + netRevenue: true, + currency: 'USD', + meta: undefined, + native: {'native': 'native'}, + mediaType: NATIVE + }]; + + let bids = spec.interpretResponse({body: lwResponse}); + + expect(bids).to.deep.equal(expectedResponse); + }) + it('should handle multiple success response', function() { let lwResponse = { ads: [ From 80b1079a06943e7e2b407dcf03fa35b9b5d86f4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Mon, 20 Jan 2020 10:51:47 +0100 Subject: [PATCH 19/35] Read sizes from mediatype.banner --- modules/livewrappedBidAdapter.js | 11 ++++++- .../modules/livewrappedBidAdapter_spec.js | 30 ++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/modules/livewrappedBidAdapter.js b/modules/livewrappedBidAdapter.js index 776fc9b9f55..c5c71a4131e 100644 --- a/modules/livewrappedBidAdapter.js +++ b/modules/livewrappedBidAdapter.js @@ -189,7 +189,7 @@ function bidToAdRequest(bid) { callerAdUnitId: bid.params.adUnitName || bid.adUnitCode || bid.placementCode, bidId: bid.bidId, transactionId: bid.transactionId, - formats: bid.sizes.map(sizeToFormat), + formats: getSizes(bid).map(sizeToFormat), options: bid.params.options }; @@ -204,6 +204,15 @@ function bidToAdRequest(bid) { return adRequest; } +function getSizes(bid) { + if (typeof utils.deepAccess(bid, 'mediaTypes.banner.sizes') !== 'undefined') { + return bid.mediaTypes.banner.sizes; + } else if (Array.isArray(bid.sizes) && bid.sizes.length > 0) { + return bid.sizes; + } + return []; +} + function sizeToFormat(size) { return { width: size[0], diff --git a/test/spec/modules/livewrappedBidAdapter_spec.js b/test/spec/modules/livewrappedBidAdapter_spec.js index 8037c0f0c8b..68ae22efa0d 100644 --- a/test/spec/modules/livewrappedBidAdapter_spec.js +++ b/test/spec/modules/livewrappedBidAdapter_spec.js @@ -398,7 +398,7 @@ describe('Livewrapped adapter tests', function () { delete testbidRequest.bids[0].params.userId; delete testbidRequest.bids[0].params.seats; delete testbidRequest.bids[0].params.adUnitId; - testbidRequest.bids[0].mediaTypes = {'native': {'nativedata': 'content parsed serverside only'},'banner': {'sizes': [[980, 240], [980, 120]]}}; + testbidRequest.bids[0].mediaTypes = {'native': {'nativedata': 'content parsed serverside only'}, 'banner': {'sizes': [[980, 240], [980, 120]]}}; let result = spec.buildRequests(testbidRequest.bids, testbidRequest); let data = JSON.parse(result.data); @@ -421,6 +421,34 @@ describe('Livewrapped adapter tests', function () { expect(data).to.deep.equal(expectedQuery); }); + it('should use mediaTypes.banner.sizes before legacy sizes', function() { + sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); + sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); + let testbidRequest = clone(bidderRequest); + delete testbidRequest.bids[0].params.userId; + delete testbidRequest.bids[0].params.seats; + delete testbidRequest.bids[0].params.adUnitId; + testbidRequest.bids[0].mediaTypes = {'banner': {'sizes': [[728, 90]]}}; + let result = spec.buildRequests(testbidRequest.bids, testbidRequest); + let data = JSON.parse(result.data); + + let expectedQuery = { + auctionId: 'F7557995-65F5-4682-8782-7D5D34D82A8C', + publisherId: '26947112-2289-405D-88C1-A7340C57E63E', + url: 'https://www.domain.com', + version: '1.2', + cookieSupport: true, + adRequests: [{ + callerAdUnitId: 'panorama_d_1', + bidId: '2ffb201a808da7', + transactionId: '3D1C8CF7-D288-4D7F-8ADD-97C553056C3D', + formats: [{width: 728, height: 90}] + }] + }; + + expect(data).to.deep.equal(expectedQuery); + }); + it('should pass gdpr true parameters', function() { sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false); sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true); From 4c2db4250393ec7c20905bf8bd8f47a1ca2367dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn?= Date: Mon, 20 Jan 2020 11:14:26 +0100 Subject: [PATCH 20/35] Revert accidental commit --- .../gpt/prebidServer_native_example.html | 30 +++++-------------- karma.conf.maker.js | 8 ++--- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/integrationExamples/gpt/prebidServer_native_example.html b/integrationExamples/gpt/prebidServer_native_example.html index fadf6e3b6e1..16c7d38a427 100644 --- a/integrationExamples/gpt/prebidServer_native_example.html +++ b/integrationExamples/gpt/prebidServer_native_example.html @@ -59,21 +59,15 @@ } } }, - bids: [/*{ + bids: [{ bidder: 'appnexus', params: { placementId: 13232354, // placementId: 14141943, allowSmallerSizes: true } - },*/ { - bidder: 'livewrapped', - params: { - adUnitId:"08d7773c-a5a4-e299-db72-e68c0c953834", - test: 1, - url: "https://vk.se" - } - }] + + }] }, { code: '/19968336/prebid_native_example_2', // sizes: [[1, 1]], @@ -99,20 +93,13 @@ }, } }, - bids: [/*{ + bids: [{ bidder: 'appnexus', params: { placementId: 13232354, allowSmallerSizes: true } - },*/ { - bidder: 'livewrapped', - params: { - adUnitId:"08d7773c-a5a4-e299-db72-e68c0c953834", - test: 1, - url: "https://vk.se" - } - }] + }] }]; pbjs.addAdUnits(adUnits); @@ -130,8 +117,7 @@ bidders: ['appnexus'], timeout: 1000, //default value is 1000 adapter: 'prebidServer', //if we have any other s2s adapter, default value is s2s -// endpoint: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' - endpoint: 'http://localhost:8000/openrtb2/auction' + endpoint: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' } }); pbjs.requestBids({ @@ -147,8 +133,8 @@