Skip to content

Commit

Permalink
ADS-4131 Change the format of LiftIgniter activity
Browse files Browse the repository at this point in the history
Instead of cpm (price per 1000 impressions), send cpmm (price per 1 million impressions). Also include a price field that sums all the cpmms in the batc.
  • Loading branch information
yonran committed Jun 29, 2020
1 parent e518420 commit 90c3e50
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
23 changes: 14 additions & 9 deletions modules/mavenDistributionAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = []
Expand All @@ -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] || {}
Expand All @@ -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
Expand All @@ -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'
Expand Down
15 changes: 9 additions & 6 deletions test/spec/modules/mavenDistributionAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
}
Expand Down Expand Up @@ -2259,21 +2259,24 @@ 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)
})
});
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)
})
})
Expand Down

0 comments on commit 90c3e50

Please sign in to comment.