Skip to content

Commit

Permalink
Support for user block from the Adapter (#4779)
Browse files Browse the repository at this point in the history
* Support for user block from the Adapter

* Added Unit tests and using utils.getCookie and utils.setCookie()

* Dummy change to triger CI

* Dummy change

* Support for pixel sync urls
  • Loading branch information
redaguermas authored Feb 12, 2020
1 parent 720038e commit 41fb95f
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 4 deletions.
37 changes: 34 additions & 3 deletions modules/nobidBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as utils from '../src/utils';
import { registerBidder } from '../src/adapters/bidderFactory';
import { BANNER } from '../src/mediaTypes';
const BIDDER_CODE = 'nobid';
window.nobidVersion = '1.2.0';
window.nobidVersion = '1.2.1';
window.nobid = window.nobid || {};
window.nobid.bidResponses = window.nobid.bidResponses || {};
window.nobid.timeoutTotal = 0;
Expand All @@ -11,6 +11,15 @@ window.nobid.refreshCount = 0;
function log(msg, obj) {
utils.logInfo('-NoBid- ' + msg, obj)
}
function nobidSetCookie(cname, cvalue, hours) {
var d = new Date();
d.setTime(d.getTime() + (hours * 60 * 60 * 1000));
var expires = 'expires=' + d.toUTCString();
utils.setCookie(cname, cvalue, expires);
}
function nobidGetCookie(cname) {
return utils.getCookie(cname);
}
function nobidBuildRequests(bids, bidderRequest) {
var serializeState = function(divIds, siteId, adunits) {
var filterAdUnitsByIds = function(divIds, adUnits) {
Expand Down Expand Up @@ -146,6 +155,11 @@ function nobidBuildRequests(bids, bidderRequest) {
if (typeof window.nobid.refreshLimit !== 'undefined') {
if (window.nobid.refreshLimit < window.nobid.refreshCount) return false;
}
let ublock = nobidGetCookie('_ublock');
if (ublock) {
log('Request blocked for user. hours: ', ublock);
return false;
}
/* DISCOVER SLOTS */
var divids = [];
var siteId = 0;
Expand Down Expand Up @@ -180,7 +194,13 @@ function nobidInterpretResponse(response, bidRequest) {
var setRefreshLimit = function(response) {
if (response && typeof response.rlimit !== 'undefined') window.nobid.refreshLimit = response.rlimit;
}
var setUserBlock = function(response) {
if (response && typeof response.ublock !== 'undefined') {
nobidSetCookie('_ublock', '1', response.ublock);
}
}
setRefreshLimit(response);
setUserBlock(response);
var bidResponses = [];
for (var i = 0; response.bids && i < response.bids.length; i++) {
var bid = response.bids[i];
Expand Down Expand Up @@ -273,8 +293,8 @@ export const spec = {
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function(serverResponse, bidRequest) {
log('interpretResponse', serverResponse);
log('interpretResponse', bidRequest);
log('interpretResponse -> serverResponse', serverResponse);
log('interpretResponse -> bidRequest', bidRequest);
return nobidInterpretResponse(serverResponse.body, bidRequest);
},

Expand Down Expand Up @@ -305,6 +325,17 @@ export const spec = {
type: 'iframe',
url: 'https://public.servenobid.com/sync.html' + params
}];
} else if (syncOptions.pixelEnabled && serverResponses.length > 0) {
let syncs = [];
if (serverResponses[0].body.syncs && serverResponses[0].body.syncs.length > 0) {
serverResponses[0].body.syncs.forEach(element => {
syncs.push({
type: 'image',
url: element
});
})
}
return syncs;
} else {
utils.logWarn('-NoBid- Please enable iframe based user sync.', syncOptions);
return [];
Expand Down
55 changes: 54 additions & 1 deletion test/spec/modules/nobidBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import * as utils from 'src/utils';
import { spec } from 'modules/nobidBidAdapter';
import { newBidder } from 'src/adapters/bidderFactory';
import { deepClone } from 'src/utils';

describe('Nobid Adapter', function () {
const adapter = newBidder(spec);
Expand Down Expand Up @@ -281,6 +281,59 @@ describe('Nobid Adapter', function () {
});
});

describe('interpretResponseWithUserLimit', 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';
const ULIMIT = 1;
let response = {
country: 'US',
ip: '68.83.15.75',
device: 'COMPUTER',
site: 2,
ublock: ULIMIT,
bids: [
{id: 1,
bdrid: 101,
divid: ADUNIT_300x250,
dealid: DEAL_ID,
creativeid: CREATIVE_ID_300x250,
size: {'w': 300, 'h': 250},
adm: ADMARKUP_300x250,
price: '' + PRICE_300x250
}
]
};

it('should ULimit be respected', 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',
}
];
spec.interpretResponse({ body: response }, {bidderRequest: bidderRequest});
let request = spec.buildRequests(bidRequests, bidderRequest);
expect(request).to.equal(undefined);
});
});

describe('getUserSyncs', function () {
const GDPR_CONSENT_STRING = 'GDPR_CONSENT_STRING';
it('should get correct user sync when iframeEnabled', function () {
Expand Down

0 comments on commit 41fb95f

Please sign in to comment.