Skip to content

Commit f86cf98

Browse files
author
Waley Chen
committed
Merge pull request #207 from 10gen/metrics
:okr: Intercom and Google Analytics integrations
2 parents 58b64df + 1cf9faa commit f86cf98

File tree

13 files changed

+144
-134
lines changed

13 files changed

+144
-134
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"mongodb-connection-model": "^3.0.6",
7878
"mongodb-instance-model": "^1.0.2",
7979
"mongodb-ns": "^1.0.1",
80+
"mongodb-js-metrics": "^0.2.2",
8081
"ms": "^0.7.1",
8182
"node-notifier": "^4.3.1",
8283
"scout-server": "http://bin.mongodb.org/js/scout-server/v0.4.6/scout-server-0.4.6.tar.gz"
@@ -103,7 +104,6 @@
103104
"backoff": "^2.4.1",
104105
"bootstrap": "https://github.com/twbs/bootstrap/archive/v3.3.5.tar.gz",
105106
"browserify": "^12.0.1",
106-
"bugsnag-js": "^2.4.8",
107107
"chalk": "^1.1.1",
108108
"d3": "^3.5.6",
109109
"del": "^2.0.2",

src/app.js

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ app.extend({
1313
}
1414
});
1515

16-
var bugsnag = require('./bugsnag');
17-
bugsnag.listen(app);
18-
16+
var metrics = require('mongodb-js-metrics');
1917
var _ = require('lodash');
2018
var domReady = require('domready');
2119
var qs = require('qs');
@@ -27,6 +25,7 @@ var localLinks = require('local-links');
2725
var QueryOptions = require('./models/query-options');
2826
var Connection = require('./models/connection');
2927
var MongoDBInstance = require('./models/mongodb-instance');
28+
var User = require('./models/user');
3029
var Router = require('./router');
3130
var Statusbar = require('./statusbar');
3231

@@ -116,6 +115,9 @@ var Application = View.extend({
116115
clientStartedAt: 'date',
117116
clientStalledTimeout: 'number'
118117
},
118+
children: {
119+
user: User
120+
},
119121
events: {
120122
'click a': 'onLinkClick'
121123
},
@@ -143,14 +145,26 @@ var Application = View.extend({
143145
pushState: false,
144146
root: '/'
145147
});
148+
149+
metrics.listen(app);
150+
151+
User.getOrCreate(function(err, user) {
152+
if (err) {
153+
metrics.error(err, 'user: get or create');
154+
return;
155+
}
156+
this.user.set(user.serialize());
157+
this.user.trigger('sync');
158+
}.bind(this));
159+
146160
app.statusbar.hide();
147161
},
148162
onFatalError: function(id, err) {
149163
debug('clearing client stall timeout...');
150164
clearTimeout(this.clientStalledTimeout);
151165

152166
console.error('Fatal Error!: ', id, err);
153-
bugsnag.notifyException(err, 'Fatal Error: ' + id);
167+
metrics.error(err, 'Fatal Error: ' + id);
154168
app.statusbar.fatal(err);
155169
},
156170
// ms we'll wait for a `scout-client` instance
@@ -228,20 +242,30 @@ var state = new Application({
228242
connection_id: connection_id
229243
});
230244

231-
// @todo (imlucas): Feature flags can be overrideen
232-
// via `window.localStorage`.
245+
/**
246+
* @todo (imlucas): Feature flags can be overridden
247+
* via `window.localStorage`.
248+
*/
233249
var FEATURES = {
234250
querybuilder: true,
235251
keychain: true,
236252
'Google Map Minicharts': true,
237253
'Connect with SSL': false,
238254
'Connect with Kerberos': false,
239255
'Connect with LDAP': false,
240-
'Connect with X.509': false
256+
'Connect with X.509': false,
257+
intercom: true,
258+
bugsnag: true,
259+
'google-analytics': true
241260
};
242261

