1/** 2 * One reader in N tells the site a story was read (DECISIONS #184): a beacon after the page is 3 * idle, once per story per browser session, only where the page said so (data.views). The sample 4 * keeps the counter cheap; the rail only needs the order of stories. 5 */ 6export default function init(data) { 7 const v = data.views; 8 if (!v || !v.url || !v.post || !('sendBeacon' in navigator) || navigator.webdriver) return; 9 const key = 'vp:seen:' + v.post; 10 try { if (sessionStorage.getItem(key)) return; sessionStorage.setItem(key, '1'); } catch (e) { /* storage blocked: count anyway */ } 11 if (Math.random() * (v.rate || 10) >= 1) return; 12 const send = () => { const body = new FormData(); body.append('id', String(v.post)); navigator.sendBeacon(v.url, body); }; 13 if ('requestIdleCallback' in window) requestIdleCallback(send, { timeout: 4000 }); else setTimeout(send, 1500); 14}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.