Spaces:
Running

uas-eus-webhook / shared /js /analytics.js
uas-deploy
deploy 2026-12-02T15:07:30Z
03c9ca7
Raw History Blame Contribute Delete
1.84 kB
/* First-party, consent-gated PostHog loader.
- Loads ONLY after the consent banner opt-in (consent.js sets window.__analyticsAllowed).
- The PostHog snippet is self-hosted (shared/vendor/posthog/array.js) and ALL traffic goes
through our own proxy api.uas.eus/posthog (webhook app) -> PostHog EU. No third-party
requests or cookies ever reach the browser directly.
- Cookieless: memory persistence only; URLs stripped of query strings. */
(function () {
var started = false;
function start() {
if (started) return;
var cfg = (window.SITE_CONFIG && window.SITE_CONFIG.analytics) || {};
if (!window.__analyticsAllowed || !cfg.enabled || !cfg.posthogKey || /^PENDING/.test(cfg.posthogKey)) return;
started = true;
var s = document.createElement('script');
s.src = 'shared/vendor/posthog/array.js';
s.onload = function () {
try {
window.posthog.init(cfg.posthogKey, {
api_host: cfg.posthogHost || 'https://api.uas.eus/posthog',
persistence: 'memory', // cookieless (GDPR): nothing in localStorage/cookies
autocapture: true,
capture_pageview: true,
capture_pageleave: true,
respect_dnt: true,
disable_session_recording: true,
sanitize_properties: function (props) {
if (props && props.$current_url) props.$current_url = String(props.$current_url).split('?')[0];
if (props && props.$referrer) props.$referrer = String(props.$referrer).split('?')[0];
return props;
}
});
} catch (e) { console.warn('posthog init failed', e); }
};
document.head.appendChild(s);
}
window.addEventListener('consent', start);
if (document.readyState !== 'loading') start();
else window.addEventListener('DOMContentLoaded', start);
})();