Skip to content

Commit e410b28

Browse files
authored
Adquery Bid Adapter : IdSystem fix getId and decode method, added userSync with iframe type (#11019)
* adquery/prebid_qid_work5 * adquery/prebid_qid_work4
1 parent 796ad95 commit e410b28

File tree

4 files changed

+101
-27
lines changed

4 files changed

+101
-27
lines changed

modules/adqueryBidAdapter.js

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {registerBidder} from '../src/adapters/bidderFactory.js';
22
import {BANNER} from '../src/mediaTypes.js';
3-
import {buildUrl, logInfo, parseSizesInput, triggerPixel} from '../src/utils.js';
3+
import {buildUrl, logInfo, logMessage, parseSizesInput, triggerPixel} from '../src/utils.js';
44

55
/**
66
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
@@ -14,7 +14,9 @@ const ADQUERY_GVLID = 902;
1414
const ADQUERY_BIDDER_CODE = 'adquery';
1515
const ADQUERY_BIDDER_DOMAIN_PROTOCOL = 'https';
1616
const ADQUERY_BIDDER_DOMAIN = 'bidder.adquery.io';
17-
const ADQUERY_USER_SYNC_DOMAIN = ADQUERY_BIDDER_DOMAIN_PROTOCOL + '://' + ADQUERY_BIDDER_DOMAIN + '/prebid/userSync?1=1';
17+
const ADQUERY_STATIC_DOMAIN_PROTOCOL = 'https';
18+
const ADQUERY_STATIC_DOMAIN = 'api.adquery.io';
19+
const ADQUERY_USER_SYNC_DOMAIN = ADQUERY_BIDDER_DOMAIN;
1820
const ADQUERY_DEFAULT_CURRENCY = 'PLN';
1921
const ADQUERY_NET_REVENUE = true;
2022
const ADQUERY_TTL = 360;
@@ -26,7 +28,6 @@ export const spec = {
2628
supportedMediaTypes: [BANNER],
2729

2830
/**
29-
* f
3031
* @param {object} bid
3132
* @return {boolean}
3233
*/
@@ -41,10 +42,18 @@ export const spec = {
4142
*/
4243
buildRequests: (bidRequests, bidderRequest) => {
4344
const requests = [];
45+
46+
let adqueryRequestUrl = buildUrl({
47+
protocol: ADQUERY_BIDDER_DOMAIN_PROTOCOL,
48+
hostname: ADQUERY_BIDDER_DOMAIN,
49+
pathname: '/prebid/bid',
50+
// search: params
51+
});
52+
4453
for (let i = 0, len = bidRequests.length; i < len; i++) {
4554
const request = {
4655
method: 'POST',
47-
url: ADQUERY_BIDDER_DOMAIN_PROTOCOL + '://' + ADQUERY_BIDDER_DOMAIN + '/prebid/bid',
56+
url: adqueryRequestUrl, // ADQUERY_BIDDER_DOMAIN_PROTOCOL + '://' + ADQUERY_BIDDER_DOMAIN + '/prebid/bid',
4857
data: buildRequest(bidRequests[i], bidderRequest),
4958
options: {
5059
withCredentials: false,
@@ -62,8 +71,8 @@ export const spec = {
6271
* @return {Bid[]}
6372
*/
6473
interpretResponse: (response, request) => {
65-
logInfo(request);
66-
logInfo(response);
74+
logMessage(request);
75+
logMessage(response);
6776

6877
const res = response && response.body && response.body.data;
6978
let bidResponses = [];
@@ -125,7 +134,6 @@ export const spec = {
125134
*/
126135
onBidWon: (bid) => {
127136
logInfo('onBidWon', bid);
128-
129137
const bidString = JSON.stringify(bid);
130138
let copyOfBid = JSON.parse(bidString);
131139
delete copyOfBid.ad;
@@ -169,21 +177,48 @@ export const spec = {
169177
});
170178
triggerPixel(adqueryRequestUrl);
171179
},
180+
/**
181+
* Retrieves user synchronization URLs based on provided options and consents.
182+
*
183+
* @param {object} syncOptions - Options for synchronization.
184+
* @param {object[]} serverResponses - Array of server responses.
185+
* @param {object} gdprConsent - GDPR consent object.
186+
* @param {object} uspConsent - USP consent object.
187+
* @returns {object[]} - Array of synchronization URLs.
188+
*/
172189
getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent) => {
173-
let syncUrl = ADQUERY_USER_SYNC_DOMAIN;
174-
if (gdprConsent && gdprConsent.consentString) {
175-
if (typeof gdprConsent.gdprApplies === 'boolean') {
176-
syncUrl += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`;
177-
} else {
178-
syncUrl += `&gdpr=0&gdpr_consent=${gdprConsent.consentString}`;
179-
}
190+
logMessage('getUserSyncs', syncOptions, serverResponses, gdprConsent, uspConsent);
191+
let syncData = {
192+
'gdpr': gdprConsent && gdprConsent.gdprApplies ? 1 : 0,
193+
'gdpr_consent': gdprConsent && gdprConsent.consentString ? gdprConsent.consentString : '',
194+
'ccpa_consent': uspConsent && uspConsent.uspConsent ? uspConsent.uspConsent : '',
195+
};
196+
197+
if (window.qid) { // only for new users (new qid)
198+
syncData.qid = window.qid;
180199
}
181-
if (uspConsent && uspConsent.consentString) {
182-
syncUrl += `&ccpa_consent=${uspConsent.consentString}`;
200+
201+
let syncUrlObject = {
202+
protocol: ADQUERY_BIDDER_DOMAIN_PROTOCOL,
203+
hostname: ADQUERY_USER_SYNC_DOMAIN,
204+
pathname: '/prebid/userSync',
205+
search: syncData
206+
};
207+
208+
if (syncOptions.iframeEnabled) {
209+
syncUrlObject.protocol = ADQUERY_STATIC_DOMAIN_PROTOCOL;
210+
syncUrlObject.hostname = ADQUERY_STATIC_DOMAIN;
211+
syncUrlObject.pathname = '/user-sync-iframe.html';
212+
213+
return [{
214+
type: 'iframe',
215+
url: buildUrl(syncUrlObject)
216+
}];
183217
}
218+
184219
return [{
185220
type: 'image',
186-
url: syncUrl
221+
url: buildUrl(syncUrlObject)
187222
}];
188223
}
189224
};
@@ -205,7 +240,7 @@ function buildRequest(validBidRequests, bidderRequest) {
205240
// onetime User ID
206241
const ramdomValues = Array.from(window.crypto.getRandomValues(new Uint32Array(4)));
207242
userId = ramdomValues.map(val => val.toString(36)).join('').substring(0, 20);
208-
logInfo('generated onetime User ID: ', userId);
243+
logMessage('generated onetime User ID: ', userId);
209244
window.qid = userId;
210245
}
211246

modules/adqueryIdSystem.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import {ajax} from '../src/ajax.js';
99
import {getStorageManager} from '../src/storageManager.js';
1010
import {submodule} from '../src/hook.js';
11-
import {isFn, isPlainObject, isStr, logError, logInfo} from '../src/utils.js';
11+
import {isFn, isPlainObject, isStr, logError, logInfo, logMessage} from '../src/utils.js';
1212
import {MODULE_TYPE_UID} from '../src/activities/modules.js';
1313

1414
/**
@@ -66,7 +66,18 @@ export const adqueryIdSubmodule = {
6666
* @returns {IdResponse|undefined}
6767
*/
6868
getId(config) {
69-
logInfo('adqueryIdSubmodule getId');
69+
logMessage('adqueryIdSubmodule getId');
70+
71+
let qid = storage.getDataFromLocalStorage('qid');
72+
73+
if (qid) {
74+
return {
75+
callback: function (callback) {
76+
callback(qid);
77+
}
78+
}
79+
}
80+
7081
if (!isPlainObject(config.params)) {
7182
config.params = {};
7283
}

test/spec/modules/adqueryBidAdapter_spec.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,39 @@ describe('adqueryBidAdapter', function () {
155155

156156
describe('getUserSyncs', function () {
157157
it('should return iframe sync', function () {
158-
let sync = spec.getUserSyncs()
158+
let sync = spec.getUserSyncs(
159+
{
160+
iframeEnabled: true,
161+
pixelEnabled: true,
162+
},
163+
{},
164+
{
165+
consentString: 'ALL',
166+
gdprApplies: true,
167+
},
168+
{}
169+
)
159170
expect(sync.length).to.equal(1)
160171
expect(sync[0].type === 'iframe')
161172
expect(typeof sync[0].url === 'string')
162173
})
174+
it('should return image sync', function () {
175+
let sync = spec.getUserSyncs(
176+
{
177+
iframeEnabled: false,
178+
pixelEnabled: true,
179+
},
180+
{},
181+
{
182+
consentString: 'ALL',
183+
gdprApplies: true,
184+
},
185+
{}
186+
)
187+
expect(sync.length).to.equal(1)
188+
expect(sync[0].type === 'image')
189+
expect(typeof sync[0].url === 'string')
190+
})
163191

164192
it('Should return array of objects with proper sync config , include GDPR', function() {
165193
const syncData = spec.getUserSyncs({}, {}, {

test/spec/modules/adqueryIdSystem_spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,23 @@ describe('AdqueryIdSystem', function () {
3838
const callback = adqueryIdSubmodule.getId(config).callback;
3939
callback(callbackSpy);
4040
const request = server.requests[0];
41-
expect(request.url).to.contains(`https://bidder.adquery.io/prebid/qid?qid=`);
42-
request.respond(200, {'Content-Type': 'application/json'}, JSON.stringify({qid: '6dd9eab7dfeab7df6dd9ea'}));
43-
expect(callbackSpy.lastCall.lastArg).to.deep.equal('6dd9eab7dfeab7df6dd9ea');
41+
expect(request.url).to.contain(`https://bidder.adquery.io/prebid/qid`);
42+
request.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ qid: 'qid_string' }));
43+
expect(callbackSpy.lastCall.lastArg).to.deep.equal('qid_string');
4444
});
4545

4646
it('allows configurable id url', function () {
4747
const config = {
4848
params: {
49-
url: 'https://another_bidder.adquery.io/qid'
49+
url: 'https://bidder2.adquery.io'
5050
}
5151
};
5252
const callbackSpy = sinon.spy();
5353
const callback = adqueryIdSubmodule.getId(config).callback;
5454
callback(callbackSpy);
5555
const request = server.requests[0];
56-
expect(request.url).to.contains('https://another_bidder.adquery.io/qid');
57-
request.respond(200, {'Content-Type': 'application/json'}, JSON.stringify({qid: 'testqid'}));
56+
expect(request.url).to.contains('https://bidder2.adquery.io');
57+
request.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ qid: 'testqid' }));
5858
expect(callbackSpy.lastCall.lastArg).to.deep.equal('testqid');
5959
});
6060
});

0 commit comments

Comments
 (0)