Browse Source

Merge branch 'remove-metrics' into 'master'

Remove metrics

Closes #4

See merge request timvisee/send!11
Tim Visée 4 years ago
parent
commit
d3f9b82672
10 changed files with 8 additions and 261 deletions
  1. 1 1
      README.md
  2. 0 2
      android/android.js
  3. 0 11
      app/api.js
  4. 2 32
      app/controller.js
  5. 0 2
      app/main.js
  6. 0 186
      app/metrics.js
  7. 1 1
      app/ui/archiveTile.js
  8. 1 1
      app/ui/noStreams.js
  9. 1 4
      app/ui/signupDialog.js
  10. 2 21
      app/user.js

+ 1 - 1
README.md

@@ -53,7 +53,7 @@ Thanks [Mozilla][mozilla] for building this amazing tool!
 
 ---
 
-**Docs:** [FAQ](docs/faq.md), [Encryption](docs/encryption.md), [Build](docs/build.md), [Docker](docs/docker.md), [Metrics](docs/metrics.md), [More](docs/)
+**Docs:** [FAQ](docs/faq.md), [Encryption](docs/encryption.md), [Build](docs/build.md), [Docker](docs/docker.md), [More](docs/)
 
 ---
 

+ 0 - 2
android/android.js

@@ -4,7 +4,6 @@ import html from 'choo/html';
 import * as Sentry from '@sentry/browser';
 
 import { setApiUrlPrefix, getConstants } from '../app/api';
-import metrics from '../app/metrics';
 //import assets from '../common/assets';
 import Archive from '../app/archive';
 import Header from '../app/ui/header';
@@ -83,7 +82,6 @@ function body(main) {
     state.user = new User(storage, LIMITS);
     state.sentry = Sentry;
   });
-  app.use(metrics);
   app.route('/', body(home));
   app.route('/upload', upload);
   app.route('/share/:id', share);

+ 0 - 11
app/api.js

@@ -420,17 +420,6 @@ export async function setFileList(bearerToken, kid, data) {
   return response.ok;
 }
 
