diff --git a/modules/adqueryBidAdapter.js b/modules/adqueryBidAdapter.js index 8a953f0d97f..2f7832a33e9 100644 --- a/modules/adqueryBidAdapter.js +++ b/modules/adqueryBidAdapter.js @@ -1,7 +1,6 @@ import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER} from '../src/mediaTypes.js'; -import { logInfo, buildUrl, triggerPixel, parseSizesInput } from '../src/utils.js'; -import { getStorageManager } from '../src/storageManager.js'; +import {buildUrl, logInfo, parseSizesInput, triggerPixel} from '../src/utils.js'; const ADQUERY_GVLID = 902; const ADQUERY_BIDDER_CODE = 'adquery'; @@ -11,7 +10,6 @@ const ADQUERY_USER_SYNC_DOMAIN = ADQUERY_BIDDER_DOMAIN_PROTOCOL + '://' + ADQUER const ADQUERY_DEFAULT_CURRENCY = 'PLN'; const ADQUERY_NET_REVENUE = true; const ADQUERY_TTL = 360; -const storage = getStorageManager({bidderCode: ADQUERY_BIDDER_CODE}); /** @type {BidderSpec} */ export const spec = { @@ -55,10 +53,6 @@ export const spec = { * @return {Bid[]} */ interpretResponse: (response, request) => { - logInfo(request); - logInfo(response); - - let qid = null; const res = response && response.body && response.body.data; let bidResponses = []; @@ -87,17 +81,6 @@ export const spec = { bidResponses.push(bidResponse); logInfo('bidResponses', bidResponses); - if (res && res.qid) { - if (storage.getDataFromLocalStorage('qid')) { - qid = storage.getDataFromLocalStorage('qid'); - if (qid && qid.includes('%7B%22')) { - storage.setDataInLocalStorage('qid', res.qid); - } - } else { - storage.setDataInLocalStorage('qid', res.qid); - } - } - return bidResponses; }, @@ -189,8 +172,28 @@ export const spec = { } }; + function buildRequest(validBidRequests, bidderRequest) { let bid = validBidRequests; + logInfo('buildRequest: ', bid); + + let userId = null; + if (window.qid) { + userId = window.qid; + } + + if (bid.userId && bid.userId.qid) { + userId = bid.userId.qid + } + + if (!userId) { + // onetime User ID + const randomValues = Array.from(window.crypto.getRandomValues(new Uint32Array(4))); + userId = randomValues.map(it => it.toString(36)).join().substring(20); + + window.qid = userId; + } + let pageUrl = ''; if (bidderRequest && bidderRequest.refererInfo) { pageUrl = bidderRequest.refererInfo.page || ''; @@ -199,11 +202,10 @@ function buildRequest(validBidRequests, bidderRequest) { return { v: '$prebid.version$', placementCode: bid.params.placementId, - // TODO: fix auctionId leak: https://github.com/prebid/Prebid.js/issues/9781 - auctionId: bid.auctionId, + auctionId: null, type: bid.params.type, adUnitCode: bid.adUnitCode, - bidQid: storage.getDataFromLocalStorage('qid') || null, + bidQid: userId, bidId: bid.bidId, bidder: bid.bidder, bidPageUrl: pageUrl, diff --git a/modules/adqueryIdSystem.js b/modules/adqueryIdSystem.js index 82df787a2b4..d6d609b66e4 100644 --- a/modules/adqueryIdSystem.js +++ b/modules/adqueryIdSystem.js @@ -8,7 +8,7 @@ import {ajax} from '../src/ajax.js'; import {getStorageManager} from '../src/storageManager.js'; import {submodule} from '../src/hook.js'; -import { isFn, isStr, isPlainObject, logError } from '../src/utils.js'; +import {isFn, isPlainObject, isStr, logError, logInfo} from '../src/utils.js'; import {MODULE_TYPE_UID} from '../src/activities/modules.js'; const MODULE_NAME = 'qid'; @@ -51,11 +51,7 @@ export const adqueryIdSubmodule = { * @returns {{qid:Object}} */ decode(value) { - let qid = storage.getDataFromLocalStorage('qid'); - if (isStr(qid)) { - return {qid: qid}; - } - return (value && typeof value['qid'] === 'string') ? { 'qid': value['qid'] } : undefined; + return {qid: value} }, /** * performs action to obtain id and return a value in the callback's response argument @@ -64,38 +60,57 @@ export const adqueryIdSubmodule = { * @returns {IdResponse|undefined} */ getId(config) { + logInfo('adqueryIdSubmodule getId'); if (!isPlainObject(config.params)) { config.params = {}; } - const url = paramOrDefault(config.params.url, + + const url = paramOrDefault( + config.params.url, `https://bidder.adquery.io/prebid/qid`, - config.params.urlArg); + config.params.urlArg + ); const resp = function (callback) { - let qid = storage.getDataFromLocalStorage('qid'); - if (isStr(qid)) { - const responseObj = {qid: qid}; - callback(responseObj); - } else { - const callbacks = { - success: response => { - let responseObj; - if (response) { - try { - responseObj = JSON.parse(response); - } catch (error) { - logError(error); - } + let qid = window.qid; + + if (!qid) { + const ramdomValues = window.crypto.getRandomValues(new Uint32Array(4)); + qid = (ramdomValues[0].toString(36) + + ramdomValues[1].toString(36) + + ramdomValues[2].toString(36) + + ramdomValues[3].toString(36)) + .substring(0, 20); + + const randomValues = Array.from(window.crypto.getRandomValues(new Uint32Array(4))); + qid = randomValues.map(it => it.toString(36)).join().substring(20); + logInfo('adqueryIdSubmodule ID QID GENERTAED:', qid); + } + logInfo('adqueryIdSubmodule ID QID:', qid); + + const callbacks = { + success: response => { + let responseObj; + if (response) { + try { + responseObj = JSON.parse(response); + } catch (error) { + logError(error); } - callback(responseObj); - }, - error: error => { - logError(`${MODULE_NAME}: ID fetch encountered an error`, error); - callback(); } - }; - ajax(url, callbacks, undefined, {method: 'GET'}); - } + if (responseObj.qid) { + let myQid = responseObj.qid; + storage.setDataInLocalStorage('qid', myQid); + return callback(myQid); + } + callback(); + }, + error: error => { + logError(`${MODULE_NAME}: ID fetch encountered an error`, error); + callback(); + } + }; + ajax(url + '?qid=' + qid, callbacks, undefined, {method: 'GET'}); }; return {callback: resp}; }, diff --git a/test/spec/modules/adqueryIdSystem_spec.js b/test/spec/modules/adqueryIdSystem_spec.js index a6b4e9d1529..d6abddf3adb 100644 --- a/test/spec/modules/adqueryIdSystem_spec.js +++ b/test/spec/modules/adqueryIdSystem_spec.js @@ -1,5 +1,6 @@ -import { adqueryIdSubmodule, storage } from 'modules/adqueryIdSystem.js'; -import { server } from 'test/mocks/xhr.js'; +import {adqueryIdSubmodule, storage} from 'modules/adqueryIdSystem.js'; +import {server} from 'test/mocks/xhr.js'; +import sinon from 'sinon'; const config = { storage: { @@ -18,7 +19,7 @@ describe('AdqueryIdSystem', function () { }); }); - describe('getId', function() { + describe('getId', function () { let getDataFromLocalStorageStub; beforeEach(function() { @@ -29,7 +30,7 @@ describe('AdqueryIdSystem', function () { getDataFromLocalStorageStub.restore(); }); - it('gets a adqueryId', function() { + it('gets a adqueryId', function () { const config = { params: {} }; @@ -37,36 +38,24 @@ describe('AdqueryIdSystem', function () { const callback = adqueryIdSubmodule.getId(config).callback; callback(callbackSpy); const request = server.requests[0]; - expect(request.url).to.eq(`https://bidder.adquery.io/prebid/qid`); - request.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ qid: 'qid' })); - expect(callbackSpy.lastCall.lastArg).to.deep.equal({qid: 'qid'}); + expect(request.url).to.contains(`https://bidder.adquery.io/prebid/qid?qid=`); + request.respond(200, {'Content-Type': 'application/json'}, JSON.stringify({qid: '6dd9eab7dfeab7df6dd9ea'})); + expect(callbackSpy.lastCall.lastArg).to.deep.equal('6dd9eab7dfeab7df6dd9ea'); }); - it('gets a cached adqueryId', function() { - const config = { - params: {} - }; - getDataFromLocalStorageStub.withArgs('qid').returns('qid'); - - const callbackSpy = sinon.spy(); - const callback = adqueryIdSubmodule.getId(config).callback; - callback(callbackSpy); - expect(callbackSpy.lastCall.lastArg).to.deep.equal({qid: 'qid'}); - }); - - it('allows configurable id url', function() { + it('allows configurable id url', function () { const config = { params: { - url: 'https://bidder.adquery.io' + url: 'https://another_bidder.adquery.io/qid' } }; const callbackSpy = sinon.spy(); const callback = adqueryIdSubmodule.getId(config).callback; callback(callbackSpy); const request = server.requests[0]; - expect(request.url).to.eq('https://bidder.adquery.io'); - request.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ qid: 'testqid' })); - expect(callbackSpy.lastCall.lastArg).to.deep.equal({qid: 'testqid'}); + expect(request.url).to.contains('https://another_bidder.adquery.io'); + request.respond(200, {'Content-Type': 'application/json'}, JSON.stringify({qid: 'testqid'})); + expect(callbackSpy.lastCall.lastArg).to.deep.equal('testqid'); }); }); });