Update index.js

Do not send the x-umami-cache request header when the cache is not defined (the first request sent to the umami server when the visitor opens the page)
This commit is contained in:
榆木 2023-04-21 12:04:30 +08:00 committed by GitHub
parent b39ef68372
commit 5d8fb2f791
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -162,11 +162,16 @@
const send = payload => {
if (trackingDisabled()) return;
const headers = {
'Content-Type': 'application/json'
};
if (typeof cache !== 'undefined') {
headers['x-umami-cache'] = cache;
}
return fetch(endpoint, {
method: 'POST',
body: JSON.stringify({ type: 'event', payload }),
headers: { 'Content-Type': 'application/json', ['x-umami-cache']: cache },
headers: headers
})
.then(res => res.text())
.then(text => (cache = text));