diff --git a/modules/onetagBidAdapter.js b/modules/onetagBidAdapter.js index 6280dd12268..fd66c8ce69f 100644 --- a/modules/onetagBidAdapter.js +++ b/modules/onetagBidAdapter.js @@ -4,7 +4,10 @@ import { BANNER, VIDEO } from '../src/mediaTypes.js'; import { INSTREAM, OUTSTREAM } from '../src/video.js'; import { Renderer } from '../src/Renderer.js'; import find from 'core-js-pure/features/array/find.js'; -const { registerBidder } = require('../src/adapters/bidderFactory.js'); +import { getStorageManager } from '../src/storageManager.js'; +import { registerBidder } from '../src/adapters/bidderFactory.js'; + +const storage = getStorageManager(); const ENDPOINT = 'https://onetag-sys.com/prebid-request'; const USER_SYNC_ENDPOINT = 'https://onetag-sys.com/usync/'; @@ -62,14 +65,15 @@ function buildRequests(validBidRequests, bidderRequest) { if (bidderRequest && bidderRequest.userId) { payload.userId = bidderRequest.userId; } - if (window.localStorage) { - payload.onetagSid = window.localStorage.getItem('onetag_sid'); - } - const payloadString = JSON.stringify(payload); + try { + if (storage.hasLocalStorage()) { + payload.onetagSid = storage.getDataFromLocalStorage('onetag_sid'); + } + } catch (e) {} return { method: 'POST', url: ENDPOINT, - data: payloadString + data: JSON.stringify(payload) } } @@ -161,17 +165,22 @@ function onetagRenderer({renderer, width, height, vastXml, adUnitCode}) { } function getFrameNesting() { - let frame = window; + let topmostFrame = window; + let parent = window.parent; + let currentFrameNesting = 0; try { - while (frame !== frame.top) { + while (topmostFrame !== topmostFrame.parent) { + parent = topmostFrame.parent; // eslint-disable-next-line no-unused-expressions - frame.location.href; - frame = frame.parent; + parent.location.href; + topmostFrame = topmostFrame.parent; } - } catch (e) {} + } catch (e) { + currentFrameNesting = parent === topmostFrame.top ? 1 : 2; + } return { - topmostFrame: frame, - currentFrameNesting: frame.top === frame ? 1 : 2 + topmostFrame, + currentFrameNesting } } @@ -198,8 +207,11 @@ function getDocumentVisibility(window) { function getPageInfo() { const { topmostFrame, currentFrameNesting } = getFrameNesting(); return { - location: encodeURIComponent(topmostFrame.location.href), - referrer: encodeURIComponent(topmostFrame.document.referrer) || '0', + location: topmostFrame.location.href, + referrer: + topmostFrame.document.referrer !== '' + ? topmostFrame.document.referrer + : null, masked: currentFrameNesting, wWidth: topmostFrame.innerWidth, wHeight: topmostFrame.innerHeight, @@ -216,7 +228,11 @@ function getPageInfo() { docHidden: getDocumentVisibility(topmostFrame), docHeight: topmostFrame.document.body ? topmostFrame.document.body.scrollHeight : null, hLength: history.length, - timing: getTiming() + timing: getTiming(), + version: { + prebid: '$prebid.version$', + adapter: '1.0.0' + } }; } @@ -256,6 +272,7 @@ function setGeneralInfo(bidRequest) { this['auctionId'] = bidRequest.auctionId; this['transactionId'] = bidRequest.transactionId; this['pubId'] = params.pubId; + this['ext'] = params.ext; if (params.pubClick) { this['click'] = params.pubClick; } @@ -326,7 +343,7 @@ function parseSizes(bid) { function getSizes(sizes) { const ret = []; - for (let i = 0, lenght = sizes.length; i < lenght; i++) { + for (let i = 0; i < sizes.length; i++) { const size = sizes[i]; ret.push({width: size[0], height: size[1]}) } diff --git a/test/spec/modules/onetagBidAdapter_spec.js b/test/spec/modules/onetagBidAdapter_spec.js index a951c74b20b..c1462c3814d 100644 --- a/test/spec/modules/onetagBidAdapter_spec.js +++ b/test/spec/modules/onetagBidAdapter_spec.js @@ -132,10 +132,10 @@ describe('onetag', function () { const data = JSON.parse(d); it('Should contain all keys', function () { expect(data).to.be.an('object'); - expect(data).to.include.all.keys('location', 'referrer', 'masked', 'sHeight', 'sWidth', 'docHeight', 'wHeight', 'wWidth', 'oHeight', 'oWidth', 'aWidth', 'aHeight', 'sLeft', 'sTop', 'hLength', 'bids', 'docHidden', 'xOffset', 'yOffset', 'onetagSid'); + expect(data).to.include.all.keys('location', 'referrer', 'masked', 'sHeight', 'sWidth', 'docHeight', 'wHeight', 'wWidth', 'oHeight', 'oWidth', 'aWidth', 'aHeight', 'sLeft', 'sTop', 'hLength', 'bids', 'docHidden', 'xOffset', 'yOffset', 'timing', 'version'); expect(data.location).to.be.a('string'); - expect(data.masked).to.be.a('number'); - expect(data.referrer).to.be.a('string'); + expect(data.masked).to.be.oneOf([0, 1, 2]); + expect(data.referrer).to.satisfy(referrer => referrer === null || typeof referrer === 'string'); expect(data.sHeight).to.be.a('number'); expect(data.sWidth).to.be.a('number'); expect(data.wWidth).to.be.a('number'); @@ -148,6 +148,7 @@ describe('onetag', function () { expect(data.sTop).to.be.a('number'); expect(data.hLength).to.be.a('number'); expect(data.bids).to.be.an('array'); + expect(data.version).to.have.all.keys('prebid', 'adapter'); const bids = data['bids']; for (let i = 0; i < bids.length; i++) { const bid = bids[i];