Skip to content

Commit

Permalink
Added more values to originData
Browse files Browse the repository at this point in the history
  • Loading branch information
Kim Van Crombrugge committed Apr 20, 2020
1 parent e0a6d7c commit 57f0033
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 50 deletions.
83 changes: 34 additions & 49 deletions modules/adheseBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import { registerBidder } from '../src/adapters/bidderFactory';
import { BANNER, VIDEO } from '../src/mediaTypes';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';

const BIDDER_CODE = 'adhese';
const USER_SYNC_BASE_URL = 'https://user-sync.adhese.com/iframe/user_sync.html';
Expand All @@ -11,23 +11,22 @@ export const spec = {
supportedMediaTypes: [BANNER, VIDEO],

isBidRequestValid: function(bid) {
return !!(bid.params.account && bid.params.location && (bid.params.format || bid.sizes));
return !!(bid.params.account && bid.params.location && (bid.params.format || bid.mediaTypes.banner.sizes));
},

buildRequests: function(validBidRequests, bidderRequest) {
if (validBidRequests.length === 0) {
return null;
}
const gdprConsent = bidderRequest.gdprConsent;
const refererInfo = bidderRequest.refererInfo;

const { gdprConsent, refererInfo } = bidderRequest;

const account = getAccount(validBidRequests);
const targets = validBidRequests.map(bid => bid.params.data).reduce(mergeTargets, {});
const gdprParams = (gdprConsent && gdprConsent.consentString) ? [ 'xt' + gdprConsent.consentString, 'tlall' ] : [];
const refererParams = (refererInfo && refererInfo.referer) ? [ 'xf' + base64urlEncode(refererInfo.referer) ] : [];
const gdprParams = (gdprConsent && gdprConsent.consentString) ? [`xt${gdprConsent.consentString}`] : [];
const refererParams = (refererInfo && refererInfo.referer) ? [`xf${base64urlEncode(refererInfo.referer)}`] : [];
const targetsParams = Object.keys(targets).map(targetCode => targetCode + targets[targetCode].join(';'));
const slotsParams = validBidRequests.map(bid => 'sl' + bidToSlotName(bid));
const params = [...slotsParams, ...targetsParams, ...gdprParams, ...refererParams].map(s => '/' + s).join('');
const params = [...slotsParams, ...targetsParams, ...gdprParams, ...refererParams].map(s => `/${s}`).join('');
const cacheBuster = '?t=' + new Date().getTime();
const uri = 'https://ads-' + account + '.adhese.com/json' + params + cacheBuster;

Expand Down Expand Up @@ -86,15 +85,7 @@ function adResponse(bid, ad) {
creativeId: adDetails.creativeId,
dealId: adDetails.dealId,
adhese: {
creativeId: adDetails.creativeId,
dealId: adDetails.dealId,
priority: adDetails.priority,
orderProperty: adDetails.orderProperty,
adFormat: adDetails.adFormat,
adType: adDetails.adType,
adspaceId: adDetails.adspaceId,
libId: adDetails.libId,
viewableImpressionCounter: adDetails.viewableImpressionCounter
originData: adDetails.originData
}
});

Expand Down Expand Up @@ -127,17 +118,16 @@ function bidToSlotName(bid) {
if (bid.params.format) {
return bid.params.location + '-' + bid.params.format;
}

var sizes = bid.sizes;
var format = '';

var sizes = bid.mediaTypes.banner.sizes;
sizes.sort();
sizes.forEach(function(size){
format += (format.length>0?'_':'') + size[0] + 'x' + size[1];
});
if (format.length>0)
var format = sizes.map(size => size[0] + 'x' + size[1]).join('_');

if (format.length > 0) {
return bid.params.location + '-' + format;
else
} else {
return bid.params.location;
}
}

function getAccount(validBidRequests) {
Expand All @@ -149,7 +139,7 @@ function getbaseAdResponse(response) {
}

function isAdheseAd(ad) {
return !ad.origin || ad.origin === 'JERLICIA' || ad.origin === 'DALE';
return !ad.origin || ad.origin === 'JERLICIA';
}

function getMediaType(markup) {
Expand All @@ -175,40 +165,35 @@ function getPrice(ad) {
function getAdDetails(ad) {
let creativeId = '';
let dealId = '';
let priority = -1;
let orderProperty = {};
let adFormat = '';
let adType = '';
let adspaceId = '';
let libId = '';
let viewableImpressionCounter = '';
let originData = {};

if (isAdheseAd(ad)) {
creativeId = ad.id;
dealId = ad.orderId;
priority = ad.priority;
orderProperty = ad.orderProperty;
adFormat = ad.adFormat;
adType = ad.adType;
libId = ad.libId;
adspaceId = ad.adspaceId;
viewableImpressionCounter = ad.viewableImpressionCounter;
originData = { priority: ad.priority, orderProperty: ad.orderProperty, adFormat: ad.adFormat, adType: ad.adType, libId: ad.libId, adspaceId: ad.adspaceId, viewableImpressionCounter: ad.viewableImpressionCounter, slotId: ad.slotID, slotName: ad.slotName, advertiserId: ad.advertiserId, adId: ad.id };
} else {
creativeId = ad.origin + (ad.originInstance ? '-' + ad.originInstance : '');
if (ad.originData && ad.originData.seatbid && ad.originData.seatbid.length) {
const seatbid = ad.originData.seatbid[0];
if (seatbid.bid && seatbid.bid.length) {
const bid = seatbid.bid[0];
creativeId = String(bid.crid || '');
dealId = String(bid.dealid || '');
if (ad.originData) {
originData = ad.originData;
originData.slotId = ad.slotID;
originData.slotName = ad.slotName;
originData.adType = ad.adType;
if (ad.adFormat) originData.adFormat = ad.adFormat;
if (ad.originData.seatbid && ad.originData.seatbid.length) {
const seatbid = ad.originData.seatbid[0];
if (seatbid.bid && seatbid.bid.length) {
const bid = seatbid.bid[0];
creativeId = String(bid.crid || '');
dealId = String(bid.dealid || '');
}
}
}
}
return { creativeId: creativeId, dealId: dealId, priority: priority, orderProperty: orderProperty, adFormat: adFormat, adType: adType, libId: libId, adspaceId: adspaceId, viewableImpressionCounter: viewableImpressionCounter };
return { creativeId: creativeId, dealId: dealId, originData: originData };
}

function base64urlEncode(s) {
return btoa(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, '');
return btoa(s).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
}

registerBidder(spec);
47 changes: 46 additions & 1 deletion test/spec/modules/adheseBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expect} from 'chai';
import {spec} from 'modules/adheseBidAdapter';
import {spec} from 'modules/adheseBidAdapter.js';

const BID_ID = 456;
const TTL = 360;
Expand Down Expand Up @@ -120,6 +120,7 @@ describe('AdheseAdapter', function () {
origin: 'APPNEXUS',
originInstance: '',
ext: 'js',
slotID: '10',
slotName: '_main_page_-leaderboard',
adType: 'leaderboard',
originData: {
Expand Down Expand Up @@ -153,6 +154,19 @@ describe('AdheseAdapter', function () {
mediaType: 'banner',
netRevenue: NET_REVENUE,
ttl: TTL,
adhese: {
originData: {
adType: 'leaderboard',
seatbid: [
{
bid: [ { crid: '60613369', dealid: null } ],
seat: '958'
}
],
slotId: '10',
slotName: '_main_page_-leaderboard'
}
}
}];
expect(spec.interpretResponse(sspBannerResponse, bidRequest)).to.deep.equal(expectedResponse);
});
Expand Down Expand Up @@ -185,6 +199,7 @@ describe('AdheseAdapter', function () {
mediaType: 'video',
netRevenue: NET_REVENUE,
ttl: TTL,
adhese: { originData: {} }
}];
expect(spec.interpretResponse(sspVideoResponse, bidRequest)).to.deep.equal(expectedResponse);
});
Expand Down Expand Up @@ -235,6 +250,21 @@ describe('AdheseAdapter', function () {
let expectedResponse = [{
requestId: BID_ID,
ad: '<script id="body" type="text/javascript"></script><img src=\'https://hosts-demo.adhese.com/track/742898\' style=\'height:1px; width:1px; margin: -1px -1px; display:none;\'/>',
adhese: {
originData: {
adFormat: 'largeleaderboard',
adId: '742898',
adType: 'largeleaderboard',
adspaceId: '162363',
libId: '90511',
orderProperty: undefined,
priority: undefined,
viewableImpressionCounter: undefined,
slotId: '29306',
slotName: '_main_page_-leaderboard',
advertiserId: '2081'
}
},
cpm: 5.96,
currency: 'USD',
creativeId: '742898',
Expand Down Expand Up @@ -279,6 +309,21 @@ describe('AdheseAdapter', function () {
let expectedResponse = [{
requestId: BID_ID,
vastXml: '<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'no\'?><VAST version=\'2.0\' xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\' xsi:noNamespaceSchemaLocation=\'vast.xsd\'></VAST>',
adhese: {
originData: {
adFormat: '',
adId: '742470',
adType: 'preroll',
adspaceId: '164196',
libId: '89860',
orderProperty: undefined,
priority: undefined,
viewableImpressionCounter: undefined,
slotId: '41711',
slotName: '_main_page_-leaderboard',
advertiserId: '2263',
}
},
cpm: 0,
currency: 'USD',
creativeId: '742470',
Expand Down

0 comments on commit 57f0033

Please sign in to comment.