diff --git a/modules/ixBidAdapter.js b/modules/ixBidAdapter.js index 6c5f90b7a2a..8b6b32e83ec 100644 --- a/modules/ixBidAdapter.js +++ b/modules/ixBidAdapter.js @@ -696,7 +696,8 @@ function buildRequest(validBidRequests, bidderRequest, impressions, version) { r = addRequestedFeatureToggles(r, FEATURE_TOGGLES.REQUESTED_FEATURE_TOGGLES) // getting ixdiags for adunits of the video, outstream & multi format (MF) style - let ixdiag = buildIXDiag(validBidRequests); + const fledgeEnabled = deepAccess(bidderRequest, 'fledgeEnabled') + let ixdiag = buildIXDiag(validBidRequests, fledgeEnabled); for (var key in ixdiag) { r.ext.ixdiag[key] = ixdiag[key]; } @@ -952,6 +953,7 @@ function addImpressions(impressions, impKeys, r, adUnitIndex) { const dfpAdUnitCode = impressions[impKeys[adUnitIndex]].dfp_ad_unit_code; const tid = impressions[impKeys[adUnitIndex]].tid; const sid = impressions[impKeys[adUnitIndex]].sid; + const auctionEnvironment = impressions[impKeys[adUnitIndex]].ae; const bannerImpressions = impressionObjects.filter(impression => BANNER in impression); const otherImpressions = impressionObjects.filter(impression => !(BANNER in impression)); @@ -991,12 +993,18 @@ function addImpressions(impressions, impKeys, r, adUnitIndex) { _bannerImpression.banner.pos = position; } - if (dfpAdUnitCode || gpid || tid || sid) { + if (dfpAdUnitCode || gpid || tid || sid || auctionEnvironment) { _bannerImpression.ext = {}; + _bannerImpression.ext.dfp_ad_unit_code = dfpAdUnitCode; _bannerImpression.ext.gpid = gpid; _bannerImpression.ext.tid = tid; _bannerImpression.ext.sid = sid; + + // enable fledge auction + if (auctionEnvironment == 1) { + _bannerImpression.ext.ae = 1; + } } if ('bidfloor' in bannerImps[0]) { @@ -1220,15 +1228,16 @@ function _getUserIds(bidRequest) { /** * Calculates IX diagnostics values and packages them into an object * - * @param {array} validBidRequests The valid bid requests from prebid + * @param {array} validBidRequests - The valid bid requests from prebid + * @param {bool} fledgeEnabled - Flag indicating if protected audience (fledge) is enabled * @return {Object} IX diag values for ad units */ -function buildIXDiag(validBidRequests) { +function buildIXDiag(validBidRequests, fledgeEnabled) { var adUnitMap = validBidRequests .map(bidRequest => bidRequest.adUnitCode) .filter((value, index, arr) => arr.indexOf(value) === index); - var ixdiag = { + let ixdiag = { mfu: 0, bu: 0, iu: 0, @@ -1239,12 +1248,13 @@ function buildIXDiag(validBidRequests) { version: '$prebid.version$', userIds: _getUserIds(validBidRequests[0]), url: window.location.href.split('?')[0], - vpd: defaultVideoPlacement + vpd: defaultVideoPlacement, + ae: fledgeEnabled }; // create ad unit map and collect the required diag properties - for (let i = 0; i < adUnitMap.length; i++) { - var bid = validBidRequests.filter(bidRequest => bidRequest.adUnitCode === adUnitMap[i])[0]; + for (let adUnit of adUnitMap) { + let bid = validBidRequests.filter(bidRequest => bidRequest.adUnitCode === adUnit)[0]; if (deepAccess(bid, 'mediaTypes')) { if (Object.keys(bid.mediaTypes).length > 1) { @@ -1350,7 +1360,7 @@ function createVideoImps(validBidRequest, videoImps) { * @param {object} missingBannerSizes reference to missing banner config sizes * @param {object} bannerImps reference to created banner impressions */ -function createBannerImps(validBidRequest, missingBannerSizes, bannerImps) { +function createBannerImps(validBidRequest, missingBannerSizes, bannerImps, bidderRequest) { let imp = bidToBannerImp(validBidRequest); const bannerSizeDefined = includesSize(deepAccess(validBidRequest, 'mediaTypes.banner.sizes'), deepAccess(validBidRequest, 'params.size')); @@ -1366,6 +1376,21 @@ function createBannerImps(validBidRequest, missingBannerSizes, bannerImps) { bannerImps[validBidRequest.adUnitCode].tagId = deepAccess(validBidRequest, 'params.tagId'); bannerImps[validBidRequest.adUnitCode].pos = deepAccess(validBidRequest, 'mediaTypes.banner.pos'); + // Add Fledge flag if enabled + const fledgeEnabled = deepAccess(bidderRequest, 'fledgeEnabled') + if (fledgeEnabled) { + const auctionEnvironment = deepAccess(validBidRequest, 'ortb2Imp.ext.ae') + if (auctionEnvironment) { + if (isInteger(auctionEnvironment)) { + bannerImps[validBidRequest.adUnitCode].ae = auctionEnvironment; + } else { + logWarn('error setting auction environment flag - must be an integer') + } + } else if (deepAccess(bidderRequest, 'defaultForSlots') == 1) { + bannerImps[validBidRequest.adUnitCode].ae = 1 + } + } + // AdUnit-Specific First Party Data const adUnitFPD = deepAccess(validBidRequest, 'ortb2Imp.ext.data'); if (adUnitFPD) { @@ -1720,7 +1745,7 @@ export const spec = { for (const type in adUnitMediaTypes) { switch (adUnitMediaTypes[type]) { case BANNER: - createBannerImps(validBidRequest, missingBannerSizes, bannerImps); + createBannerImps(validBidRequest, missingBannerSizes, bannerImps, bidderRequest); break; case VIDEO: createVideoImps(validBidRequest, videoImps) @@ -1795,13 +1820,18 @@ export const spec = { const bids = []; let bid = null; - if (!serverResponse.hasOwnProperty('body') || !serverResponse.body.hasOwnProperty('seatbid')) { - FEATURE_TOGGLES.setFeatureToggles(serverResponse); + // Extract the FLEDGE auction configuration list from the response + let fledgeAuctionConfigs = deepAccess(serverResponse, 'body.ext.protectedAudienceAuctionConfigs') || []; + + FEATURE_TOGGLES.setFeatureToggles(serverResponse); + + if (!serverResponse.hasOwnProperty('body')) { return bids; } const responseBody = serverResponse.body; - const seatbid = responseBody.seatbid; + const seatbid = responseBody.seatbid || []; + for (let i = 0; i < seatbid.length; i++) { if (!seatbid[i].hasOwnProperty('bid')) { continue; @@ -1837,8 +1867,28 @@ export const spec = { } } - FEATURE_TOGGLES.setFeatureToggles(serverResponse); - return bids; + if (Array.isArray(fledgeAuctionConfigs) && fledgeAuctionConfigs.length > 0) { + // Validate and filter fledgeAuctionConfigs + fledgeAuctionConfigs = fledgeAuctionConfigs.filter(config => { + if (!isValidAuctionConfig(config)) { + logWarn('Malformed auction config detected:', config); + return false; + } + return true; + }); + + try { + return { + bids, + fledgeAuctionConfigs, + }; + } catch (error) { + logWarn('Error attaching AuctionConfigs', error); + return bids; + } + } else { + return bids; + } }, /** @@ -2059,6 +2109,15 @@ function getFormatCount(imp) { return formatCount; } +/** + * Checks if auction config is valid + * @param {object} config + * @returns bool + */ +function isValidAuctionConfig(config) { + return typeof config === 'object' && config !== null; +} + /** * Adds device.w / device.h info * @param {object} r diff --git a/modules/ixBidAdapter.md b/modules/ixBidAdapter.md index 638cb11c5ab..0705c5932cf 100644 --- a/modules/ixBidAdapter.md +++ b/modules/ixBidAdapter.md @@ -469,6 +469,11 @@ pbjs.setConfig({ The timeout value must be a positive whole number in milliseconds. +Protected Audience API (FLEDGE) +=========================== + +In order to enable receiving [Protected Audience API](https://developer.chrome.com/en/docs/privacy-sandbox/fledge/) traffic, follow Prebid's documentation on [fledgeForGpt](https://docs.prebid.org/dev-docs/modules/fledgeForGpt.html) module to build and enable Fledge. + Additional Information ====================== diff --git a/test/spec/modules/ixBidAdapter_spec.js b/test/spec/modules/ixBidAdapter_spec.js index 853215d95ad..eb87f51b6f9 100644 --- a/test/spec/modules/ixBidAdapter_spec.js +++ b/test/spec/modules/ixBidAdapter_spec.js @@ -188,6 +188,35 @@ describe('IndexexchangeAdapter', function () { } ]; + const DEFAULT_BANNER_VALID_BID_WITH_FLEDGE_ENABLED = [ + { + bidder: 'ix', + params: { + siteId: '123', + size: [300, 250] + }, + sizes: [[300, 250], [300, 600]], + mediaTypes: { + banner: { + sizes: [[300, 250], [300, 600]], + pos: 0 + } + }, + ortb2Imp: { + ext: { + tid: '173f49a8-7549-4218-a23c-e7ba59b47229', + ae: 1 // Fledge enabled + }, + }, + adUnitCode: 'div-fledge-ad-1460505748561-0', + transactionId: '173f49a8-7549-4218-a23c-e7ba59b47229', + bidId: '1a2b3c4d', + bidderRequestId: '11a22b33c44d', + auctionId: '1aa2bb3cc4dd', + schain: SAMPLE_SCHAIN + } + ]; + const DEFAULT_BANNER_VALID_BID_PARAM_NO_SIZE = [ { bidder: 'ix', @@ -735,6 +764,49 @@ describe('IndexexchangeAdapter', function () { } }; + const DEFAULT_OPTION_FLEDGE_ENABLED_GLOBALLY = { + gdprConsent: { + gdprApplies: true, + consentString: '3huaa11=qu3198ae', + vendorData: {} + }, + refererInfo: { + page: 'https://www.prebid.org', + canonicalUrl: 'https://www.prebid.org/the/link/to/the/page' + }, + ortb2: { + site: { + page: 'https://www.prebid.org' + }, + source: { + tid: 'mock-tid' + } + }, + fledgeEnabled: true, + defaultForSlots: 1 + }; + + const DEFAULT_OPTION_FLEDGE_ENABLED = { + gdprConsent: { + gdprApplies: true, + consentString: '3huaa11=qu3198ae', + vendorData: {} + }, + refererInfo: { + page: 'https://www.prebid.org', + canonicalUrl: 'https://www.prebid.org/the/link/to/the/page' + }, + ortb2: { + site: { + page: 'https://www.prebid.org' + }, + source: { + tid: 'mock-tid' + } + }, + fledgeEnabled: true + }; + const DEFAULT_IDENTITY_RESPONSE = { IdentityIp: { responsePending: false, @@ -3146,6 +3218,71 @@ describe('IndexexchangeAdapter', function () { }); }); + describe('buildRequestFledge', function () { + it('impression should have ae=1 in ext when fledge module is enabled and ae is set in ad unit', function () { + const bidderRequest = deepClone(DEFAULT_OPTION_FLEDGE_ENABLED); + const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID_WITH_FLEDGE_ENABLED[0]); + const requestBidFloor = spec.buildRequests([bid], bidderRequest)[0]; + const impression = extractPayload(requestBidFloor).imp[0]; + + expect(impression.ext.ae).to.equal(1); + }); + + it('impression should have ae=1 in ext when fledge module is enabled globally and default is set through setConfig', function () { + const bidderRequest = deepClone(DEFAULT_OPTION_FLEDGE_ENABLED_GLOBALLY); + const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); + const requestBidFloor = spec.buildRequests([bid], bidderRequest)[0]; + const impression = extractPayload(requestBidFloor).imp[0]; + + expect(impression.ext.ae).to.equal(1); + }); + + it('impression should have ae=1 in ext when fledge module is enabled globally but no default set through setConfig but set at ad unit level', function () { + const bidderRequest = deepClone(DEFAULT_OPTION_FLEDGE_ENABLED); + const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID_WITH_FLEDGE_ENABLED[0]); + const requestBidFloor = spec.buildRequests([bid], bidderRequest)[0]; + const impression = extractPayload(requestBidFloor).imp[0]; + + expect(impression.ext.ae).to.equal(1); + }); + + it('impression should not have ae=1 in ext when fledge module is enabled globally through setConfig but overidden at ad unit level', function () { + const bidderRequest = deepClone(DEFAULT_OPTION_FLEDGE_ENABLED); + const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); + const requestBidFloor = spec.buildRequests([bid], bidderRequest)[0]; + const impression = extractPayload(requestBidFloor).imp[0]; + + expect(impression.ext.ae).to.be.undefined; + }); + + it('impression should not have ae=1 in ext when fledge module is disabled', function () { + const bidderRequest = deepClone(DEFAULT_OPTION); + const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); + const requestBidFloor = spec.buildRequests([bid], bidderRequest)[0]; + const impression = extractPayload(requestBidFloor).imp[0]; + + expect(impression.ext.ae).to.be.undefined; + }); + + it('should contain correct IXdiag ae property for Fledge', function () { + const bid = DEFAULT_BANNER_VALID_BID_WITH_FLEDGE_ENABLED[0]; + const bidderRequestWithFledgeEnabled = deepClone(DEFAULT_OPTION_FLEDGE_ENABLED); + const request = spec.buildRequests([bid], bidderRequestWithFledgeEnabled); + const diagObj = extractPayload(request[0]).ext.ixdiag; + expect(diagObj.ae).to.equal(true); + }); + + it('should log warning for non integer auction environment in ad unit for fledge', () => { + const logWarnSpy = sinon.spy(utils, 'logWarn'); + const bid = DEFAULT_BANNER_VALID_BID_WITH_FLEDGE_ENABLED[0]; + bid.ortb2Imp.ext.ae = 'malformed' + const bidderRequestWithFledgeEnabled = deepClone(DEFAULT_OPTION_FLEDGE_ENABLED); + spec.buildRequests([bid], bidderRequestWithFledgeEnabled); + expect(logWarnSpy.calledWith('error setting auction environment flag - must be an integer')).to.be.true; + logWarnSpy.restore(); + }); + }); + describe('interpretResponse', function () { // generate bidderRequest with real buildRequest logic for intepretResponse testing let bannerBidderRequest @@ -3669,6 +3806,140 @@ describe('IndexexchangeAdapter', function () { const result = spec.interpretResponse({ body: DEFAULT_NATIVE_BID_RESPONSE }, nativeBidderRequest); expect(result[0]).to.deep.equal(expectedParse[0]); }); + + describe('Auction config response', function () { + let bidderRequestWithFledgeEnabled; + let serverResponseWithoutFledgeConfigs; + let serverResponseWithFledgeConfigs; + let serverResponseWithMalformedAuctionConfig; + let serverResponseWithMalformedAuctionConfigs; + + beforeEach(() => { + bidderRequestWithFledgeEnabled = spec.buildRequests(DEFAULT_BANNER_VALID_BID_WITH_FLEDGE_ENABLED, {})[0]; + bidderRequestWithFledgeEnabled.fledgeEnabled = true; + + serverResponseWithoutFledgeConfigs = { + body: { + ...DEFAULT_BANNER_BID_RESPONSE + } + }; + + serverResponseWithFledgeConfigs = { + body: { + ...DEFAULT_BANNER_BID_RESPONSE, + ext: { + protectedAudienceAuctionConfigs: [ + { + bidId: '59f219e54dc2fc', + config: { + seller: 'https://seller.test.indexexchange.com', + decisionLogicUrl: 'https://seller.test.indexexchange.com/decision-logic.js', + interestGroupBuyers: ['https://buyer.test.indexexchange.com'], + sellerSignals: { + callbackURL: 'https://test.com/ig/v1/ck74j8bcvc9c73a8eg6g' + }, + perBuyerSignals: { + 'https://buyer.test.indexexchange.com': {} + } + } + } + ] + } + } + }; + + serverResponseWithMalformedAuctionConfig = { + body: { + ...DEFAULT_BANNER_BID_RESPONSE, + ext: { + protectedAudienceAuctionConfigs: ['malformed'] + } + } + }; + + serverResponseWithMalformedAuctionConfigs = { + body: { + ...DEFAULT_BANNER_BID_RESPONSE, + ext: { + protectedAudienceAuctionConfigs: 'malformed' + } + } + }; + }); + + it('should correctly interpret response with auction configs', () => { + const result = spec.interpretResponse(serverResponseWithFledgeConfigs, bidderRequestWithFledgeEnabled); + const expectedOutput = [ + { + bidId: '59f219e54dc2fc', + config: { + ...serverResponseWithFledgeConfigs.body.ext.protectedAudienceAuctionConfigs[0].config, + perBuyerSignals: { + 'https://buyer.test.indexexchange.com': {} + } + } + } + ]; + expect(result.fledgeAuctionConfigs).to.deep.equal(expectedOutput); + }); + + it('should correctly interpret response without auction configs', () => { + const result = spec.interpretResponse(serverResponseWithoutFledgeConfigs, bidderRequestWithFledgeEnabled); + expect(result.fledgeAuctionConfigs).to.be.undefined; + }); + + it('should handle malformed auction configs gracefully', () => { + const result = spec.interpretResponse(serverResponseWithMalformedAuctionConfig, bidderRequestWithFledgeEnabled); + expect(result.fledgeAuctionConfigs).to.be.empty; + }); + + it('should log warning for malformed auction configs', () => { + const logWarnSpy = sinon.spy(utils, 'logWarn'); + spec.interpretResponse(serverResponseWithMalformedAuctionConfig, bidderRequestWithFledgeEnabled); + expect(logWarnSpy.calledWith('Malformed auction config detected:', 'malformed')).to.be.true; + logWarnSpy.restore(); + }); + + it('should return bids when protected audience auction conigs is malformed', () => { + const result = spec.interpretResponse(serverResponseWithMalformedAuctionConfigs, bidderRequestWithFledgeEnabled); + expect(result.fledgeAuctionConfigs).to.be.undefined; + expect(result.length).to.be.greaterThan(0); + }); + }); + + describe('interpretResponse when server response is empty', function() { + let serverResponseWithoutBody; + let serverResponseWithoutSeatbid; + let bidderRequestWithFledgeEnabled; + let bidderRequestWithoutFledgeEnabled; + + beforeEach(() => { + serverResponseWithoutBody = {}; + + serverResponseWithoutSeatbid = { + body: {} + }; + + bidderRequestWithFledgeEnabled = spec.buildRequests(DEFAULT_BANNER_VALID_BID_WITH_FLEDGE_ENABLED, {})[0]; + bidderRequestWithFledgeEnabled.fledgeEnabled = true; + + bidderRequestWithoutFledgeEnabled = spec.buildRequests(DEFAULT_BANNER_VALID_BID, {})[0]; + }); + + it('should return empty bids when response does not have body', function () { + let result = spec.interpretResponse(serverResponseWithoutBody, bidderRequestWithFledgeEnabled); + expect(result).to.deep.equal([]); + result = spec.interpretResponse(serverResponseWithoutBody, bidderRequestWithoutFledgeEnabled); + expect(result).to.deep.equal([]); + }); + + it('should return empty bids when response body does not have seatbid', function () { + let result = spec.interpretResponse(serverResponseWithoutSeatbid, bidderRequestWithFledgeEnabled); + expect(result).to.deep.equal([]); + result = spec.interpretResponse(serverResponseWithoutSeatbid, bidderRequestWithoutFledgeEnabled); + expect(result).to.deep.equal([]); + }); + }); }); describe('bidrequest consent', function () {