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

Update Openx analytics adapter #5761

Merged
merged 2 commits into from
Sep 21, 2020
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
11 changes: 7 additions & 4 deletions modules/openxAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,15 @@ function isValidConfig({options: analyticsOptions}) {
}

function buildCampaignFromUtmCodes() {
const location = utils.getWindowLocation();
const queryParams = utils.parseQS(location && location.search);
let campaign = {};
let queryParams = utils.parseQS(utils.getWindowLocation() && utils.getWindowLocation().search);

UTM_TAGS.forEach(function(utmKey) {
let utmValue = queryParams[utmKey];
if (utmValue) {
let key = UTM_TO_CAMPAIGN_PROPERTIES[utmKey];
campaign[key] = utmValue;
campaign[key] = decodeURIComponent(utmValue);
}
});
return campaign;
Expand Down Expand Up @@ -326,7 +327,7 @@ function onAuctionInit({auctionId, timestamp: startTime, timeout, adUnitCodes})
* @param {PbBidRequest} bidRequest
*/
function onBidRequested(bidRequest) {
const {auctionId, bids: bidderRequests, start} = bidRequest;
const {auctionId, bids: bidderRequests, start, timeout} = bidRequest;
const auction = auctionMap[auctionId];
const adUnitCodeToAdUnitMap = auction.adUnitCodeToAdUnitMap;

Expand All @@ -341,6 +342,7 @@ function onBidRequested(bidRequest) {
source: src,
startTime: start,
timedOut: false,
timeLimit: timeout,
bids: {}
};
});
Expand Down Expand Up @@ -640,13 +642,14 @@ function buildAuctionPayload(auction) {

function buildBidRequestPayload(bidRequestsMap) {
return utils._map(bidRequestsMap, (bidRequest) => {
let {bidder, source, bids, mediaTypes, timedOut} = bidRequest;
let {bidder, source, bids, mediaTypes, timeLimit, timedOut} = bidRequest;
return {
bidder,
source,
hasBidderResponded: Object.keys(bids).length > 0,
availableAdSizes: getMediaTypeSizes(mediaTypes),
availableMediaTypes: getMediaTypes(mediaTypes),
timeLimit,
timedOut,
bidResponses: utils._map(bidRequest.bids, (bidderBidResponse) => {
let {
Expand Down
12 changes: 10 additions & 2 deletions test/spec/modules/openxAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ describe('openx analytics adapter', function() {
const bidRequestedOpenX = {
auctionId: 'test-auction-id',
auctionStart: CURRENT_TIME,
timeout: 2000,
bids: [
{
adUnitCode: AD_UNIT_CODE,
Expand All @@ -100,6 +101,7 @@ describe('openx analytics adapter', function() {
const bidRequestedCloseX = {
auctionId: 'test-auction-id',
auctionStart: CURRENT_TIME,
timeout: 1000,
bids: [
{
adUnitCode: AD_UNIT_CODE,
Expand Down Expand Up @@ -334,7 +336,7 @@ describe('openx analytics adapter', function() {

it('should track values from query params when they exist', function () {
sinon.stub(utils, 'getWindowLocation').returns({search: '?' +
'utm_campaign=test-campaign-name&' +
'utm_campaign=test%20campaign-name&' +
'utm_source=test-source&' +
'utm_medium=test-medium&'
});
Expand All @@ -348,7 +350,8 @@ describe('openx analytics adapter', function() {
clock.tick(SLOT_LOAD_WAIT_TIME);
auction = JSON.parse(server.requests[0].requestBody)[0];

expect(auction.campaign.name).to.equal('test-campaign-name');
// ensure that value are URI decoded
expect(auction.campaign.name).to.equal('test campaign-name');
expect(auction.campaign.source).to.equal('test-source');
expect(auction.campaign.medium).to.equal('test-medium');
expect(auction.campaign.content).to.be.undefined;
Expand Down Expand Up @@ -466,6 +469,11 @@ describe('openx analytics adapter', function() {
expect(openxBidRequest.timedOut).to.equal(true);
expect(closexBidRequest.timedOut).to.equal(true);
});

it('should track the timeout value ie timeLimit', function () {
expect(openxBidRequest.timeLimit).to.equal(2000);
expect(closexBidRequest.timeLimit).to.equal(1000);
});
});

describe('when there are bid responses', function () {
Expand Down