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

Update Roxot prebid analytic adapter #1034

Merged
merged 30 commits into from
Apr 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6101172
add roxot adapter
Sep 15, 2016
4406098
Merge remote-tracking branch 'upstream/master'
kir-roxot Sep 22, 2016
08039e2
Merge branch 'master' of github.com:prebid/Prebid.js
kir-roxot Sep 29, 2016
992c981
update roxot analytics system
kir-roxot Sep 30, 2016
752422c
Merge branch 'master' of github.com:prebid/Prebid.js
kir-roxot Sep 30, 2016
d098b41
remove unused test
kir-roxot Sep 30, 2016
c230290
remove unused import
kir-roxot Sep 30, 2016
7ce1d58
Merge branch 'master' of github.com:prebid/Prebid.js
kir-roxot Oct 4, 2016
3f34fac
update code after review
kir-roxot Oct 12, 2016
4d68205
Merge branch 'master' of github.com:prebid/Prebid.js
kir-roxot Oct 24, 2016
993e6f1
Merge branch 'master' of github.com:prebid/Prebid.js
kir-roxot Feb 3, 2017
3552515
Merge branch 'master' of github.com:prebid/Prebid.js
kir-roxot Feb 28, 2017
699c6fc
add analytic adapter - roxot prebid analytic
Mar 1, 2017
e4449de
Update roxot prebid analytic
Mar 1, 2017
cf3c480
update
kir-roxot Mar 3, 2017
0d9cf48
Fix tests
paglliac Mar 5, 2017
1f49842
Merge branch 'master' of github.com:prebid/Prebid.js into feature/rox…
kir-roxot Mar 7, 2017
9a20ee0
Fix Roxot tests
kir-roxot Mar 7, 2017
6830f74
Fix endpoint
kir-roxot Mar 7, 2017
946e149
Register config only once.
kir-roxot Mar 15, 2017
4b06cb7
Clear ad parameter for optimize traffic
kir-roxot Mar 22, 2017
645d10c
Merge branch 'master' of github.com:prebid/Prebid.js into feature/rox…
kir-roxot Mar 22, 2017
ae802d0
Fix after review
kir-roxot Mar 27, 2017
a2762e9
Merge branch 'master' of github.com:prebid/Prebid.js into feature/rox…
kir-roxot Apr 5, 2017
f3ed3f7
Fix remove ad from global object
kir-roxot Apr 10, 2017
f7c3eab
Add tests.
Aleksandr-roxot Apr 10, 2017
c608729
Merge branch 'master' of https://github.com/prebid/Prebid.js into fea…
Aleksandr-roxot Apr 10, 2017
8702ba3
Remove request_bids event from AnalyticsAdapter.js
Aleksandr-roxot Apr 10, 2017
b6ac875
Remove extra dependencies
Aleksandr-roxot Apr 11, 2017
b1dcfdf
Merge branch 'master' of https://github.com/prebid/Prebid.js into fea…
Aleksandr-roxot Apr 11, 2017
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"babel-plugin-transform-es3-member-expression-literals": "^6.8.0",
"babel-plugin-transform-es3-property-literals": "^6.8.0",
"babel-plugin-transform-object-assign": "^6.8.0",
"babel-preset-es2015": "^6.5.0",
"babel-preset-es2015": "^6.24.1",
"block-loader": "^2.1.0",
"chai": "^3.3.0",
"coveralls": "^2.11.11",
Expand Down
2 changes: 2 additions & 0 deletions src/adapters/analytics/AnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const events = require('src/events');
const utils = require('../../utils');

