Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit 6398c68

Browse files
authored
BeOpAdapter - First Party Cookie read and set (#16) (prebid#12486)
1 parent a7fb4ad commit 6398c68

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

modules/beopBidAdapter.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
buildUrl,
3-
deepAccess, getBidIdParameter,
3+
deepAccess, generateUUID, getBidIdParameter,
44
getValue,
55
isArray,
66
isPlainObject,
@@ -10,6 +10,7 @@ import {
1010
} from '../src/utils.js';
1111
import {getRefererInfo} from '../src/refererDetection.js';
1212
import {registerBidder} from '../src/adapters/bidderFactory.js';
13+
import { getStorageManager } from '../src/storageManager.js';
1314
import {config} from '../src/config.js';
1415
import {getAllOrtbKeywords} from '../libraries/keywords/keywords.js';
1516

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

2223
const BIDDER_CODE = 'beop';
2324
const ENDPOINT_URL = 'https://hb.beop.io/bid';
25+
const COOKIE_NAME = 'beopid';
2426
const TCF_VENDOR_ID = 666;
2527

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

2831
export const spec = {
2932
code: BIDDER_CODE,
@@ -64,6 +67,19 @@ export const spec = {
6467
const kwdsFromRequest = firstSlot.kwds;
6568
let keywords = getAllOrtbKeywords(bidderRequest.ortb2, kwdsFromRequest);
6669

70+
let beopid = '';
71+
if (storage.cookiesAreEnabled) {
72+
beopid = storage.getCookie(COOKIE_NAME, undefined);
73+
if (!beopid) {
74+
beopid = generateUUID();
75+
let expirationDate = new Date();
76+
expirationDate.setTime(expirationDate.getTime() + 86400 * 183 * 1000);
77+
storage.setCookie(COOKIE_NAME, beopid, expirationDate.toUTCString());
78+
}
79+
} else {
80+
storage.setCookie(COOKIE_NAME, '', 0);
81+
}
82+
6783
const payloadObject = {
6884
at: new Date().toString(),
6985
nid: firstSlot.nid,
@@ -74,6 +90,7 @@ export const spec = {
7490
lang: (window.navigator.language || window.navigator.languages[0]),
7591
kwds: keywords,
7692
dbg: false,
93+
fg: beopid,
7794
slts: slots,
7895
is_amp: deepAccess(bidderRequest, 'referrerInfo.isAmp'),
7996
gdpr_applies: gdpr ? gdpr.gdprApplies : false,

test/spec/modules/beopBidAdapter_spec.js

+12
Original file line numberDiff line numberDiff line change
@@ -327,4 +327,16 @@ describe('BeOp Bid Adapter tests', () => {
327327
expect(payload.eids[0].source).to.equal('provider.com');
328328
});
329329
})
330+
331+
describe('Ensure first party cookie is well managed', function () {
332+
let bidRequests = [];
333+
334+
it(`should generate a new uuid`, function () {
335+
let bid = Object.assign({}, validBid);
336+
bidRequests.push(bid);
337+
const request = spec.buildRequests(bidRequests, {});
338+
const payload = JSON.parse(request.data);
339+
expect(payload.fg).to.exist;
340+
})
341+
})
330342
});

0 commit comments

Comments
 (0)