From 0750135e15348ece8091c759563baa73010293e1 Mon Sep 17 00:00:00 2001 From: Matt Lane Date: Thu, 7 Jul 2016 15:30:28 -0700 Subject: [PATCH] Emit initial auction event * Generate random v4 UUID for auction id * Remove redundant param from BID_RESPONSE event * Send all configuration options * Remove referrer --- src/adaptermanager.js | 8 +++++++- src/adapters/analytics/AnalyticsAdapter.js | 7 ++++++- src/adapters/analytics/ga.js | 2 +- src/bidmanager.js | 2 +- src/constants.json | 1 + src/utils.js | 13 +++++++++++++ 6 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/adaptermanager.js b/src/adaptermanager.js index ed5aef80a7b..8a2cabc772f 100644 --- a/src/adaptermanager.js +++ b/src/adaptermanager.js @@ -26,7 +26,13 @@ function getBids({ bidderCode, requestId, bidderRequestId, adUnits }) { } exports.callBids = ({ adUnits, cbTimeout }) => { - const requestId = utils.getUniqueIdentifierStr(); + const requestId = utils.generateUUID(); + + const auctionInit = { + timestamp: Date.now(), + requestId, + }; + events.emit(CONSTANTS.EVENTS.AUCTION_INIT, auctionInit); getBidderCodes(adUnits).forEach(bidderCode => { const adapter = _bidderRegistry[bidderCode]; diff --git a/src/adapters/analytics/AnalyticsAdapter.js b/src/adapters/analytics/AnalyticsAdapter.js index 54824757050..62f7143b947 100644 --- a/src/adapters/analytics/AnalyticsAdapter.js +++ b/src/adapters/analytics/AnalyticsAdapter.js @@ -5,6 +5,7 @@ import { ajax } from 'src/ajax'; const events = require('src/events'); const utils = require('../../utils'); +const AUCTION_INIT = CONSTANTS.EVENTS.AUCTION_INIT; const BID_REQUESTED = CONSTANTS.EVENTS.BID_REQUESTED; const BID_TIMEOUT = CONSTANTS.EVENTS.BID_TIMEOUT; const BID_RESPONSE = CONSTANTS.EVENTS.BID_RESPONSE; @@ -67,7 +68,7 @@ export default function AnalyticsAdapter({ url, analyticsType, global, handler } } } - function _enable() { + function _enable(config) { var _this = this; //first send all events fired before enableAnalytics called @@ -93,6 +94,10 @@ export default function AnalyticsAdapter({ url, analyticsType, global, handler } events.on(BID_TIMEOUT, args => this.enqueue({ eventType: BID_TIMEOUT, args })); events.on(BID_WON, args => this.enqueue({ eventType: BID_WON, args })); events.on(BID_ADJUSTMENT, args => this.enqueue({ eventType: BID_ADJUSTMENT, args })); + events.on(AUCTION_INIT, args => { + args.config = config.options; // enableAnaltyics configuration object + this.enqueue({ eventType: AUCTION_INIT, args }); + }); // finally set this function to return log message, prevents multiple adapter listeners this.enableAnalytics = function _enable() { diff --git a/src/adapters/analytics/ga.js b/src/adapters/analytics/ga.js index 24ab37cd73f..0ea3e3ba928 100644 --- a/src/adapters/analytics/ga.js +++ b/src/adapters/analytics/ga.js @@ -71,7 +71,7 @@ exports.enableAnalytics = function ({ provider, options }) { }); //bidResponses - events.on(BID_RESPONSE, function (adunit, bid) { + events.on(BID_RESPONSE, function (bid) { sendBidResponseToGa(bid); sendBidTimeouts(bid); }); diff --git a/src/bidmanager.js b/src/bidmanager.js index a636cb1ad26..6715c290c87 100644 --- a/src/bidmanager.js +++ b/src/bidmanager.js @@ -88,7 +88,7 @@ exports.addBidResponse = function (adUnitCode, bid) { events.emit(CONSTANTS.EVENTS.BID_ADJUSTMENT, bid); //emit the bidResponse event - events.emit(CONSTANTS.EVENTS.BID_RESPONSE, adUnitCode, bid); + events.emit(CONSTANTS.EVENTS.BID_RESPONSE, bid); //append price strings const priceStringsObj = getPriceBucketString(bid.cpm, bid.height, bid.width); diff --git a/src/constants.json b/src/constants.json index caabf9eb7e3..5e03c5e5eaf 100644 --- a/src/constants.json +++ b/src/constants.json @@ -28,6 +28,7 @@ "objectType_string": "string", "objectType_number": "number", "EVENTS": { + "AUCTION_INIT": "auctionInit", "BID_ADJUSTMENT": "bidAdjustment", "BID_TIMEOUT": "bidTimeout", "BID_REQUESTED": "bidRequested", diff --git a/src/utils.js b/src/utils.js index c9ba7ccf957..507df5b6bc5 100644 --- a/src/utils.js +++ b/src/utils.js @@ -55,6 +55,19 @@ function _getUniqueIdentifierStr() { //generate a random string (to be used as a dynamic JSONP callback) exports.getUniqueIdentifierStr = _getUniqueIdentifierStr; +/** + * Returns a random v4 UUID of the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx, + * where each x is replaced with a random hexadecimal digit from 0 to f, + * and y is replaced with a random hexadecimal digit from 8 to b. + * https://gist.github.com/jed/982883 via node-uuid + */ +exports.generateUUID = function generateUUID(placeholder) { + return placeholder ? + (placeholder ^ Math.random() * 16 >> placeholder/4).toString(16) + : + ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, generateUUID); +}; + exports.getBidIdParamater = function (key, paramsObj) { if (paramsObj && paramsObj[key]) { return paramsObj[key];