Add simple traffic analytics with source attribution and conversion funnel

- track.js captures first-touch source per session (utm_source/src param
  or external referrer domain) and logs bridge/start page views.
- Join clicks now carry the source; all events aggregate per-source in
  data/analytics.json on the persistent volume.
- Admin: new Traffic & Conversions card with funnel totals (bridge ->
  start -> join click rates) and a per-source breakdown table.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-08-11 08:07:41 -05:00
parent ba14a1f1a9
commit 4115d3a920
8 changed files with 56 additions and 5 deletions
+18
View File
@@ -0,0 +1,18 @@
(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&&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;
const path=location.pathname.replace(/\/$/,'')||'/';
const page=path==='/'?'bridge':(path==='/start'?'start':null);
if(page)fetch('/api/public/track',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({event:page,source:getSource()})}).catch(()=>{});
})();