Skip to content

Commit

Permalink
Emit initial auction event
Browse files Browse the repository at this point in the history
* Generate random v4 UUID for auction id
* Remove redundant param from BID_RESPONSE event
* Send all configuration options
* Remove referrer
  • Loading branch information
matthewlane committed Jul 10, 2016
1 parent ce010c2 commit 0750135
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/adaptermanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
7 changes: 6 additions & 1 deletion src/adapters/analytics/AnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/analytics/ga.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion src/bidmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"objectType_string": "string",
"objectType_number": "number",
"EVENTS": {
"AUCTION_INIT": "auctionInit",
"BID_ADJUSTMENT": "bidAdjustment",
"BID_TIMEOUT": "bidTimeout",
"BID_REQUESTED": "bidRequested",
Expand Down
13 changes: 13 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 0750135

Please sign in to comment.