From 3c7c1be386e010d0426a9c4ff148dff152ca91f2 Mon Sep 17 00:00:00 2001 From: adquery Date: Thu, 20 Jul 2023 13:26:43 +0200 Subject: [PATCH 1/4] adquery/prebid_qid_work2 --- modules/adqueryBidAdapter.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/adqueryBidAdapter.js b/modules/adqueryBidAdapter.js index 8a953f0d97f..94bff86f94d 100644 --- a/modules/adqueryBidAdapter.js +++ b/modules/adqueryBidAdapter.js @@ -199,8 +199,7 @@ 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, From 0d94e946e89f2a5428294a177b3c6fe72556fd7d Mon Sep 17 00:00:00 2001 From: adquery Date: Wed, 2 Aug 2023 13:55:35 +0200 Subject: [PATCH 2/4] adquery/prebid_qid_work2 --- modules/adqueryBidAdapter.js | 39 +++++++----- modules/adqueryIdSystem.js | 75 ++++++++++++++--------- test/spec/modules/adqueryIdSystem_spec.js | 38 ++++-------- 3 files changed, 80 insertions(+), 72 deletions(-) diff --git a/modules/adqueryBidAdapter.js b/modules/adqueryBidAdapter.js index 94bff86f94d..f31e510a10b 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 = { @@ -58,7 +56,6 @@ export const spec = { logInfo(request); logInfo(response); - let qid = null; const res = response && response.body && response.body.data; let bidResponses = []; @@ -87,17 +84,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; }, @@ -187,10 +173,29 @@ export const spec = { url: syncUrl }]; } - }; + 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 || ''; @@ -202,7 +207,7 @@ function buildRequest(validBidRequests, bidderRequest) { 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..6d6a768e4af 100644 --- a/test/spec/modules/adqueryIdSystem_spec.js +++ b/test/spec/modules/adqueryIdSystem_spec.js @@ -1,5 +1,5 @@ -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'; const config = { storage: { @@ -18,10 +18,10 @@ describe('AdqueryIdSystem', function () { }); }); - describe('getId', function() { + describe('getId', function () { let getDataFromLocalStorageStub; - beforeEach(function() { + beforeEach(function () { getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); }); @@ -29,7 +29,7 @@ describe('AdqueryIdSystem', function () { getDataFromLocalStorageStub.restore(); }); - it('gets a adqueryId', function() { + it('gets a adqueryId', function () { const config = { params: {} }; @@ -37,36 +37,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: 'qid_value'})); + expect(callbackSpy.lastCall.lastArg).to.deep.equal('qid_value'); }); - 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/qid'); + request.respond(200, {'Content-Type': 'application/json'}, JSON.stringify({qid: 'testqid'})); + expect(callbackSpy.lastCall.lastArg).to.deep.equal('testqid'); }); }); }); From b4a032e02438b4cd2527b94d5199e7ca7f42cf03 Mon Sep 17 00:00:00 2001 From: adquery Date: Wed, 2 Aug 2023 15:51:43 +0200 Subject: [PATCH 3/4] adquery/prebid_qid_work2 --- modules/adqueryBidAdapter.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/adqueryBidAdapter.js b/modules/adqueryBidAdapter.js index f31e510a10b..ec867c682e7 100644 --- a/modules/adqueryBidAdapter.js +++ b/modules/adqueryBidAdapter.js @@ -116,8 +116,12 @@ export const spec = { */ onBidWon: (bid) => { logInfo('onBidWon', bid); + const bidString = JSON.stringify(bid); - const encodedBuf = window.btoa(bidString); + let copyOfBid = JSON.parse(bidString); + delete copyOfBid.ad; + const shortBidString = JSON.stringify(bid); + const encodedBuf = window.btoa(shortBidString); let params = { q: encodedBuf, From 45ad0eb20dec07e434bb7de09f6f9ccc41a8ae62 Mon Sep 17 00:00:00 2001 From: ppydys Date: Fri, 18 Aug 2023 11:10:06 +0200 Subject: [PATCH 4/4] adquery/prebid_qid_work2 --- modules/adqueryBidAdapter.js | 6 +++--- modules/adqueryIdSystem.js | 10 ++-------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/modules/adqueryBidAdapter.js b/modules/adqueryBidAdapter.js index ec867c682e7..0f445fdfd78 100644 --- a/modules/adqueryBidAdapter.js +++ b/modules/adqueryBidAdapter.js @@ -194,9 +194,9 @@ function buildRequest(validBidRequests, bidderRequest) { 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); - + const ramdomValues = Array.from(window.crypto.getRandomValues(new Uint32Array(4))); + userId = ramdomValues.map(val => val.toString(36)).join('').substring(0, 20); + logInfo('generated onetime User ID: ', userId); window.qid = userId; } diff --git a/modules/adqueryIdSystem.js b/modules/adqueryIdSystem.js index d6d609b66e4..c5d01d7fbed 100644 --- a/modules/adqueryIdSystem.js +++ b/modules/adqueryIdSystem.js @@ -75,15 +75,9 @@ export const adqueryIdSubmodule = { 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 ramdomValues = Array.from(window.crypto.getRandomValues(new Uint32Array(4))); + qid = ramdomValues.map(val => val.toString(36)).join('').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);