Spaces:
Running

File size: 1,842 Bytes
51f4b1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* 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);
})();