mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
Enabling caching in tracker script.
This commit is contained in:
parent
777dfeac0e
commit
7cf0927741
@ -9,7 +9,8 @@ export async function getSession(req) {
|
||||
throw new Error('Invalid request');
|
||||
}
|
||||
|
||||
const { website: website_uuid, hostname, screen, language, cache } = payload;
|
||||
const { website: website_uuid, hostname, screen, language } = payload;
|
||||
const cache = req.headers['x-umami-cache'];
|
||||
|
||||
if (cache) {
|
||||
const result = await parseToken(cache);
|
||||
|
@ -7,7 +7,6 @@ import { removeTrailingSlash } from '../lib/url';
|
||||
navigator: { language },
|
||||
location: { hostname, pathname, search },
|
||||
localStorage,
|
||||
sessionStorage,
|
||||
document,
|
||||
history,
|
||||
} = window;
|
||||
@ -21,14 +20,12 @@ import { removeTrailingSlash } from '../lib/url';
|
||||
const hostUrl = attr('data-host-url');
|
||||
const autoTrack = attr('data-auto-track') !== 'false';
|
||||
const dnt = attr('data-do-not-track');
|
||||
const useCache = attr('data-cache');
|
||||
const cssEvents = attr('data-css-events') !== 'false';
|
||||
const domain = attr('data-domains') || '';
|
||||
const domains = domain.split(',').map(n => n.trim());
|
||||
|
||||
const eventClass = /^umami--([a-z]+)--([\w]+[\w-]*)$/;
|
||||
const eventSelect = "[class*='umami--']";
|
||||
const cacheKey = 'umami.cache';
|
||||
|
||||
const trackingDisabled = () =>
|
||||
(localStorage && localStorage.getItem('umami.disabled')) ||
|
||||
@ -42,6 +39,7 @@ import { removeTrailingSlash } from '../lib/url';
|
||||
const listeners = {};
|
||||
let currentUrl = `${pathname}${search}`;
|
||||
let currentRef = document.referrer;
|
||||
let cache;
|
||||
|
||||
/* Collect metrics */
|
||||
|
||||
@ -49,6 +47,7 @@ import { removeTrailingSlash } from '../lib/url';
|
||||
const req = new XMLHttpRequest();
|
||||
req.open('POST', url, true);
|
||||
req.setRequestHeader('Content-Type', 'application/json');
|
||||
if (cache) req.setRequestHeader('x-umami-cache', cache);
|
||||
|
||||
req.onreadystatechange = () => {
|
||||
if (req.readyState === 4) {
|
||||
@ -64,7 +63,6 @@ import { removeTrailingSlash } from '../lib/url';
|
||||
hostname,
|
||||
screen,
|
||||
language,
|
||||
cache: useCache && sessionStorage.getItem(cacheKey),
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
@ -84,7 +82,7 @@ import { removeTrailingSlash } from '../lib/url';
|
||||
type,
|
||||
payload,
|
||||
},
|
||||
res => useCache && sessionStorage.setItem(cacheKey, res),
|
||||
res => (cache = res),
|
||||
);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user