(function(){
'use strict';
var cfg=window.DDB_REVENUE_TRACE||{};
function round(v){return Math.round((Number(v)||0)*100)/100;}
function resourceRows(){
 var rows=performance.getEntriesByType('resource').map(function(r){return {name:r.name.split('?')[0],initiator_type:r.initiatorType,duration_ms:round(r.duration),transfer_size:r.transferSize||0,decoded_body_size:r.decodedBodySize||0};});
 rows.sort(function(a,b){return b.duration_ms-a.duration_ms;}); return rows.slice(0,30);
}
function chartTiming(){
 var nodes=[].slice.call(document.querySelectorAll('[data-echart], .ddb-echart, [data-chart]'));
 return {chart_nodes:nodes.length, chart_canvases:document.querySelectorAll('canvas').length, chart_svgs:document.querySelectorAll('svg').length};
}
window.addEventListener('load',function(){setTimeout(function(){
 var nav=performance.getEntriesByType('navigation')[0]; if(!nav)return;
 var payload={schema:'DDB_REVENUE_BROWSER_TRACE_V1',request_id:cfg.request_id||'',captured_at:new Date().toISOString(),url:location.href,
 server:cfg.server||{},navigation:{dns_ms:round(nav.domainLookupEnd-nav.domainLookupStart),connect_ms:round(nav.connectEnd-nav.connectStart),request_wait_ttfb_ms:round(nav.responseStart-nav.requestStart),response_download_ms:round(nav.responseEnd-nav.responseStart),dom_interactive_ms:round(nav.domInteractive-nav.startTime),dom_content_loaded_ms:round(nav.domContentLoadedEventEnd-nav.startTime),load_complete_ms:round(nav.loadEventEnd-nav.startTime),transfer_size:nav.transferSize||0,decoded_body_size:nav.decodedBodySize||0},
 resources:{count:performance.getEntriesByType('resource').length,slowest:resourceRows()},charts:chartTiming(),user_agent:navigator.userAgent};
 var body=JSON.stringify(payload); var url=cfg.beacon_url||'index.php?page=revenue-performance-beacon';
 if(navigator.sendBeacon){navigator.sendBeacon(url,new Blob([body],{type:'application/json'}));}else{fetch(url,{method:'POST',headers:{'Content-Type':'application/json'},body:body,credentials:'same-origin',keepalive:true});}
 },400);});
})();
