please add support for deferS2Sbidders as described in the issue
Assistant
To add support for the deferS2Sbidders flag in the TCF Control module as described in the issue, we need to modify the GDPR enforcement mechanism in Prebid.js. This will involve enhancing the consent management module to account for the new deferS2Sbidders configuration and implementing the logic to defer server-side bidders when specific TCF rules (like basicAds) are enforced.
Below is a step-by-step guide on how to proceed with this implementation:
1. Update Configuration Schema
The deferS2Sbidders flag needs to be added under the rules for consent enforcement in the consentManagement.gdpr configuration.
Modify the config.js file where configurations are defined and validated:
js
// In ./repos/Prebid.js/src/config.js
const VALID_PURPOSE_RULES = {
enforcePurpose: true,
enforceVendor: true,
deferS2Sbidders: false, // Add the new deferS2Sbidders flag with a default value
};
// Validate rules in the consent configuration
function validateGdprRules(rules) {
if (!Array.isArray(rules)) {
logError('GDPR rules must be an array.');
return false;
}
for (const rule of rules) {
if (!rule.purpose || typeof rule.purpose !== 'string') {
logError('Each GDPR rule must have a "purpose" string.');
return false;
}
// Validate rule properties
for (const key in rule) {
if (!VALID_PURPOSE_RULES.hasOwnProperty(key)) {
logWarn(`Unknown GDPR rule property: ${key}`);
}
}
}
return true;
}
// Add this to the relevant configuration settings
export function newConfig() {
// Add deferS2Sbidders support to the default GDPR configuration
const defaults = {
consentManagement: {
gdpr: {
rules: [
{
purpose: "basicAds",
enforcePurpose: true,
enforceVendor: true,
deferS2Sbidders: false, // Default to false
},
],
},
},
};
// ... (rest of the function)
}
The logic for enforcing GDPR rules should be updated to account for the deferS2Sbidders flag. Specifically, when a rule for basicAds contains deferS2Sbidders: true, server-side bidders should not be rejected outright even if their GVL ID is missing.
Update the consent enforcement logic in the gdprEnforcement module:
js
// In ./repos/Prebid.js/src/consentHandler.js
class GdprConsentHandler extends ConsentHandler {
hashFields = ['gdprApplies', 'consentString'];
getConsentMeta() {
const consentData = this.getConsentData();
if (consentData && consentData.vendorData && this.generatedTime) {
return {
gdprApplies: consentData.gdprApplies,
consentStringSize: (isStr(consentData.vendorData.tcString)) ? consentData.vendorData.tcString.length : 0,
generatedAt: this.generatedTime,
apiVersion: consentData.apiVersion,
};
}
}
enforceGDPRRules(bidder, rules) {
const consentData = this.getConsentData();
for (const rule of rules) {
if (rule.purpose === 'basicAds' && rule.deferS2Sbidders) {
// If deferS2Sbidders is true, skip enforcement for server-side bidders
if (isServerSideBidder(bidder)) {
logWarn(`Deferring enforcement of basicAds for server-side bidder: ${bidder}`);
continue;
}
}
// Other enforcement logic here
if (!this.isPurposeAllowed(rule.purpose, consentData)) {
logError(`Bidder ${bidder} not allowed for purpose: ${rule.purpose}`);
return false; // Block the bidder
}
}
return true; // Allow the bidder
}
}
// Utility function to determine if a bidder is server-side
function isServerSideBidder(bidder) {
// Logic to check if the bidder is server-side
// This may involve checking if the bidder is part of the S2S adapter configuration
return config.getConfig('s2sConfig')?.bidders?.includes(bidder);
}
3. Integrate with GDPR Enforcement Module
Ensure that the enforceGDPRRules method is called during the auction to evaluate the consent data and apply the rules.
js
// In ./repos/Prebid.js/src/enforcement/gdpr.js
import {gdprDataHandler} from '../consentHandler.js';
function enforceGDPR(bidderRequest) {
const rules = config.getConfig('consentManagement.gdpr.rules');
const gdprHandler = gdprDataHandler;
for (const bid of bidderRequest.bids) {
const bidder = bid.bidder;
// Enforce GDPR rules for each bidder
if (!gdprHandler.enforceGDPRRules(bidder, rules)) {
logWarn(`Bidder ${bidder} rejected due to GDPR restrictions.`);
// Remove the bidder from the auction
bidderRequest.bids = bidderRequest.bids.filter(b => b.bidder !== bidder);
}
}
}
4. Add Unit Tests
Add tests to validate the implementation of deferS2Sbidders.
js
// In ./test/unit/consentHandler_spec.js
describe('GdprConsentHandler', function () {
it('should allow server-side bidders when deferS2Sbidders is true', function () {
const handler = new GdprConsentHandler();
handler.setConsentData({ gdprApplies: true, vendorData: {} });
const rules = [
{ purpose: 'basicAds', enforcePurpose: true, enforceVendor: true, deferS2Sbidders: true }
];
const isAllowed = handler.enforceGDPRRules('serverSideBidder', rules);
expect(isAllowed).to.be.true;
});
it('should block server-side bidders when deferS2Sbidders is false', function () {
const handler = new GdprConsentHandler();
handler.setConsentData({ gdprApplies: true, vendorData: {} });
const rules = [
{ purpose: 'basicAds', enforcePurpose: true, enforceVendor: true, deferS2Sbidders: false }
];
const isAllowed = handler.enforceGDPRRules('serverSideBidder', rules);
expect(isAllowed).to.be.false;
});
});
5. Documentation Update
Update the Prebid.js documentation to describe the new deferS2Sbidders configuration option, its purpose, and usage.
This implementation ensures that server-side bidders are deferred for enforcement when deferS2Sbidders is enabled, addressing the issue described.
Thanks for pointing that out! Since the tcfControl module is the appropriate place to handle this logic, we will update it to support the new deferS2Sbidders configuration. Here's how we can modify the tcfControl module to include this feature:
1. Update the tcfControl Module Configuration
Add support for the deferS2Sbidders flag in the module's configuration, ensuring it works as part of the TCF rule enforcement for server-side bidders.
js
// In modules/tcfControl.js
import { config } from '../src/config.js';
import { logWarn, logInfo } from '../src/utils.js';
import { getGlobal } from '../src/prebidGlobal.js';
export const MODULE_NAME = 'tcfControl';
const DEFAULT_RULES = [{
purpose: 'basicAds',
enforcePurpose: true,
enforceVendor: true,
deferS2Sbidders: false, // Add the deferS2Sbidders flag with default as false
}, {
purpose: 'personalizedAds',
enforcePurpose: true,
enforceVendor: true,
}, {
purpose: 'transmitPreciseGeo',
enforcePurpose: true,
enforceVendor: true,
}];
// Utility function to check if a bidder is server-side
function isServerSideBidder(bidder) {
const s2sConfig = config.getConfig('s2sConfig') || {};
return s2sConfig.bidders && s2sConfig.bidders.includes(bidder);
}
// Function to enforce TCF rules for a bidder
function enforceTCF(bidder, rules, gdprData) {
for (const rule of rules) {
if (rule.purpose === 'basicAds' && rule.deferS2Sbidders) {
if (isServerSideBidder(bidder)) {
logWarn(`${MODULE_NAME}: Deferring TCF enforcement for server-side bidder: ${bidder}`);
continue; // Skip enforcement for server-side bidders
}
}
// Check purpose enforcement
if (rule.enforcePurpose && !gdprData.purposeAllowed[rule.purpose]) {
logWarn(`${MODULE_NAME}: Bidder ${bidder} blocked for purpose: ${rule.purpose}`);
return false; // Block the bidder
}
// Check vendor enforcement
if (rule.enforceVendor && !gdprData.vendorAllowed[bidder]) {
logWarn(`${MODULE_NAME}: Bidder ${bidder} blocked due to vendor restrictions.`);
return false; // Block the bidder
}
}
return true; // Allow the bidder
}
// Main function to process bidders based on TCF rules
export function processBidders(bidderRequests, gdprData) {
const rules = config.getConfig('consentManagement.gdpr.rules') || DEFAULT_RULES;
bidderRequests.forEach((bidderRequest) => {
bidderRequest.bids = bidderRequest.bids.filter(bid => {
const isAllowed = enforceTCF(bid.bidder, rules, gdprData);
if (!isAllowed) {
logInfo(`${MODULE_NAME}: Bidder ${bid.bidder} removed due to TCF enforcement.`);
}
return isAllowed;
});
});
}
// Hook to integrate with Prebid.js auction flow
export function initTcfControl() {
const pbjs = getGlobal();
pbjs.onEvent('auctionInit', (auctionDetails) => {
const gdprData = pbjs.getConsentData() || {};
if (gdprData && gdprData.gdprApplies) {
processBidders(auctionDetails.bidderRequests, gdprData);
}
});
}
initTcfControl();
2. How It Works
deferS2Sbidders Handling:
If a rule has deferS2Sbidders: true and the bidder is a server-side bidder, the enforcement for that bidder is skipped for the basicAds purpose.
For all other purposes or if deferS2Sbidders is false, the standard TCF enforcement applies.
Integration with Auction Flow:
The processBidders function is called during the auctionInit event, ensuring that any blocked bidders are filtered out before the auction starts.
3. Unit Tests
Add unit tests to verify the behavior of deferS2Sbidders in the tcfControl module.
Add deferS2Sbidders as a new configuration option under consentManagement.gdpr.rules.
Explain its purpose and provide an example configuration.
md
#### deferS2Sbidders
- **Type**: Boolean
- **Default**: `false`
- **Description**: When set to `true` for the `basicAds` purpose, server-side bidders are deferred from TCF enforcement. This allows publishers to avoid blocking server-side bidders that lack GVL IDs.
Example:
```js
pbjs.setConfig({
consentManagement: {
gdpr: {
rules: [{
purpose: "basicAds",
enforcePurpose: true,
enforceVendor: true,
deferS2Sbidders: true // Enable deferral for server-side bidders
}]
}
}
});
code
---
This implementation ensures that the `deferS2Sbidders` flag is handled appropriately, deferring TCF enforcement for server-side bidders when necessary.