Просмотр исходного кода

Send compile metrics (#3576)

* Support analytics events with a custom sampling rate

* Send compile metrics for beta users

GitOrigin-RevId: 86379f58e0bb4983a56cb6f0dcd6da916de3b8ba
Paulo Jorge Reis 5 лет назад
Родитель
Сommit
70fb5da37d

+ 26 - 1
services/web/frontend/js/ide/pdf/controllers/PdfController.js

@@ -5,6 +5,7 @@ import PreviewPane from '../../../features/preview/components/preview-pane'
 import { react2angular } from 'react2angular'
 import { rootContext } from '../../../shared/context/root-context'
 import 'ace/ace'
+
 const AUTO_COMPILE_MAX_WAIT = 5000
 // We add a 1 second debounce to sending user changes to server if they aren't
 // collaborating with anyone. This needs to be higher than that, and allow for
@@ -689,7 +690,31 @@ App.controller('PdfController', function(
 
     // display the combined result
     if (response != null) {
-      response.finally(annotateFiles)
+      response.finally(() => {
+        annotateFiles()
+        sendCompileMetrics()
+      })
+    }
+  }
+
+  function sendCompileMetrics() {
+    const hasCompiled =
+      $scope.pdf.view !== 'errors' && $scope.pdf.view !== 'validation-problems'
+    const sendMetricsForUser =
+      window.user.betaProgram && !window.user.alphaProgram
+
+    if (hasCompiled && sendMetricsForUser) {
+      const metadata = {
+        errors: $scope.pdf.logEntries.errors.length,
+        warnings: $scope.pdf.logEntries.warnings.length,
+        typesetting: $scope.pdf.logEntries.typesetting.length,
+        newLogsUI: window.showNewLogsUI
+      }
+      eventTracking.sendMBSampled(
+        'compile-result',
+        JSON.stringify(metadata),
+        0.05
+      )
     }
   }
 

+ 2 - 2
services/web/frontend/js/main/event.js

@@ -105,8 +105,8 @@ App.factory('eventTracking', function($http, localStorage) {
       })
     },
 
-    sendMBSampled(key, segmentation) {
-      if (Math.random() < 0.01) {
+    sendMBSampled(key, segmentation, rate = 0.01) {
+      if (Math.random() < rate) {
         return this.sendMB(key, segmentation)
       }
     },