feat: add opt-in umami analytics (WIP)

This commit is contained in:
David Ralph
2021-06-21 17:42:14 +01:00
parent 4449957fe6
commit f7c39eeebb
23 changed files with 135 additions and 10 deletions

View File

@@ -0,0 +1,49 @@
export default class Analytics {
constructor(id) {
this.id = id;
this.domain = window.constants.UMAMI_DOMAIN;
}
async postEvent(type, name) {
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: name.toLowerCase().replaceAll(' ', '-'),
hostname: 'localhost',
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}`
}
})
});
}
}