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

Changed data structure in Platform One Analytic Adapter #4647

Merged
merged 17 commits into from
Jan 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
59 changes: 33 additions & 26 deletions modules/yieldoneAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,51 +78,58 @@ const yieldoneAnalytics = Object.assign(adapter({analyticsType}), {
args.forEach((bid) => {
const reqBidId = `${bid.bidId}_${bid.auctionId}`;
const reqBidderId = `${bid.bidder}_${bid.auctionId}`;
if (!eventsStorage[bid.auctionId]) eventsStorage[bid.auctionId] = [];
if (!eventsStorage[bid.auctionId]) eventsStorage[bid.auctionId] = {events: []};
if ((requestedBidders[reqBidderId] || reqBidders[bid.bidder]) && requestedBids[reqBidId]) {
if (!reqBidders[bid.bidder]) {
reqBidders[bid.bidder] = requestedBidders[reqBidderId];
reqBidders[bid.bidder].pubId = pubId;
eventsStorage[bid.auctionId].push({eventType, params: reqBidders[bid.bidder]});
eventsStorage[bid.auctionId].events.push({eventType, params: reqBidders[bid.bidder]});
delete requestedBidders[reqBidderId];
}
reqBidders[bid.bidder].bids.push(requestedBids[reqBidId]);
delete requestedBids[reqBidId];
}
});
} else {
args.pubId = pubId;
currentAuctionId = args.auctionId || currentAuctionId;
if (currentAuctionId) {
const eventsStorage = yieldoneAnalytics.eventsStorage;
if (!eventsStorage[currentAuctionId]) eventsStorage[currentAuctionId] = [];
if (!eventsStorage[currentAuctionId]) eventsStorage[currentAuctionId] = {events: []};
const referrer = args.refererInfo && args.refererInfo.referer;
if (referrer && referrers[currentAuctionId] !== referrer) {
referrers[currentAuctionId] = referrer;
}
eventsStorage[currentAuctionId].push({
eventType,
params: args
});
}
}
if (
eventType === CONSTANTS.EVENTS.AUCTION_END || eventType === CONSTANTS.EVENTS.BID_WON
) {
args.adServerTargeting = targeting.getAllTargeting(
auctionManager.getAdUnitCodes(),
auctionManager.getBidsReceived()
);
if (yieldoneAnalytics.eventsStorage[args.auctionId]) {
yieldoneAnalytics.eventsStorage[args.auctionId].forEach((it) => {
it.page = {url: referrers[currentAuctionId]};
const adUnitNameMap = makeAdUnitNameMap();
if (adUnitNameMap) {
addAdUnitName(it.params, adUnitNameMap);
const params = Object.assign({}, args);
delete params.ad;
if (params.bidsReceived) {
params.bidsReceived = params.bidsReceived.map((bid) => {
const res = Object.assign({}, bid);
delete res.ad;
return res;
});
}
eventsStorage[currentAuctionId].events.push({eventType, params});

if (
eventType === CONSTANTS.EVENTS.AUCTION_END || eventType === CONSTANTS.EVENTS.BID_WON
) {
params.adServerTargeting = targeting.getAllTargeting(
auctionManager.getAdUnitCodes(),
auctionManager.getBidsReceived()
);
if (yieldoneAnalytics.eventsStorage[currentAuctionId]) {
yieldoneAnalytics.eventsStorage[currentAuctionId].page = {url: referrers[currentAuctionId]};
yieldoneAnalytics.eventsStorage[currentAuctionId].pubId = pubId;
yieldoneAnalytics.eventsStorage[currentAuctionId].wrapper_version = '$prebid.version$';
yieldoneAnalytics.eventsStorage[currentAuctionId].events.forEach((it) => {
const adUnitNameMap = makeAdUnitNameMap();
if (adUnitNameMap) {
addAdUnitName(it.params, adUnitNameMap);
}
});
}
});
yieldoneAnalytics.sendStat(yieldoneAnalytics.eventsStorage[currentAuctionId], currentAuctionId);
}
}
yieldoneAnalytics.sendStat(yieldoneAnalytics.eventsStorage[args.auctionId], args.auctionId);
}
},
sendStat(events, auctionId) {
Expand Down
68 changes: 43 additions & 25 deletions test/spec/modules/yieldoneAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ describe('Yieldone Prebid Analytic', function () {

const responses = [
{
ad: 'test ad content 1',
width: 300,
height: 250,
statusMessage: 'Bid available',
Expand All @@ -124,6 +125,7 @@ describe('Yieldone Prebid Analytic', function () {
timeToRespond: 100
},
{
ad: 'test ad content 2',
width: 336,
height: 280,
statusMessage: 'Bid available',
Expand All @@ -135,6 +137,7 @@ describe('Yieldone Prebid Analytic', function () {
timeToRespond: 100
},
{
ad: 'test ad content 3',
width: 300,
height: 250,
statusMessage: 'Bid available',
Expand All @@ -158,6 +161,7 @@ describe('Yieldone Prebid Analytic', function () {
];

const winner = {
ad: 'test ad content 3',
width: 300,
height: 250,
statusMessage: 'Bid available',
Expand All @@ -169,69 +173,83 @@ describe('Yieldone Prebid Analytic', function () {
timeToRespond: 100
};

const auctionEnd = {
auctionId: auctionId,
bidsReceived: responses.slice(0, 3)
};

const preparedResponses = responses.map((resp) => {
const res = Object.assign({}, resp);
delete res.ad;
return res;
});

const expectedEvents = [
{
eventType: constants.EVENTS.AUCTION_INIT,
page: {url: testReferrer},
params: {
config: initOptions,
auctionId: auctionId,
pubId: initOptions.pubId
auctionId: auctionId
}
},
{
eventType: constants.EVENTS.BID_REQUESTED,
page: {url: testReferrer},
params: Object.assign({pubId: initOptions.pubId}, request[0])
params: Object.assign(request[0])
},
{
eventType: constants.EVENTS.BID_REQUESTED,
page: {url: testReferrer},
params: Object.assign({pubId: initOptions.pubId}, request[1])
params: Object.assign(request[1])
},
{
eventType: constants.EVENTS.BID_REQUESTED,
page: {url: testReferrer},
params: Object.assign({pubId: initOptions.pubId}, request[2])
params: Object.assign(request[2])
},
{
eventType: constants.EVENTS.BID_RESPONSE,
page: {url: testReferrer},
params: Object.assign({pubId: initOptions.pubId}, responses[0])
params: Object.assign(preparedResponses[0])
},
{
eventType: constants.EVENTS.BID_RESPONSE,
page: {url: testReferrer},
params: Object.assign({pubId: initOptions.pubId}, responses[1])
params: Object.assign(preparedResponses[1])
},
{
eventType: constants.EVENTS.BID_RESPONSE,
page: {url: testReferrer},
params: Object.assign({pubId: initOptions.pubId}, responses[2])
params: Object.assign(preparedResponses[2])
},
{
eventType: constants.EVENTS.BID_TIMEOUT,
page: {url: testReferrer},
params: Object.assign({pubId: initOptions.pubId}, request[2])
params: Object.assign(request[2])
},
{
eventType: constants.EVENTS.AUCTION_END,
page: {url: testReferrer},
params: {
auctionId: auctionId,
pubId: initOptions.pubId,
adServerTargeting: fakeTargeting
adServerTargeting: fakeTargeting,
bidsReceived: preparedResponses.slice(0, 3)
}
}
];
const expectedResult = {
pubId: initOptions.pubId,
page: {url: testReferrer},
wrapper_version: '$prebid.version$',
events: expectedEvents
};

const preparedWinnerParams = Object.assign({adServerTargeting: fakeTargeting}, winner);
delete preparedWinnerParams.ad;
const wonExpectedEvents = [
{
eventType: constants.EVENTS.BID_WON,
page: {url: testReferrer},
params: Object.assign({pubId: initOptions.pubId, adServerTargeting: fakeTargeting}, winner)
params: preparedWinnerParams
}
];
const wonExpectedResult = {
pubId: initOptions.pubId,
page: {url: testReferrer},
wrapper_version: '$prebid.version$',
events: wonExpectedEvents
};

adapterManager.enableAnalytics({
provider: 'yieldone',
Expand All @@ -250,17 +268,17 @@ describe('Yieldone Prebid Analytic', function () {

events.emit(constants.EVENTS.BID_TIMEOUT, [responses[3], responses[4]]);

events.emit(constants.EVENTS.AUCTION_END, {auctionId: auctionId});
events.emit(constants.EVENTS.AUCTION_END, auctionEnd);

expect(yieldoneAnalytics.eventsStorage[auctionId]).to.deep.equal(expectedEvents);
expect(yieldoneAnalytics.eventsStorage[auctionId]).to.deep.equal(expectedResult);

delete yieldoneAnalytics.eventsStorage[auctionId];

setTimeout(function() {
events.emit(constants.EVENTS.BID_WON, winner);

sinon.assert.callCount(sendStatStub, 2);
expect(yieldoneAnalytics.eventsStorage[auctionId]).to.deep.equal(wonExpectedEvents);
expect(yieldoneAnalytics.eventsStorage[auctionId]).to.deep.equal(wonExpectedResult);

delete yieldoneAnalytics.eventsStorage[auctionId];
done();
Expand Down