src/ApplicationBundle/Modules/HoneybeeWeb/Resources/views/website/analytics.html.twig line 1

Open in your IDE?
  1. {# WEB-5 §33 — the first-party conversion beacon. Privacy-lean BY CONSTRUCTION: respects
  2.    Do-Not-Track, sets no cookie, mints a random per-TAB session id (sessionStorage — gone
  3.    when the tab closes), sends only whitelisted events (WebAnalyticsCore refuses the rest).
  4.    Events: page_view on load · data-wa clicks · any .pp-cta = cta_click · form_start on
  5.    first input in an intent form · form_complete fired by the form on success. #}
  6. <script>
  7. (function () {
  8.     'use strict';
  9.     if (navigator.doNotTrack === '1' || window.doNotTrack === '1') { return; }
  10.     var URL_WA = "{{ route_exists('honeybee_wa_event') ? url('honeybee_wa_event') : '' }}";
  11.     if (!URL_WA) { return; }   // route not loaded on this box — nothing to beacon to
  12.     var sid = '';
  13.     try {
  14.         sid = sessionStorage.getItem('hb_wa_sid') || '';
  15.         if (!sid) {
  16.             sid = Array.from(crypto.getRandomValues(new Uint8Array(8)))
  17.                 .map(function (b) { return b.toString(16).padStart(2, '0'); }).join('');
  18.             sessionStorage.setItem('hb_wa_sid', sid);
  19.         }
  20.     } catch (e) { sid = ''; }
  21.     var q = new URLSearchParams(window.location.search);
  22.     function send(ev, meta) {
  23.         try {
  24.             var fd = new FormData();
  25.             fd.append('event', ev);
  26.             fd.append('page', window.location.pathname);
  27.             if (meta) { fd.append('meta', String(meta).slice(0, 300)); }
  28.             ['utm_source', 'utm_medium', 'utm_campaign'].forEach(function (k) {
  29.                 var v = q.get(k); if (v) { fd.append(k, v); }
  30.             });
  31.             if (document.referrer) { fd.append('ref', document.referrer.slice(0, 160)); }
  32.             if (sid) { fd.append('sid', sid); }
  33.             if (!(navigator.sendBeacon && navigator.sendBeacon(URL_WA, fd))) {
  34.                 fetch(URL_WA, { method: 'POST', body: fd, keepalive: true }).catch(function () {});
  35.             }
  36.         } catch (e) { /* analytics must never break a page */ }
  37.     }
  38.     window.hbWa = send;
  39.     send('page_view');
  40.     document.addEventListener('click', function (e) {
  41.         var a = e.target && e.target.closest ? e.target.closest('a,button') : null;
  42.         if (!a) { return; }
  43.         var wa = a.getAttribute && a.getAttribute('data-wa');
  44.         if (wa) { send(wa, a.getAttribute('href') || a.textContent.trim().slice(0, 80)); return; }
  45.         if (a.className && String(a.className).indexOf('pp-cta') !== -1) {
  46.             send(window.location.pathname === '/pricing' ? 'pricing_cta' : 'cta_click',
  47.                 a.getAttribute('href') || a.textContent.trim().slice(0, 80));
  48.         }
  49.     }, true);
  50.     var formStarted = false;
  51.     document.addEventListener('focusin', function (e) {
  52.         if (formStarted || !e.target || !e.target.closest) { return; }
  53.         var f = e.target.closest('form.pp-form, form[data-intent]');
  54.         if (f) { formStarted = true; send('form_start', f.getAttribute('data-intent') || ''); }
  55.     }, true);
  56. })();
  57. </script>