From 5d8fb2f79191f535241c015dff4b7bb7e1e37f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A6=86=E6=9C=A8?= <43062104+yumusb@users.noreply.github.com> Date: Fri, 21 Apr 2023 12:04:30 +0800 Subject: [PATCH] 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) --- tracker/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tracker/index.js b/tracker/index.js index 4d680c7e..7c727326 100644 --- a/tracker/index.js +++ b/tracker/index.js @@ -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));