c5e2c30ff3
track.js: on join pages with a ctb1_ clickid, count 30s of VISIBLE time (1s ticks, pauses when tab hidden), then report engaged once per session. server.js: relay engaged ctb1_ clickids to the CTB backend per the spec contract (X-Offer-Secret header, any-200-is-done); light in-process dedupe. New volume config keys ctbOfferPostbackUrl + ctbOfferSecret (PATCH allowlist). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
44 lines
2.1 KiB
JavaScript
44 lines
2.1 KiB
JavaScript
(function(){
|
|
function getSource(){
|
|
try{
|
|
let s=sessionStorage.getItem('ctb.src');
|
|
if(s)return s;
|
|
const p=new URLSearchParams(location.search);
|
|
s=p.get('utm_source')||p.get('src')||'';
|
|
if(!s){const v=p.get('v');if(v&&/^[a-z]{2,12}$/.test(v))s='angle:'+v;}
|
|
if(!s&&document.referrer){try{const h=new URL(document.referrer).hostname;if(h&&h!==location.hostname)s=h}catch(e){}}
|
|
s=s||'(direct)';
|
|
sessionStorage.setItem('ctb.src',s);
|
|
return s;
|
|
}catch(e){return '(direct)'}
|
|
}
|
|
window.ctbGetSource=getSource;
|
|
try{
|
|
const p2=new URLSearchParams(location.search);
|
|
const cid=p2.get('clickid')||p2.get('cid');
|
|
if(cid&&!sessionStorage.getItem('ctb.clickid'))sessionStorage.setItem('ctb.clickid',cid.slice(0,80));
|
|
}catch(e){}
|
|
window.ctbGetClickId=function(){try{return sessionStorage.getItem('ctb.clickid')||''}catch(e){return ''}};
|
|
const path=location.pathname.replace(/\/$/,'')||'/';
|
|
const page=path==='/'?'bridge':(path==='/start'?'start':(path==='/training'?'training':(path==='/join-now'?'joinnow':(/^\/join\/\d+$/.test(path)?'join':null))));
|
|
if(page)fetch('/api/public/track',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({event:page,source:getSource()})}).catch(()=>{});
|
|
|
|
// CTB Rewards featured offer: a ctb1_ clickid means this visitor earns
|
|
// coins for a REAL look at the tour — count 30 seconds of visible time on
|
|
// a join page, then report "engaged" once (server relays it to CTB).
|
|
(function(){
|
|
const cid=window.ctbGetClickId();
|
|
if(!cid||cid.indexOf('ctb1_')!==0)return;
|
|
if(page!=='join'&&page!=='joinnow')return;
|
|
try{ if(sessionStorage.getItem('ctb.engaged')===cid)return; }catch(e){}
|
|
let seen=0;
|
|
const t=setInterval(function(){
|
|
if(document.visibilityState!=='visible')return;
|
|
if(++seen<30)return;
|
|
clearInterval(t);
|
|
try{ sessionStorage.setItem('ctb.engaged',cid); }catch(e){}
|
|
fetch('/api/public/track',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({event:'engaged',source:getSource(),clickid:cid})}).catch(()=>{});
|
|
},1000);
|
|
})();
|
|
})();
|