Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
Script simplification: In-place `headers` + re-order
Ali Khaleqi Yektae12e5b0d2e8a
diff --git a/src/tracker/index.js b/src/tracker/index.jsindex a20a7d70c..8b38c49d3 100644--- a/src/tracker/index.js+++ b/src/tracker/index.js@@ -173,25 +173,18 @@const send = async (payload, type = 'event') => {if (trackingDisabled()) return;-- const headers = {- 'Content-Type': 'application/json',- };-- if (typeof cache !== 'undefined') {- headers['x-umami-cache'] = cache;- }-try {const res = await fetch(endpoint, {method: 'POST',body: JSON.stringify({ type, payload }),- headers,+ headers: {+ 'Content-Type': 'application/json',+ ...(typeof cache !== 'undefined' && { 'x-umami-cache': cache }),+ },credentials: 'omit',});const data = await res.json();-if (data) {disabled = !!data.disabled;cache = data.cache;@@ -230,9 +223,9 @@let currentUrl = href;let currentRef = referrer.startsWith(origin) ? '' : referrer;- let cache;let initialized = false;let disabled = false;+ let cache;if (autoTrack && !trackingDisabled()) {if (document.readyState === 'complete') {