mirror of
https://github.com/mue/mue.git
synced 2026-07-18 06:24:17 +02:00
feat: new welcome modal, refactor many things, various bug fixes, use material-ui v5 etc
Co-authored-by: Alex Sparkes <turbomarshmello@gmail.com>
This commit is contained in:
@@ -1,71 +1,73 @@
|
||||
export default class Stats {
|
||||
constructor(id) {
|
||||
this.id = id;
|
||||
this.domain = window.constants.UMAMI_DOMAIN;
|
||||
constructor(id) {
|
||||
this.id = id;
|
||||
this.url = window.constants.UMAMI_DOMAIN + '/api/collect';
|
||||
this.offline = (localStorage.getItem('offlineMode') !== 'true');
|
||||
}
|
||||
|
||||
async postEvent(type, name) {
|
||||
const value = name.toLowerCase().replaceAll(' ', '-');
|
||||
|
||||
if (!this.offline) {
|
||||
// umami
|
||||
await fetch(this.url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
type: 'event',
|
||||
payload: {
|
||||
website: this.id,
|
||||
url: '/',
|
||||
event_type: type,
|
||||
event_value: value
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
async postEvent(type, name) {
|
||||
const value = name.toLowerCase().replaceAll(' ', '-');
|
||||
// local
|
||||
let data = JSON.parse(localStorage.getItem('statsData'));
|
||||
// tl;dr this creates the objects if they don't exist
|
||||
// this really needs a cleanup at some point
|
||||
if (!data[type] || !data[type][value]) {
|
||||
if (!data[type]) {
|
||||
data[type] = {};
|
||||
}
|
||||
|
||||
await fetch(this.domain + '/api/collect', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
type: 'event',
|
||||
payload: {
|
||||
website: this.id,
|
||||
url: '/',
|
||||
event_type: type,
|
||||
event_value: value,
|
||||
hostname: 'localhost',
|
||||
language: localStorage.getItem('language').replace('_', '-'),
|
||||
screen: `${window.screen.width}x${window.screen.height}`
|
||||
}
|
||||
})
|
||||
});
|
||||
if (!data[type][value]) {
|
||||
data[type][value] = 1;
|
||||
}
|
||||
} else {
|
||||
data[type][value] = data[type][value] + 1;
|
||||
}
|
||||
localStorage.setItem('statsData', JSON.stringify(data));
|
||||
}
|
||||
|
||||
let data = JSON.parse(localStorage.getItem('statsData'));
|
||||
// tl;dr this creates the objects if they don't exist
|
||||
// this really needs a cleanup at some point
|
||||
if (!data[type] || !data[type][value]) {
|
||||
if (!data[type]) {
|
||||
data[type] = {};
|
||||
}
|
||||
|
||||
if (!data[type][value]) {
|
||||
data[type][value] = 1;
|
||||
}
|
||||
} else {
|
||||
data[type][value] = data[type][value] + 1;
|
||||
}
|
||||
localStorage.setItem('statsData', JSON.stringify(data));
|
||||
async tabLoad() {
|
||||
if (!this.offline) {
|
||||
// umami
|
||||
await fetch(this.url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
type: 'pageview',
|
||||
payload: {
|
||||
website: this.id,
|
||||
url: '/',
|
||||
language: localStorage.getItem('language').replace('_', '-'),
|
||||
screen: `${window.screen.width}x${window.screen.height}`
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
async tabLoad() {
|
||||
await fetch(this.domain + '/api/collect', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
type: 'pageview',
|
||||
payload: {
|
||||
website: this.id,
|
||||
url: '/',
|
||||
referrer: '',
|
||||
hostname: 'localhost',
|
||||
language: localStorage.getItem('language').replace('_', '-'),
|
||||
screen: `${window.screen.width}x${window.screen.height}`
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
let data = JSON.parse(localStorage.getItem('statsData'));
|
||||
data['tabs-opened'] = data['tabs-opened'] + 1 || 1;
|
||||
localStorage.setItem('statsData', JSON.stringify(data));
|
||||
}
|
||||
// local
|
||||
let data = JSON.parse(localStorage.getItem('statsData'));
|
||||
data['tabs-opened'] = data['tabs-opened'] + 1 || 1;
|
||||
localStorage.setItem('statsData', JSON.stringify(data));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user