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

Revert "NoBid Bid Adapter : add support for first party user id" #10728

Merged
merged 1 commit into from
Nov 14, 2023
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
123 changes: 1 addition & 122 deletions modules/nobidBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@ import { hasPurpose1Consent } from '../src/utils/gpdr.js';
const GVLID = 816;
const BIDDER_CODE = 'nobid';
const storage = getStorageManager({bidderCode: BIDDER_CODE});
window.nobidVersion = '1.4.1';
window.nobidVersion = '1.3.3';
window.nobid = window.nobid || {};
window.nobid.bidResponses = window.nobid.bidResponses || {};
window.nobid.timeoutTotal = 0;
window.nobid.bidWonTotal = 0;
window.nobid.refreshCount = 0;
window.nobid.firstPartyIds = null;
window.nobid.firstPartyIdEnabled = false;
const FIRST_PARTY_KEY = 'fppcid.nobid.io';
const FIRST_PARTY_SOURCE_KEY = 'fpid.nobid.io';
const FIRST_PARTY_DATA_EXPIRY_DAYS = 7 * 24 * 3600 * 1000;
function log(msg, obj) {
logInfo('-NoBid- ' + msg, obj)
}
Expand Down Expand Up @@ -140,10 +135,8 @@ function nobidBuildRequests(bids, bidderRequest) {
src.push({source: eid.source, uids: ids});
}
});
if (window.nobid.firstPartyIds && window.nobid.firstPartyIds) src.push({source: FIRST_PARTY_SOURCE_KEY, uids: [{id: window.nobid.firstPartyIds.ids}]});
return src;
}
if (window.nobid.firstPartyIds && window.nobid.firstPartyIds.ids) return [{source: FIRST_PARTY_SOURCE_KEY, uids: [{id: window.nobid.firstPartyIds.ids}]}];
}
var state = {};
state['sid'] = siteId;
Expand Down Expand Up @@ -293,20 +286,13 @@ function nobidInterpretResponse(response, bidRequest) {
var setRefreshLimit = function(response) {
if (response && typeof response.rlimit !== 'undefined') window.nobid.refreshLimit = response.rlimit;
}
var setFirstPartyIdEnabled = function(response) {
if (response && typeof response.fpid !== 'undefined') window.nobid.firstPartyIdEnabled = response.fpid;
if (window?.nobid?.firstPartyIdEnabled) {
nobidFirstPartyData.loadOrCreateFirstPartyData();
}
}
var setUserBlock = function(response) {
if (response && typeof response.ublock !== 'undefined') {
nobidSetCookie('_ublock', '1', response.ublock);
}
}
setRefreshLimit(response);
setUserBlock(response);
setFirstPartyIdEnabled(response);
var bidResponses = [];
for (var i = 0; response.bids && i < response.bids.length; i++) {
var bid = response.bids[i];
Expand Down Expand Up @@ -373,113 +359,6 @@ window.addEventListener('message', function (event) {
}
}
}, false);
const nobidFirstPartyData = {
isJson: function (str) {
return str && str.startsWith('{') && str.endsWith('}');
},
hasLocalStorage: function () {
try {
return window.localStorage;
} catch (error) {
logWarn('Local storage api disabled', error);
}
return false;
},
readFirstPartyDataIds: function () {
try {
if (this.hasLocalStorage()) {
const idsStr = window.localStorage.getItem(FIRST_PARTY_SOURCE_KEY);
if (this.isJson(idsStr)) {
const idsObj = JSON.parse(idsStr);
if (idsObj.ts + FIRST_PARTY_DATA_EXPIRY_DAYS < Date.now()) return { pid: idsObj.pid }; // expired?
return idsObj;
}
return null;
}
} catch (error) {
logWarn('Local storage api disabled', error);
}
return null;
},
loadOrCreateFirstPartyData: function () {
const storeFirstPartyDataIds = function ({ids: theIds, pid: thePid}) {
try {
if (nobidFirstPartyData.hasLocalStorage()) {
window.localStorage.setItem(FIRST_PARTY_SOURCE_KEY, JSON.stringify({ids: theIds, pid: thePid, ts: Date.now()}));
}
} catch (error) {
logWarn('Local storage api disabled', error);
}
};
const readFirstPartyId = function () {
try {
if (nobidFirstPartyData.hasLocalStorage()) {
const idStr = window.localStorage.getItem(FIRST_PARTY_KEY);
if (nobidFirstPartyData.isJson(idStr)) {
return JSON.parse(idStr);
}
return null;
}
} catch (error) {
logWarn('Local storage api disabled', error);
}
return null;
};
const storeFirstPartyId = function (theId) {
try {
if (nobidFirstPartyData.hasLocalStorage()) {
window.localStorage.setItem(FIRST_PARTY_KEY, JSON.stringify(theId));
}
} catch (error) {
logWarn('Local storage api disabled', error);
}
};
const _loadOrCreateFirstPartyData = function () {
const generateGUID = function () {
let d = new Date().getTime();
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
const r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
});
};
const ajaxGet = function (ajaxParams, callback) {
const ajax = new XMLHttpRequest();
ajax.withCredentials = false;
ajax.timeout = ajaxParams.timeout;
ajax.open('GET', ajaxParams.url, true);
ajax.onreadystatechange = function () {
if (this.readyState === XMLHttpRequest.DONE) {
callback(this.response);
}
};
ajax.send(ajaxParams.data);
};
let firstPartyIdObj = readFirstPartyId();
if (!firstPartyIdObj || !firstPartyIdObj.id || !firstPartyIdObj.ts) {
const firstPartyId = generateGUID();
firstPartyIdObj = {id: firstPartyId, ts: Date.now()};
storeFirstPartyId(firstPartyIdObj);
}
let firstPartyIds = nobidFirstPartyData.readFirstPartyDataIds();
if (firstPartyIdObj?.ts && !firstPartyIds?.ids) {
const pid = firstPartyIds?.pid || '';
const pdate = firstPartyIdObj.ts;
const firstPartyId = firstPartyIdObj.id;
const url = `https://api.intentiq.com/profiles_engine/ProfilesEngineServlet?at=39&mi=10&pt=17&dpn=1&iiqidtype=2&dpi=430542822&iiqpcid=${firstPartyId}&iiqpciddate=${pdate}&pid=${pid}`;
if (window.nobid.firstPartyRequestInProgress) return;
window.nobid.firstPartyRequestInProgress = true;
ajaxGet({ url: url }, function (response) {
response = JSON.parse(response);
if (response?.data) storeFirstPartyDataIds({ ids: response.data, pid: response.pid });
});
}
};
window.nobid.firstPartyIds = this.readFirstPartyDataIds();
if (window.nobid.firstPartyIdEnabled && !window.nobid.firstPartyIds?.ids) _loadOrCreateFirstPartyData();
}
};
window.nobid.firstPartyIds = nobidFirstPartyData.readFirstPartyDataIds();
export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
Expand Down
129 changes: 39 additions & 90 deletions test/spec/modules/nobidBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,27 @@ describe('Nobid Adapter', function () {
'auctionId': '1d1a030790a475',
};

it('should return true when required params found 1', function () {
it('should return true when required params found', function () {
expect(spec.isBidRequestValid(bid)).to.equal(true);
});

it('should return true when required params found 2', function () {
let mybid = Object.assign({}, bid);
delete mybid.params;
mybid.params = {
it('should return true when required params found', function () {
let bid = Object.assign({}, bid);
delete bid.params;
bid.params = {
'siteId': 2
};
expect(spec.isBidRequestValid(mybid)).to.equal(true);

expect(spec.isBidRequestValid(bid)).to.equal(true);
});

it('should return false when required params are not passed', function () {
let mybid = Object.assign({}, bid);
delete mybid.params;
mybid.params = {
let bid = Object.assign({}, bid);
delete bid.params;
bid.params = {
'siteId': 0
};
expect(spec.isBidRequestValid(mybid)).to.equal(false);
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
});

Expand Down Expand Up @@ -252,12 +253,12 @@ describe('Nobid Adapter', function () {
});

it('sends bid request to site id', function () {
const request = spec.buildRequests(bidRequests);
const payload = JSON.parse(request.data);
expect(payload.a).to.exist;
expect(payload.a[0].sid).to.equal(2);
expect(payload.a[0].at).to.equal('banner');
expect(payload.a[0].params.siteId).to.equal(2);
const request = spec.buildRequests(bidRequests);
const payload = JSON.parse(request.data);
expect(payload.a).to.exist;
expect(payload.a[0].sid).to.equal(2);
expect(payload.a[0].at).to.equal('banner');
expect(payload.a[0].params.siteId).to.equal(2);
});

it('sends bid request to ad type', function () {
Expand Down Expand Up @@ -422,58 +423,6 @@ describe('Nobid Adapter', function () {
});
});

describe('First Party ID Test', function () {
const CREATIVE_ID_300x250 = 'CREATIVE-100';
const ADUNIT_300x250 = 'ADUNIT-1';
const ADMARKUP_300x250 = 'ADMARKUP-300x250';
const PRICE_300x250 = 0.51;
const REQUEST_ID = '3db3773286ee59';
const DEAL_ID = 'deal123';
let response = {
country: 'US',
ip: '68.83.15.75',
device: 'COMPUTER',
site: 2,
fpid: true,
bids: [
{id: 1,
bdrid: 101,
divid: ADUNIT_300x250,
creativeid: CREATIVE_ID_300x250,
size: {'w': 300, 'h': 250},
adm: ADMARKUP_300x250,
price: '' + PRICE_300x250
}
]
};

it('first party ID', function () {
const bidderRequest = {
bids: [{
bidId: REQUEST_ID,
adUnitCode: ADUNIT_300x250
}]
}
const bidRequests = [
{
'bidder': 'nobid',
'params': {
'siteId': 2
},
'adUnitCode': 'adunit-code',
'sizes': [[300, 250]],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475',
}
];
const request = spec.buildRequests(bidRequests, bidderRequest);
expect(request.method).to.equal('POST');
spec.interpretResponse({ body: response }, {bidderRequest: bidderRequest});
expect(window.nobid.firstPartyIdEnabled).to.equal(true);
});
});

describe('isVideoBidRequestValid', function () {
let bid = {
bidder: 'nobid',
Expand Down Expand Up @@ -686,12 +635,12 @@ describe('Nobid Adapter', function () {
});

it('sends bid request to site id', function () {
const request = spec.buildRequests(bidRequests);
const payload = JSON.parse(request.data);
expect(payload.a).to.exist;
expect(payload.a[0].sid).to.equal(2);
expect(payload.a[0].at).to.equal('banner');
expect(payload.a[0].params.siteId).to.equal(2);
const request = spec.buildRequests(bidRequests);
const payload = JSON.parse(request.data);
expect(payload.a).to.exist;
expect(payload.a[0].sid).to.equal(2);
expect(payload.a[0].at).to.equal('banner');
expect(payload.a[0].params.siteId).to.equal(2);
});

it('sends bid request to ad type', function () {
Expand Down Expand Up @@ -990,19 +939,19 @@ describe('Nobid Adapter', function () {
auctionId: '1d1a030790a475',
coppa: true,
schain: {
validation: 'strict',
config: {
ver: '1.0',
complete: 1,
nodes: [
{
asi: 'indirectseller.com',
sid: '00001',
name: 'name.com',
hp: 1
}
]
}
validation: 'strict',
config: {
ver: '1.0',
complete: 1,
nodes: [
{
asi: 'indirectseller.com',
sid: '00001',
name: 'name.com',
hp: 1
}
]
}
}
}
];
Expand Down Expand Up @@ -1052,7 +1001,7 @@ describe('Nobid Adapter', function () {
]
};

it('Limit should be respected', function () {
it('should ULimit be respected', function () {
const bidderRequest = {
bids: [{
bidId: REQUEST_ID,
Expand Down Expand Up @@ -1111,8 +1060,8 @@ describe('Nobid Adapter', function () {
});

it('should get correct user sync when !iframeEnabled', function () {
let pixel = spec.getUserSyncs({})
expect(pixel.length).to.equal(0);
let pixel = spec.getUserSyncs({})
expect(pixel.length).to.equal(0);
});
});

Expand Down