From a41bd72dba7b71ba988260d4a8fb456972cc3312 Mon Sep 17 00:00:00 2001 From: Jack Date: Tue, 12 May 2020 01:33:49 +0100 Subject: [PATCH] added analytics events --- public/js/account.js | 1 + public/js/commandline.js | 7 ++++++- public/js/db.js | 2 +- public/js/script.js | 36 +++++++++++++++++++++--------------- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/public/js/account.js b/public/js/account.js index 12a48a460..2b95680c7 100644 --- a/public/js/account.js +++ b/public/js/account.js @@ -13,6 +13,7 @@ $(".pageLogin .register input").keyup(e => { }).then(function() { // Update successful. showNotification("Account created", 2000); + firebase.analytics().logEvent("accountCreated", usr.uid); }).catch(function(error) { // An error happened. usr.delete().then(function() { diff --git a/public/js/commandline.js b/public/js/commandline.js index b7d342db8..ca284d690 100644 --- a/public/js/commandline.js +++ b/public/js/commandline.js @@ -254,7 +254,12 @@ $("#commandLine input").keydown((e) => { subgroup = obj.subgroup; } }); - if (!subgroup) hideCommandLine(); + if (!subgroup) { + firebase.analytics().logEvent('usedCommandLine', { + command: command + }); + hideCommandLine(); + } return; } if (e.keyCode == 38 || e.keyCode == 40) { diff --git a/public/js/db.js b/public/js/db.js index 6bc57c288..2b8bbd751 100644 --- a/public/js/db.js +++ b/public/js/db.js @@ -23,7 +23,7 @@ async function db_getUserResults() { .where('uid', '==', user.uid) .get() .then(data => { - + console.log('getting data from db!'); data.docs.forEach(doc => { ret.push(doc.data()); }) diff --git a/public/js/script.js b/public/js/script.js index 5770fd55d..c7b0f2e7b 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -412,6 +412,16 @@ function showResult() { mode2 = config.words; } hideCrown(); + let completedEvent = { + wpm: stats.wpm, + correctChars: stats.correctChars, + incorrectChars: stats.incorrectChars, + acc: stats.acc, + mode: config.mode, + mode2: mode2, + punctuation: config.punctuation, + timestamp: Date.now() + }; if (stats.wpm > 0 && stats.wpm < 250 && stats.acc > 50 && stats.acc <= 100) { if (firebase.auth().currentUser != null) { db_getUserHighestWpm(config.mode, mode2).then(data => { @@ -419,29 +429,22 @@ function showResult() { if (data < stats.wpm) { showCrown(); } - let dbObj = { - uid: firebase.auth().currentUser.uid, - wpm: stats.wpm, - correctChars: stats.correctChars, - incorrectChars: stats.incorrectChars, - acc: stats.acc, - mode: config.mode, - mode2: mode2, - punctuation: config.punctuation, - timestamp: Date.now() - }; - db_testCompleted(dbObj); - dbSnapshot.unshift(dbObj); + completedEvent.uid = firebase.auth().currentUser.uid; + db_testCompleted(completedEvent); + dbSnapshot.unshift(completedEvent); }); } else { showNotification("Sign in to save your result",3000); } + completedEvent.valid = true; } else { - showNotification("Test invalid",3000); + showNotification("Test invalid", 3000); + completedEvent.valid = false; } - let infoText = ""; + firebase.analytics().logEvent('testCompleted', completedEvent); + let infoText = ""; infoText = config.mode; if (config.mode == "time") { @@ -609,6 +612,9 @@ function changePage(page) { swapElements(activePage, $(".page.pageLogin"), 250); } } + firebase.analytics().logEvent('changedPage', { + page: page + }); } function changeMode(mode) {