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

LiveWrapped Analytics Adapter: pass originalCPM to analytics #7623

Merged
merged 2 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions modules/livewrappedAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {ajax} from '../src/ajax.js';
import adapter from '../src/AnalyticsAdapter.js';
import CONSTANTS from '../src/constants.json';
import adapterManager from '../src/adapterManager.js';
import { getGlobal } from '../src/prebidGlobal.js';

const ANALYTICSTYPE = 'endpoint';
const URL = 'https://lwadm.com/analytics/10';
Expand All @@ -14,6 +15,7 @@ const TIMEOUTSENT = 8;
const ADRENDERFAILEDSENT = 16;

let initOptions;
let prebidGlobal = getGlobal();
export const BID_WON_TIMEOUT = 500;

const cache = {
Expand Down Expand Up @@ -79,6 +81,7 @@ let livewrappedAnalyticsAdapter = Object.assign(adapter({EMPTYURL, ANALYTICSTYPE
bidResponse.width = args.width;
bidResponse.height = args.height;
bidResponse.cpm = args.cpm;
bidResponse.originalCpm = prebidGlobal.convertCurrency(args.originalCpm, args.originalCurrency, args.currency);
bidResponse.ttr = args.timeToRespond;
bidResponse.readyToSend = 1;
bidResponse.mediaType = args.mediaType == 'native' ? 2 : (args.mediaType == 'video' ? 4 : 1);
Expand Down Expand Up @@ -237,6 +240,7 @@ function getResponses(gdpr, auctionIds) {
width: bid.width,
height: bid.height,
cpm: bid.cpm,
orgCpm: bid.originalCpm,
ttr: bid.ttr,
IsBid: bid.isBid,
mediaType: bid.mediaType,
Expand Down Expand Up @@ -276,6 +280,7 @@ function getWins(gdpr, auctionIds) {
width: bid.width,
height: bid.height,
cpm: bid.cpm,
orgCpm: bid.originalCpm,
mediaType: bid.mediaType,
gdpr: gdprPos,
floor: bid.lwFloor ? bid.lwFloor : (bid.floorData ? bid.floorData.floorValue : undefined),
Expand Down
27 changes: 23 additions & 4 deletions test/spec/modules/livewrappedAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import livewrappedAnalyticsAdapter, { BID_WON_TIMEOUT } from 'modules/livewrappe
import CONSTANTS from 'src/constants.json';
import { config } from 'src/config.js';
import { server } from 'test/mocks/xhr.js';
import { setConfig } from 'modules/currency.js';

let events = require('src/events');
let utils = require('src/utils');
Expand All @@ -28,6 +29,9 @@ const BID1 = {
width: 980,
height: 240,
cpm: 1.1,
originalCpm: 12.0,
currency: 'USD',
originalCurrency: 'FOO',
timeToRespond: 200,
bidId: '2ecff0db240757',
requestId: '2ecff0db240757',
Expand All @@ -43,6 +47,9 @@ const BID2 = Object.assign({}, BID1, {
width: 300,
height: 250,
cpm: 2.2,
originalCpm: 23.0,
currency: 'USD',
originalCurrency: 'FOO',
timeToRespond: 300,
bidId: '3ecff0db240757',
requestId: '3ecff0db240757',
Expand Down Expand Up @@ -178,6 +185,7 @@ const ANALYTICS_MESSAGE = {
width: 980,
height: 240,
cpm: 1.1,
orgCpm: 120,
ttr: 200,
IsBid: true,
mediaType: 1,
Expand All @@ -192,6 +200,7 @@ const ANALYTICS_MESSAGE = {
width: 300,
height: 250,
cpm: 2.2,
orgCpm: 230,
ttr: 300,
IsBid: true,
mediaType: 1,
Expand Down Expand Up @@ -219,6 +228,7 @@ const ANALYTICS_MESSAGE = {
width: 980,
height: 240,
cpm: 1.1,
orgCpm: 120,
mediaType: 1,
gdpr: 0,
auctionId: 0
Expand All @@ -231,6 +241,7 @@ const ANALYTICS_MESSAGE = {
width: 300,
height: 250,
cpm: 2.2,
orgCpm: 230,
mediaType: 1,
gdpr: 0,
auctionId: 0
Expand Down Expand Up @@ -279,6 +290,14 @@ describe('Livewrapped analytics adapter', function () {
sandbox.stub(document, 'getElementById').returns(element);

clock = sandbox.useFakeTimers(1519767013781);
setConfig({
adServerCurrency: 'USD',
rates: {
USD: {
FOO: 0.1
}
}
});
});

afterEach(function () {
Expand Down Expand Up @@ -453,15 +472,15 @@ describe('Livewrapped analytics adapter', function () {
{
'floorData': {
'floorValue': 1.1,
'floorCurrency': 'SEK'
'floorCurrency': 'FOO'
}
}));
events.emit(BID_WON, Object.assign({},
MOCK.BID_WON[0],
{
'floorData': {
'floorValue': 1.1,
'floorCurrency': 'SEK'
'floorCurrency': 'FOO'
}
}));
events.emit(AUCTION_END, MOCK.AUCTION_END);
Expand All @@ -476,11 +495,11 @@ describe('Livewrapped analytics adapter', function () {

expect(message.responses.length).to.equal(1);
expect(message.responses[0].floor).to.equal(1.1);
expect(message.responses[0].floorCur).to.equal('SEK');
expect(message.responses[0].floorCur).to.equal('FOO');

expect(message.wins.length).to.equal(1);
expect(message.wins[0].floor).to.equal(1.1);
expect(message.wins[0].floorCur).to.equal('SEK');
expect(message.wins[0].floorCur).to.equal('FOO');
});

it('should forward Livewrapped floor data', function () {
Expand Down