Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yahoo bid adapter: User sync pixels, consent signals update #10028

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions modules/yahoosspBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,37 @@ function extractUserSyncUrls(syncOptions, pixels) {
return userSyncObjects;
}

/**
* @param {string} url
* @param {object} consentData
* @param {object} consentData.gpp
* @param {string} consentData.gpp.gppConsent
* @param {array} consentData.gpp.applicableSections
* @param {object} consentData.gdpr
* @param {object} consentData.gdpr.consentString
* @param {object} consentData.gdpr.gdprApplies
* @param {string} consentData.uspConsent
*/
function updateConsentQueryParams(url, consentData) {
const parameterMap = {
'gdpr_consent': consentData.gdpr.consentString,
'gdpr': consentData.gdpr.gdprApplies ? '1' : '0',
'us_privacy': consentData.uspConsent,
'gpp': consentData.gpp.gppString,
'gpp_sid': consentData.gpp.applicableSections ? consentData.gpp.applicableSections.join(',') : ''
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here as well I think you need to add safe checks because thee gdpr, gpp and uspConent objects might be undefined or null

  const parameterMap = {
    'gdpr_consent': consentData.gdpr?.consentString,
    'gdpr': consentData.gdpr?.gdprApplies ? '1' : '0',
    'us_privacy': consentData?.uspConsent,
    'gpp': consentData.gpp?.gppString,
    'gpp_sid': consentData.gpp?.applicableSections ? consentData.gpp.applicableSections.join(',') : ''
  }

Something like that, (not tested)


const existingUrl = new URL(url);
const params = existingUrl.searchParams;

for (const [key, value] of Object.entries(parameterMap)) {
params.set(key, value);
}

existingUrl.search = params.toString();
return existingUrl.toString();
};

function getSupportedEids(bid) {
if (isArray(deepAccess(bid, 'userIdAsEids'))) {
return bid.userIdAsEids.filter(eid => {
Expand Down Expand Up @@ -244,7 +275,9 @@ function generateOpenRtbObject(bidderRequest, bid) {
regs: {
ext: {
'us_privacy': bidderRequest.uspConsent ? bidderRequest.uspConsent : '',
gdpr: bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies ? 1 : 0
gdpr: bidderRequest.gdprConsent && bidderRequest.gdprConsent.gdprApplies ? 1 : 0,
gpp: bidderRequest.gppConsent.gppString,
gpp_sid: bidderRequest.gppConsent.applicableSections
Copy link
Collaborator

@robertrmartinez robertrmartinez Jul 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slimkrazy

Hi, I work for Magnite and during version testing between 7.50.0 and 7.54.0 we noticed many of our pubs had yahoossp bids stop filling.

This is the only PR for the bid adapter during that time and I think it might point to this spot here

The object gppConsent is not guaranteed to be defined.

For example on one of our publisher sites we see it throws the following error:

image

An easy fix for this is to change this to be like so:

          gpp: bidderRequest.gppConsent?.gppString,
          gpp_sid: bidderRequest.gppConsent?.applicableSections

Let me know if this makes sense.

I tested it using Chrome Overrides and can see bid requests going out now:

image

CC @patmmccann

}
},
source: {
Expand Down Expand Up @@ -518,6 +551,7 @@ function createRenderer(bidderRequest, bidResponse) {
}
return renderer;
}

/* Utility functions */

export const spec = {
Expand Down Expand Up @@ -634,11 +668,19 @@ export const spec = {
return response;
},

getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) {
getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent, gppConsent) {
const bidResponse = !isEmpty(serverResponses) && serverResponses[0].body;

if (bidResponse && bidResponse.ext && bidResponse.ext.pixels) {
return extractUserSyncUrls(syncOptions, bidResponse.ext.pixels);
const userSyncObjects = extractUserSyncUrls(syncOptions, bidResponse.ext.pixels);
userSyncObjects.forEach(userSyncObject => {
userSyncObject.url = updateConsentQueryParams(userSyncObject.url, {
gpp: gppConsent,
gdpr: gdprConsent,
uspConsent: uspConsent
});
});
return userSyncObjects;
}

return [];
Expand Down
2 changes: 1 addition & 1 deletion modules/yahoosspBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,6 @@ const adUnits = [{
This adapter does not support passing legacy overrides via 'bidder.params.ext' since most of the data should be passed using prebid modules (First Party Data, Schain, Price Floors etc.).
If you do not know how to pass a custom parameter that you previously used, please contact us using the information provided above.

Thanks you,
Thank you,
Yahoo SSP

154 changes: 103 additions & 51 deletions test/spec/modules/yahoosspBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,16 @@ let generateBidderRequest = (bidRequestArray, adUnitCode, ortb2 = {}) => {
numIframes: 0,
stack: ['https://publisher-test.com'],
},
uspConsent: '1-Y-',
gdprConsent: {
consentString: 'BOtmiBKOtmiBKABABAENAFAAAAACeAAA',
vendorData: {},
gdprApplies: true
},
gppConsent: {
gppString: 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN',
applicableSections: [1, 2, 3]
},
start: new Date().getTime(),
timeout: 1000,
ortb2
Expand Down Expand Up @@ -177,11 +182,6 @@ const generateResponseMock = (admPayloadType, vastVersion, videoContext) => {

// Unit tests
describe('YahooSSP Bid Adapter:', () => {
it('PLACEHOLDER TO PASS GULP', () => {
const obj = {};
expect(obj).to.be.an('object');
});

describe('Validate basic properties', () => {
it('should define the correct bidder code', () => {
expect(spec.code).to.equal('yahoossp')
Expand All @@ -193,70 +193,112 @@ describe('YahooSSP Bid Adapter:', () => {
});

describe('getUserSyncs()', () => {
const IMAGE_PIXEL_URL = 'http://image-pixel.com/foo/bar?1234&baz=true';
const IFRAME_ONE_URL = 'http://image-iframe.com/foo/bar?1234&baz=true';
const IMAGE_PIXEL_URL = 'http://image-pixel.com/foo/bar?1234&baz=true&gdpr=foo&gdpr_consent=bar';
const IFRAME_ONE_URL = 'http://image-iframe.com/foo/bar?1234&baz=true&us_privacy=hello&gpp=goodbye';
const IFRAME_TWO_URL = 'http://image-iframe-two.com/foo/bar?1234&baz=true';

let serverResponses = [];
beforeEach(() => {
serverResponses[0] = {
body: {
ext: {
pixels: `<script>document.write('<iframe src="${IFRAME_ONE_URL}"></iframe>` +
`<img src="${IMAGE_PIXEL_URL}"></iframe>` +
`<iframe src="${IFRAME_TWO_URL}"></iframe>');</script>`
}
const SERVER_RESPONSES = [{
body: {
ext: {
pixels: `<script>document.write('<iframe src="${IFRAME_ONE_URL}"></iframe>` +
`<img src="${IMAGE_PIXEL_URL}"></iframe>` +
`<iframe src="${IFRAME_TWO_URL}"></iframe>');</script>`
}
}
});

after(() => {
serverResponses = undefined;
});
}];
const bidderRequest = generateBuildRequestMock({}).bidderRequest;

it('for only iframe enabled syncs', () => {
let syncOptions = {
iframeEnabled: true,
pixelEnabled: false
};
let pixelsObjects = spec.getUserSyncs(syncOptions, serverResponses);
expect(pixelsObjects.length).to.equal(2);
expect(pixelsObjects).to.deep.equal(
[
{type: 'iframe', 'url': IFRAME_ONE_URL},
{type: 'iframe', 'url': IFRAME_TWO_URL}
]
)
let pixelObjects = spec.getUserSyncs(
syncOptions,
SERVER_RESPONSES,
bidderRequest.gdprConsent,
bidderRequest.uspConsent,
bidderRequest.gppConsent
);
expect(pixelObjects.length).to.equal(2);

pixelObjects.forEach(pixelObject => {
expect(pixelObject).to.have.all.keys('type', 'url');
expect(pixelObject.type).to.equal('iframe');
});
});

it('for only pixel enabled syncs', () => {
let syncOptions = {
iframeEnabled: false,
pixelEnabled: true
};
let pixelsObjects = spec.getUserSyncs(syncOptions, serverResponses);
expect(pixelsObjects.length).to.equal(1);
expect(pixelsObjects).to.deep.equal(
[
{type: 'image', 'url': IMAGE_PIXEL_URL}
]
)
let pixelObjects = spec.getUserSyncs(
syncOptions,
SERVER_RESPONSES,
bidderRequest.gdprConsent,
bidderRequest.uspConsent,
bidderRequest.gppConsent
);
expect(pixelObjects.length).to.equal(1);
expect(pixelObjects[0]).to.have.all.keys('type', 'url');
expect(pixelObjects[0].type).to.equal('image');
});

it('for both pixel and iframe enabled syncs', () => {
let syncOptions = {
iframeEnabled: true,
pixelEnabled: true
};
let pixelsObjects = spec.getUserSyncs(syncOptions, serverResponses);
expect(pixelsObjects.length).to.equal(3);
expect(pixelsObjects).to.deep.equal(
[
{type: 'iframe', 'url': IFRAME_ONE_URL},
{type: 'image', 'url': IMAGE_PIXEL_URL},
{type: 'iframe', 'url': IFRAME_TWO_URL}
]
)
let pixelObjects = spec.getUserSyncs(
syncOptions,
SERVER_RESPONSES,
bidderRequest.gdprConsent,
bidderRequest.uspConsent,
bidderRequest.gppConsent
);
expect(pixelObjects.length).to.equal(3);
let iframeCount = 0;
let imageCount = 0;
pixelObjects.forEach(pixelObject => {
if (pixelObject.type == 'iframe') {
iframeCount++;
} else if (pixelObject.type == 'image') {
imageCount++;
}
});
expect(iframeCount).to.equal(2);
expect(imageCount).to.equal(1);
});

describe('user consent parameters are updated', () => {
let syncOptions = {
iframeEnabled: true,
pixelEnabled: true
};
let pixelObjects = spec.getUserSyncs(
syncOptions,
SERVER_RESPONSES,
bidderRequest.gdprConsent,
bidderRequest.uspConsent,
bidderRequest.gppConsent
);
pixelObjects.forEach(pixelObject => {
let url = pixelObject.url;
let urlParams = new URL(url).searchParams;
const expectedParams = {
'baz': 'true',
'gdpr_consent': bidderRequest.gdprConsent.consentString,
'gdpr': bidderRequest.gdprConsent.gdprApplies ? '1' : '0',
'us_privacy': bidderRequest.uspConsent,
'gpp': bidderRequest.gppConsent.gppString,
'gpp_sid': Array.isArray(bidderRequest.gppConsent.applicableSections) ? bidderRequest.gppConsent.applicableSections.join(',') : ''
}
for (const [key, value] of Object.entries(expectedParams)) {
it(`Updates the ${key} consent param in user sync URL ${url}`, () => {
expect(urlParams.get(key)).to.equal(value);
});
};
});
});
});

Expand Down Expand Up @@ -749,7 +791,15 @@ describe('YahooSSP Bid Adapter:', () => {
expect(options.withCredentials).to.be.false;
});

it('adds the ortb2 gpp consent info to the request', function () {
it('set the GPP consent data from the data within the bid request', function () {
const { validBidRequests, bidderRequest } = generateBuildRequestMock({});
let clonedBidderRequest = {...bidderRequest};
const data = spec.buildRequests(validBidRequests, clonedBidderRequest)[0].data;
expect(data.regs.ext.gpp).to.equal(bidderRequest.gppConsent.gppString);
expect(data.regs.ext.gpp_sid).to.eql(bidderRequest.gppConsent.applicableSections);
});

it('overrides the GPP consent data using data from the ortb2 config object', function () {
const { validBidRequests, bidderRequest } = generateBuildRequestMock({});
const ortb2 = {
regs: {
Expand All @@ -759,8 +809,8 @@ describe('YahooSSP Bid Adapter:', () => {
};
let clonedBidderRequest = {...bidderRequest, ortb2};
const data = spec.buildRequests(validBidRequests, clonedBidderRequest)[0].data;
expect(data.regs.ext.gpp).to.equal('somegppstring');
expect(data.regs.ext.gpp_sid).to.eql([6, 7]);
expect(data.regs.ext.gpp).to.equal(ortb2.regs.gpp);
expect(data.regs.ext.gpp_sid).to.eql(ortb2.regs.gpp_sid);
});
});

Expand Down Expand Up @@ -930,8 +980,10 @@ describe('YahooSSP Bid Adapter:', () => {

expect(data.regs).to.deep.equal({
ext: {
'us_privacy': '',
gdpr: 1
'us_privacy': bidderRequest.uspConsent,
gdpr: 1,
gpp: bidderRequest.gppConsent.gppString,
gpp_sid: bidderRequest.gppConsent.applicableSections
}
});

Expand Down