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

feat(openxAnalyticsAdaptor): Added userId tracking for v2 pipeline. #22

Merged
merged 2 commits into from
May 7, 2020
Merged
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
43 changes: 36 additions & 7 deletions modules/openxAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ openxAdapter.enableAnalytics = function(adapterConfig = {options: {}}) {
['testPipeline', 'boolean', false],
['adIdKey', 'string', false],
['payloadWaitTime', 'number', false],
['payloadWaitTimePadding', 'number', false],
];

let failedValidation = fieldValidations.find(([property, type, required]) => {
Expand Down Expand Up @@ -887,13 +888,14 @@ function onBidRequested(bidRequest) {
const adUnitCodeToBidderRequestMap = auction.adUnitCodeToBidderRequestMap;

bidderRequests.forEach(bidderRequest => {
const { adUnitCode, bidder, bidId: requestId, mediaTypes, params, src } = bidderRequest;
const { adUnitCode, bidder, bidId: requestId, mediaTypes, params, src, userId } = bidderRequest;

adUnitCodeToBidderRequestMap[adUnitCode][requestId] = {
bidder,
params,
mediaTypes,
source: src,
userId,
startTime: start,
timedOut: false,
bids: {}
Expand Down Expand Up @@ -954,13 +956,16 @@ function onBidResponse(bidResponse) {
}

function onBidTimeout(args) {
utils
._map(args, value => value)
.forEach(({ auctionId, adUnitCode, bidId: requestId }) => {
utils._each(args, ({auctionId, adUnitCode, bidId: requestId}) => {
if (auctionMap[auctionId]
&& auctionMap[auctionId].adUnitCodeToBidderRequestMap
&& auctionMap[auctionId].adUnitCodeToBidderRequestMap[adUnitCode]
&& auctionMap[auctionId].adUnitCodeToBidderRequestMap[adUnitCode][requestId]
) {
auctionMap[auctionId].adUnitCodeToBidderRequestMap[adUnitCode][requestId].timedOut = true;
});
}
});
}

/**
*
* @param {PbAuction} endedAuction
Expand Down Expand Up @@ -1079,11 +1084,18 @@ function buildAuctionPayload(auction) {
function buildBidRequestsPayload(adUnitCodeToBidderRequestMap) {
return utils._map(adUnitCodeToBidderRequestMap, (bidderRequestMap, adUnitCode) => {
return utils._map(bidderRequestMap, (bidderRequest) => {
let {bidder, source, bids, mediaTypes, timedOut} = bidderRequest;
let {bidder, source, bids, mediaTypes, timedOut, userId} = bidderRequest;
return {
adUnitCode,
bidder,
source,
// return an array of objects containing the module name and id
userIds: utils._map(userId, (id, module) => {
return {
module: module,
id: getUserId(module, id)};
})
.filter(({id}) => id),
hasBidderResponded: Object.keys(bids).length > 0,
availableAdSizes: getMediaTypeSizes(mediaTypes),
availableMediaTypes: getMediaTypes(mediaTypes),
Expand Down Expand Up @@ -1135,6 +1147,23 @@ function buildAuctionPayload(auction) {
}).flat();
}

function getUserId(module, idOrIdObject) {
let normalizedId;

switch (module) {
case 'digitrustid':
normalizedId = utils.deepAccess(idOrIdObject, 'data.id');
break;
case 'lipb':
normalizedId = idOrIdObject.lipbid;
break;
default:
normalizedId = idOrIdObject;
}

return normalizedId;
}

function getMediaTypeSizes(mediaTypes) {
return utils._map(mediaTypes, (mediaTypeConfig, mediaType) => {
return utils.parseSizesInput(mediaTypeConfig.sizes)
Expand Down
51 changes: 24 additions & 27 deletions test/spec/modules/openxAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,9 @@ describe('openx analytics adapter', function() {
bidId: 'test-openx-request-id',
bidder: 'openx',
params: { unit: 'test-openx-ad-unit-id' },
userId: {
tdid: 'test-tradedesk-id'
}
}
],
start: 1586000000010
Expand All @@ -617,6 +620,9 @@ describe('openx analytics adapter', function() {
bidId: 'test-closex-request-id',
bidder: 'closex',
params: { unit: 'test-closex-ad-unit-id' },
userId: {
tdid: 'test-tradedesk-id'
}
}
],
start: 1586000000020
Expand Down Expand Up @@ -657,17 +663,20 @@ describe('openx analytics adapter', function() {
ts: 'test-closex-ts'
};

const bidTimeoutOpenX = [{
const bidTimeoutOpenX = {
0: {
adUnitCode: AD_UNIT_CODE,
auctionId: 'test-auction-id',
bidId: 'test-openx-request-id'
}];
}};

const bidTimeoutCloseX = [{
adUnitCode: AD_UNIT_CODE,
auctionId: 'test-auction-id',
bidId: 'test-closex-request-id'
}];
const bidTimeoutCloseX = {
0: {
adUnitCode: AD_UNIT_CODE,
auctionId: 'test-auction-id',
bidId: 'test-closex-request-id'
}
};

const bidWonOpenX = {
requestId: 'test-openx-request-id',
Expand All @@ -691,7 +700,6 @@ describe('openx analytics adapter', function() {
auctionId: 'test-auction-id'
};


function simulateAuction(events) {
let highestBid;

Expand Down Expand Up @@ -871,6 +879,14 @@ describe('openx analytics adapter', function() {
expect(closexBidder.adUnitCode).to.equal(AD_UNIT_CODE);
});

it('should track the user ids', function () {
let openxBidder = auction.bidRequests.find(bidderRequest => bidderRequest.bidder === 'openx');
let closexBidder = auction.bidRequests.find(bidderRequest => bidderRequest.bidder === 'closex');

expect(openxBidder.userIds).to.deep.include({module: 'tdid', id: bidRequestedOpenX.bids[0].userId.tdid});
expect(closexBidder.userIds).to.deep.include({module: 'tdid', id: bidRequestedCloseX.bids[0].userId.tdid});
});

it('should not have responded', function () {
let openxBidder = auction.bidRequests.find(bidderRequest => bidderRequest.bidder === 'openx');
let closexBidder = auction.bidRequests.find(bidderRequest => bidderRequest.bidder === 'closex');
Expand Down Expand Up @@ -1195,18 +1211,6 @@ describe('openx analytics adapter', function() {
ts: 'test-closex-ts'
};

const bidTimeoutOpenX = [{
adUnitCode: AD_UNIT_CODE,
auctionId: 'test-auction-id',
bidId: 'test-openx-request-id'
}];

const bidTimeoutCloseX = [{
adUnitCode: AD_UNIT_CODE,
auctionId: 'test-auction-id',
bidId: 'test-closex-request-id'
}];

const openxAdUnitInfo = [{'code': 'test-div-1',
'mediaTypes': {'banner': {'sizes': [[300, 250]]}},
'bids': [{'bidder': 'openx',
Expand Down Expand Up @@ -1239,13 +1243,6 @@ describe('openx analytics adapter', function() {
auctionId: 'test-auction-id'
};

const bidWonCloseX = {
requestId: 'test-closex-request-id',
adId: 'test-closex-ad-id',
adUnitCode: AD_UNIT_CODE,
auctionId: 'test-auction-id'
};

let highestBid;
const onSlotLoadEvent = {
eventType: SLOT_LOADED,
Expand Down