finished metrics
This commit is contained in:
parent
76a6f02eb7
commit
99477774cf
9 changed files with 542 additions and 173 deletions
|
@ -1,20 +1,53 @@
|
|||
const FileReceiver = require('./fileReceiver');
|
||||
const { notify } = require('./utils');
|
||||
const { notify, findMetric } = require('./utils');
|
||||
const $ = require('jquery');
|
||||
require('jquery-circle-progress');
|
||||
|
||||
const Raven = window.Raven;
|
||||
|
||||
if (!localStorage.hasOwnProperty('totalDownloads')) {
|
||||
localStorage.setItem('totalDownloads', 0);
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
//link back to homepage
|
||||
$('.send-new').attr('href', window.location.origin);
|
||||
$('.send-new').click(function() {
|
||||
window.analytics
|
||||
.sendEvent('recipient', 'restarted', {
|
||||
cd2: 'completed'
|
||||
});
|
||||
})
|
||||
|
||||
if (location.pathname.toString().includes('download')) {
|
||||
$('.send-new').click(function(target) {
|
||||
target.preventDefault();
|
||||
window.analytics
|
||||
.sendEvent('recipient', 'restarted', {
|
||||
cd2: 'completed'
|
||||
})
|
||||
.then(() => {
|
||||
location.href = target.currentTarget.href;
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
$('.legal-links a, .social-links a, #dl-firefox').click(function(target) {
|
||||
target.preventDefault();
|
||||
let metric = findMetric(target.currentTarget.href);
|
||||
// record exited event by recipient
|
||||
window.analytics
|
||||
.sendEvent('recipient', 'exited', {
|
||||
cd3: metric
|
||||
})
|
||||
.then(() => {
|
||||
location.href = target.currentTarget.href;
|
||||
});
|
||||
})
|
||||
|
||||
$('#expired-send-new').click(function() {
|
||||
localStorage.setItem('referrer', 'errored-download');
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
const filename = $('#dl-filename').html();
|
||||
const bytelength = $('#dl-bytelength').html();
|
||||
const timeToExpiry = $('#dl-ttl').html();
|
||||
|
||||
//initiate progress bar
|
||||
$('#dl-progress').circleProgress({
|
||||
|
@ -26,9 +59,41 @@ $(document).ready(function() {
|
|||
});
|
||||
$('#download-btn').click(download);
|
||||
function download() {
|
||||
let totalDownloads = localStorage.getItem('totalDownloads');
|
||||
localStorage.setItem('totalDownloads', Number(totalDownloads) + 1);
|
||||
|
||||
const fileReceiver = new FileReceiver();
|
||||
let unexpiredFiles = 0;
|
||||
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
const id = localStorage.key(i);
|
||||
if (id != 'totalUploads' &&
|
||||
id != 'totalDownloads' &&
|
||||
id != 'referrer') {
|
||||
unexpiredFiles += 1;
|
||||
}
|
||||
}
|
||||
|
||||
let totalUploads = 0;
|
||||
if (localStorage.hasOwnProperty('totalUploads')) {
|
||||
totalUploads = localStorage.getItem('totalUploads');
|
||||
}
|
||||
|
||||
fileReceiver.on('progress', progress => {
|
||||
|
||||
window.onunload = function() {
|
||||
localStorage.setItem('referrer', 'cancelled-download');
|
||||
// record download-stopped (cancelled by tab close or reload)
|
||||
window.analytics
|
||||
.sendEvent('recipient', 'download-stopped', {
|
||||
cm1: bytelength,
|
||||
cm5: totalUploads,
|
||||
cm6: unexpiredFiles,
|
||||
cm7: localStorage.getItem('totalDownloads'),
|
||||
cd2: 'cancelled'
|
||||
})
|
||||
}
|
||||
|
||||
$('#download-page-one').attr('hidden', true);
|
||||
$('#download-progress').removeAttr('hidden');
|
||||
const percent = progress[0] / progress[1];
|
||||
|
@ -57,15 +122,18 @@ $(document).ready(function() {
|
|||
notify(translated[0]);
|
||||
$('.title').html(translated[1]);
|
||||
});
|
||||
window.onunload = null;
|
||||
}
|
||||
});
|
||||
|
||||
let downloadEnd;
|
||||
fileReceiver.on('decrypting', isStillDecrypting => {
|
||||
// The file is being decrypted
|
||||
if (isStillDecrypting) {
|
||||
console.log('Decrypting');
|
||||
} else {
|
||||
console.log('Done decrypting');
|
||||
downloadEnd = new Date().getTime();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -78,9 +146,32 @@ $(document).ready(function() {
|
|||
}
|
||||
});
|
||||
|
||||
const startTime = new Date().getTime();
|
||||
|
||||
// record download-started by recipient
|
||||
window.analytics
|
||||
.sendEvent('recipient', 'download-started', {
|
||||
cm1: bytelength,
|
||||
cm4: timeToExpiry,
|
||||
cm5: totalUploads,
|
||||
cm6: unexpiredFiles,
|
||||
cm7: localStorage.getItem('totalDownloads')
|
||||
});
|
||||
|
||||
fileReceiver
|
||||
.download()
|
||||
.catch(() => {
|
||||
.catch(err => {
|
||||
// record download-stopped (errored) by recipient
|
||||
window.analytics
|
||||
.sendEvent('recipient', 'download-stopped', {
|
||||
cm1: bytelength,
|
||||
cm5: totalUploads,
|
||||
cm6: unexpiredFiles,
|
||||
cm7: localStorage.getItem('totalDownloads'),
|
||||
cd2: 'errored',
|
||||
cd6: err
|
||||
});
|
||||
|
||||
document.l10n.formatValue('expiredPageHeader')
|
||||
.then(translated => {
|
||||
$('.title').text(translated);
|
||||
|
@ -91,6 +182,24 @@ $(document).ready(function() {
|
|||
return;
|
||||
})
|
||||
.then(([decrypted, fname]) => {
|
||||
const endTime = new Date().getTime();
|
||||
const totalTime = endTime - startTime;
|
||||
const downloadTime = endTime - downloadEnd;
|
||||
const downloadSpeed = bytelength / (downloadTime / 1000);
|
||||
|
||||
localStorage.setItem('referrer', 'completed-download');
|
||||
// record download-stopped (completed) by recipient
|
||||
window.analytics
|
||||
.sendEvent('recipient', 'download-stopped', {
|
||||
cm1: bytelength,
|
||||
cm2: totalTime,
|
||||
cm3: downloadSpeed,
|
||||
cm5: totalUploads,
|
||||
cm6: unexpiredFiles,
|
||||
cm7: localStorage.getItem('totalDownloads'),
|
||||
cd2: 'completed'
|
||||
});
|
||||
|
||||
const dataView = new DataView(decrypted);
|
||||
const blob = new Blob([dataView]);
|
||||
const downloadUrl = URL.createObjectURL(blob);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue