diff --git a/modules/kueezRtbBidAdapter.js b/modules/kueezRtbBidAdapter.js index c0fb17672af..60eced6a490 100644 --- a/modules/kueezRtbBidAdapter.js +++ b/modules/kueezRtbBidAdapter.js @@ -5,7 +5,8 @@ import { createBuildRequestsFn, createInterpretResponseFn, createUserSyncGetter, - isBidRequestValid + isBidRequestValid, + tryParseJSON } from '../libraries/vidazooUtils/bidderUtils.js'; const GVLID = 1165; @@ -14,40 +15,63 @@ const BIDDER_CODE = 'kueezrtb'; const BIDDER_VERSION = '1.0.0'; export const storage = getStorageManager({bidderCode: BIDDER_CODE}); +export const spec = { + code: BIDDER_CODE, + version: BIDDER_VERSION, + gvlid: GVLID, + supportedMediaTypes: [BANNER, VIDEO], + isBidRequestValid, + buildRequests: createBuildRequestsFn(createDomain, createUniqueRequestData, storage, BIDDER_CODE, BIDDER_VERSION, false), + interpretResponse: createInterpretResponseFn(BIDDER_CODE, false), + getUserSyncs: createUserSyncGetter({ + iframeSyncUrl: 'https://sync.kueezrtb.com/api/sync/iframe', + imageSyncUrl: 'https://sync.kueezrtb.com/api/sync/image' + }), + createFirstPartyData, +}; + export function createDomain(subDomain = DEFAULT_SUB_DOMAIN) { return `https://${subDomain}.kueezrtb.com`; } -function createUniqueRequestData(hashUrl, bid) { - const { - auctionId, - transactionId, - } = bid; +export function getAndSetFirstPartyData() { + if (!storage.hasLocalStorage()) { + return; + } + let fdata = tryParseJSON(storage.getDataFromLocalStorage('_iiq_fdata')); + if (!fdata) { + fdata = spec.createFirstPartyData(); + storage.setDataInLocalStorage('_iiq_fdata', JSON.stringify(fdata)); + } + return fdata; +} +export function createFirstPartyData() { return { - auctionId, - transactionId, + pcid: getFirstPartyUUID(), pcidDate: Date.now(), }; } -const buildRequests = createBuildRequestsFn(createDomain, createUniqueRequestData, storage, BIDDER_CODE, BIDDER_VERSION, false); - -const interpretResponse = createInterpretResponseFn(BIDDER_CODE, false); - -const getUserSyncs = createUserSyncGetter({ - iframeSyncUrl: 'https://sync.kueezrtb.com/api/sync/iframe', - imageSyncUrl: 'https://sync.kueezrtb.com/api/sync/image' -}); - -export const spec = { - code: BIDDER_CODE, - version: BIDDER_VERSION, - gvlid: GVLID, - supportedMediaTypes: [BANNER, VIDEO], - isBidRequestValid, - buildRequests, - interpretResponse, - getUserSyncs +function getFirstPartyUUID() { + 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); + }); }; +function createUniqueRequestData(hashUrl, bid) { + const {auctionId, transactionId} = bid; + const fdata = getAndSetFirstPartyData(); + return { + auctionId, + transactionId, + ...(fdata && { + iiqpcid: fdata.pcid, + iiqpcidDate: fdata.pcidDate + }) + }; +} + registerBidder(spec); diff --git a/test/spec/modules/kueezRtbBidAdapter_spec.js b/test/spec/modules/kueezRtbBidAdapter_spec.js index 2df5e299aeb..d3323a205b3 100644 --- a/test/spec/modules/kueezRtbBidAdapter_spec.js +++ b/test/spec/modules/kueezRtbBidAdapter_spec.js @@ -2,7 +2,9 @@ import {expect} from 'chai'; import { spec as adapter, createDomain, - storage + storage, + getAndSetFirstPartyData, + createFirstPartyData, } from 'modules/kueezRtbBidAdapter.js'; import * as utils from 'src/utils.js'; import {version} from 'package.json'; @@ -251,6 +253,7 @@ describe('KueezRtbBidAdapter', function () { describe('build requests', function () { let sandbox; + let createFirstPartyDataStub; before(function () { $$PREBID_GLOBAL$$.bidderSettings = { kueezrtb: { @@ -259,6 +262,10 @@ describe('KueezRtbBidAdapter', function () { }; sandbox = sinon.sandbox.create(); sandbox.stub(Date, 'now').returns(1000); + createFirstPartyDataStub = sandbox.stub(adapter, 'createFirstPartyData').returns({ + pcid: 'pcid', + pcidDate: 1000 + }); }); it('should build video request', function () { @@ -295,6 +302,8 @@ describe('KueezRtbBidAdapter', function () { referrer: 'https://www.somereferrer.com', res: `${window.top.screen.width}x${window.top.screen.height}`, schain: VIDEO_BID.schain, + iiqpcid: 'pcid', + iiqpcidDate: 1000, sizes: ['545x307'], sua: { 'source': 2, @@ -363,6 +372,8 @@ describe('KueezRtbBidAdapter', function () { auctionId: 'auction_id', bidRequestsCount: 4, bidderRequestsCount: 3, + iiqpcid: 'pcid', + iiqpcidDate: 1000, bidderWinsCount: 1, bidderTimeout: 3000, bidderRequestId: '1fdb5ff1b6eaa7', @@ -668,4 +679,36 @@ describe('KueezRtbBidAdapter', function () { expect(parsed).to.be.equal(value); }); }); + + describe('First party data', () => { + before(function () { + $$PREBID_GLOBAL$$.bidderSettings = { + kueezrtb: { + storageAllowed: true + } + }; + }); + after(function () { + $$PREBID_GLOBAL$$.bidderSettings = {}; + storage.removeDataFromLocalStorage('_iiq_fdata'); + }) + + it('should create first party data', function () { + const data = createFirstPartyData(); + expect(data).to.have.property('pcid'); + expect(data).to.have.property('pcidDate'); + }); + + it('should get and set first party data', function () { + storage.removeDataFromLocalStorage('_iiq_fdata'); + + const data = getAndSetFirstPartyData(); + expect(data).to.have.property('pcid'); + expect(data).to.have.property('pcidDate'); + + const stored = storage.getDataFromLocalStorage('_iiq_fdata'); + const parsed = tryParseJSON(stored); + expect(parsed).to.deep.equal(data); + }); + }); });