From 3c2be258426976ec920f38dedee5e2bc5862c881 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 15 Jul 2022 16:40:34 +0200 Subject: [PATCH 01/18] Remove use of local storage As requested, we remove the use of local storage. https://github.com/prebid/Prebid.js/issues/8689 --- modules/impactifyBidAdapter.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/impactifyBidAdapter.js b/modules/impactifyBidAdapter.js index a4010772db0..00ecc6065e8 100644 --- a/modules/impactifyBidAdapter.js +++ b/modules/impactifyBidAdapter.js @@ -37,9 +37,13 @@ const createOpenRtbRequest = (validBidRequests, bidderRequest) => { source: {tid: bidderRequest.auctionId} }; + // Get the url parameters + const queryString = window.location.search; + const urlParams = new URLSearchParams(queryString); + const checkPrebid = urlParams.get('_checkPrebid') // Force impactify debugging parameter - if (window.localStorage.getItem('_im_db_bidder') != null) { - request.test = Number(window.localStorage.getItem('_im_db_bidder')); + if (checkPrebid != null) { + request.test = Number(checkPrebid); } // Set Schain in request From 353f399f60f3ac8373cbeb8c481dfc93651d289f Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 15 Jul 2022 16:42:25 +0200 Subject: [PATCH 02/18] Update impactifyBidAdapter.js --- modules/impactifyBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/impactifyBidAdapter.js b/modules/impactifyBidAdapter.js index 00ecc6065e8..bb3ad63085c 100644 --- a/modules/impactifyBidAdapter.js +++ b/modules/impactifyBidAdapter.js @@ -40,7 +40,7 @@ const createOpenRtbRequest = (validBidRequests, bidderRequest) => { // Get the url parameters const queryString = window.location.search; const urlParams = new URLSearchParams(queryString); - const checkPrebid = urlParams.get('_checkPrebid') + const checkPrebid = urlParams.get('_checkPrebid'); // Force impactify debugging parameter if (checkPrebid != null) { request.test = Number(checkPrebid); From 39638eb4c72f517c67e66183f421061ff514fa56 Mon Sep 17 00:00:00 2001 From: Thomas De Stefano Date: Fri, 14 Oct 2022 15:45:48 +0200 Subject: [PATCH 03/18] Add differents mediatypes to Impactify bidder --- modules/impactifyBidAdapter.js | 141 +++++++++++++++++++++++++-------- modules/impactifyBidAdapter.md | 28 ++++++- 2 files changed, 131 insertions(+), 38 deletions(-) diff --git a/modules/impactifyBidAdapter.js b/modules/impactifyBidAdapter.js index 0717cf43741..3ff3ea793c2 100644 --- a/modules/impactifyBidAdapter.js +++ b/modules/impactifyBidAdapter.js @@ -1,3 +1,5 @@ +'use strict'; + import { deepAccess, deepSetValue, generateUUID } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; @@ -9,25 +11,79 @@ const BIDDER_ALIAS = ['imp']; const DEFAULT_CURRENCY = 'USD'; const DEFAULT_VIDEO_WIDTH = 640; const DEFAULT_VIDEO_HEIGHT = 360; -const ORIGIN = 'https://sonic.impactify.media'; +const ORIGIN = 'http://prebid.local:8000'; const LOGGER_URI = 'https://logger.impactify.media'; const AUCTIONURI = '/bidder'; const COOKIESYNCURI = '/static/cookie_sync.html'; const GVLID = 606; const GETCONFIG = config.getConfig; -const getDeviceType = () => { - // OpenRTB Device type - if ((/ipad|android 3.0|xoom|sch-i800|playbook|tablet|kindle/i.test(navigator.userAgent.toLowerCase()))) { - return 5; - } - if ((/iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile/i.test(navigator.userAgent.toLowerCase()))) { - return 4; - } - return 2; -}; +/** + * Helpers object + * @type {{getExtParamsFromBid(*): {impactify: {appId}}, createOrtbImpVideoObj(*): {context: string, playerSize: [number,number], id: string, mimes: [string]}, getDeviceType(): (number), createOrtbImpBannerObj(*, *): {format: [], id: string}}} + */ +const helpers = { + getExtParamsFromBid(bid) { + let ext = { + impactify: { + appId: bid.params.appId + }, + }; -const createOpenRtbRequest = (validBidRequests, bidderRequest) => { + if (typeof bid.params.format == 'string') { + ext.impactify.format = bid.params.format; + } + + if (typeof bid.params.style == 'string') { + ext.impactify.style = bid.params.style; + } + + if (typeof bid.params.container == 'string') { + ext.impactify.container = bid.params.container; + } + + if (typeof bid.params.size == 'string') { + ext.impactify.size = bid.params.size; + } + + return ext; + }, + getDeviceType() { + // OpenRTB Device type + if ((/ipad|android 3.0|xoom|sch-i800|playbook|tablet|kindle/i.test(navigator.userAgent.toLowerCase()))) { + return 5; + } + if ((/iphone|ipod|android|blackberry|opera|mini|windows\sce|palm|smartphone|iemobile/i.test(navigator.userAgent.toLowerCase()))) { + return 4; + } + return 2; + }, + createOrtbImpBannerObj(bid, size) { + let format = []; + format.push(size.split('x')); + + return { + id: 'banner-' + bid.bidId, + format + } + }, + createOrtbImpVideoObj(bid) { + return { + id: 'video-' + bid.bidId, + playerSize: [DEFAULT_VIDEO_WIDTH, DEFAULT_VIDEO_HEIGHT], + context: 'outstream', + mimes: ['video/mp4'], + } + } +} + +/** + * Create an OpenRTB formated object from prebid payload + * @param validBidRequests + * @param bidderRequest + * @returns {{cur: string[], validBidRequests, id, source: {tid}, imp: *[]}} + */ +function createOpenRtbRequest(validBidRequests, bidderRequest) { // Create request and set imp bids inside let request = { id: bidderRequest.auctionId, @@ -41,16 +97,17 @@ const createOpenRtbRequest = (validBidRequests, bidderRequest) => { const queryString = window.location.search; const urlParams = new URLSearchParams(queryString); const checkPrebid = urlParams.get('_checkPrebid'); - // Force impactify debugging parameter + + // Force impactify debugging parameter if present if (checkPrebid != null) { request.test = Number(checkPrebid); } - // Set Schain in request + // Set SChain in request let schain = deepAccess(validBidRequests, '0.schain'); if (schain) request.source.ext = { schain: schain }; - // Set eids + // Set Eids let bidUserId = deepAccess(validBidRequests, '0.userId'); let eids = createEidsArray(bidUserId); if (eids.length) { @@ -63,7 +120,7 @@ const createOpenRtbRequest = (validBidRequests, bidderRequest) => { request.device = { w: window.innerWidth, h: window.innerHeight, - devicetype: getDeviceType(), + devicetype: helpers.getDeviceType(), ua: navigator.userAgent, js: 1, dnt: (navigator.doNotTrack == 'yes' || navigator.doNotTrack == '1' || navigator.msDoNotTrack == '1') ? 1 : 0, @@ -95,31 +152,39 @@ const createOpenRtbRequest = (validBidRequests, bidderRequest) => { // Create imps with bids validBidRequests.forEach((bid) => { + let bannerObj = deepAccess(bid.mediaTypes, `banner`); + let videoObj = deepAccess(bid.mediaTypes, `video`); + let imp = { id: bid.bidId, bidfloor: bid.params.bidfloor ? bid.params.bidfloor : 0, - ext: { - impactify: { - appId: bid.params.appId, - format: bid.params.format, - style: bid.params.style - }, - }, - video: { - playerSize: [DEFAULT_VIDEO_WIDTH, DEFAULT_VIDEO_HEIGHT], - context: 'outstream', - mimes: ['video/mp4'], - }, + ext: helpers.getExtParamsFromBid(bid) }; - if (bid.params.container) { - imp.ext.impactify.container = bid.params.container; + + if (videoObj) { + imp.video = { + ...helpers.createOrtbImpVideoObj(bid) + } } + if (bannerObj && typeof imp.ext.size == 'string') { + imp.banner = { + ...helpers.createOrtbImpBannerObj(bid, imp.ext.size) + } + } + + // eslint-disable-next-line no-console + console.log(imp); + request.imp.push(imp); }); return request; -}; +} +/** + * Export BidderSpec type object and register it to Prebid + * @type {{supportedMediaTypes: string[], interpretResponse: ((function(ServerResponse, *): Bid[])|*), code: string, aliases: string[], getUserSyncs: ((function(SyncOptions, ServerResponse[], *, *): UserSync[])|*), buildRequests: (function(*, *): {method: string, data: string, url}), onTimeout: (function(*): boolean), gvlid: number, isBidRequestValid: ((function(BidRequest): (boolean))|*), onBidWon: (function(*): boolean)}} + */ export const spec = { code: BIDDER_CODE, gvlid: GVLID, @@ -133,13 +198,21 @@ export const spec = { * @return boolean True if this is a valid bid, and false otherwise. */ isBidRequestValid: function (bid) { - if (!bid.params.appId || typeof bid.params.appId != 'string' || !bid.params.format || typeof bid.params.format != 'string' || !bid.params.style || typeof bid.params.style != 'string') { + let isBanner = deepAccess(bid.mediaTypes, `banner`); + + if (typeof bid.params.appId != 'string' || !bid.params.appId) { + return false; + } + if (typeof bid.params.format != 'string' || typeof bid.params.style != 'string' || !bid.params.format || !bid.params.style) { + return false; + } + if (typeof bid.params.format != 'string' || bid.params.format !== 'screen' || bid.params.format !== 'display') { return false; } - if (bid.params.format != 'screen' && bid.params.format != 'display') { + if (typeof bid.params.style != 'string' || bid.params.style !== 'inline' || bid.params.style !== 'impact' || bid.params.style !== 'static') { return false; } - if (bid.params.style != 'inline' && bid.params.style != 'impact' && bid.params.style != 'static') { + if (isBanner && (typeof bid.params.size != 'string' || !bid.params.size.includes('x') || bid.params.size.split('x').length != 2)) { return false; } diff --git a/modules/impactifyBidAdapter.md b/modules/impactifyBidAdapter.md index 3de9a8cfb84..807a3813baa 100644 --- a/modules/impactifyBidAdapter.md +++ b/modules/impactifyBidAdapter.md @@ -11,13 +11,13 @@ Maintainer: thomas.destefano@impactify.io Module that connects to the Impactify solution. The impactify bidder need 3 parameters: - appId : This is your unique publisher identifier - - format : This is the ad format needed, can be : screen or display - - style : This is the ad style needed, can be : inline, impact or static + - format : This is the ad format needed, can be : screen or display (Only for video media type) + - style : This is the ad style needed, can be : inline, impact or static (Only for video media type) # Test Parameters ``` - var adUnits = [{ - code: 'your-slot-div-id', // This is your slot div id + var adUnitsVideo = [{ + code: 'your-slot-div-id-video', // This is your slot div id mediaTypes: { video: { context: 'outstream' @@ -32,4 +32,24 @@ The impactify bidder need 3 parameters: } }] }]; + + var adUnitsBanner = [{ + code: 'your-slot-div-id-banner', // This is your slot div id + mediaTypes: { + banner: { + sizes: [ + [728, 90] + ] + } + }, + bids: [{ + bidder: 'impactify', + params: { + appId: 'example.com', + format: 'display', + size: '728x90', + style: 'static' + } + }] + }]; ``` From 321b1424287fab76991c15bfd2776a777fbe6081 Mon Sep 17 00:00:00 2001 From: Thomas De Stefano Date: Thu, 20 Oct 2022 12:18:21 +0200 Subject: [PATCH 04/18] Add differents mediatypes to Impactify bidder --- modules/impactifyBidAdapter.js | 8 +- test/spec/modules/impactifyBidAdapter_spec.js | 77 +++++++++++++++---- 2 files changed, 64 insertions(+), 21 deletions(-) diff --git a/modules/impactifyBidAdapter.js b/modules/impactifyBidAdapter.js index 3ff3ea793c2..8935cbb256c 100644 --- a/modules/impactifyBidAdapter.js +++ b/modules/impactifyBidAdapter.js @@ -166,9 +166,9 @@ function createOpenRtbRequest(validBidRequests, bidderRequest) { ...helpers.createOrtbImpVideoObj(bid) } } - if (bannerObj && typeof imp.ext.size == 'string') { + if (bannerObj && typeof imp.ext.impactify.size == 'string') { imp.banner = { - ...helpers.createOrtbImpBannerObj(bid, imp.ext.size) + ...helpers.createOrtbImpBannerObj(bid, imp.ext.impactify.size) } } @@ -206,10 +206,10 @@ export const spec = { if (typeof bid.params.format != 'string' || typeof bid.params.style != 'string' || !bid.params.format || !bid.params.style) { return false; } - if (typeof bid.params.format != 'string' || bid.params.format !== 'screen' || bid.params.format !== 'display') { + if (bid.params.format !== 'screen' && bid.params.format !== 'display') { return false; } - if (typeof bid.params.style != 'string' || bid.params.style !== 'inline' || bid.params.style !== 'impact' || bid.params.style !== 'static') { + if (bid.params.style !== 'inline' && bid.params.style !== 'impact' && bid.params.style !== 'static') { return false; } if (isBanner && (typeof bid.params.size != 'string' || !bid.params.size.includes('x') || bid.params.size.split('x').length != 2)) { diff --git a/test/spec/modules/impactifyBidAdapter_spec.js b/test/spec/modules/impactifyBidAdapter_spec.js index 8bb2d089ad8..0147530dfce 100644 --- a/test/spec/modules/impactifyBidAdapter_spec.js +++ b/test/spec/modules/impactifyBidAdapter_spec.js @@ -20,88 +20,131 @@ var gdprData = { describe('ImpactifyAdapter', function () { describe('isBidRequestValid', function () { - let validBid = { - bidder: 'impactify', - params: { - appId: '1', - format: 'screen', - style: 'inline' + let validBids = [ + { + bidder: 'impactify', + params: { + appId: 'example.com', + format: 'screen', + style: 'inline' + } + }, + { + bidder: 'impactify', + params: { + appId: 'example.com', + format: 'display', + size: '728x90', + style: 'static' + } } - }; + ]; it('should return true when required params found', function () { - expect(spec.isBidRequestValid(validBid)).to.equal(true); + expect(spec.isBidRequestValid(validBids[0])).to.equal(true); + expect(spec.isBidRequestValid(validBids[1])).to.equal(true); }); it('should return false when required params are not passed', function () { - let bid = Object.assign({}, validBid); + let bid = Object.assign({}, validBids[0]); delete bid.params; bid.params = {}; expect(spec.isBidRequestValid(bid)).to.equal(false); + + let bid2 = Object.assign({}, validBids[1]); + delete bid2.params; + bid2.params = {}; + expect(spec.isBidRequestValid(bid2)).to.equal(false); }); it('should return false when appId is missing', () => { - const bid = utils.deepClone(validBid); + const bid = utils.deepClone(validBids[0]); delete bid.params.appId; - expect(spec.isBidRequestValid(bid)).to.equal(false); + + const bid2 = utils.deepClone(validBids[1]); + delete bid2.params.appId; + expect(spec.isBidRequestValid(bid2)).to.equal(false); }); it('should return false when appId is not a string', () => { - const bid = utils.deepClone(validBid); + const bid = utils.deepClone(validBids[0]); + const bid2 = utils.deepClone(validBids[1]); bid.params.appId = 123; + bid2.params.appId = 123; expect(spec.isBidRequestValid(bid)).to.equal(false); + expect(spec.isBidRequestValid(bid2)).to.equal(false); bid.params.appId = false; + bid2.params.appId = false; expect(spec.isBidRequestValid(bid)).to.equal(false); + expect(spec.isBidRequestValid(bid2)).to.equal(false); bid.params.appId = void (0); + bid2.params.appId = void (0); expect(spec.isBidRequestValid(bid)).to.equal(false); + expect(spec.isBidRequestValid(bid2)).to.equal(false); bid.params.appId = {}; + bid2.params.appId = {}; expect(spec.isBidRequestValid(bid)).to.equal(false); + expect(spec.isBidRequestValid(bid2)).to.equal(false); }); it('should return false when format is missing', () => { - const bid = utils.deepClone(validBid); + const bid = utils.deepClone(validBids[0]); delete bid.params.format; expect(spec.isBidRequestValid(bid)).to.equal(false); }); it('should return false when format is not a string', () => { - const bid = utils.deepClone(validBid); + const bid = utils.deepClone(validBids[0]); + const bid2 = utils.deepClone(validBids[1]); bid.params.format = 123; + bid2.params.format = 123; + expect(spec.isBidRequestValid(bid)).to.equal(false); expect(spec.isBidRequestValid(bid)).to.equal(false); bid.params.format = false; + bid2.params.format = false; expect(spec.isBidRequestValid(bid)).to.equal(false); + expect(spec.isBidRequestValid(bid2)).to.equal(false); bid.params.format = void (0); + bid2.params.format = void (0); expect(spec.isBidRequestValid(bid)).to.equal(false); + expect(spec.isBidRequestValid(bid2)).to.equal(false); bid.params.format = {}; + bid2.params.format = {}; expect(spec.isBidRequestValid(bid)).to.equal(false); + expect(spec.isBidRequestValid(bid2)).to.equal(false); }); it('should return false when format is not equals to screen or display', () => { - const bid = utils.deepClone(validBid); + const bid = utils.deepClone(validBids[0]); if (bid.params.format != 'screen' && bid.params.format != 'display') { expect(spec.isBidRequestValid(bid)).to.equal(false); } + + const bid2 = utils.deepClone(validBids[1]); + if (bid2.params.format != 'screen' && bid2.params.format != 'display') { + expect(spec.isBidRequestValid(bid2)).to.equal(false); + } }); it('should return false when style is missing', () => { - const bid = utils.deepClone(validBid); + const bid = utils.deepClone(validBids[0]); delete bid.params.style; expect(spec.isBidRequestValid(bid)).to.equal(false); }); it('should return false when style is not a string', () => { - const bid = utils.deepClone(validBid); + const bid = utils.deepClone(validBids[0]); bid.params.style = 123; expect(spec.isBidRequestValid(bid)).to.equal(false); From eb91d30e223baf89135c921582a780c77dbd8aca Mon Sep 17 00:00:00 2001 From: Thomas De Stefano Date: Thu, 20 Oct 2022 17:47:29 +0200 Subject: [PATCH 05/18] Add differents mediatypes to Impactify bidder --- modules/impactifyBidAdapter.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/impactifyBidAdapter.js b/modules/impactifyBidAdapter.js index 8935cbb256c..8ff15e6ddb6 100644 --- a/modules/impactifyBidAdapter.js +++ b/modules/impactifyBidAdapter.js @@ -60,7 +60,11 @@ const helpers = { }, createOrtbImpBannerObj(bid, size) { let format = []; - format.push(size.split('x')); + let sizes = size.split('x'); + sizes[0] = parseInt(sizes[0]); + sizes[1] = parseInt(sizes[1]); + + format.push(sizes); return { id: 'banner-' + bid.bidId, @@ -172,9 +176,6 @@ function createOpenRtbRequest(validBidRequests, bidderRequest) { } } - // eslint-disable-next-line no-console - console.log(imp); - request.imp.push(imp); }); From 63049a76c90b3dfcdec01528f5ce97e4200b02e9 Mon Sep 17 00:00:00 2001 From: Thomas De Stefano Date: Fri, 21 Oct 2022 09:36:56 +0200 Subject: [PATCH 06/18] Add format parameter for banner --- modules/impactifyBidAdapter.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/impactifyBidAdapter.js b/modules/impactifyBidAdapter.js index 8ff15e6ddb6..ae95c972c96 100644 --- a/modules/impactifyBidAdapter.js +++ b/modules/impactifyBidAdapter.js @@ -59,16 +59,14 @@ const helpers = { return 2; }, createOrtbImpBannerObj(bid, size) { - let format = []; let sizes = size.split('x'); - sizes[0] = parseInt(sizes[0]); - sizes[1] = parseInt(sizes[1]); - - format.push(sizes); return { id: 'banner-' + bid.bidId, - format + format: [{ + w: parseInt(sizes[0]), + h: parseInt(sizes[1]) + }] } }, createOrtbImpVideoObj(bid) { From 749ae94d0cc8cd72c40f9f88f67041e118f5d292 Mon Sep 17 00:00:00 2001 From: Thomas De Stefano Date: Mon, 28 Nov 2022 09:49:00 +0100 Subject: [PATCH 07/18] add getFloor --- modules/impactifyBidAdapter.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/modules/impactifyBidAdapter.js b/modules/impactifyBidAdapter.js index ae95c972c96..3a942883c44 100644 --- a/modules/impactifyBidAdapter.js +++ b/modules/impactifyBidAdapter.js @@ -3,7 +3,7 @@ import { deepAccess, deepSetValue, generateUUID } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; -import {ajax} from '../src/ajax.js'; +import { ajax } from '../src/ajax.js'; import { createEidsArray } from './userId/eids.js'; const BIDDER_CODE = 'impactify'; @@ -76,6 +76,17 @@ const helpers = { context: 'outstream', mimes: ['video/mp4'], } + }, + getFloor(bid) { + const floorInfo = bid.getFloor({ + currency: DEFAULT_CURRENCY, + mediaType: '*', + size: '*' + }); + if (typeof floorInfo === 'object' && floorInfo.currency === DEFAULT_CURRENCY && !isNaN(parseFloat(floorInfo.floor))) { + return parseFloat(floorInfo.floor); + } + return null; } } @@ -168,12 +179,20 @@ function createOpenRtbRequest(validBidRequests, bidderRequest) { ...helpers.createOrtbImpVideoObj(bid) } } + if (bannerObj && typeof imp.ext.impactify.size == 'string') { imp.banner = { ...helpers.createOrtbImpBannerObj(bid, imp.ext.impactify.size) } } + if (typeof bid.getFloor === 'function') { + const floor = helpers.getFloor(bid); + if (floor) { + imp.bidfloor = floor; + } + } + request.imp.push(imp); }); From 1d787e5f83b0f52ea60d82bdaeb604fc1861fd79 Mon Sep 17 00:00:00 2001 From: Thomas De Stefano Date: Wed, 30 Nov 2022 14:34:07 +0100 Subject: [PATCH 08/18] add getFloor --- test/spec/modules/impactifyBidAdapter_spec.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/spec/modules/impactifyBidAdapter_spec.js b/test/spec/modules/impactifyBidAdapter_spec.js index 0147530dfce..6975328390a 100644 --- a/test/spec/modules/impactifyBidAdapter_spec.js +++ b/test/spec/modules/impactifyBidAdapter_spec.js @@ -158,6 +158,19 @@ describe('ImpactifyAdapter', function () { bid.params.style = {}; expect(spec.isBidRequestValid(bid)).to.equal(false); }); + + it('should pass bidfloor', function () { + videoBidRequests[0].getFloor = function() { + return { + currency: 'USD', + floor: 1.23, + } + } + + const res = spec.buildRequests(videoBidRequests, videoBidderRequest) + const resData = JSON.parse(res.data) + expect(resData.imp[0].bidfloor).to.equal(1.23) + }); }); describe('buildRequests', function () { let videoBidRequests = [ From 2a4f279e66590d2499c21d929a251cff89b1dc7b Mon Sep 17 00:00:00 2001 From: Thomas De Stefano Date: Thu, 1 Dec 2022 16:02:14 +0100 Subject: [PATCH 09/18] add getFloor --- modules/impactifyBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/impactifyBidAdapter.js b/modules/impactifyBidAdapter.js index 3a942883c44..79ff0cfb8eb 100644 --- a/modules/impactifyBidAdapter.js +++ b/modules/impactifyBidAdapter.js @@ -11,7 +11,7 @@ const BIDDER_ALIAS = ['imp']; const DEFAULT_CURRENCY = 'USD'; const DEFAULT_VIDEO_WIDTH = 640; const DEFAULT_VIDEO_HEIGHT = 360; -const ORIGIN = 'http://prebid.local:8000'; +const ORIGIN = 'https://sonic.impactify.media'; const LOGGER_URI = 'https://logger.impactify.media'; const AUCTIONURI = '/bidder'; const COOKIESYNCURI = '/static/cookie_sync.html'; From 4ce79d2bea50618d5b1e2a6467f1c6012949b958 Mon Sep 17 00:00:00 2001 From: Pang Ronnie Date: Fri, 29 Sep 2023 16:07:52 +0800 Subject: [PATCH 10/18] add parsing of local storage --- modules/impactifyBidAdapter.js | 17 ++++++++- test/spec/modules/impactifyBidAdapter_spec.js | 38 ++++++++++++++++++- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/modules/impactifyBidAdapter.js b/modules/impactifyBidAdapter.js index 79ff0cfb8eb..99919a09ae5 100644 --- a/modules/impactifyBidAdapter.js +++ b/modules/impactifyBidAdapter.js @@ -4,6 +4,7 @@ import { deepAccess, deepSetValue, generateUUID } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { ajax } from '../src/ajax.js'; +import {getStorageManager} from '../src/storageManager.js' import { createEidsArray } from './userId/eids.js'; const BIDDER_CODE = 'impactify'; @@ -17,7 +18,8 @@ const AUCTIONURI = '/bidder'; const COOKIESYNCURI = '/static/cookie_sync.html'; const GVLID = 606; const GETCONFIG = config.getConfig; - +export const storage = getStorageManager({bidderCode: BIDDER_CODE}); +const STORAGE_KEY = '_im_str' /** * Helpers object * @type {{getExtParamsFromBid(*): {impactify: {appId}}, createOrtbImpVideoObj(*): {context: string, playerSize: [number,number], id: string, mimes: [string]}, getDeviceType(): (number), createOrtbImpBannerObj(*, *): {format: [], id: string}}} @@ -87,7 +89,12 @@ const helpers = { return parseFloat(floorInfo.floor); } return null; + }, + + getLocalStorage() { + return storage.localStorageIsEnabled() ? storage.getDataFromLocalStorage(STORAGE_KEY) : ''; } + } /** @@ -208,6 +215,7 @@ export const spec = { gvlid: GVLID, supportedMediaTypes: ['video', 'banner'], aliases: BIDDER_ALIAS, + local_storage_key: STORAGE_KEY, /** * Determines whether or not the given bid request is valid. @@ -247,11 +255,18 @@ export const spec = { buildRequests: function (validBidRequests, bidderRequest) { // Create a clean openRTB request let request = createOpenRtbRequest(validBidRequests, bidderRequest); + const imStr = helpers.getLocalStorage(); + const options = { + customHeaders: { + 'x-impact': imStr, + } + } return { method: 'POST', url: ORIGIN + AUCTIONURI, data: JSON.stringify(request), + options }; }, diff --git a/test/spec/modules/impactifyBidAdapter_spec.js b/test/spec/modules/impactifyBidAdapter_spec.js index 6975328390a..4efd1ad2d2c 100644 --- a/test/spec/modules/impactifyBidAdapter_spec.js +++ b/test/spec/modules/impactifyBidAdapter_spec.js @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { spec } from 'modules/impactifyBidAdapter.js'; +import { spec, storage } from 'modules/impactifyBidAdapter.js'; import * as utils from 'src/utils.js'; const BIDDER_CODE = 'impactify'; @@ -173,6 +173,9 @@ describe('ImpactifyAdapter', function () { }); }); describe('buildRequests', function () { + let getLocalStorageStub; + let localStorageIsEnabledStub; + let videoBidRequests = [ { bidder: 'impactify', @@ -221,11 +224,42 @@ describe('ImpactifyAdapter', function () { referer: 'https://impactify.io' } }; - + afterEach(function() { + localStorageIsEnabledStub.restore(); + getLocalStorageStub.restore(); + }); it('sends video bid request to ENDPOINT via POST', function () { + localStorageIsEnabledStub = sinon.stub(storage, 'localStorageIsEnabled'); + localStorageIsEnabledStub.returns(true); + + getLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); + getLocalStorageStub.returns('testValue'); + const request = spec.buildRequests(videoBidRequests, videoBidderRequest); + expect(request.url).to.equal(ORIGIN + AUCTIONURI); expect(request.method).to.equal('POST'); + expect(request.options.customHeaders['x-impact']).to.equal('testValue'); + }); + + it('should set header value from localstorage correctly', function () { + localStorageIsEnabledStub = sinon.stub(storage, 'localStorageIsEnabled'); + localStorageIsEnabledStub.returns(true); + + getLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); + getLocalStorageStub.returns('testValue'); + const request = spec.buildRequests(videoBidRequests, videoBidderRequest); + + expect(request.options.customHeaders['x-impact']).to.equal('testValue'); + }); + + it('should set header value to empty if localstorage is not enabled', function () { + localStorageIsEnabledStub = sinon.stub(storage, 'localStorageIsEnabled'); + localStorageIsEnabledStub.returns(false); + + const request = spec.buildRequests(videoBidRequests, videoBidderRequest); + + expect(request.options.customHeaders['x-impact']).to.equal(''); }); }); describe('interpretResponse', function () { From ab9db7fdd14846fdbc16b35b5d1970ad5677e87b Mon Sep 17 00:00:00 2001 From: Pang Ronnie Date: Mon, 2 Oct 2023 16:32:06 +0800 Subject: [PATCH 11/18] delete unused var --- modules/impactifyBidAdapter.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/impactifyBidAdapter.js b/modules/impactifyBidAdapter.js index 99919a09ae5..b791ffd1714 100644 --- a/modules/impactifyBidAdapter.js +++ b/modules/impactifyBidAdapter.js @@ -215,7 +215,6 @@ export const spec = { gvlid: GVLID, supportedMediaTypes: ['video', 'banner'], aliases: BIDDER_ALIAS, - local_storage_key: STORAGE_KEY, /** * Determines whether or not the given bid request is valid. From 228e6f1698c305d846f3442029b0257ad9daa8fa Mon Sep 17 00:00:00 2001 From: Pang Ronnie Date: Mon, 2 Oct 2023 16:46:17 +0800 Subject: [PATCH 12/18] fix spacing with import --- modules/impactifyBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/impactifyBidAdapter.js b/modules/impactifyBidAdapter.js index b791ffd1714..2bafcae9c70 100644 --- a/modules/impactifyBidAdapter.js +++ b/modules/impactifyBidAdapter.js @@ -4,7 +4,7 @@ import { deepAccess, deepSetValue, generateUUID } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { ajax } from '../src/ajax.js'; -import {getStorageManager} from '../src/storageManager.js' +import { getStorageManager } from '../src/storageManager.js' import { createEidsArray } from './userId/eids.js'; const BIDDER_CODE = 'impactify'; From 498d4b455391e2841cee718d990d551c8a296dd5 Mon Sep 17 00:00:00 2001 From: Thomas De Stefano Date: Wed, 11 Oct 2023 15:58:46 +0200 Subject: [PATCH 13/18] Add local storage key management --- modules/impactifyBidAdapter.js | 48 +++++++++++-------- modules/impactifyBidAdapter.md | 14 ++++-- test/spec/modules/impactifyBidAdapter_spec.js | 10 ++++ 3 files changed, 49 insertions(+), 23 deletions(-) diff --git a/modules/impactifyBidAdapter.js b/modules/impactifyBidAdapter.js index 2bafcae9c70..851e151dfbd 100644 --- a/modules/impactifyBidAdapter.js +++ b/modules/impactifyBidAdapter.js @@ -4,8 +4,8 @@ import { deepAccess, deepSetValue, generateUUID } from '../src/utils.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { ajax } from '../src/ajax.js'; -import { getStorageManager } from '../src/storageManager.js' -import { createEidsArray } from './userId/eids.js'; +import { getStorageManager } from '../src/storageManager.js'; +import { createEidsArray } from 'modules/userId/eids.js'; const BIDDER_CODE = 'impactify'; const BIDDER_ALIAS = ['imp']; @@ -14,12 +14,13 @@ const DEFAULT_VIDEO_WIDTH = 640; const DEFAULT_VIDEO_HEIGHT = 360; const ORIGIN = 'https://sonic.impactify.media'; const LOGGER_URI = 'https://logger.impactify.media'; -const AUCTIONURI = '/bidder'; -const COOKIESYNCURI = '/static/cookie_sync.html'; -const GVLID = 606; -const GETCONFIG = config.getConfig; -export const storage = getStorageManager({bidderCode: BIDDER_CODE}); +const AUCTION_URI = '/bidder'; +const COOKIE_SYNC_URI = '/static/cookie_sync.html'; +const GVL_ID = 606; +const GET_CONFIG = config.getConfig; +const STORAGE = getStorageManager({gvlid: GVL_ID, bidderCode: BIDDER_CODE}); const STORAGE_KEY = '_im_str' + /** * Helpers object * @type {{getExtParamsFromBid(*): {impactify: {appId}}, createOrtbImpVideoObj(*): {context: string, playerSize: [number,number], id: string, mimes: [string]}, getDeviceType(): (number), createOrtbImpBannerObj(*, *): {format: [], id: string}}} @@ -50,6 +51,7 @@ const helpers = { return ext; }, + getDeviceType() { // OpenRTB Device type if ((/ipad|android 3.0|xoom|sch-i800|playbook|tablet|kindle/i.test(navigator.userAgent.toLowerCase()))) { @@ -60,6 +62,7 @@ const helpers = { } return 2; }, + createOrtbImpBannerObj(bid, size) { let sizes = size.split('x'); @@ -71,6 +74,7 @@ const helpers = { }] } }, + createOrtbImpVideoObj(bid) { return { id: 'video-' + bid.bidId, @@ -79,6 +83,7 @@ const helpers = { mimes: ['video/mp4'], } }, + getFloor(bid) { const floorInfo = bid.getFloor({ currency: DEFAULT_CURRENCY, @@ -91,8 +96,8 @@ const helpers = { return null; }, - getLocalStorage() { - return storage.localStorageIsEnabled() ? storage.getDataFromLocalStorage(STORAGE_KEY) : ''; + getImStrFromLocalStorage() { + return STORAGE.localStorageIsEnabled(false) ? STORAGE.getDataFromLocalStorage(STORAGE_KEY, false) : ''; } } @@ -161,7 +166,7 @@ function createOpenRtbRequest(validBidRequests, bidderRequest) { this.syncStore.uspConsent = bidderRequest.uspConsent; } - if (GETCONFIG('coppa') == true) deepSetValue(request, 'regs.coppa', 1); + if (GET_CONFIG('coppa') == true) deepSetValue(request, 'regs.coppa', 1); if (bidderRequest.uspConsent) { deepSetValue(request, 'regs.ext.us_privacy', bidderRequest.uspConsent); @@ -212,9 +217,10 @@ function createOpenRtbRequest(validBidRequests, bidderRequest) { */ export const spec = { code: BIDDER_CODE, - gvlid: GVLID, + gvlid: GVL_ID, supportedMediaTypes: ['video', 'banner'], aliases: BIDDER_ALIAS, + storageAllowed: true, /** * Determines whether or not the given bid request is valid. @@ -254,16 +260,18 @@ export const spec = { buildRequests: function (validBidRequests, bidderRequest) { // Create a clean openRTB request let request = createOpenRtbRequest(validBidRequests, bidderRequest); - const imStr = helpers.getLocalStorage(); - const options = { - customHeaders: { - 'x-impact': imStr, - } + const imStr = helpers.getImStrFromLocalStorage(); + const options = {} + + if (imStr) { + options.customHeaders = { + 'x-impact': imStr + }; } return { method: 'POST', - url: ORIGIN + AUCTIONURI, + url: ORIGIN + AUCTION_URI, data: JSON.stringify(request), options }; @@ -355,7 +363,7 @@ export const spec = { return [{ type: 'iframe', - url: ORIGIN + COOKIESYNCURI + params + url: ORIGIN + COOKIE_SYNC_URI + params }]; }, @@ -364,7 +372,7 @@ export const spec = { * @param {Bid} The bid that won the auction */ onBidWon: function(bid) { - ajax(`${LOGGER_URI}/log/bidder/won`, null, JSON.stringify(bid), { + ajax(`${LOGGER_URI}/prebid/won`, null, JSON.stringify(bid), { method: 'POST', contentType: 'application/json' }); @@ -377,7 +385,7 @@ export const spec = { * @param {data} Containing timeout specific data */ onTimeout: function(data) { - ajax(`${LOGGER_URI}/log/bidder/timeout`, null, JSON.stringify(data[0]), { + ajax(`${LOGGER_URI}/prebid/timeout`, null, JSON.stringify(data[0]), { method: 'POST', contentType: 'application/json' }); diff --git a/modules/impactifyBidAdapter.md b/modules/impactifyBidAdapter.md index 807a3813baa..de3373395dc 100644 --- a/modules/impactifyBidAdapter.md +++ b/modules/impactifyBidAdapter.md @@ -10,12 +10,20 @@ Maintainer: thomas.destefano@impactify.io Module that connects to the Impactify solution. The impactify bidder need 3 parameters: - - appId : This is your unique publisher identifier - - format : This is the ad format needed, can be : screen or display (Only for video media type) - - style : This is the ad style needed, can be : inline, impact or static (Only for video media type) +- appId : This is your unique publisher identifier +- format : This is the ad format needed, can be : screen or display (Only for video media type) +- style : This is the ad style needed, can be : inline, impact or static (Only for video media type) + +Note : Impactify adapter need storage access to work properly (Do not forget to set storageAllowed to true). # Test Parameters ``` + pbjs.bidderSettings = { + impactify: { + storageAllowed: true // Mandatory + } + }; + var adUnitsVideo = [{ code: 'your-slot-div-id-video', // This is your slot div id mediaTypes: { diff --git a/test/spec/modules/impactifyBidAdapter_spec.js b/test/spec/modules/impactifyBidAdapter_spec.js index 4efd1ad2d2c..a703b165724 100644 --- a/test/spec/modules/impactifyBidAdapter_spec.js +++ b/test/spec/modules/impactifyBidAdapter_spec.js @@ -1,6 +1,7 @@ import { expect } from 'chai'; import { spec, storage } from 'modules/impactifyBidAdapter.js'; import * as utils from 'src/utils.js'; +import sinon from 'sinon'; const BIDDER_CODE = 'impactify'; const BIDDER_ALIAS = ['imp']; @@ -19,6 +20,15 @@ var gdprData = { }; describe('ImpactifyAdapter', function () { + beforeEach(function () { + $$PREBID_GLOBAL$$.bidderSettings = { + impactify: { + storageAllowed: true + } + }; + sinon.stub(document.body, 'appendChild'); + }); + describe('isBidRequestValid', function () { let validBids = [ { From 27f4d31850a933afed005c48a40127bc76c4d9e6 Mon Sep 17 00:00:00 2001 From: Thomas De Stefano Date: Thu, 12 Oct 2023 14:42:23 +0200 Subject: [PATCH 14/18] Adjustments --- modules/impactifyBidAdapter.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/impactifyBidAdapter.js b/modules/impactifyBidAdapter.js index 501567fbff0..655152c5572 100644 --- a/modules/impactifyBidAdapter.js +++ b/modules/impactifyBidAdapter.js @@ -111,11 +111,11 @@ const helpers = { function createOpenRtbRequest(validBidRequests, bidderRequest) { // Create request and set imp bids inside let request = { - id: bidderRequest.auctionId, + id: bidderRequest.bidderRequestId, validBidRequests, cur: [DEFAULT_CURRENCY], imp: [], - source: {tid: bidderRequest.auctionId} + source: {tid: bidderRequest.ortb2?.source?.tid} }; // Get the url parameters @@ -133,10 +133,12 @@ function createOpenRtbRequest(validBidRequests, bidderRequest) { if (schain) request.source.ext = { schain: schain }; // Set Eids - let bidUserId = deepAccess(validBidRequests, '0.userId'); - let eids = createEidsArray(bidUserId); - if (eids.length) { - deepSetValue(request, 'user.ext.eids', eids); + let bidUserId = deepAccess(validBidRequests, '0.userIdAsEids'); + if(bidUserId) { + let eids = createEidsArray(bidUserId); + if (eids.length) { + deepSetValue(request, 'user.ext.eids', eids); + } } // Set device/user/site @@ -393,4 +395,4 @@ export const spec = { return true; } }; -registerBidder(spec); \ No newline at end of file +registerBidder(spec); From 439b8eaf40ac250171ea1cd9784e43fcf252a2a2 Mon Sep 17 00:00:00 2001 From: Thomas De Stefano Date: Thu, 26 Oct 2023 09:55:50 +0200 Subject: [PATCH 15/18] Fix eids object --- modules/impactifyBidAdapter.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/impactifyBidAdapter.js b/modules/impactifyBidAdapter.js index 655152c5572..9146bfb9893 100644 --- a/modules/impactifyBidAdapter.js +++ b/modules/impactifyBidAdapter.js @@ -5,7 +5,6 @@ import { registerBidder } from '../src/adapters/bidderFactory.js'; import { config } from '../src/config.js'; import { ajax } from '../src/ajax.js'; import { getStorageManager } from '../src/storageManager.js'; -import { createEidsArray } from 'modules/userId/eids.js'; const BIDDER_CODE = 'impactify'; const BIDDER_ALIAS = ['imp']; @@ -84,6 +83,12 @@ const helpers = { } }, + getEids(bidRequest) { + if (deepAccess(bidRequest, 'userIdAsEids')) { + return bidRequest.userIdAsEids || []; + } + }, + getFloor(bid) { const floorInfo = bid.getFloor({ currency: DEFAULT_CURRENCY, @@ -134,8 +139,8 @@ function createOpenRtbRequest(validBidRequests, bidderRequest) { // Set Eids let bidUserId = deepAccess(validBidRequests, '0.userIdAsEids'); - if(bidUserId) { - let eids = createEidsArray(bidUserId); + if (bidUserId) { + let eids = helpers.getEids(validBidRequests); if (eids.length) { deepSetValue(request, 'user.ext.eids', eids); } From d73ab69d0dcdb3b57ef5701ea741b1b98a3ed4ff Mon Sep 17 00:00:00 2001 From: Thomas De Stefano Date: Thu, 26 Oct 2023 11:04:26 +0200 Subject: [PATCH 16/18] Fix eids object --- modules/impactifyBidAdapter.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/modules/impactifyBidAdapter.js b/modules/impactifyBidAdapter.js index 9146bfb9893..036aca2d995 100644 --- a/modules/impactifyBidAdapter.js +++ b/modules/impactifyBidAdapter.js @@ -138,12 +138,9 @@ function createOpenRtbRequest(validBidRequests, bidderRequest) { if (schain) request.source.ext = { schain: schain }; // Set Eids - let bidUserId = deepAccess(validBidRequests, '0.userIdAsEids'); - if (bidUserId) { - let eids = helpers.getEids(validBidRequests); - if (eids.length) { - deepSetValue(request, 'user.ext.eids', eids); - } + let eids = deepAccess(validBidRequests, '0.userIdAsEids'); + if (eids && eids.length) { + deepSetValue(request, 'user.ext.eids', eids); } // Set device/user/site From a08152963eb3e1f908d749a816132765325ac432 Mon Sep 17 00:00:00 2001 From: Thomas De Stefano Date: Thu, 26 Oct 2023 11:05:38 +0200 Subject: [PATCH 17/18] Fix eids object --- modules/impactifyBidAdapter.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/modules/impactifyBidAdapter.js b/modules/impactifyBidAdapter.js index 036aca2d995..bea8f4f1f93 100644 --- a/modules/impactifyBidAdapter.js +++ b/modules/impactifyBidAdapter.js @@ -83,12 +83,6 @@ const helpers = { } }, - getEids(bidRequest) { - if (deepAccess(bidRequest, 'userIdAsEids')) { - return bidRequest.userIdAsEids || []; - } - }, - getFloor(bid) { const floorInfo = bid.getFloor({ currency: DEFAULT_CURRENCY, From 1120cf2a0f029b146a027cfb511c91f9112b1177 Mon Sep 17 00:00:00 2001 From: Thomas De Stefano Date: Fri, 27 Oct 2023 19:45:10 +0200 Subject: [PATCH 18/18] Fix tests --- modules/impactifyBidAdapter.js | 4 +- test/spec/modules/impactifyBidAdapter_spec.js | 110 +++++++++++++----- 2 files changed, 82 insertions(+), 32 deletions(-) diff --git a/modules/impactifyBidAdapter.js b/modules/impactifyBidAdapter.js index bea8f4f1f93..f446050265a 100644 --- a/modules/impactifyBidAdapter.js +++ b/modules/impactifyBidAdapter.js @@ -17,8 +17,8 @@ const AUCTION_URI = '/bidder'; const COOKIE_SYNC_URI = '/static/cookie_sync.html'; const GVL_ID = 606; const GET_CONFIG = config.getConfig; -const STORAGE = getStorageManager({gvlid: GVL_ID, bidderCode: BIDDER_CODE}); -const STORAGE_KEY = '_im_str' +export const STORAGE = getStorageManager({gvlid: GVL_ID, bidderCode: BIDDER_CODE}); +export const STORAGE_KEY = '_im_str' /** * Helpers object diff --git a/test/spec/modules/impactifyBidAdapter_spec.js b/test/spec/modules/impactifyBidAdapter_spec.js index 4a0c6ee64d3..adf968d610d 100644 --- a/test/spec/modules/impactifyBidAdapter_spec.js +++ b/test/spec/modules/impactifyBidAdapter_spec.js @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import { spec, storage } from 'modules/impactifyBidAdapter.js'; +import { spec, STORAGE, STORAGE_KEY } from 'modules/impactifyBidAdapter.js'; import * as utils from 'src/utils.js'; import sinon from 'sinon'; @@ -20,6 +20,10 @@ var gdprData = { }; describe('ImpactifyAdapter', function () { + let getLocalStorageStub; + let localStorageIsEnabledStub; + let sandbox; + beforeEach(function () { $$PREBID_GLOBAL$$.bidderSettings = { impactify: { @@ -27,6 +31,15 @@ describe('ImpactifyAdapter', function () { } }; sinon.stub(document.body, 'appendChild'); + sandbox = sinon.sandbox.create(); + getLocalStorageStub = sandbox.stub(STORAGE, 'getDataFromLocalStorage'); + localStorageIsEnabledStub = sandbox.stub(STORAGE, 'localStorageIsEnabled'); + }); + + afterEach(function() { + $$PREBID_GLOBAL$$.bidderSettings = {}; + document.body.appendChild.restore(); + sandbox.restore(); }); describe('isBidRequestValid', function () { @@ -50,6 +63,55 @@ describe('ImpactifyAdapter', function () { } ]; + let videoBidRequests = [ + { + bidder: 'impactify', + params: { + appId: '1', + format: 'screen', + style: 'inline' + }, + mediaTypes: { + video: { + context: 'instream' + } + }, + adUnitCode: 'adunit-code', + sizes: [[DEFAULT_VIDEO_WIDTH, DEFAULT_VIDEO_HEIGHT]], + bidId: '123456789', + bidderRequestId: '987654321', + auctionId: '19ab94a9-b0d7-4ed7-9f80-ad0c033cf1b1', + transactionId: 'f7b2c372-7a7b-11eb-9439-0242ac130002', + userId: { + pubcid: '87a0327b-851c-4bb3-a925-0c7be94548f5' + }, + userIdAsEids: [ + { + source: 'pubcid.org', + uids: [ + { + id: '87a0327b-851c-4bb3-a925-0c7be94548f5', + atype: 1 + } + ] + } + ] + } + ]; + let videoBidderRequest = { + bidderRequestId: '98845765110', + auctionId: '165410516454', + bidderCode: 'impactify', + bids: [ + { + ...videoBidRequests[0] + } + ], + refererInfo: { + referer: 'https://impactify.io' + } + }; + it('should return true when required params found', function () { expect(spec.isBidRequestValid(validBids[0])).to.equal(true); expect(spec.isBidRequestValid(validBids[1])).to.equal(true); @@ -168,24 +230,8 @@ describe('ImpactifyAdapter', function () { bid.params.style = {}; expect(spec.isBidRequestValid(bid)).to.equal(false); }); - - it('should pass bidfloor', function () { - videoBidRequests[0].getFloor = function() { - return { - currency: 'USD', - floor: 1.23, - } - } - - const res = spec.buildRequests(videoBidRequests, videoBidderRequest) - const resData = JSON.parse(res.data) - expect(resData.imp[0].bidfloor).to.equal(1.23) - }); }); describe('buildRequests', function () { - let getLocalStorageStub; - let localStorageIsEnabledStub; - let videoBidRequests = [ { bidder: 'impactify', @@ -234,15 +280,23 @@ describe('ImpactifyAdapter', function () { referer: 'https://impactify.io' } }; - afterEach(function() { - localStorageIsEnabledStub.restore(); - getLocalStorageStub.restore(); + + it('should pass bidfloor', function () { + videoBidRequests[0].getFloor = function() { + return { + currency: 'USD', + floor: 1.23, + } + } + + const res = spec.buildRequests(videoBidRequests, videoBidderRequest); + const resData = JSON.parse(res.data) + expect(resData.imp[0].bidfloor).to.equal(1.23) }); + it('sends video bid request to ENDPOINT via POST', function () { - localStorageIsEnabledStub = sinon.stub(storage, 'localStorageIsEnabled'); localStorageIsEnabledStub.returns(true); - getLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); getLocalStorageStub.returns('testValue'); const request = spec.buildRequests(videoBidRequests, videoBidderRequest); @@ -253,23 +307,19 @@ describe('ImpactifyAdapter', function () { }); it('should set header value from localstorage correctly', function () { - localStorageIsEnabledStub = sinon.stub(storage, 'localStorageIsEnabled'); localStorageIsEnabledStub.returns(true); - - getLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); getLocalStorageStub.returns('testValue'); - const request = spec.buildRequests(videoBidRequests, videoBidderRequest); + const request = spec.buildRequests(videoBidRequests, videoBidderRequest); + expect(request.options.customHeaders).to.be.an('object'); expect(request.options.customHeaders['x-impact']).to.equal('testValue'); }); it('should set header value to empty if localstorage is not enabled', function () { - localStorageIsEnabledStub = sinon.stub(storage, 'localStorageIsEnabled'); localStorageIsEnabledStub.returns(false); const request = spec.buildRequests(videoBidRequests, videoBidderRequest); - - expect(request.options.customHeaders['x-impact']).to.equal(''); + expect(request.options.customHeaders).to.be.undefined; }); }); describe('interpretResponse', function () { @@ -510,4 +560,4 @@ describe('ImpactifyAdapter', function () { const result = spec.onTimeout(bid); assert.ok(result); }); -}) \ No newline at end of file +})