From bb0683d6a55e635c3684c55430276b184c302ae4 Mon Sep 17 00:00:00 2001 From: lovephp-sweety Date: Wed, 1 Sep 2021 12:20:16 +0300 Subject: [PATCH 1/2] Add User Syncs and Partner --- modules/adpartnerBidAdapter.js | 96 +++++++++- modules/adpartnerBidAdapter.md | 12 ++ test/spec/modules/adpartnerBidAdapter_spec.js | 168 +++++++++++++++++- 3 files changed, 267 insertions(+), 9 deletions(-) diff --git a/modules/adpartnerBidAdapter.js b/modules/adpartnerBidAdapter.js index 243a8d81c9d..e8942884a9c 100644 --- a/modules/adpartnerBidAdapter.js +++ b/modules/adpartnerBidAdapter.js @@ -11,7 +11,7 @@ export const spec = { code: BIDDER_CODE, isBidRequestValid: function (bidRequest) { - return !!parseInt(bidRequest.params.unitId); + return !!parseInt(bidRequest.params.unitId) || !!parseInt(bidRequest.params.partnerId); }, buildRequests: function (validBidRequests, bidderRequest) { @@ -25,24 +25,42 @@ export const spec = { let bidRequests = []; let beaconParams = { tag: [], + partner: [], sizes: [], referer: '' }; validBidRequests.forEach(function(validBidRequest) { - bidRequests.push({ - unitId: parseInt(validBidRequest.params.unitId), + let bidRequestObject = { adUnitCode: validBidRequest.adUnitCode, sizes: validBidRequest.sizes, bidId: validBidRequest.bidId, referer: referer - }); + }; + + if (parseInt(validBidRequest.params.unitId)) { + bidRequestObject.unitId = parseInt(validBidRequest.params.unitId); + beaconParams.tag.push(validBidRequest.params.unitId); + } + + if (parseInt(validBidRequest.params.partnerId)) { + bidRequestObject.unitId = 0; + bidRequestObject.partnerId = parseInt(validBidRequest.params.partnerId); + beaconParams.partner.push(validBidRequest.params.partnerId); + } + + bidRequests.push(bidRequestObject); - beaconParams.tag.push(validBidRequest.params.unitId); beaconParams.sizes.push(spec.joinSizesToString(validBidRequest.sizes)); beaconParams.referer = encodeURIComponent(referer); }); + if (beaconParams.partner.length > 0) { + beaconParams.partner = beaconParams.partner.join(','); + } else { + delete beaconParams.partner; + } + beaconParams.tag = beaconParams.tag.join(','); beaconParams.sizes = beaconParams.sizes.join(','); @@ -125,7 +143,73 @@ export const spec = { postRequest(endpoint, data) { ajax(endpoint, null, data, {method: 'POST'}); - } + }, + + getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) { + const syncs = []; + + if (!syncOptions.iframeEnabled && !syncOptions.pixelEnabled) { + return syncs; + } + + let appendGdprParams = function (url, gdprParams) { + if (gdprParams === null) { + return url; + } + + return url + (url.indexOf('?') >= 0 ? '&' : '?') + gdprParams; + }; + + let gdprParams = null; + if (gdprConsent) { + if (typeof gdprConsent.gdprApplies === 'boolean') { + gdprParams = `gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`; + } else { + gdprParams = `gdpr_consent=${gdprConsent.consentString}`; + } + } + + serverResponses.forEach(resp => { + if (resp.body) { + Object.keys(resp.body).map(function(key, index) { + let respObject = resp.body[key]; + if (respObject['syncs'] !== undefined && + Array.isArray(respObject.syncs) && + respObject.syncs.length > 0) { + if (syncOptions.iframeEnabled) { + respObject.syncs.filter(function (syncIframeObject) { + if (syncIframeObject['type'] !== undefined && + syncIframeObject['link'] !== undefined && + syncIframeObject.type === 'iframe') { return true; } + return false; + }).forEach(function (syncIframeObject) { + syncs.push({ + type: 'iframe', + url: appendGdprParams(syncIframeObject.link, gdprParams) + }); + }); + } + if (syncOptions.pixelEnabled) { + respObject.syncs.filter(function (syncImageObject) { + if (syncImageObject['type'] !== undefined && + syncImageObject['link'] !== undefined && + syncImageObject.type === 'image') { return true; } + return false; + }).forEach(function (syncImageObject) { + syncs.push({ + type: 'image', + url: appendGdprParams(syncImageObject.link, gdprParams) + }); + }); + } + } + }); + } + }); + + return syncs; + }, + } registerBidder(spec); diff --git a/modules/adpartnerBidAdapter.md b/modules/adpartnerBidAdapter.md index c05d6e54e9c..2dc1c31c4c3 100644 --- a/modules/adpartnerBidAdapter.md +++ b/modules/adpartnerBidAdapter.md @@ -27,6 +27,18 @@ About us : https://adpartner.pro } } ] + }, + { + code: 'div-adpartner-example-2', + sizes: [[300, 250]], + bids: [ + { + bidder: "adpartner", + params: { + partnerId: 6698 + } + } + ] } ]; ``` diff --git a/test/spec/modules/adpartnerBidAdapter_spec.js b/test/spec/modules/adpartnerBidAdapter_spec.js index dc530af620d..fa49bbe0ac9 100644 --- a/test/spec/modules/adpartnerBidAdapter_spec.js +++ b/test/spec/modules/adpartnerBidAdapter_spec.js @@ -52,7 +52,7 @@ describe('AdpartnerAdapter', function () { }); describe('buildRequests', function () { - let validEndpoint = ENDPOINT_PROTOCOL + '://' + ENDPOINT_DOMAIN + ENDPOINT_PATH + '?tag=123,456&sizes=300x250|300x600,728x90&referer=https%3A%2F%2Ftest.domain'; + let validEndpoint = ENDPOINT_PROTOCOL + '://' + ENDPOINT_DOMAIN + ENDPOINT_PATH + '?tag=123,456&partner=777&sizes=300x250|300x600,728x90,300x250&referer=https%3A%2F%2Ftest.domain'; let validRequest = [ { @@ -72,6 +72,15 @@ describe('AdpartnerAdapter', function () { 'adUnitCode': 'adunit-code-2', 'sizes': [[728, 90]], 'bidId': '22aidtbx5eabd9' + }, + { + 'bidder': BIDDER_CODE, + 'params': { + 'partnerId': 777 + }, + 'adUnitCode': 'partner-code-3', + 'sizes': [[300, 250]], + 'bidId': '5d4531d5a6c013' } ]; @@ -100,6 +109,9 @@ describe('AdpartnerAdapter', function () { expect(payload[1].unitId).to.equal(456); expect(payload[1].sizes).to.deep.equal([[728, 90]]); expect(payload[1].bidId).to.equal('22aidtbx5eabd9'); + expect(payload[2].partnerId).to.equal(777); + expect(payload[2].sizes).to.deep.equal([[300, 250]]); + expect(payload[2].bidId).to.equal('5d4531d5a6c013'); }); }); @@ -113,8 +125,10 @@ describe('AdpartnerAdapter', function () { describe('interpretResponse', function () { const bidRequest = { 'method': 'POST', - 'url': ENDPOINT_PROTOCOL + '://' + ENDPOINT_DOMAIN + ENDPOINT_PATH + '?tag=123,456&code=adunit-code-1,adunit-code-2&bid=30b31c1838de1e,22aidtbx5eabd9&sizes=300x250|300x600,728x90&referer=https%3A%2F%2Ftest.domain', - 'data': '[{"unitId": 13144370,"adUnitCode": "div-gpt-ad-1460505748561-0","sizes": [[300, 250], [300, 600]],"bidId": "2bdcb0b203c17d","referer": "https://test.domain/index.html"},{"unitId": 13144370,"adUnitCode":"div-gpt-ad-1460505748561-1","sizes": [[768, 90]],"bidId": "3dc6b8084f91a8","referer": "https://test.domain/index.html"}]' + 'url': ENDPOINT_PROTOCOL + '://' + ENDPOINT_DOMAIN + ENDPOINT_PATH + '?tag=123,456&partner=777code=adunit-code-1,adunit-code-2,partner-code-3&bid=30b31c1838de1e,22aidtbx5eabd9,5d4531d5a6c013&sizes=300x250|300x600,728x90,300x250&referer=https%3A%2F%2Ftest.domain', + 'data': '[{"unitId": 13144370,"adUnitCode": "div-gpt-ad-1460505748561-0","sizes": [[300, 250], [300, 600]],"bidId": "2bdcb0b203c17d","referer": "https://test.domain/index.html"},' + + '{"unitId": 13144370,"adUnitCode":"div-gpt-ad-1460505748561-1","sizes": [[768, 90]],"bidId": "3dc6b8084f91a8","referer": "https://test.domain/index.html"},' + + '{"unitId": 0,"partnerId": 777,"adUnitCode":"div-gpt-ad-1460505748561-2","sizes": [[300, 250]],"bidId": "5d4531d5a6c013","referer": "https://test.domain/index.html"}]' }; const bidResponse = { @@ -239,4 +253,152 @@ describe('AdpartnerAdapter', function () { expect(ajaxStub.firstCall.args[1]).to.deep.equal(JSON.stringify(bid.winNotification[0].data)); }); }); + + describe('getUserSyncs', function () { + const bidResponse = [{ + body: { + 'div-gpt-ad-1460505748561-0': + { + 'ad': '
ad
', + 'width': 300, + 'height': 250, + 'creativeId': '8:123456', + 'adomain': [ + 'test.domain' + ], + 'syncs': [ + {'type': 'image', 'link': 'https://test.domain/tracker_1.gif'}, + {'type': 'image', 'link': 'https://test.domain/tracker_2.gif'}, + {'type': 'image', 'link': 'https://test.domain/tracker_3.gif'} + ], + 'winNotification': [ + { + 'method': 'POST', + 'path': '/hb/bid_won?test=1', + 'data': { + 'ad': [ + {'dsp': 8, 'id': 800008, 'cost': 1.0e-5, 'nurl': 'https://test.domain/'} + ], + 'unit_id': 1234, + 'site_id': 123 + } + } + ], + 'cpm': 0.01, + 'currency': 'USD', + 'netRevenue': true + } + }, + headers: {} + }]; + + it('should return nothing when sync is disabled', function () { + const syncOptions = { + 'iframeEnabled': false, + 'pixelEnabled': false + }; + + let syncs = spec.getUserSyncs(syncOptions); + expect(syncs).to.deep.equal([]); + }); + + it('should register image sync when only image is enabled where gdprConsent is undefined', function () { + const syncOptions = { + 'iframeEnabled': false, + 'pixelEnabled': true + }; + + const gdprConsent = undefined; + let syncs = spec.getUserSyncs(syncOptions, bidResponse, gdprConsent); + expect(syncs.length).to.equal(3); + expect(syncs[0].type).to.equal('image'); + expect(syncs[0].url).to.equal('https://test.domain/tracker_1.gif'); + }); + + it('should register image sync when only image is enabled where gdprConsent is defined', function () { + const syncOptions = { + 'iframeEnabled': false, + 'pixelEnabled': true + }; + const gdprConsent = { + consentString: 'someString', + vendorData: {}, + gdprApplies: true, + apiVersion: 2 + }; + + let syncs = spec.getUserSyncs(syncOptions, bidResponse, gdprConsent); + expect(syncs.length).to.equal(3); + expect(syncs[0].type).to.equal('image'); + expect(syncs[0].url).to.equal('https://test.domain/tracker_1.gif?gdpr=1&gdpr_consent=someString'); + }); + + // it('should register iframe sync when iframe and image are enabled', function () { + // const syncOptions = { + // 'iframeEnabled': true, + // 'pixelEnabled': true + // }; + // + // let syncs = spec.getUserSyncs(syncOptions); + // expect(syncs[0].type).to.equal('iframe'); + // expect(syncs[0].url).includes('https://hb.adwmg.com/cphb.html?'); + // }); + // + // it('should send GDPR consent if enabled', function() { + // const syncOptions = { + // 'iframeEnabled': true, + // 'pixelEnabled': true + // }; + // const gdprConsent = { + // consentString: 'CO9rhBTO9rhBTAcABBENBCCsAP_AAH_AACiQHItf_X_fb3_j-_59_9t0eY1f9_7_v20zjgeds-8Nyd_X_L8X42M7vB36pq4KuR4Eu3LBIQdlHOHcTUmw6IkVqTPsbk2Mr7NKJ7PEinMbe2dYGH9_n9XTuZKY79_s___z__-__v__7_f_r-3_3_vp9V---3YHIgEmGpfARZiWOBJNGlUKIEIVxIdACACihGFomsICVwU7K4CP0EDABAagIwIgQYgoxZBAAAAAElEQEgB4IBEARAIAAQAqQEIACNAEFgBIGAQACgGhYARQBCBIQZHBUcpgQESLRQTyVgCUXexhhCGUUANAg4AA.YAAAAAAAAAAA', + // vendorData: {}, + // gdprApplies: true, + // apiVersion: 2 + // }; + // const serverResponse = {}; + // let syncs = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent); + // expect(syncs[0].url).includes('gdpr=1'); + // expect(syncs[0].url).includes(`gdpr_consent=${gdprConsent.consentString}`); + // }); + // + // it('should not add GDPR consent params twice', function() { + // const syncOptions = { + // 'iframeEnabled': true, + // 'pixelEnabled': true + // }; + // const gdprConsent = { + // consentString: 'CO9rhBTO9rhBTAcABBENBCCsAP_AAH_AACiQHItf_X_fb3_j-_59_9t0eY1f9_7_v20zjgeds-8Nyd_X_L8X42M7vB36pq4KuR4Eu3LBIQdlHOHcTUmw6IkVqTPsbk2Mr7NKJ7PEinMbe2dYGH9_n9XTuZKY79_s___z__-__v__7_f_r-3_3_vp9V---3YHIgEmGpfARZiWOBJNGlUKIEIVxIdACACihGFomsICVwU7K4CP0EDABAagIwIgQYgoxZBAAAAAElEQEgB4IBEARAIAAQAqQEIACNAEFgBIGAQACgGhYARQBCBIQZHBUcpgQESLRQTyVgCUXexhhCGUUANAg4AA.YAAAAAAAAAAA', + // vendorData: {}, + // gdprApplies: true, + // apiVersion: 2 + // }; + // const gdprConsent2 = { + // consentString: 'CO9rhBTO9rhBTAcABBENBCCsAP_AAH_AACiQHItf_7_fb3_j-_59_9t0eY1f9_7_v20zjgeds-8Nyd_X_L8X42M7vB36pq4KuR4Eu3LBIQdlHOHcTUmw6IkVqTPsbk2Mr7NKJ7PEinMbe2dYGH9_n9XTuZKY79_s___z__-__v__7_f_r-3_3_vp9V---3YHIgEmGpfARZiWOBJNGlUKIEIVxIdACACihGFomsICVwU7K4CP0EDABAagIwIgQYgoxZBAAAAAElEQEgB4IBEARAIAAQAqQEIACNAEFgBIGAQACgGhYARQBCBIQZHBUcpgQESLRQTyVgCUXexhhCGUUANAg4AA.YAAAAAAAAAAA', + // vendorData: {}, + // gdprApplies: true, + // apiVersion: 2 + // }; + // const serverResponse = {}; + // let syncs = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent); + // syncs = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent2); + // expect(syncs[0].url.match(/gdpr/g).length).to.equal(2); // gdpr + gdpr_consent + // expect(syncs[0].url.match(/gdpr_consent/g).length).to.equal(1); + // }); + // + // it('should delete \'&\' symbol at the end of usersync URL', function() { + // const syncOptions = { + // 'iframeEnabled': true, + // 'pixelEnabled': true + // }; + // const gdprConsent = { + // consentString: 'CO9rhBTO9rhBTAcABBENBCCsAP_AAH_AACiQHItf_X_fb3_j-_59_9t0eY1f9_7_v20zjgeds-8Nyd_X_L8X42M7vB36pq4KuR4Eu3LBIQdlHOHcTUmw6IkVqTPsbk2Mr7NKJ7PEinMbe2dYGH9_n9XTuZKY79_s___z__-__v__7_f_r-3_3_vp9V---3YHIgEmGpfARZiWOBJNGlUKIEIVxIdACACihGFomsICVwU7K4CP0EDABAagIwIgQYgoxZBAAAAAElEQEgB4IBEARAIAAQAqQEIACNAEFgBIGAQACgGhYARQBCBIQZHBUcpgQESLRQTyVgCUXexhhCGUUANAg4AA.YAAAAAAAAAAA', + // vendorData: {}, + // gdprApplies: true, + // apiVersion: 2 + // }; + // const serverResponse = {}; + // let syncs = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent); + // expect(syncs[0].url.slice(-1)).to.not.equal('&'); + // }); + }); }); From 71d8f97643e9072ebd7d86ca3962c1745faaf3f3 Mon Sep 17 00:00:00 2001 From: Viktor Davidiants <57586844+vdavidiants@users.noreply.github.com> Date: Wed, 1 Sep 2021 12:25:47 +0300 Subject: [PATCH 2/2] Delete Tests --- test/spec/modules/adpartnerBidAdapter_spec.js | 68 ------------------- 1 file changed, 68 deletions(-) diff --git a/test/spec/modules/adpartnerBidAdapter_spec.js b/test/spec/modules/adpartnerBidAdapter_spec.js index fa49bbe0ac9..94b56f7735b 100644 --- a/test/spec/modules/adpartnerBidAdapter_spec.js +++ b/test/spec/modules/adpartnerBidAdapter_spec.js @@ -332,73 +332,5 @@ describe('AdpartnerAdapter', function () { expect(syncs[0].type).to.equal('image'); expect(syncs[0].url).to.equal('https://test.domain/tracker_1.gif?gdpr=1&gdpr_consent=someString'); }); - - // it('should register iframe sync when iframe and image are enabled', function () { - // const syncOptions = { - // 'iframeEnabled': true, - // 'pixelEnabled': true - // }; - // - // let syncs = spec.getUserSyncs(syncOptions); - // expect(syncs[0].type).to.equal('iframe'); - // expect(syncs[0].url).includes('https://hb.adwmg.com/cphb.html?'); - // }); - // - // it('should send GDPR consent if enabled', function() { - // const syncOptions = { - // 'iframeEnabled': true, - // 'pixelEnabled': true - // }; - // const gdprConsent = { - // consentString: 'CO9rhBTO9rhBTAcABBENBCCsAP_AAH_AACiQHItf_X_fb3_j-_59_9t0eY1f9_7_v20zjgeds-8Nyd_X_L8X42M7vB36pq4KuR4Eu3LBIQdlHOHcTUmw6IkVqTPsbk2Mr7NKJ7PEinMbe2dYGH9_n9XTuZKY79_s___z__-__v__7_f_r-3_3_vp9V---3YHIgEmGpfARZiWOBJNGlUKIEIVxIdACACihGFomsICVwU7K4CP0EDABAagIwIgQYgoxZBAAAAAElEQEgB4IBEARAIAAQAqQEIACNAEFgBIGAQACgGhYARQBCBIQZHBUcpgQESLRQTyVgCUXexhhCGUUANAg4AA.YAAAAAAAAAAA', - // vendorData: {}, - // gdprApplies: true, - // apiVersion: 2 - // }; - // const serverResponse = {}; - // let syncs = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent); - // expect(syncs[0].url).includes('gdpr=1'); - // expect(syncs[0].url).includes(`gdpr_consent=${gdprConsent.consentString}`); - // }); - // - // it('should not add GDPR consent params twice', function() { - // const syncOptions = { - // 'iframeEnabled': true, - // 'pixelEnabled': true - // }; - // const gdprConsent = { - // consentString: 'CO9rhBTO9rhBTAcABBENBCCsAP_AAH_AACiQHItf_X_fb3_j-_59_9t0eY1f9_7_v20zjgeds-8Nyd_X_L8X42M7vB36pq4KuR4Eu3LBIQdlHOHcTUmw6IkVqTPsbk2Mr7NKJ7PEinMbe2dYGH9_n9XTuZKY79_s___z__-__v__7_f_r-3_3_vp9V---3YHIgEmGpfARZiWOBJNGlUKIEIVxIdACACihGFomsICVwU7K4CP0EDABAagIwIgQYgoxZBAAAAAElEQEgB4IBEARAIAAQAqQEIACNAEFgBIGAQACgGhYARQBCBIQZHBUcpgQESLRQTyVgCUXexhhCGUUANAg4AA.YAAAAAAAAAAA', - // vendorData: {}, - // gdprApplies: true, - // apiVersion: 2 - // }; - // const gdprConsent2 = { - // consentString: 'CO9rhBTO9rhBTAcABBENBCCsAP_AAH_AACiQHItf_7_fb3_j-_59_9t0eY1f9_7_v20zjgeds-8Nyd_X_L8X42M7vB36pq4KuR4Eu3LBIQdlHOHcTUmw6IkVqTPsbk2Mr7NKJ7PEinMbe2dYGH9_n9XTuZKY79_s___z__-__v__7_f_r-3_3_vp9V---3YHIgEmGpfARZiWOBJNGlUKIEIVxIdACACihGFomsICVwU7K4CP0EDABAagIwIgQYgoxZBAAAAAElEQEgB4IBEARAIAAQAqQEIACNAEFgBIGAQACgGhYARQBCBIQZHBUcpgQESLRQTyVgCUXexhhCGUUANAg4AA.YAAAAAAAAAAA', - // vendorData: {}, - // gdprApplies: true, - // apiVersion: 2 - // }; - // const serverResponse = {}; - // let syncs = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent); - // syncs = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent2); - // expect(syncs[0].url.match(/gdpr/g).length).to.equal(2); // gdpr + gdpr_consent - // expect(syncs[0].url.match(/gdpr_consent/g).length).to.equal(1); - // }); - // - // it('should delete \'&\' symbol at the end of usersync URL', function() { - // const syncOptions = { - // 'iframeEnabled': true, - // 'pixelEnabled': true - // }; - // const gdprConsent = { - // consentString: 'CO9rhBTO9rhBTAcABBENBCCsAP_AAH_AACiQHItf_X_fb3_j-_59_9t0eY1f9_7_v20zjgeds-8Nyd_X_L8X42M7vB36pq4KuR4Eu3LBIQdlHOHcTUmw6IkVqTPsbk2Mr7NKJ7PEinMbe2dYGH9_n9XTuZKY79_s___z__-__v__7_f_r-3_3_vp9V---3YHIgEmGpfARZiWOBJNGlUKIEIVxIdACACihGFomsICVwU7K4CP0EDABAagIwIgQYgoxZBAAAAAElEQEgB4IBEARAIAAQAqQEIACNAEFgBIGAQACgGhYARQBCBIQZHBUcpgQESLRQTyVgCUXexhhCGUUANAg4AA.YAAAAAAAAAAA', - // vendorData: {}, - // gdprApplies: true, - // apiVersion: 2 - // }; - // const serverResponse = {}; - // let syncs = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent); - // expect(syncs[0].url.slice(-1)).to.not.equal('&'); - // }); }); });