-export function sendMetrics(blob) {
-  if (!navigator.sendBeacon) {
-    return;
-  }
-  try {
-    navigator.sendBeacon(getApiUrl('/api/metrics'), blob);
-  } catch (e) {
-    console.error(e);
-  }
-}
-
 export async function getConstants() {
   const response = await fetch(getApiUrl('/config'));
 

+ 2 - 32
app/controller.js

@@ -1,4 +1,3 @@
-import * as metrics from './metrics';
 import FileReceiver from './fileReceiver';
 import FileSender from './fileSender';
 import copyDialog from './ui/copyDialog';
@@ -54,7 +53,6 @@ export default function(state, emitter) {
 
   emitter.on('logout', async () => {
     await state.user.logout();
-    metrics.loggedOut({ trigger: 'button' });
     emitter.emit('pushState', '/');
   });
 
@@ -68,14 +66,6 @@ export default function(state, emitter) {
 
   emitter.on('delete', async ownedFile => {
     try {
-      metrics.deletedUpload({
-        size: ownedFile.size,
-        time: ownedFile.time,
-        speed: ownedFile.speed,
-        type: ownedFile.type,
-        ttl: ownedFile.expiresAt - Date.now(),
-        location
-      });
       state.storage.remove(ownedFile.id);
       await ownedFile.del();
     } catch (e) {
@@ -123,7 +113,7 @@ export default function(state, emitter) {
       source: query.utm_source,
       term: query.utm_term
     });
-    state.modal = signupDialog(source);
+    state.modal = signupDialog();
     render();
   });
 
@@ -159,12 +149,9 @@ export default function(state, emitter) {
 
     const links = openLinksInNewTab();
     await delay(200);
-    const start = Date.now();
     try {
       const ownedFile = await sender.upload(archive, state.user.bearerToken);
       state.storage.totalUploads += 1;
-      const duration = Date.now() - start;
-      metrics.completedUpload(archive, duration);
       faviconProgressbar.updateFavicon(0);
 
       state.storage.addFile(ownedFile);
@@ -181,7 +168,6 @@ export default function(state, emitter) {
     } catch (err) {
       if (err.message === '0') {
         //cancelled. do nothing
-        metrics.cancelledUpload(archive, err.duration);
         render();
       } else if (err.message === '401') {
         const refreshed = await state.user.refresh();
@@ -197,7 +183,6 @@ export default function(state, emitter) {
           scope.setExtra('size', err.size);
           state.sentry.captureException(err);
         });
-        metrics.stoppedUpload(archive, err.duration);
         emitter.emit('pushState', '/error');
       }
     } finally {
@@ -249,13 +234,11 @@ export default function(state, emitter) {
     render();
   });
 
-  emitter.on('download', async file => {
+  emitter.on('download', async () => {
     state.transfer.on('progress', updateProgress);
     state.transfer.on('decrypting', render);
     state.transfer.on('complete', render);
     const links = openLinksInNewTab();
-    const size = file.size;
-    const start = Date.now();
     try {
       const dl = state.transfer.download({
         stream: state.capabilities.streamDownload
@@ -263,12 +246,6 @@ export default function(state, emitter) {
       render();
       await dl;
       state.storage.totalDownloads += 1;
-      const duration = Date.now() - start;
-      metrics.completedDownload({
-        size,
-        duration,
-        password_protected: file.requiresPassword
-      });
       faviconProgressbar.updateFavicon(0);
     } catch (err) {
       if (err.message === '0') {
@@ -286,12 +263,6 @@ export default function(state, emitter) {
             scope.setExtra('progress', err.progress);
             state.sentry.captureException(err);
           });
-          const duration = Date.now() - start;
-          metrics.stoppedDownload({
-            size,
-            duration,
-            password_protected: file.requiresPassword
-          });
         }
         emitter.emit('pushState', location);
       }
@@ -302,7 +273,6 @@ export default function(state, emitter) {
 
   emitter.on('copy', ({ url }) => {
     copyToClipboard(url);
-    // metrics.copiedLink({ location });
   });
 
   emitter.on('closeModal', () => {

+ 0 - 2
app/main.js

@@ -10,7 +10,6 @@ import controller from './controller';
 import dragManager from './dragManager';
 import pasteManager from './pasteManager';
 import storage from './storage';
-import metrics from './metrics';
 import experiments from './experiments';
 import * as Sentry from '@sentry/browser';
 import './main.css';
@@ -68,7 +67,6 @@ if (process.env.NODE_ENV === 'production') {
   // eslint-disable-next-line require-atomic-updates
   window.app = app;
   app.use(experiments);
-  app.use(metrics);
   app.use(controller);
   app.use(dragManager);
   app.use(pasteManager);

+ 0 - 186
app/metrics.js

@@ -1,186 +0,0 @@
-import storage from './storage';
-import { platform, locale } from './utils';
-import { sendMetrics } from './api';
-
-let appState = null;
-let experiment = null;
-const HOUR = 1000 * 60 * 60;
-const events = [];
-let session_id = Date.now();
-const lang = locale();
-
-export default function initialize(state, emitter) {
-  appState = state;
-
-  emitter.on('DOMContentLoaded', () => {
-    experiment = storage.enrolled;
-    if (!appState.user.firstAction) {
-      appState.user.firstAction =
-        appState.route === '/' ? 'upload' : 'download';
-    }
-    const query = appState.query;
-    addEvent('client_visit', {
-      entrypoint: appState.route === '/' ? 'upload' : 'download',
-      referrer: document.referrer,
-      utm_campaign: query.utm_campaign,
-      utm_content: query.utm_content,
-      utm_medium: query.utm_medium,
-      utm_source: query.utm_source,
-      utm_term: query.utm_term
-    });
-  });
-  emitter.on('experiment', experimentEvent);
-  window.addEventListener('unload', submitEvents);
-}
-
-function sizeOrder(n) {
-  return Math.floor(Math.log10(n));
-}
-
-function submitEvents() {
-  if (navigator.doNotTrack === '1') {
-    return;
-  }
-  sendMetrics(
-    new Blob(
-      [
-        JSON.stringify({
-          now: Date.now(),
-          session_id,
-          lang,
-          platform: platform(),
-          events
-        })
-      ],
-      { type: 'text/plain' } // see http://crbug.com/490015
-    )
-  );
-  events.splice(0);
-}
-
-async function addEvent(event_type, event_properties) {
-  const user_id = await appState.user.metricId();
-  const device_id = await appState.user.deviceId();
-  const ab_id = Object.keys(experiment)[0];
-  if (ab_id) {
-    event_properties.experiment = ab_id;
-    event_properties.variant = experiment[ab_id];
-  }
-  events.push({
-    device_id,
-    event_properties,
-    event_type,
-    time: Date.now(),
-    user_id,
-    user_properties: {
-      anonymous: !appState.user.loggedIn,
-      first_action: appState.user.firstAction,
-      active_count: storage.files.length
-    }
-  });
-  if (events.length === 25) {
-    submitEvents();
-  }
-}
-
-function cancelledUpload(archive, duration) {
-  return addEvent('client_upload', {
-    download_limit: archive.dlimit,
-    duration: sizeOrder(duration),
-    file_count: archive.numFiles,
-    password_protected: !!archive.password,
-    size: sizeOrder(archive.size),
-    status: 'cancel',
-    time_limit: archive.timeLimit
-  });
-}
-
-function completedUpload(archive, duration) {
-  return addEvent('client_upload', {
-    download_limit: archive.dlimit,
-    duration: sizeOrder(duration),
-    file_count: archive.numFiles,
-    password_protected: !!archive.password,
-    size: sizeOrder(archive.size),
-    status: 'ok',
-    time_limit: archive.timeLimit
-  });
-}
-
-function stoppedUpload(archive, duration = 0) {
-  return addEvent('client_upload', {
-    download_limit: archive.dlimit,
-    duration: sizeOrder(duration),
-    file_count: archive.numFiles,
-    password_protected: !!archive.password,
-    size: sizeOrder(archive.size),
-    status: 'error',
-    time_limit: archive.timeLimit
-  });
-}
-
-function stoppedDownload(params) {
-  return addEvent('client_download', {
-    duration: sizeOrder(params.duration),
-    password_protected: params.password_protected,
-    size: sizeOrder(params.size),
-    status: 'error'
-  });
-}
-
-function completedDownload(params) {
-  return addEvent('client_download', {
-    duration: sizeOrder(params.duration),
-    password_protected: params.password_protected,
-    size: sizeOrder(params.size),
-    status: 'ok'
-  });
-}
-
-function deletedUpload(ownedFile) {
-  return addEvent('client_delete', {
-    age: Math.floor((Date.now() - ownedFile.createdAt) / HOUR),
-    downloaded: ownedFile.dtotal > 0,
-    status: 'ok'
-  });
-}
-
-function experimentEvent(params) {
-  return addEvent('client_experiment', params);
-}
-
-function submittedSignup(params) {
-  return addEvent('client_login', {
-    status: 'ok',
-    trigger: params.trigger
-  });
-}
-
-function canceledSignup(params) {
-  return addEvent('client_login', {
-    status: 'cancel',
-    trigger: params.trigger
-  });
-}
-
-function loggedOut(params) {
-  addEvent('client_logout', {
-    status: 'ok',
-    trigger: params.trigger
-  });
-  // flush events and start new anon session
-  submitEvents();
-  session_id = Date.now();
-}
-
-export {
-  cancelledUpload,
-  stoppedUpload,
-  completedUpload,
-  deletedUpload,
-  stoppedDownload,
-  completedDownload,
-  submittedSignup,
-  canceledSignup,
-  loggedOut
-};

+ 1 - 1
app/ui/archiveTile.js

@@ -580,7 +580,7 @@ module.exports.preview = function(state, emit) {
   function download(event) {
     event.preventDefault();
     event.target.disabled = true;
-    emit('download', archive);
+    emit('download');
   }
 };
 

+ 1 - 1
app/ui/noStreams.js

@@ -100,7 +100,7 @@ module.exports = function(state, emit) {
         );
         break;
       case 'download':
-        emit('download', archive);
+        emit('download');
         break;
     }
     return false;

+ 1 - 4
app/ui/signupDialog.js

@@ -1,9 +1,8 @@
 const html = require('choo/html');
 const assets = require('../../common/assets');
 const { bytes } = require('../utils');
-const { canceledSignup, submittedSignup } = require('../metrics');
 
-module.exports = function(trigger) {
+module.exports = function() {
   return function(state, emit, close) {
     const DAYS = Math.floor(state.LIMITS.MAX_EXPIRE_SECONDS / 86400);
     let submitting = false;
@@ -72,7 +71,6 @@ module.exports = function(trigger) {
     }
 
     function cancel(event) {
-      canceledSignup({ trigger });
       close(event);
     }
 
@@ -85,7 +83,6 @@ module.exports = function(trigger) {
 
       const el = document.getElementById('email-input');
       const email = el.value;
-      submittedSignup({ trigger });
       emit('login', emailish(email) ? email : null);
     }
   };

+ 2 - 21
app/user.js

@@ -109,27 +109,8 @@ export default class User {
   async startAuthFlow(trigger, utms = {}) {
     this.utms = utms;
     this.trigger = trigger;
-    try {
-      const params = new URLSearchParams({
-        entrypoint: `send-${trigger}`,
-        form_type: 'email',
-        utm_source: utms.source || 'send',
-        utm_campaign: utms.campaign || 'none'
-      });
-      const res = await fetch(
-        `${this.authConfig.issuer}/metrics-flow?${params.toString()}`,
-        {
-          mode: 'cors'
-        }
-      );
-      const { flowId, flowBeginTime } = await res.json();
-      this.flowId = flowId;
-      this.flowBeginTime = flowBeginTime;
-    } catch (e) {
-      console.error(e);
-      this.flowId = null;
-      this.flowBeginTime = null;
-    }
+    this.flowId = null;
+    this.flowBeginTime = null;
   }
 
   async login(email) {

Some files were not shown because too many files changed in this diff