Skip to content

Commit 7b54fdb

Browse files
authored
chore: track web-vitals performance events COMPASS-5201 (#2553)
1 parent 9f22cb7 commit 7b54fdb

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

package-lock.json

Lines changed: 16 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@
246246
"sinon": "^8.1.1",
247247
"sinon-chai": "^3.7.0",
248248
"storage-mixin": "^4.7.0",
249-
"uuid": "^3.0.0"
249+
"uuid": "^3.0.0",
250+
"web-vitals": "^2.1.2"
250251
},
251252
"optionalDependencies": {
252253
"vscode-windows-registry": "1.0.2"

packages/compass/src/app/index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var _ = require('lodash');
3030
var View = require('ampersand-view');
3131
var async = require('async');
3232
var ipc = require('hadron-ipc');
33+
var webvitals = require('web-vitals');
3334

3435
var semver = require('semver');
3536

@@ -53,7 +54,7 @@ ipc.once('app:launched', function() {
5354
}
5455
});
5556

56-
const { log, mongoLogId, debug } =
57+
const { log, mongoLogId, debug, track } =
5758
require('@mongodb-js/compass-logging').createLoggerAndTelemetry('COMPASS-APP');
5859

5960
window.addEventListener('error', (event) => {
@@ -119,6 +120,21 @@ var Application = View.extend({
119120
ipc.on('window:show-compass-tour', this.showTour.bind(this, true));
120121
ipc.on('window:show-network-optin', this.showOptIn.bind(this));
121122
ipc.on('window:show-security-panel', this.showSecurity.bind(this));
123+
124+
function trackPerfEvent({ name, value }) {
125+
const fullName = {
126+
'FCP': 'First Contentful Paint',
127+
'LCP': 'Largest Contentful Paint',
128+
'FID': 'First Input Delay',
129+
'CLS': 'Cumulative Layout Shift'
130+
}[name];
131+
track(fullName, { value });
132+
}
133+
134+
webvitals.getFCP(trackPerfEvent);
135+
webvitals.getLCP(trackPerfEvent);
136+
webvitals.getFID(trackPerfEvent);
137+
webvitals.getCLS(trackPerfEvent);
122138
},
123139
startRouter: function() {
124140
if (this.router) {

0 commit comments

Comments
 (0)