code wiki / _hdl_build / nx_ad_view.nx

nx_ad_view.nx source

↩ module page · 62 lines · 3008 B

1// nx_ad_view.nx -- LIB (PURE, no I/O): honest VIEWPORT-VERIFIED impression counting for the "Brought 2// to you by" ad engine. Counts ONLY genuinely-SEEN impressions to the MRC standard (>=50% of an ad's 3// pixels in the viewable area for >=1 CONTINUOUS second display / >=2s video) -- NEVER served-but- 4// unseen. This is the "evidence & science, no fake impressions like Google/others" honesty law applied 5// to ad measurement: the named exceed axis vs incumbents' inflated serve-counts. Also records WHERE on 6// the page (slot class) so delivery placement is transparent. [bar: srch_adview.raw -- MRC viewability] 7// 8// PRIVACY BY CONSTRUCTION: inputs are AGGREGATE buckets [viewed, slot, dwell_ms, n] -- NO visitor id, 9// IP, or fingerprint. The first-party client runtime measures 50%-in-viewport + continuous dwell and 10// posts only an aggregate bucket; this organ owns the COUNTING RULE (count iff viewed AND dwell>=min). 11// Mirrors nx_ad_botfilter's aggregate class-bucket shape -- "filter unseen" can never become "track 12// people". license_tier: ORIGINAL 13import "nx_syscalls.nx" 14 15const AV_MIN_DISPLAY: i64 = 1000 // MRC: >=1 continuous second (display ads) [srch_adview.raw] 16const AV_MIN_VIDEO: i64 = 2000 // MRC: >=2 continuous seconds (video ads) 17 18// slot classes (WHERE on page): 0=above-fold 1=below-fold 2=in-article (transparent placement) 19 20// 1 if this is a VIEWABLE impression by the MRC rule, else 0. viewed = client measured >=50% of the 21// ad's pixels in the viewable area; dwell_ms = continuous in-view time; min_ms = the MRC threshold. 22func av_viewable(viewed: i64, dwell_ms: i64, min_ms: i64) -> i64 { 23 if viewed != 1 { return 0 } 24 if dwell_ms < min_ms { return 0 } 25 return 1 26} 27 28// tally over m buckets (flat [viewed, slot, dwell_ms, n]): writes VIEWABLE count to *ovw and TOTAL 29// SERVED count to *osv. The honest viewability RATE = ovw/osv; ONLY ovw is billable (the meter must 30// count viewable, never served). Returns served total. Aggregate-only. 31func av_tally(ev: *i64, m: i64, min_ms: i64, ovw: *i64, osv: *i64) -> i64 { 32 var vw: i64 = 0 33 var sv: i64 = 0 34 var b: i64 = 0 35 while b < m { 36 let viewed: i64 = ev[b * 4] 37 let dwell: i64 = ev[b * 4 + 2] 38 let cnt: i64 = ev[b * 4 + 3] 39 sv = sv + cnt 40 if av_viewable(viewed, dwell, min_ms) == 1 { vw = vw + cnt } 41 b = b + 1 42 } 43 ovw[0] = vw 44 osv[0] = sv 45 return sv 46} 47 48// VIEWABLE count restricted to one slot class (WHERE on page) -- lets a campaign see honest per- 49// position performance (above/below fold) without any per-visitor data. 50func av_tally_slot(ev: *i64, m: i64, min_ms: i64, want_slot: i64) -> i64 { 51 var vw: i64 = 0 52 var b: i64 = 0 53 while b < m { 54 let viewed: i64 = ev[b * 4] 55 let slot: i64 = ev[b * 4 + 1] 56 let dwell: i64 = ev[b * 4 + 2] 57 let cnt: i64 = ev[b * 4 + 3] 58 if slot == want_slot { if av_viewable(viewed, dwell, min_ms) == 1 { vw = vw + cnt } } 59 b = b + 1 60 } 61 return vw 62}