(function(){"use strict";if(typeof h4bsMeasurement!=="object")return;const consent=()=>document.cookie.split(";").some(part=>part.trim()===String(h4bsMeasurement.consentCookie||"h4bs_analytics_consent")+"=1");const emit=(name,detail)=>{document.dispatchEvent(new CustomEvent("h4bs:conversion",{detail:Object.assign({name:name,postId:Number(h4bsMeasurement.postId||0)},detail||{})}));if(!consent())return;if(window.dataLayer&&name)window.dataLayer.push({event:name,h4_post_id:Number(h4bsMeasurement.postId||0)});};document.addEventListener("click",event=>{const target=event.target.closest("a,button,[data-h4bs-conversion]");if(!target)return;const name=String(target.dataset.h4bsConversion||h4bsMeasurement.eventName||"");if(name)emit(name,{href:target.href||"",label:(target.textContent||"").trim().slice(0,100)});});if(!h4bsMeasurement.rumEnabled||!consent()||typeof PerformanceObserver!=="function")return;const send=(metric,value)=>navigator.sendBeacon(h4bsMeasurement.endpoint,new URLSearchParams({action:"h4bs_measure",nonce:String(h4bsMeasurement.nonce||""),metric:metric,value:String(value),post_id:String(h4bsMeasurement.postId||0),event:""}));try{new PerformanceObserver(list=>list.getEntries().forEach(entry=>send("lcp",entry.startTime))).observe({type:"largest-contentful-paint",buffered:true});new PerformanceObserver(list=>list.getEntries().forEach(entry=>{if(!entry.hadRecentInput)send("cls",entry.value);})).observe({type:"layout-shift",buffered:true});new PerformanceObserver(list=>list.getEntries().forEach(entry=>send("inp",entry.duration))).observe({type:"event",buffered:true,durationThreshold:40});}catch(error){/* Unsupported observer types are intentionally ignored. */}}());
