Skip to content

Commit

Permalink
Merge branch 'master' into rubicon-feature/s2s-test-module
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Harper committed Oct 6, 2017
2 parents 3a4c24f + a9dda35 commit 4a3abd7
Show file tree
Hide file tree
Showing 33 changed files with 1,517 additions and 1,228 deletions.
15 changes: 9 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,22 @@ function bundle(dev, moduleArr) {

var entries = [helpers.getBuiltPrebidCoreFile(dev)].concat(helpers.getBuiltModules(dev, modules));

var outputFileName = argv.bundleName ? argv.bundleName : 'prebid.js';

// change output filename if argument --tag given
if (argv.tag && argv.tag.length) {
outputFileName = outputFileName.replace(/\.js$/, `.${argv.tag}.js`);
}

gutil.log('Concatenating files:\n', entries);
gutil.log('Appending ' + prebid.globalVarName + '.processQueue();');
gutil.log('Generating bundle:', outputFileName);

return gulp.src(
entries
)
.pipe(gulpif(dev, sourcemaps.init({loadMaps: true})))
.pipe(concat(argv.bundleName ? argv.bundleName : 'prebid.js'))
.pipe(concat(outputFileName))
.pipe(gulpif(!argv.manualEnable, footer('\n<%= global %>.processQueue();', {
global: prebid.globalVarName
}
Expand Down Expand Up @@ -142,11 +150,6 @@ gulp.task('devpack', ['clean'], function () {
gulp.task('webpack', ['clean'], function () {
var cloned = _.cloneDeep(webpackConfig);

// change output filename if argument --tag given
if (argv.tag && argv.tag.length) {
cloned.output.filename = 'prebid.' + argv.tag + '.js';
}

delete cloned.devtool;

var externalModules = helpers.getArgModules();
Expand Down
4 changes: 3 additions & 1 deletion integrationExamples/gpt/pbjs_example_gpt.html
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@
},
{
bidder: 'yieldmo',
params: {}
params: {
placementId: 'ym_12341234' // Optional Yieldmo Placement ID
}
},
{
bidder: 'adequant',
Expand Down
2 changes: 1 addition & 1 deletion integrationExamples/gpt/pbjs_video_adUnit.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
var videoAdUnit = {
code: 'video1',
sizes: [640,480],
mediaType: 'video',
mediaTypes: { video: {} },
bids: [
{
bidder: 'appnexusAst',
Expand Down
2 changes: 1 addition & 1 deletion modules/adomikAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ adomikAdapter.sendTypedEvent = function() {
splittedUrl.forEach((split, i) => {
const partUrl = `${split}&id=${adomikAdapter.currentContext.id}&part=${i}&on=${splittedUrl.length - 1}`;
const img = new Image(1, 1);
img.src = 'http://' + adomikAdapter.currentContext.url + '/?q=' + partUrl;
img.src = 'https://' + adomikAdapter.currentContext.url + '/?q=' + partUrl;
})
};

Expand Down
94 changes: 94 additions & 0 deletions modules/adxcgAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import {ajax} from 'src/ajax';
import adapter from 'src/AnalyticsAdapter';
import adaptermanager from 'src/adaptermanager';
import * as url from 'src/url';
import * as utils from 'src/utils';

const emptyUrl = '';
const analyticsType = 'endpoint';
const adxcgAnalyticsVersion = 'v1.04';

let initOptions;
let auctionTimestamp;
let events = {
bidRequests: [],
bidResponses: []
};

var adxcgAnalyticsAdapter = Object.assign(adapter(
{
emptyUrl,
analyticsType
}), {
track({eventType, args}) {
if (typeof args !== 'undefined') {
if (eventType === 'bidTimeout') {
events.bidTimeout = args;
} else if (eventType === 'auctionInit') {
events.auctionInit = args;
auctionTimestamp = args.timestamp;
} else if (eventType === 'bidRequested') {
events.bidRequests.push(args);
} else if (eventType === 'bidResponse') {
events.bidResponses.push(mapBidResponse(args));
} else if (eventType === 'bidWon') {
send({
bidWon: mapBidResponse(args)
});
}
}

if (eventType === 'auctionEnd') {
send(events);
}
}
});

function mapBidResponse(bidResponse) {
return {
adUnitCode: bidResponse.adUnitCode,
statusMessage: bidResponse.statusMessage,
bidderCode: bidResponse.bidderCode,
adId: bidResponse.adId,
mediaType: bidResponse.mediaType,
creative_id: bidResponse.creative_id,
width: bidResponse.width,
height: bidResponse.height,
cpm: bidResponse.cpm,
timeToRespond: bidResponse.timeToRespond
};
}

function send(data) {
data.initOptions = initOptions;
data.auctionTimestamp = auctionTimestamp;

let location = utils.getTopWindowLocation();
let secure = location.protocol == 'https:';

let adxcgAnalyticsRequestUrl = url.format({
protocol: secure ? 'https' : 'http',
hostname: secure ? 'hbarxs.adxcg.net' : 'hbarx.adxcg.net',
pathname: '/pbrx',
search: {
auctionTimestamp: auctionTimestamp,
adxcgAnalyticsVersion: adxcgAnalyticsVersion,
prebidVersion: $$PREBID_GLOBAL$$.version
}
});

ajax(adxcgAnalyticsRequestUrl, undefined, JSON.stringify(data), {method: 'POST'});
}

adxcgAnalyticsAdapter.originEnableAnalytics = adxcgAnalyticsAdapter.enableAnalytics;
adxcgAnalyticsAdapter.enableAnalytics = function (config) {
initOptions = config.options;
adxcgAnalyticsAdapter.originEnableAnalytics(config);
};

adaptermanager.registerAnalyticsAdapter({
adapter: adxcgAnalyticsAdapter,
code: 'adxcg'
});

export default adxcgAnalyticsAdapter;
9 changes: 6 additions & 3 deletions modules/adyoulikeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { STATUS } from 'src/constants';
import adaptermanager from 'src/adaptermanager';

var AdyoulikeAdapter = function AdyoulikeAdapter() {
const _VERSION = '0.1';
const _VERSION = '0.2';

const baseAdapter = new Adapter('adyoulike');

Expand All @@ -21,7 +21,7 @@ var AdyoulikeAdapter = function AdyoulikeAdapter() {

const placements = validBids.map(bid => bid.params.placement);
if (!utils.isEmpty(placements)) {
const body = createBody(placements);
const body = createBody(bidRequests, placements);
const endpoint = createEndpoint();
ajax(endpoint,
(response) => {
Expand Down Expand Up @@ -61,10 +61,11 @@ var AdyoulikeAdapter = function AdyoulikeAdapter() {
}

/* Create request body */
function createBody(placements) {
function createBody(bidRequests, placements) {
const body = {
Version: _VERSION,
Placements: placements,
TransactionIds: {}
};

// performance isn't supported by mobile safari iOS7. window.performance works, but
Expand All @@ -80,6 +81,8 @@ var AdyoulikeAdapter = function AdyoulikeAdapter() {
body.PageRefreshed = false;
}

placements.forEach(placement => { body.TransactionIds[placement] = bidRequests[placement].transactionId; });

return JSON.stringify(body);
}

Expand Down
71 changes: 45 additions & 26 deletions modules/appnexusAstBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ const NATIVE_MAPPING = {
cta: 'ctatext',
image: {
serverName: 'main_image',
serverParams: { required: true, sizes: [{}] }
requiredParams: { required: true },
minimumParams: { sizes: [{}] },
},
icon: {
serverName: 'icon',
serverParams: { required: true, sizes: [{}] }
requiredParams: { required: true },
minimumParams: { sizes: [{}] },
},
sponsoredBy: 'sponsored_by'
sponsoredBy: 'sponsored_by',
};
const SOURCE = 'pbjs';

Expand Down Expand Up @@ -260,32 +262,11 @@ function bidToTag(bid) {
tag.keywords = getKeywords(bid.params.keywords);
}

if (bid.mediaType === 'native') {
if (bid.mediaType === 'native' || utils.deepAccess(bid, 'mediaTypes.native')) {
tag.ad_types = ['native'];

if (bid.nativeParams) {
const nativeRequest = {};

// map standard prebid native asset identifier to /ut parameters
// e.g., tag specifies `body` but /ut only knows `description`
// mapping may be in form {tag: '<server name>'} or
// {tag: {serverName: '<server name>', serverParams: {...}}}
Object.keys(bid.nativeParams).forEach(key => {
// check if one of the <server name> forms is used, otherwise
// a mapping wasn't specified so pass the key straight through
const requestKey =
(NATIVE_MAPPING[key] && NATIVE_MAPPING[key].serverName) ||
NATIVE_MAPPING[key] ||
key;

// if the mapping for this identifier specifies required server
// params via the `serverParams` object, merge that in
nativeRequest[requestKey] = Object.assign({},
NATIVE_MAPPING[key] && NATIVE_MAPPING[key].serverParams,
bid.nativeParams[key]
);
});

const nativeRequest = buildNativeRequest(bid.nativeParams);
tag['native'] = {layouts: [nativeRequest]};
}
}
Expand Down Expand Up @@ -343,6 +324,44 @@ function getRtbBid(tag) {
return tag && tag.ads && tag.ads.length && tag.ads.find(ad => ad.rtb);
}

function buildNativeRequest(params) {
const request = {};

// map standard prebid native asset identifier to /ut parameters
// e.g., tag specifies `body` but /ut only knows `description`.
// mapping may be in form {tag: '<server name>'} or
// {tag: {serverName: '<server name>', requiredParams: {...}}}
Object.keys(params).forEach(key => {
// check if one of the <server name> forms is used, otherwise
// a mapping wasn't specified so pass the key straight through
const requestKey =
(NATIVE_MAPPING[key] && NATIVE_MAPPING[key].serverName) ||
NATIVE_MAPPING[key] ||
key;

// required params are always passed on request
const requiredParams = NATIVE_MAPPING[key] && NATIVE_MAPPING[key].requiredParams;
request[requestKey] = Object.assign({}, requiredParams, params[key]);

// minimum params are passed if no non-required params given on adunit
const minimumParams = NATIVE_MAPPING[key] && NATIVE_MAPPING[key].minimumParams;

if (requiredParams && minimumParams) {
// subtract required keys from adunit keys
const adunitKeys = Object.keys(params[key]);
const requiredKeys = Object.keys(requiredParams);
const remaining = adunitKeys.filter(key => !requiredKeys.includes(key));

// if none are left over, the minimum params needs to be sent
if (remaining.length === 0) {
request[requestKey] = Object.assign({}, request[requestKey], minimumParams);
}
}
});

return request;
}

function outstreamRender(bid) {
// push to render queue because ANOutstreamVideo may not be loaded yet
bid.renderer.push(() => {
Expand Down
4 changes: 2 additions & 2 deletions modules/criteoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ var CriteoAdapter = function CriteoAdapter() {
var w = parseInt(sizeString.substring(0, xIndex));
var h = parseInt(sizeString.substring(xIndex + 1, sizeString.length))
return new Criteo.PubTag.DirectBidding.Size(w, h);
}
)
}),
bid.params.publisherSubId
)
);

Expand Down
35 changes: 27 additions & 8 deletions modules/prebidServerBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import bidmanager from 'src/bidmanager';
import * as utils from 'src/utils';
import { ajax } from 'src/ajax';
import { STATUS, S2S } from 'src/constants';
import { userSync } from 'src/userSync.js';
import { cookieSet } from 'src/cookie.js';
import adaptermanager from 'src/adaptermanager';
import { config } from 'src/config';
import { StorageManager, pbjsSyncsKey } from 'src/storagemanager';

const getConfig = config.getConfig;

const TYPE = S2S.SRC;
const cookieSetUrl = 'https://acdn.adnxs.com/cookieset/cs.js';
let _synced = false;

/**
* Try to convert a value to a type.
Expand Down Expand Up @@ -112,6 +111,7 @@ function PrebidServer() {
tid: bidRequest.tid,
max_bids: config.maxBids,
timeout_millis: config.timeout,
secure: config.secure,
url: utils.getTopWindowUrl(),
prebid_version: '$prebid.version$',
ad_units: bidRequest.ad_units.filter(hasSizes),
Expand All @@ -135,6 +135,27 @@ function PrebidServer() {
return unit.sizes && unit.sizes.length;
}

/**
* Run a cookie sync for the given type, url, and bidder
*
* @param {string} type the type of sync, "image", "redirect", "iframe"
* @param {string} url the url to sync
* @param {string} bidder name of bidder doing sync for
*/
function doBidderSync(type, url, bidder) {
if (!url) {
utils.logError(`No sync url for bidder "${bidder}": ${url}`);
} else if (type === 'image' || type === 'redirect') {
utils.logMessage(`Invoking image pixel user sync for bidder: "${bidder}"`);
utils.triggerPixel(url);
} else if (type == 'iframe') {
utils.logMessage(`Invoking iframe user sync for bidder: "${bidder}"`);
utils.insertUserSyncIframe(url);
} else {
utils.logError(`User sync type "${type}" not supported for bidder: "${bidder}"`);
}
}

/* Notify Prebid of bid responses so bids can get in the auction */
function handleResponse(response, requestedBidders) {
let result;
Expand All @@ -145,7 +166,7 @@ function PrebidServer() {
if (result.bidder_status) {
result.bidder_status.forEach(bidder => {
if (bidder.no_cookie && !_cookiesQueued) {
userSync.registerSync(bidder.usersync.type, bidder.bidder, bidder.usersync.url);
doBidderSync(bidder.usersync.type, bidder.usersync.url, bidder.bidder);
}
});
}
Expand Down Expand Up @@ -214,12 +235,10 @@ function PrebidServer() {
* @param {} {bidders} list of bidders to request user syncs for.
*/
baseAdapter.queueSync = function({bidderCodes}) {
let syncedList = StorageManager.get(pbjsSyncsKey) || [];
// filter synced bidders - https://github.com/prebid/Prebid.js/issues/1582
syncedList = bidderCodes.filter(bidder => !syncedList.includes(bidder));
if (syncedList.length === 0) {
if (_synced) {
return;
}
_synced = true;
const payload = JSON.stringify({
uuid: utils.generateUUID(),
bidders: bidderCodes
Expand All @@ -230,7 +249,7 @@ function PrebidServer() {
if (response.status === 'ok') {
bidderCodes.forEach(code => StorageManager.add(pbjsSyncsKey, code, true));
}
response.bidder_status.forEach(bidder => queueSync({bidder: bidder.bidder, url: bidder.usersync.url, type: bidder.usersync.type}));
response.bidder_status.forEach(bidder => doBidderSync(bidder.usersync.type, bidder.usersync.url, bidder.bidder));
} catch (e) {
utils.logError(e);
}
Expand Down
Loading

0 comments on commit 4a3abd7

Please sign in to comment.