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

Taboola Bid Adapter: fix ortb2 user override issue #11516

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
49 changes: 26 additions & 23 deletions modules/taboolaBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const userData = {
return tblaId;
}
}
return undefined;
},
getCookieDataByKey(cookieData, key) {
if (!cookieData) {
Expand All @@ -78,6 +79,7 @@ export const userData = {
if (hasLocalStorage() && localStorageIsEnabled()) {
return getDataFromLocalStorage(STORAGE_KEY);
}
return undefined;
},
getFromTRC() {
return window.TRC ? window.TRC.user_id : 0;
Expand Down Expand Up @@ -271,35 +273,38 @@ function getSiteProperties({publisherId}, refererInfo, ortb2) {
function fillTaboolaReqData(bidderRequest, bidRequest, data) {
const {refererInfo, gdprConsent = {}, uspConsent} = bidderRequest;
const site = getSiteProperties(bidRequest.params, refererInfo, bidderRequest.ortb2);
const device = {ua: navigator.userAgent};
let user = {
buyeruid: userData.getUserId(gdprConsent, uspConsent),
ext: {}
};
if (bidderRequest && bidderRequest.ortb2 && bidderRequest.ortb2.user) {
user.data = bidderRequest.ortb2.user.data;
deepSetValue(data, 'device.ua', navigator.userAgent);
const extractedUserId = userData.getUserId(gdprConsent, uspConsent);
if (data.user == undefined) {
data.user = {
buyeruid: 0,
ext: {}
}
}
const regs = {
coppa: 0,
ext: {}
};

if (extractedUserId && extractedUserId !== 0) {
deepSetValue(data, 'user.buyeruid', extractedUserId);
}
if (data.regs?.ext == undefined) {
data.regs = {
ext: {}
}
}
deepSetValue(data, 'regs.coppa', 0);
if (gdprConsent.gdprApplies) {
user.ext.consent = bidderRequest.gdprConsent.consentString;
regs.ext.gdpr = 1;
deepSetValue(data, 'user.ext.consent', bidderRequest.gdprConsent.consentString);
deepSetValue(data, 'regs.ext.gdpr', 1);
}

if (uspConsent) {
regs.ext.us_privacy = uspConsent;
deepSetValue(data, 'regs.ext.us_privacy', uspConsent);
}

if (bidderRequest.ortb2?.regs?.gpp) {
regs.ext.gpp = bidderRequest.ortb2.regs.gpp;
regs.ext.gpp_sid = bidderRequest.ortb2.regs.gpp_sid;
deepSetValue(data, 'regs.ext.gpp', bidderRequest.ortb2.regs.gpp);
deepSetValue(data, 'regs.ext.gpp_sid', bidderRequest.ortb2.regs.gpp_sid);
}

if (config.getConfig('coppa')) {
regs.coppa = 1;
deepSetValue(data, 'regs.coppa', 1);
}

const ortb2 = bidderRequest.ortb2 || {
Expand All @@ -308,16 +313,14 @@ function fillTaboolaReqData(bidderRequest, bidRequest, data) {
wlang: []
};

deepSetValue(data, 'source.fd', 1);

data.id = bidderRequest.bidderRequestId;
data.site = site;
data.device = device;
data.source = {fd: 1};
data.tmax = (bidderRequest.timeout == undefined) ? undefined : parseInt(bidderRequest.timeout);
data.bcat = ortb2.bcat || bidRequest.params.bcat || [];
data.badv = ortb2.badv || bidRequest.params.badv || [];
data.wlang = ortb2.wlang || bidRequest.params.wlang || [];
data.user = user;
data.regs = regs;
deepSetValue(data, 'ext.pageType', ortb2?.ext?.data?.pageType || ortb2?.ext?.data?.section || bidRequest.params.pageType);
deepSetValue(data, 'ext.prebid.version', '$prebid.version$');
}
Expand Down
18 changes: 11 additions & 7 deletions test/spec/modules/taboolaBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ describe('Taboola Adapter', function () {
}],
id: 'mock-uuid',
'test': 0,
'device': {'ua': navigator.userAgent},
'user': {
'buyeruid': 0,
'ext': {},
},
'regs': {'ext': {}, 'coppa': 0},
'source': {'fd': 1},
'site': {
'id': commonBidRequest.params.publisherId,
'name': commonBidRequest.params.publisherId,
Expand All @@ -208,16 +215,9 @@ describe('Taboola Adapter', function () {
'publisher': {'id': commonBidRequest.params.publisherId},
'content': {'language': navigator.language}
},
'device': {'ua': navigator.userAgent},
'source': {'fd': 1},
'bcat': [],
'badv': [],
'wlang': [],
'user': {
'buyeruid': 0,
'ext': {},
},
'regs': {'coppa': 0, 'ext': {}},
'ext': {
'prebid': {
'version': '$prebid.version$'
Expand Down Expand Up @@ -363,12 +363,16 @@ describe('Taboola Adapter', function () {
bcat: ['EX1', 'EX2', 'EX3'],
badv: ['site.com'],
wlang: ['de'],
user: {
id: 'externalUserIdPassed'
}
}
}
const res = spec.buildRequests([defaultBidRequest], bidderRequest);
expect(res.data.bcat).to.deep.equal(bidderRequest.ortb2.bcat)
expect(res.data.badv).to.deep.equal(bidderRequest.ortb2.badv)
expect(res.data.wlang).to.deep.equal(bidderRequest.ortb2.wlang)
expect(res.data.user.id).to.deep.equal(bidderRequest.ortb2.user.id)
ahmadlob marked this conversation as resolved.
Show resolved Hide resolved
});

it('should pass pageType if exists in ortb2', function () {
Expand Down