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

Emit initial auction event #441

Merged
merged 1 commit into from
Jul 12, 2016
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
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