Skip to content

Commit

Permalink
BeOpAdapter - First Party Cookie read and set (#16) (prebid#12486)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebrobert authored Dec 3, 2024
1 parent a7fb4ad commit 6398c68
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
19 changes: 18 additions & 1 deletion modules/beopBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
buildUrl,
deepAccess, getBidIdParameter,
deepAccess, generateUUID, getBidIdParameter,
getValue,
isArray,
isPlainObject,
Expand All @@ -10,6 +10,7 @@ import {
} from '../src/utils.js';
import {getRefererInfo} from '../src/refererDetection.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { getStorageManager } from '../src/storageManager.js';
import {config} from '../src/config.js';
import {getAllOrtbKeywords} from '../libraries/keywords/keywords.js';

Expand All @@ -21,9 +22,11 @@ import {getAllOrtbKeywords} from '../libraries/keywords/keywords.js';

const BIDDER_CODE = 'beop';
const ENDPOINT_URL = 'https://hb.beop.io/bid';
const COOKIE_NAME = 'beopid';
const TCF_VENDOR_ID = 666;

const validIdRegExp = /^[0-9a-fA-F]{24}$/
const storage = getStorageManager({bidderCode: BIDDER_CODE});

export const spec = {
code: BIDDER_CODE,
Expand Down Expand Up @@ -64,6 +67,19 @@ export const spec = {
const kwdsFromRequest = firstSlot.kwds;
let keywords = getAllOrtbKeywords(bidderRequest.ortb2, kwdsFromRequest);

let beopid = '';
if (storage.cookiesAreEnabled) {
beopid = storage.getCookie(COOKIE_NAME, undefined);
if (!beopid) {
beopid = generateUUID();
let expirationDate = new Date();
expirationDate.setTime(expirationDate.getTime() + 86400 * 183 * 1000);
storage.setCookie(COOKIE_NAME, beopid, expirationDate.toUTCString());
}
} else {
storage.setCookie(COOKIE_NAME, '', 0);
}

const payloadObject = {
at: new Date().toString(),
nid: firstSlot.nid,
Expand All @@ -74,6 +90,7 @@ export const spec = {
lang: (window.navigator.language || window.navigator.languages[0]),
kwds: keywords,
dbg: false,
fg: beopid,
slts: slots,
is_amp: deepAccess(bidderRequest, 'referrerInfo.isAmp'),
gdpr_applies: gdpr ? gdpr.gdprApplies : false,
Expand Down
12 changes: 12 additions & 0 deletions test/spec/modules/beopBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,16 @@ describe('BeOp Bid Adapter tests', () => {
expect(payload.eids[0].source).to.equal('provider.com');
});
})

describe('Ensure first party cookie is well managed', function () {
let bidRequests = [];

it(`should generate a new uuid`, function () {
let bid = Object.assign({}, validBid);
bidRequests.push(bid);
const request = spec.buildRequests(bidRequests, {});
const payload = JSON.parse(request.data);
expect(payload.fg).to.exist;
})
})
});

0 comments on commit 6398c68

Please sign in to comment.