Skip to content

Commit

Permalink
Attempt to store queue in-prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Larson committed Aug 18, 2020
1 parent 774a1b6 commit 829ad84
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions modules/concertAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,17 @@ const {
}
} = CONSTANTS;

let queue = [];

let concertAnalytics = Object.assign(adapter({url, analyticsType}), {
track({ eventType, args }) {
// eslint-disable-next-line no-console
console.log('got event', eventType, args);
switch (eventType) {
case BID_RESPONSE:
if (args.bidder !== 'concert') break;
queue.push(mapBidEvent(eventType, args));
this.queue.push(mapBidEvent(eventType, args));
break;

case BID_WON:
if (args.bidder !== 'concert') break;
queue.push(mapBidEvent(eventType, args));
this.queue.push(mapBidEvent(eventType, args));
break;

case AUCTION_END:
Expand All @@ -45,7 +41,10 @@ let concertAnalytics = Object.assign(adapter({url, analyticsType}), {
default:
break;
}
}
},

queue: [],
eventsStorage: []
});

function mapBidEvent(eventType, args) {
Expand Down Expand Up @@ -85,24 +84,18 @@ function sampleAnalytics() {
}

function sendEvents() {
concertAnalytics.eventsStorage = queue;
// eslint-disable-next-line no-console
console.log('set concert events storage', concertAnalytics.eventsStorage);
concertAnalytics.eventsStorage = concertAnalytics.queue.slice();

if (!queue.length) return;
if (!concertAnalytics.queue.length) return;

if (!pageIncludedInSample) {
utils.logMessage('Page not included in sample for Concert Analytics');
return;
}

try {
const body = JSON.stringify(queue);
ajax(url, () => {
// eslint-disable-next-line no-console
console.log('flushing bid queue');
queue = []
}, body, {
const body = JSON.stringify(concertAnalytics.queue);
ajax(url, () => concertAnalytics.queue = [], body, {
contentType: 'application/json',
method: 'POST'
});
Expand Down

0 comments on commit 829ad84

Please sign in to comment.