diff --git a/modules/mavenDistributionAnalyticsAdapter.js b/modules/mavenDistributionAnalyticsAdapter.js index bd7c3264108..989357ad579 100644 --- a/modules/mavenDistributionAnalyticsAdapter.js +++ b/modules/mavenDistributionAnalyticsAdapter.js @@ -46,10 +46,10 @@ const MAX_BATCH_SIZE = 32 */ /** - * // cpms, zoneIndexes, and zoneNames all have the same length + * // cpmms, zoneIndexes, and zoneNames all have the same length * @typedef {{ * auc: string - * cpms: number[] + * cpmms: number[] * zoneIndexes: number[] * zoneNames: string[] * }} AuctionEndSummary @@ -62,7 +62,7 @@ const MAX_BATCH_SIZE = 32 */ export function summarizeAuctionEnd(args, adapterConfig) { /** @type {{[code: string]: number}} */ - const cpmsMap = {} + const cpmmsMap = {} const zoneNames = [] const zoneIndexes = [] const adUnitCodes = [] @@ -71,7 +71,7 @@ export function summarizeAuctionEnd(args, adapterConfig) { let someZoneNameNonNull = false let allZoneNamesNonNull = true args.adUnits.forEach(adUnit => { - cpmsMap[adUnit.code] = 0 + cpmmsMap[adUnit.code] = 0 adUnitCodes.push(adUnit.code) const zoneConfig = zoneMap[adUnit.code] || {} @@ -86,14 +86,14 @@ export function summarizeAuctionEnd(args, adapterConfig) { allZoneNamesNonNull = allZoneNamesNonNull && zoneNameNonNull }) args.bidsReceived.forEach(bid => { - cpmsMap[bid.adUnitCode] = Math.max(cpmsMap[bid.adUnitCode], bid.cpm || 0) + cpmmsMap[bid.adUnitCode] = Math.max(cpmmsMap[bid.adUnitCode], Math.round(bid.cpm * 1000 || 0)) }) - const cpms = args.adUnits.map(adUnit => cpmsMap[adUnit.code]) + const cpmms = args.adUnits.map(adUnit => cpmmsMap[adUnit.code]) /** @type {AuctionEndSummary} */ const eventToSend = { auc: args.auctionId, - cpms: cpms, + cpmms: cpmms, } if (!allZoneNamesNonNull) eventToSend.codes = adUnitCodes if (someZoneNameNonNull) eventToSend.zoneNames = zoneNames @@ -102,12 +102,17 @@ export function summarizeAuctionEnd(args, adapterConfig) { } /** + * Price is in microdollars * @param {AuctionEndSummary[]} batch - * @return {{batch: string}} + * @return {{batch: string, price: number}} */ export function createSendOptionsFromBatch(batch) { const batchJson = JSON.stringify(batch) - return { batch: batchJson } + let price = 0 + batch.forEach(auctionEndSummary => { + auctionEndSummary.cpmms.forEach(cpmm => price += cpmm) + }) + return { batch: batchJson, price: price } } const STATE_DOM_CONTENT_LOADING = 'wait-for-$p-to-be-defined' diff --git a/test/spec/modules/mavenDistributionAnalyticsAdapter_spec.js b/test/spec/modules/mavenDistributionAnalyticsAdapter_spec.js index e1e761dfdb9..6eae6ac7d74 100644 --- a/test/spec/modules/mavenDistributionAnalyticsAdapter_spec.js +++ b/test/spec/modules/mavenDistributionAnalyticsAdapter_spec.js @@ -879,7 +879,7 @@ describe('MavenDistributionAnalyticsAdapter', function () { const actualSummary = summarizeAuctionEnd(args, adapterConfig) const expectedSummary = { 'auc': 'e0a2febe-dc05-4999-87ed-4c40022b6796', - cpms: [0], + cpmms: [0], zoneIndexes: [0], zoneNames: ['fixed_bottom'], } @@ -2259,7 +2259,7 @@ describe('MavenDistributionAnalyticsAdapter', function () { const actual = summarizeAuctionEnd(mavenArgs, adapterConfig) const expected = { auc: 'd01409e4-580d-4107-8d92-3c5dec19b41a', - cpms: [ 2.604162 ], + cpmms: [ 2604 ], codes: [ 'gpt-slot-channel-banner-top' ], } assert.deepEqual(actual, expected) @@ -2267,13 +2267,16 @@ describe('MavenDistributionAnalyticsAdapter', function () { }); describe('createSendOptionsFromBatch', () => { it('should create batch json', () => { - const actual = createSendOptionsFromBatch({ + const actual = createSendOptionsFromBatch([{ auc: 'aaa', - cpms: [0.04], + cpmms: [40], zoneIndexes: [3], zoneNames: ['sidebar'] - }) - const expected = {batch: '{"auc":"aaa","cpms":[0.04],"zoneIndexes":[3],"zoneNames":["sidebar"]}'} + }]) + const expected = { + batch: '[{"auc":"aaa","cpmms":[40],"zoneIndexes":[3],"zoneNames":["sidebar"]}]', + price: 40, + } assert.deepEqual(actual, expected) }) })