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');
|
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) {
|
if (cache) {
|
||||||
const result = await parseToken(cache);
|
const result = await parseToken(cache);
|
||||||
|
@ -7,7 +7,6 @@ import { removeTrailingSlash } from '../lib/url';
|
|||||||
navigator: { language },
|
navigator: { language },
|
||||||
location: { hostname, pathname, search },
|
location: { hostname, pathname, search },
|
||||||
localStorage,
|
localStorage,
|
||||||
sessionStorage,
|
|
||||||
document,
|
document,
|
||||||
history,
|
history,
|
||||||
} = window;
|
} = window;
|
||||||
@ -21,14 +20,12 @@ import { removeTrailingSlash } from '../lib/url';
|
|||||||
const hostUrl = attr('data-host-url');
|
const hostUrl = attr('data-host-url');
|
||||||
const autoTrack = attr('data-auto-track') !== 'false';
|
const autoTrack = attr('data-auto-track') !== 'false';
|
||||||
const dnt = attr('data-do-not-track');
|
const dnt = attr('data-do-not-track');
|
||||||
const useCache = attr('data-cache');
|
|
||||||
const cssEvents = attr('data-css-events') !== 'false';
|
const cssEvents = attr('data-css-events') !== 'false';
|
||||||
const domain = attr('data-domains') || '';
|
const domain = attr('data-domains') || '';
|
||||||
const domains = domain.split(',').map(n => n.trim());
|
const domains = domain.split(',').map(n => n.trim());
|
||||||
|
|
||||||
const eventClass = /^umami--([a-z]+)--([\w]+[\w-]*)$/;
|
const eventClass = /^umami--([a-z]+)--([\w]+[\w-]*)$/;
|
||||||
const eventSelect = "[class*='umami--']";
|
const eventSelect = "[class*='umami--']";
|
||||||
const cacheKey = 'umami.cache';
|
|
||||||
|
|
||||||
const trackingDisabled = () =>
|
const trackingDisabled = () =>
|
||||||
(localStorage && localStorage.getItem('umami.disabled')) ||
|
(localStorage && localStorage.getItem('umami.disabled')) ||
|
||||||
@ -42,6 +39,7 @@ import { removeTrailingSlash } from '../lib/url';
|
|||||||
const listeners = {};
|
const listeners = {};
|
||||||
let currentUrl = `${pathname}${search}`;
|
let currentUrl = `${pathname}${search}`;
|
||||||
let currentRef = document.referrer;
|
let currentRef = document.referrer;
|
||||||
|
let cache;
|
||||||
|
|
||||||
/* Collect metrics */
|
/* Collect metrics */
|
||||||
|
|
||||||
@ -49,6 +47,7 @@ import { removeTrailingSlash } from '../lib/url';
|
|||||||
const req = new XMLHttpRequest();
|
const req = new XMLHttpRequest();
|
||||||
req.open('POST', url, true);
|
req.open('POST', url, true);
|
||||||
req.setRequestHeader('Content-Type', 'application/json');
|
req.setRequestHeader('Content-Type', 'application/json');
|
||||||
|
if (cache) req.setRequestHeader('x-umami-cache', cache);
|
||||||
|
|
||||||
req.onreadystatechange = () => {
|
req.onreadystatechange = () => {
|
||||||
if (req.readyState === 4) {
|
if (req.readyState === 4) {
|
||||||
@ -64,7 +63,6 @@ import { removeTrailingSlash } from '../lib/url';
|
|||||||
hostname,
|
hostname,
|
||||||
screen,
|
screen,
|
||||||
language,
|
language,
|
||||||
cache: useCache && sessionStorage.getItem(cacheKey),
|
|
||||||
url: currentUrl,
|
url: currentUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -84,7 +82,7 @@ import { removeTrailingSlash } from '../lib/url';
|
|||||||
type,
|
type,
|
||||||
payload,
|
payload,
|
||||||
},
|
},
|
||||||
res => useCache && sessionStorage.setItem(cacheKey, res),
|
res => (cache = res),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user