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

Livewrapped Analytics Adapter: Collect AD_RENDER_FAILED events #7591

Merged
merged 1 commit into from
Oct 20, 2021
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
45 changes: 44 additions & 1 deletion modules/livewrappedAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const REQUESTSENT = 1;
const RESPONSESENT = 2;
const WINSENT = 4;
const TIMEOUTSENT = 8;
const ADRENDERFAILEDSENT = 16;

let initOptions;
export const BID_WON_TIMEOUT = 500;
Expand Down Expand Up @@ -114,6 +115,16 @@ let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE
livewrappedAnalyticsAdapter.sendEvents();
}
break;
case CONSTANTS.EVENTS.AD_RENDER_FAILED:
logInfo('LIVEWRAPPED_AD_RENDER_FAILED:', args);
let adRenderFailedBid = cache.auctions[args.bid.auctionId].bids[args.bid.requestId];
adRenderFailedBid.adRenderFailed = true;
adRenderFailedBid.reason = args.reason;
adRenderFailedBid.message = args.message;
if (adRenderFailedBid.sendStatus != 0) {
livewrappedAnalyticsAdapter.sendEvents();
}
break;
case CONSTANTS.EVENTS.BID_TIMEOUT:
logInfo('LIVEWRAPPED_BID_TIMEOUT:', args);
args.forEach(timeout => {
Expand Down Expand Up @@ -151,13 +162,15 @@ livewrappedAnalyticsAdapter.sendEvents = function() {
wins: getWins(sentRequests.gdpr, sentRequests.auctionIds),
timeouts: getTimeouts(sentRequests.auctionIds),
bidAdUnits: getbidAdUnits(),
rf: getAdRenderFailed(sentRequests.auctionIds),
rcv: getAdblockerRecovered()
};

if (events.requests.length == 0 &&
events.responses.length == 0 &&
events.wins.length == 0 &&
events.timeouts.length == 0) {
events.timeouts.length == 0 &&
events.rf.length == 0) {
return;
}

Expand Down Expand Up @@ -338,6 +351,36 @@ function getTimeouts(auctionIds) {
return timeouts;
}

function getAdRenderFailed(auctionIds) {
var adRenderFails = [];

Object.keys(cache.auctions).forEach(auctionId => {
let auctionIdPos = getAuctionIdPos(auctionIds, auctionId);
Object.keys(cache.auctions[auctionId].bids).forEach(bidId => {
let auction = cache.auctions[auctionId];
let bid = auction.bids[bidId];
if (!(bid.sendStatus & ADRENDERFAILEDSENT) && bid.adRenderFailed) {
bid.sendStatus |= ADRENDERFAILEDSENT;

adRenderFails.push({
bidder: bid.bidder,
adUnit: bid.adUnit,
adUnitId: bid.adUnitId,
timeStamp: auction.timeStamp,
auctionId: auctionIdPos,
auc: bid.auc,
buc: bid.buc,
lw: bid.lw,
rsn: bid.reason,
msg: bid.message
});
}
});
});

return adRenderFails;
}

function getbidAdUnits() {
var bidAdUnits = [];

Expand Down
32 changes: 29 additions & 3 deletions test/spec/modules/livewrappedAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const {
BIDDER_DONE,
BID_WON,
BID_TIMEOUT,
SET_TARGETING
SET_TARGETING,
AD_RENDER_FAILED
},
STATUS: {
GOOD
Expand Down Expand Up @@ -115,6 +116,14 @@ const MOCK = {
'bidId': '2ecff0db240757',
'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa'
}
],
AD_RENDER_FAILED: [
{
'bidId': '2ecff0db240757',
'reason': CONSTANTS.AD_RENDER_FAILED_REASON.CANNOT_FIND_AD,
'message': 'message',
'bid': BID1
}
]
};

Expand Down Expand Up @@ -226,6 +235,17 @@ const ANALYTICS_MESSAGE = {
gdpr: 0,
auctionId: 0
}
],
rf: [
{
timeStamp: 1519149562216,
adUnit: 'panorama_d_1',
adUnitId: 'adunitid',
bidder: 'livewrapped',
auctionId: 0,
rsn: CONSTANTS.AD_RENDER_FAILED_REASON.CANNOT_FIND_AD,
msg: 'message'
},
]
};

Expand All @@ -239,6 +259,7 @@ function performStandardAuction() {
events.emit(SET_TARGETING, MOCK.SET_TARGETING);
events.emit(BID_WON, MOCK.BID_WON[0]);
events.emit(BID_WON, MOCK.BID_WON[1]);
events.emit(AD_RENDER_FAILED, MOCK.AD_RENDER_FAILED[0]);
}

describe('Livewrapped analytics adapter', function () {
Expand Down Expand Up @@ -300,7 +321,7 @@ describe('Livewrapped analytics adapter', function () {
expect(message).to.deep.equal(ANALYTICS_MESSAGE);
});

it('should send batched message without BID_WON if necessary and further BID_WON events individually', function () {
it('should send batched message without BID_WON AND AD_RENDER_FAILED if necessary and further BID_WON and AD_RENDER_FAILED events individually', function () {
events.emit(AUCTION_INIT, MOCK.AUCTION_INIT);
events.emit(BID_REQUESTED, MOCK.BID_REQUESTED);
events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]);
Expand All @@ -313,8 +334,9 @@ describe('Livewrapped analytics adapter', function () {
clock.tick(BID_WON_TIMEOUT + 1000);

events.emit(BID_WON, MOCK.BID_WON[1]);
events.emit(AD_RENDER_FAILED, MOCK.AD_RENDER_FAILED[0]);

expect(server.requests.length).to.equal(2);
expect(server.requests.length).to.equal(3);

let message = JSON.parse(server.requests[0].requestBody);
expect(message.wins.length).to.equal(1);
Expand All @@ -324,6 +346,10 @@ describe('Livewrapped analytics adapter', function () {
message = JSON.parse(server.requests[1].requestBody);
expect(message.wins.length).to.equal(1);
expect(message.wins[0]).to.deep.equal(ANALYTICS_MESSAGE.wins[1]);

message = JSON.parse(server.requests[2].requestBody);
expect(message.rf.length).to.equal(1);
expect(message.rf[0]).to.deep.equal(ANALYTICS_MESSAGE.rf[0]);
});

it('should properly mark bids as timed out', function () {
Expand Down