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

Collect info about which ad units receive bids #4094

Merged
merged 20 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
23 changes: 23 additions & 0 deletions modules/livewrappedAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const BID_WON_TIMEOUT = 500;

const cache = {
auctions: {},
bidAdUnits: {}
};

let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE}), {
Expand Down Expand Up @@ -62,6 +63,9 @@ let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE
if (!bidResponse.ttr) {
bidResponse.ttr = time - bidResponse.start;
}
if (!cache.bidAdUnits[bidResponse.adUnit]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To confirm on this logic - it seems that it would only capture 1 bid for each adUnit; if there were multiple bids for the same adUnit, the others would be ignored through this if-block.

If above is correct, is that what you want?

Copy link
Contributor Author

@bjorn-lw bjorn-lw Aug 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is correct. What I do here is to keep track of all ad units that received at least one bid in the auction. The individual bids are handled elsewhere. Since the analytics adapter may send back bid responses to our end point in different requests, I needed a place to keep this particular information and make sure it is sent only once per adunit/auction since that makes my life so much easier in the backend.

I guess I made a failed attempt to make it clearer by calling the metric "bidAdunits" and not "adUnitBids" :( Naming is the hardest problem in Computer Science...

cache.bidAdUnits[bidResponse.adUnit] = {sent: 0, timeStamp: cache.auctions[args.auctionId].timeStamp};
}
break;
case CONSTANTS.EVENTS.BIDDER_DONE:
utils.logInfo('LIVEWRAPPED_BIDDER_DONE:', args);
Expand Down Expand Up @@ -114,6 +118,7 @@ livewrappedAnalyticsAdapter.sendEvents = function() {
responses: getResponses(),
wins: getWins(),
timeouts: getTimeouts(),
bidAdUnits: getbidAdUnits(),
rcv: getAdblockerRecovered()
};

Expand Down Expand Up @@ -229,6 +234,24 @@ function getTimeouts() {
return timeouts;
}

function getbidAdUnits() {
var bidAdUnits = [];

Object.keys(cache.bidAdUnits).forEach(adUnit => {
let bidAdUnit = cache.bidAdUnits[adUnit];
if (!bidAdUnit.sent) {
bidAdUnit.sent = 1;

bidAdUnits.push({
adUnit: adUnit,
timeStamp: bidAdUnit.timeStamp
});
}
});

return bidAdUnits;
}

adapterManager.registerAnalyticsAdapter({
adapter: livewrappedAnalyticsAdapter,
code: 'livewrapped'
Expand Down
10 changes: 10 additions & 0 deletions test/spec/modules/livewrappedAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ const MOCK = {

const ANALYTICS_MESSAGE = {
publisherId: 'CC411485-42BC-4F92-8389-42C503EE38D7',
bidAdUnits: [
{
adUnit: 'panorama_d_1',
timeStamp: 1519149562216
},
{
adUnit: 'box_d_1',
timeStamp: 1519149562216
}
],
requests: [
{
adUnit: 'panorama_d_1',
Expand Down