mirror of https://github.com/vector-im/riot-web
Analytics.js gets executed during times where localStorage is not ensured to exist
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>pull/21833/head
parent
68608c2bcb
commit
cef9dbe254
|
@ -123,8 +123,8 @@ const LAST_VISIT_TS_KEY = "mx_Riot_Analytics_lvts";
|
||||||
|
|
||||||
function getUid() {
|
function getUid() {
|
||||||
try {
|
try {
|
||||||
let data = localStorage.getItem(UID_KEY);
|
let data = localStorage && localStorage.getItem(UID_KEY);
|
||||||
if (!data) {
|
if (!data && localStorage) {
|
||||||
localStorage.setItem(UID_KEY, data = [...Array(16)].map(() => Math.random().toString(16)[2]).join(''));
|
localStorage.setItem(UID_KEY, data = [...Array(16)].map(() => Math.random().toString(16)[2]).join(''));
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
|
@ -145,15 +145,17 @@ class Analytics {
|
||||||
this.firstPage = true;
|
this.firstPage = true;
|
||||||
this._heartbeatIntervalID = null;
|
this._heartbeatIntervalID = null;
|
||||||
|
|
||||||
this.creationTs = localStorage.getItem(CREATION_TS_KEY);
|
this.creationTs = localStorage && localStorage.getItem(CREATION_TS_KEY);
|
||||||
if (!this.creationTs) {
|
if (!this.creationTs && localStorage) {
|
||||||
localStorage.setItem(CREATION_TS_KEY, this.creationTs = new Date().getTime());
|
localStorage.setItem(CREATION_TS_KEY, this.creationTs = new Date().getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.lastVisitTs = localStorage.getItem(LAST_VISIT_TS_KEY);
|
this.lastVisitTs = localStorage && localStorage.getItem(LAST_VISIT_TS_KEY);
|
||||||
this.visitCount = localStorage.getItem(VISIT_COUNT_KEY) || 0;
|
this.visitCount = localStorage && localStorage.getItem(VISIT_COUNT_KEY) || 0;
|
||||||
|
if (localStorage) {
|
||||||
localStorage.setItem(VISIT_COUNT_KEY, parseInt(this.visitCount, 10) + 1);
|
localStorage.setItem(VISIT_COUNT_KEY, parseInt(this.visitCount, 10) + 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get disabled() {
|
get disabled() {
|
||||||
return !this.baseUrl;
|
return !this.baseUrl;
|
||||||
|
|
Loading…
Reference in New Issue