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

KueezRtbBidAdapter: Add first-party data handling #12503

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
76 changes: 50 additions & 26 deletions modules/kueezRtbBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
createBuildRequestsFn,
createInterpretResponseFn,
createUserSyncGetter,
isBidRequestValid
isBidRequestValid,
tryParseJSON
} from '../libraries/vidazooUtils/bidderUtils.js';

const GVLID = 1165;
Expand All @@ -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);
45 changes: 44 additions & 1 deletion test/spec/modules/kueezRtbBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -251,6 +253,7 @@ describe('KueezRtbBidAdapter', function () {

describe('build requests', function () {
let sandbox;
let createFirstPartyDataStub;
before(function () {
$$PREBID_GLOBAL$$.bidderSettings = {
kueezrtb: {
Expand All @@ -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 () {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -363,6 +372,8 @@ describe('KueezRtbBidAdapter', function () {
auctionId: 'auction_id',
bidRequestsCount: 4,
bidderRequestsCount: 3,
iiqpcid: 'pcid',
iiqpcidDate: 1000,
bidderWinsCount: 1,
bidderTimeout: 3000,
bidderRequestId: '1fdb5ff1b6eaa7',
Expand Down Expand Up @@ -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);
});
});
});