Script simplification: In-place headers + re-order
This commit is contained in:
@@ -173,25 +173,18 @@
|
|||||||
|
|
||||||
const send = async (payload, type = 'event') => {
|
const send = async (payload, type = 'event') => {
|
||||||
if (trackingDisabled()) return;
|
if (trackingDisabled()) return;
|
||||||
|
|
||||||
const headers = {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
};
|
|
||||||
|
|
||||||
if (typeof cache !== 'undefined') {
|
|
||||||
headers['x-umami-cache'] = cache;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(endpoint, {
|
const res = await fetch(endpoint, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ type, payload }),
|
body: JSON.stringify({ type, payload }),
|
||||||
headers,
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
...(typeof cache !== 'undefined' && { 'x-umami-cache': cache }),
|
||||||
|
},
|
||||||
credentials: 'omit',
|
credentials: 'omit',
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
disabled = !!data.disabled;
|
disabled = !!data.disabled;
|
||||||
cache = data.cache;
|
cache = data.cache;
|
||||||
@@ -230,9 +223,9 @@
|
|||||||
|
|
||||||
let currentUrl = href;
|
let currentUrl = href;
|
||||||
let currentRef = referrer.startsWith(origin) ? '' : referrer;
|
let currentRef = referrer.startsWith(origin) ? '' : referrer;
|
||||||
let cache;
|
|
||||||
let initialized = false;
|
let initialized = false;
|
||||||
let disabled = false;
|
let disabled = false;
|
||||||
|
let cache;
|
||||||
|
|
||||||
if (autoTrack && !trackingDisabled()) {
|
if (autoTrack && !trackingDisabled()) {
|
||||||
if (document.readyState === 'complete') {
|
if (document.readyState === 'complete') {
|
||||||
|
|||||||
Reference in New Issue
Block a user