Files
Webklar-Kundenbereich/analytics/src/ua.js
T
2026-10-01 09:27:22 +00:00

11 lines
563 B
JavaScript

// Gröbste Bot- und Gerätetyp-Erkennung; der User-Agent wird danach verworfen.
const BOT = /bot|crawl|spider|slurp|headless|lighthouse|pingdom|uptime|curl|wget|python|go-http|java\/|facebookexternalhit|preview/i;
export function classifyUa(ua) {
const s = typeof ua === 'string' ? ua : '';
if (!s || BOT.test(s)) return { bot: true, device: 'd' };
if (/Mobi|Android.*Mobile|iPhone/i.test(s)) return { bot: false, device: 'm' };
if (/iPad|Tablet|Android(?!.*Mobile)/i.test(s)) return { bot: false, device: 't' };
return { bot: false, device: 'd' };
}