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.     // Sales qualification and completed demos/proposals are CRM facts, never browser clicks.
  39.     window.hbWa = function (event, meta) {
  40.         send(event, meta);
  41.         if (event === 'form_complete' && meta === 'demo') send('contact_submit', 'demo');
  42.     };
  43.     send('page_view');
  44.     var productPages = ['/business-suite', '/honeywatt', '/energy-operations', '/honeycore', '/honeycore/ems', '/honeycore/bms', '/honeycore/hybrid-control'];
  45.     var page = window.location.pathname, onProduct = productPages.indexOf(page) !== -1;
  46.     var pageEvents = {'/business-suite':'business_suite_view','/honeywatt':'honeywatt_view','/energy-operations':'energy_operations_view','/pricing':'pricing_detail_view'};
  47.     if (pageEvents[page]) send(pageEvents[page]);
  48.     var toolStarted = false;
  49.     document.addEventListener('input', function (event) {
  50.         if (toolStarted || !event.isTrusted || !event.target.closest('main')) return;
  51.         var toolEvent = {'/tools/rooftop-estimate':'solar_studio_start','/tools/site-assessment-estimator':'site_assessment_start'}[page];
  52.         if (toolEvent) { toolStarted = true; send(toolEvent); }
  53.     }, true);
  54.     document.addEventListener('click', function (e) {
  55.         var a = e.target && e.target.closest ? e.target.closest('a,button') : null;
  56.         if (!a) { return; }
  57.         var destination = '';
  58.         try { destination = new URL(a.getAttribute('href') || '', window.location.href).pathname; } catch (error) {}
  59.         if (onProduct && a.closest('main')) {
  60.             if (['/customers','/experience'].indexOf(destination) !== -1) send('product_proof_click', destination);
  61.             else if (destination === '/pricing') send('product_pricing_click', destination);
  62.             else if (destination.toLowerCase() === '/contact' || a.getAttribute('href') === '#request') send('product_cta_click', destination);
  63.         }
  64.         var wa = a.getAttribute && a.getAttribute('data-wa');
  65.         if (wa) { send(wa, a.getAttribute('href') || a.textContent.trim().slice(0, 80)); return; }
  66.         if (a.className && String(a.className).indexOf('pp-cta') !== -1) {
  67.             send(window.location.pathname === '/pricing' ? 'pricing_cta' : 'cta_click',
  68.                 a.getAttribute('href') || a.textContent.trim().slice(0, 80));
  69.         }
  70.     }, true);
  71.     var formStarted = false;
  72.     document.addEventListener('focusin', function (e) {
  73.         if (formStarted || !e.target || !e.target.closest) { return; }
  74.         var f = e.target.closest('form.pp-form, form[data-intent]');
  75.         if (f) { formStarted = true; send('form_start', f.getAttribute('data-intent') || ''); }
  76.     }, true);
  77. })();
  78. </script>