{# WEB-5 §33 — the first-party conversion beacon. Privacy-lean BY CONSTRUCTION: respects
Do-Not-Track, sets no cookie, mints a random per-TAB session id (sessionStorage — gone
when the tab closes), sends only whitelisted events (WebAnalyticsCore refuses the rest).
Events: page_view on load · data-wa clicks · any .pp-cta = cta_click · form_start on
first input in an intent form · form_complete fired by the form on success. #}
<script>
(function () {
'use strict';
if (navigator.doNotTrack === '1' || window.doNotTrack === '1') { return; }
var URL_WA = "{{ route_exists('honeybee_wa_event') ? url('honeybee_wa_event') : '' }}";
if (!URL_WA) { return; } // route not loaded on this box — nothing to beacon to
var sid = '';
try {
sid = sessionStorage.getItem('hb_wa_sid') || '';
if (!sid) {
sid = Array.from(crypto.getRandomValues(new Uint8Array(8)))
.map(function (b) { return b.toString(16).padStart(2, '0'); }).join('');
sessionStorage.setItem('hb_wa_sid', sid);
}
} catch (e) { sid = ''; }
var q = new URLSearchParams(window.location.search);
function send(ev, meta) {
try {
var fd = new FormData();
fd.append('event', ev);
fd.append('page', window.location.pathname);
if (meta) { fd.append('meta', String(meta).slice(0, 300)); }
['utm_source', 'utm_medium', 'utm_campaign'].forEach(function (k) {
var v = q.get(k); if (v) { fd.append(k, v); }
});
if (document.referrer) { fd.append('ref', document.referrer.slice(0, 160)); }
if (sid) { fd.append('sid', sid); }
if (!(navigator.sendBeacon && navigator.sendBeacon(URL_WA, fd))) {
fetch(URL_WA, { method: 'POST', body: fd, keepalive: true }).catch(function () {});
}
} catch (e) { /* analytics must never break a page */ }
}
window.hbWa = send;
send('page_view');
document.addEventListener('click', function (e) {
var a = e.target && e.target.closest ? e.target.closest('a,button') : null;
if (!a) { return; }
var wa = a.getAttribute && a.getAttribute('data-wa');
if (wa) { send(wa, a.getAttribute('href') || a.textContent.trim().slice(0, 80)); return; }
if (a.className && String(a.className).indexOf('pp-cta') !== -1) {
send(window.location.pathname === '/pricing' ? 'pricing_cta' : 'cta_click',
a.getAttribute('href') || a.textContent.trim().slice(0, 80));
}
}, true);
var formStarted = false;
document.addEventListener('focusin', function (e) {
if (formStarted || !e.target || !e.target.closest) { return; }
var f = e.target.closest('form.pp-form, form[data-intent]');
if (f) { formStarted = true; send('form_start', f.getAttribute('data-intent') || ''); }
}, true);
})();
</script>