const AUCTION_INIT = CONSTANTS.EVENTS.AUCTION_INIT;
const AUCTION_END = CONSTANTS.EVENTS.AUCTION_END;
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 @@ -105,6 +106,7 @@ export default function AnalyticsAdapter({ url, analyticsType, global, handler }
[BID_TIMEOUT]: args => this.enqueue({ eventType: BID_TIMEOUT, args }),
[BID_WON]: args => this.enqueue({ eventType: BID_WON, args }),
[BID_ADJUSTMENT]: args => this.enqueue({ eventType: BID_ADJUSTMENT, args }),
[AUCTION_END]: args => this.enqueue({ eventType: AUCTION_END, args }),
[AUCTION_INIT]: args => {
args.config = config.options; // enableAnaltyics configuration object
this.enqueue({ eventType: AUCTION_INIT, args });
Expand Down
99 changes: 89 additions & 10 deletions src/adapters/analytics/roxot.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,98 @@
import { ajax } from 'src/ajax';
import adapter from 'AnalyticsAdapter';
import {ajax} from "src/ajax";
import adapter from "AnalyticsAdapter";
import CONSTANTS from "src/constants.json";

const utils = require('../../utils');

const url = '//d.rxthdr.com/analytics';
const url = '//pa.rxthdr.com/analytic';
const analyticsType = 'endpoint';

export default Object.assign(adapter(
{
url,
analyticsType
let auctionInitConst = CONSTANTS.EVENTS.AUCTION_INIT;
let auctionEndConst = CONSTANTS.EVENTS.AUCTION_END;
let bidWonConst = CONSTANTS.EVENTS.BID_WON;

let initOptions = {publisherIds: []};
let bidWon = {options: {}, events: []};
let eventStack = {options: {}, events: []};

let auctionStatus = 'not_started';

function checkOptions() {
if (typeof initOptions.publisherIds === 'undefined') {
return false;
}
),

return initOptions.publisherIds.length > 0;
}

function buildBidWon(eventType, args) {
bidWon.options = initOptions;
bidWon.events = [{args: args, eventType: eventType}];
}

function buildEventStack() {
eventStack.options = initOptions;
}

function send(eventType, data, sendDataType) {
let fullUrl = url + '?publisherIds[]=' + initOptions.publisherIds.join('&publisherIds[]=') + '&host=' + window.location.hostname;

ajax(
fullUrl,
(result) => utils.logInfo('Event ' + eventType + ' sent ' + sendDataType + ' to roxot prebid analytic with result' + result),
JSON.stringify(data)
);
}

function pushEvent(eventType, args) {
eventStack.events.push({eventType, args});
}

function flushEvents() {
eventStack.events = [];
}

let roxotAdapter = Object.assign(adapter({url, analyticsType}),
{
track({ eventType, args }) {
ajax(url, (result) => utils.logInfo('Event ' + eventType + ' sent to roxot analytics with result ' + result), JSON.stringify({ eventType, args }));
track({eventType, args}) {
if (!checkOptions()) {
return;
}

let info = Object.assign({}, args);

if (info && info.ad) {
info.ad = "";
}

if (eventType === auctionInitConst) {
auctionStatus = 'started';
flushEvents();
}

if ((eventType === bidWonConst) && auctionStatus === 'not_started') {
buildBidWon(eventType,info);
send(eventType, bidWon, 'bidWon');
return;
}

if (eventType === auctionEndConst) {
buildEventStack(eventType);
send(eventType, eventStack, 'eventStack');
flushEvents();
auctionStatus = 'not_started';
} else {
pushEvent(eventType, info);
}
}
});

roxotAdapter.originEnableAnalytics = roxotAdapter.enableAnalytics;

roxotAdapter.enableAnalytics = function (config) {
initOptions = config.options;
utils.logInfo('Roxot Analytics enabled with config', initOptions);
roxotAdapter.originEnableAnalytics(config);
};

export default roxotAdapter;
35 changes: 35 additions & 0 deletions test/spec/adapters/analytics/roxot_analytic_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import roxotAnalytic from 'src/adapters/analytics/roxot';
let events = require('../../../../src/events');
let adaptermanager = require('../../../../src/adaptermanager');
let constants = require('../../../../src/constants.json');

describe('Roxot Prebid Analytic', function () {

describe('enableAnalytics', function () {


it('should catch all events', function () {
sinon.spy(roxotAnalytic, 'track');

adaptermanager.registerAnalyticsAdapter({
code: 'roxot',
adapter: roxotAnalytic
});

adaptermanager.enableAnalytics({
provider: 'roxot',
options: {
publisherIds: ['test_roxot_prebid_analytid_publisher_id']
}
});

events.emit(constants.EVENTS.AUCTION_INIT, {});
events.emit(constants.EVENTS.AUCTION_END, {});
events.emit(constants.EVENTS.BID_REQUESTED, {});
events.emit(constants.EVENTS.BID_RESPONSE, {});
events.emit(constants.EVENTS.BID_WON, {});

sinon.assert.callCount(roxotAnalytic.track, 5);
});
});
});