Skip to content

Commit

Permalink
Set default result of consent check to undefined (prebid#10327)
Browse files Browse the repository at this point in the history
  • Loading branch information
johanbrandmetrics authored and Santiago Carabone committed Aug 22, 2023
1 parent 728a21a commit da65447
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 27 deletions.
57 changes: 30 additions & 27 deletions modules/brandmetricsRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ let billableEventsInitialized = false

function init (config, userConsent) {
const hasConsent = checkConsent(userConsent)
const initialize = hasConsent !== false

if (hasConsent) {
if (initialize) {
const moduleConfig = getMergedConfig(config)
initializeBrandmetrics(moduleConfig.params.scriptId)
initializeBillableEvents()
}
return hasConsent
return initialize
}

/**
Expand All @@ -36,33 +37,35 @@ function init (config, userConsent) {
* @returns {boolean}
*/
function checkConsent (userConsent) {
let consent = false

if (userConsent && userConsent.gdpr && userConsent.gdpr.gdprApplies) {
const gdpr = userConsent.gdpr

if (gdpr.vendorData) {
const vendor = gdpr.vendorData.vendor
const purpose = gdpr.vendorData.purpose

let vendorConsent = false
if (vendor.consents) {
vendorConsent = vendor.consents[GVL_ID]
let consent

if (userConsent) {
if (userConsent.gdpr && userConsent.gdpr.gdprApplies) {
const gdpr = userConsent.gdpr

if (gdpr.vendorData) {
const vendor = gdpr.vendorData.vendor
const purpose = gdpr.vendorData.purpose

let vendorConsent = false
if (vendor.consents) {
vendorConsent = vendor.consents[GVL_ID]
}

if (vendor.legitimateInterests) {
vendorConsent = vendorConsent || vendor.legitimateInterests[GVL_ID]
}

const purposes = TCF_PURPOSES.map(id => {
return (purpose.consents && purpose.consents[id]) || (purpose.legitimateInterests && purpose.legitimateInterests[id])
})
const purposesValid = purposes.filter(p => p === true).length === TCF_PURPOSES.length
consent = vendorConsent && purposesValid
}

if (vendor.legitimateInterests) {
vendorConsent = vendorConsent || vendor.legitimateInterests[GVL_ID]
}

const purposes = TCF_PURPOSES.map(id => {
return (purpose.consents && purpose.consents[id]) || (purpose.legitimateInterests && purpose.legitimateInterests[id])
})
const purposesValid = purposes.filter(p => p === true).length === TCF_PURPOSES.length
consent = vendorConsent && purposesValid
} else if (userConsent.usp) {
const usp = userConsent.usp
consent = usp[1] !== 'N' && usp[2] !== 'Y'
}
} else if (userConsent.usp) {
const usp = userConsent.usp
consent = usp[1] !== 'N' && usp[2] !== 'Y'
}

return consent
Expand Down
6 changes: 6 additions & 0 deletions test/spec/modules/brandmetricsRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ const NO_USP_CONSENT = {
usp: '1NYY'
};

const UNDEFINED_USER_CONSENT = {};

function mockSurveyLoaded(surveyConf) {
const commands = window._brandmetrics || [];
commands.forEach(command => {
Expand Down Expand Up @@ -120,6 +122,10 @@ describe('BrandmetricsRTD module', () => {
it('should not init when there is no usp- consent', () => {
expect(brandmetricsRTD.brandmetricsSubmodule.init(VALID_CONFIG, NO_USP_CONSENT)).to.equal(false);
});

it('should init if there are no consent- objects defined', () => {
expect(brandmetricsRTD.brandmetricsSubmodule.init(VALID_CONFIG, UNDEFINED_USER_CONSENT)).to.equal(true);
});
});

describe('getBidRequestData', () => {
Expand Down

0 comments on commit da65447

Please sign in to comment.