243262
app.extend({
244263
client: null,
264+
config: {
265+
intercom: {
266+
app_id: 'p57suhg7'
267+
}
268+
},
245269
/**
246270
* Check whether a feature flag is currently enabled.
247271
*
@@ -267,6 +291,7 @@ app.extend({
267291
debug('message received from main process:', msg);
268292
this.trigger(msg);
269293
},
294+
metrics: metrics,
270295
init: function() {
271296
domReady(function() {
272297
state.render();
@@ -344,6 +369,13 @@ Object.defineProperty(app, 'router', {
344369
}
345370
});
346371

372+
Object.defineProperty(app, 'user', {
373+
get: function() {
374+
return state.user;
375+
}
376+
});
377+
378+
347379
app.init();
348380

349381
// expose app globally for debugging purposes

src/bugsnag.js

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/connect/behavior.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ module.exports = State.extend({
246246
// the user has modified the form fields and opted not to save the
247247
// changes. We need to create a new connection and leave the old
248248
// one intact.
249-
view.form.setValues({name: ''});
249+
view.form.setValues({
250+
name: ''
251+
});
250252
connection = new Connection(view.form.data);
251253
} else {
252254
connection = view.connection;

src/connect/filereader-view.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ module.exports = InputView.extend({
8888
if (spec.multi) {
8989
this.multi = spec.multi;
9090
}
91-
_.defaults(spec, {value: []});
91+
_.defaults(spec, {
92+
value: []
93+
});
9294
this.invalidClass = 'has-error';
9395
this.validityClassSelector = '.form-item-file';
9496
InputView.prototype.initialize.call(this, spec);
@@ -118,8 +120,7 @@ module.exports = InputView.extend({
118120
* Turn into no-op, as we don't work on input elements
119121
* @see ampersand-input-view.js#handleTypeChange
120122
*/
121-
handleTypeChange: function() {
122-
},
123+
handleTypeChange: function() {},
123124
/**
124125
* Turn into identity, as we don't need to trim the value
125126
* @param {Array} val the value to pass through

src/connect/index.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var debug = require('debug')('scout:connect:index');
88
var _ = require('lodash');
99
var app = require('ampersand-app');
1010
var format = require('util').format;
11+
var metrics = require('mongodb-js-metrics');
1112

1213
/**
1314
* AuthenticationOptionCollection
@@ -299,7 +300,9 @@ var ConnectView = View.extend({
299300
this.connection = new Connection(this.form.data);
300301
}
301302
this.connection.is_favorite = true;
302-
this.connection.save(null, {validate: false});
303+
this.connection.save(null, {
304+
validate: false
305+
});
303306
this.connections.add(this.connection, {
304307
merge: true
305308
});
@@ -366,23 +369,18 @@ var ConnectView = View.extend({
366369
useConnection: function(connection) {
367370
connection = connection || this.connection;
368371
app.statusbar.hide();
369-
/**
370-
* @todo (imlucas): So we can see what auth mechanisms
371-
* and accoutrement people are actually using IRL.
372-
*
373-
* metrics.trackEvent('connect success', {
374-
* authentication: model.authentication,
375-
* ssl: model.ssl
376-
* });
377-
*/
372+
metrics.track('connect success', {
373+
authentication: connection.authentication,
374+
ssl: connection.ssl
375+
});
378376

379377
/**
380378
* @see ./src/app.js `params.connection_id`
381379
*/
382380
window.open(
383381
format('%s?connection_id=%s#schema',
384-
window.location.origin,
385-
connection.getId())
382+
window.location.origin,
383+
connection.getId())
386384
);
387385
setTimeout(this.set.bind(this, {
388386
message: ''
@@ -447,8 +445,11 @@ var ConnectView = View.extend({
447445
* @api private
448446
*/
449447
onError: function(err, connection) {
450-
// @todo (imlucas): `metrics.trackEvent('connect error', authentication
451-
// + ssl boolean)`
448+
metrics.error(err, 'connect error', {
449+
authentication: connection.authentication,
450+
ssl: connection.ssl
451+
});
452+
452453
debug('showing error message', {
453454
err: err,
454455
model: connection

src/electron/menu.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,18 @@ function nonDarwinMenu(menuState) {
263263

264264
var MenuState = State.extend({
265265
props: {
266-
showCompassOverview: { type: 'boolean', default: false },
267-
showConnect: { type: 'boolean', default: true },
268-
showShare: { type: 'boolean', default: false }
266+
showCompassOverview: {
267+
type: 'boolean',
268+
default: false
269+
},
270+
showConnect: {
271+
type: 'boolean',
272+
default: true
273+
},
274+
showShare: {
275+
type: 'boolean',
276+
default: false
277+
}
269278
}
270279
});
271280

@@ -300,7 +309,7 @@ var AppMenu = (function() {
300309
getTemplate: function(winID) {
301310
var menuState = this.windowTemplates.get(winID);
302311

303-
debug("WINDOW's " + winID + ' Menu State');
312+
debug('WINDOW\'s ' + winID + ' Menu State');
304313
debug('showCompassOverview: ' + menuState.showCompassOverview);
305314
debug('showConnect: ' + menuState.showConnect);
306315
debug('showShare: ' + menuState.showShare);
@@ -329,9 +338,9 @@ var AppMenu = (function() {
329338
}
330339

331340
this.setTemplate(_window.id);
332-
debug('WINDOW ' + _window.id + "'s menu loaded");
341+
debug('WINDOW ' + _window.id + '\'s menu loaded');
333342
} else {
334-
debug('WINDOW ' + _window.id + "'s menu already loaded");
343+
debug('WINDOW ' + _window.id + '\'s menu already loaded');
335344
}
336345
},
337346

src/index.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ doctype html
22
html(lang='en')
33
head
44
title MongoDB
5-
meta(http-equiv="Content-Security-Policy", content="default-src *; script-src 'self' https://*.googleapis.com https://maps.gstatic.com http://localhost:35729 'unsafe-eval'; style-src 'self' https://fonts.googleapis.com 'unsafe-inline';")
5+
meta(http-equiv="Content-Security-Policy", content="default-src *; script-src 'self' https://*.googleapis.com https://maps.gstatic.com http://localhost:35729 https://widget.intercom.io https://js.intercomcdn.com/ 'unsafe-eval'; style-src 'self' https://fonts.googleapis.com 'unsafe-inline';")
66
meta(name='viewport', content='initial-scale=1')
77
link(rel='stylesheet', href='index.css', charset='UTF-8')
88
body

src/minicharts/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ module.exports = AmpersandView.extend(QueryBuilderMixin, {
6565
// been here before, don't need to do it again
6666
return true;
6767
}
68+
6869
if (!app.isFeatureEnabled('Geo Minicharts')) {
6970
return false;
7071
}
7172
if (!navigator.onLine) {
7273
return false;
7374
}
75+
7476
if (this.model.name === 'Document') {
7577
if (this.model.fields.length !== 2
7678
|| !this.model.fields.get('type')

src/models/connection.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var connectionSync = require('./connection-sync')();
44
var client = require('scout-client');
55
var debug = require('debug')('scout:models:connection');
66
var uuid = require('uuid');
7-
var bugsnag = require('../bugsnag');
7+
var metrics = require('mongodb-js-metrics');
88

99
/**
1010
* Configuration for connecting to a MongoDB Deployment.
@@ -46,13 +46,13 @@ module.exports = Connection.extend({
4646
return;
4747
}
4848
debug('could not get collection list :( sending to bugsnag for follow up...');
49-
bugsnag.notify(err, 'collection list failed');
49+
metrics.error(err, 'collection list failed');
5050
done(err);
5151
}.bind(this);
5252

5353
var onTested = function(err) {
5454
if (err) {
55-
bugsnag.notify(err, 'connection test failed');
55+
metrics.error(err, 'connection test failed');
5656
return done(err);
5757
}
5858

0 commit comments

Comments
 (0)