Skip to content

Commit

Permalink
Fixes for Platform One Analytics Adapter (#4359)
Browse files Browse the repository at this point in the history
* Added Y1 Analytics Adapter

* rename y1AnalyticsAdapter in yieldoneAnalyticsAdapter

* Yieldone Bid Adapter: fixes from lint check

* Yieldone Analytics Adapter: fix endpoint protocol

* Added spec file for yieldone Analytics Adapter

* Add adUnitName to analytics data for Yieldone Analytics Adapter

* Fix yieldone Analytics Adapter to log only id from adUnitPath

* Fix bug with timeout event in Yieldone Analytics Adapter
  • Loading branch information
hbanalytics authored and jsnellbaker committed Nov 4, 2019
1 parent 96694a2 commit e4cf432
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
49 changes: 48 additions & 1 deletion modules/yieldoneAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,49 @@ let currentAuctionId = '';
let url = defaultUrl;
let pubId = '';

function makeAdUnitNameMap() {
if (window.googletag && window.googletag.pubads) {
const p = googletag.pubads();
if (p && p.getSlots) {
const slots = p.getSlots();
if (slots && slots.length) {
const map = {};
slots.forEach((slot) => {
const id = slot.getSlotElementId();
const name = (slot.getAdUnitPath() || '').split('/').pop();
map[id] = name;
});
return map;
}
}
}
}

function addAdUnitNameForArray(ar, map) {
if (utils.isArray(ar)) {
ar.forEach((it) => { addAdUnitName(it, map) });
}
}

function addAdUnitName(params, map) {
if (params.adUnitCode && map[params.adUnitCode]) {
params.adUnitName = map[params.adUnitCode];
}
if (utils.isArray(params.adUnits)) {
params.adUnits.forEach((adUnit) => {
if (adUnit.code && map[adUnit.code]) {
adUnit.name = map[adUnit.code];
}
});
}
if (utils.isArray(params.adUnitCodes)) {
params.adUnitNames = params.adUnitCodes.map((code) => map[code]);
}
['bids', 'bidderRequests', 'bidsReceived', 'noBids'].forEach((it) => {
addAdUnitNameForArray(params[it], map);
});
}

const yieldoneAnalytics = Object.assign(adapter({analyticsType}), {
getUrl() { return url; },
track({eventType, args = {}}) {
Expand All @@ -36,7 +79,7 @@ const yieldoneAnalytics = Object.assign(adapter({analyticsType}), {
const reqBidId = `${bid.bidId}_${bid.auctionId}`;
const reqBidderId = `${bid.bidder}_${bid.auctionId}`;
if (!eventsStorage[bid.auctionId]) eventsStorage[bid.auctionId] = [];
if (requestedBidders[reqBidderId] && requestedBids[reqBidId]) {
if ((requestedBidders[reqBidderId] || reqBidders[bid.bidder]) && requestedBids[reqBidId]) {
if (!reqBidders[bid.bidder]) {
reqBidders[bid.bidder] = requestedBidders[reqBidderId];
reqBidders[bid.bidder].pubId = pubId;
Expand Down Expand Up @@ -73,6 +116,10 @@ const yieldoneAnalytics = Object.assign(adapter({analyticsType}), {
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);
}
});
}
yieldoneAnalytics.sendStat(yieldoneAnalytics.eventsStorage[args.auctionId], args.auctionId);
Expand Down
16 changes: 15 additions & 1 deletion test/spec/modules/yieldoneAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ describe('Yieldone Prebid Analytic', function () {
mediaTypes: {banner: {sizes: [[300, 250], [336, 280]]}},
params: {param_1: '111', param_2: '222'},
sizes: [[300, 250], [336, 280]]
},
{
adUnitCode: '0000',
auctionId: auctionId,
bidId: '14151',
bidder: 'biddertest_3',
mediaTypes: {banner: {sizes: [[300, 250], [336, 280]]}},
params: {param_1: '333', param_2: '222'},
sizes: [[300, 250], [336, 280]]
}
]
}
Expand Down Expand Up @@ -140,6 +149,11 @@ describe('Yieldone Prebid Analytic', function () {
bidId: '12131',
auctionId: auctionId,
bidder: 'biddertest_3'
},
{
bidId: '14151',
auctionId: auctionId,
bidder: 'biddertest_3'
}
];

Expand Down Expand Up @@ -234,7 +248,7 @@ describe('Yieldone Prebid Analytic', function () {
events.emit(constants.EVENTS.BID_RESPONSE, responses[1]);
events.emit(constants.EVENTS.BID_RESPONSE, responses[2]);

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

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

Expand Down

0 comments on commit e4cf432

Please sign in to comment.