code wiki / _hdl_build / nx_ad_serve_policy.nx
nx_ad_serve_policy.nx source
↩ module page · 49 lines · 2239 B
1// nx_ad_serve_policy.nx -- LIB: the polite SERVE POLICY for the performance ad engine (ADS-012,
2// CALLOUT-004). Extends the ADS-004 placement with the WHEN/WHETHER decision:
3// - ONCE PER VISIT: the byline appears at most once per visit (polite, gets out of the way;
4// X-ADS-POLITE-001) -- no engagement farming, no attention extraction.
5// - GEO-TARGETED: serve only where the campaign chose to (visit geo in the campaign's geo set).
6// - OFFER-ONLY-WHERE-VALUABLE: beyond the byline, the value-exchange OFFER appears only where it
7// is genuinely useful (e.g. a shopping property in the visitor's geo) -- never forced.
8//
9// PRIVACY: the only signals are (a) a transient "shown this visit" flag (no identity; rides the
10// existing nx_no_cookie_session) and (b) a COARSE geo (country/region, not PII). No visitor is
11// tracked. license_tier: ORIGINAL
12import "nx_ad_serve.nx"
13import "nx_syscalls.nx"
14
15// 1 if `geo` is a whole comma-separated token of `targets` (token-boundary exact: "US" does NOT
16// match "USA"), else 0.
17func sp_geo_match(geo: *u8, targets: *u8) -> i64 {
18 let gl: i64 = as_len(geo)
19 let tl: i64 = as_len(targets)
20 var i: i64 = 0
21 while i < tl {
22 var e: i64 = i
23 var go: i64 = 1
24 while go == 1 { if e >= tl { go = 0 } else { if targets[e] == (44 as u8) { go = 0 } else { e = e + 1 } } }
25 let tklen: i64 = e - i
26 if tklen == gl {
27 var k: i64 = 0
28 var eq: i64 = 1
29 while k < gl { if targets[i + k] != geo[k] { eq = 0; k = gl } else { k = k + 1 } }
30 if eq == 1 { return 1 }
31 }
32 i = e + 1
33 }
34 return 0
35}
36
37// serve the byline? NO if already shown this visit (once-per-visit), else only where the campaign
38// geo-targets the visit.
39func sp_should_serve(already_shown: i64, geo: *u8, targets: *u8) -> i64 {
40 if already_shown == 1 { return 0 }
41 return sp_geo_match(geo, targets)
42}
43
44// offer the value-exchange? ONLY where genuinely valuable (a shopping-class property) AND the
45// campaign geo-targets the visit. Never a popup wall, never forced.
46func sp_should_offer(is_shopping: i64, geo: *u8, targets: *u8) -> i64 {
47 if is_shopping == 0 { return 0 }
48 return sp_geo_match(geo, targets)
49}