@iann29/rastro 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -9
- package/agent/integration.md +40 -19
- package/agent/manifest.json +13 -7
- package/agent/manifest.schema.json +18 -8
- package/dist/client/federation.d.ts +18 -8
- package/dist/client/federation.d.ts.map +1 -1
- package/dist/client/federation.js +7 -1
- package/dist/client/federation.js.map +1 -1
- package/dist/client/identity.d.ts +11 -0
- package/dist/client/identity.d.ts.map +1 -0
- package/dist/client/identity.js +123 -0
- package/dist/client/identity.js.map +1 -0
- package/dist/client/index.d.ts +242 -5
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +102 -3
- package/dist/client/index.js.map +1 -1
- package/dist/component/_generated/api.d.ts +2 -0
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +87 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/ingest.d.ts.map +1 -1
- package/dist/component/ingest.js +30 -19
- package/dist/component/ingest.js.map +1 -1
- package/dist/component/people.d.ts +79 -0
- package/dist/component/people.d.ts.map +1 -0
- package/dist/component/people.js +249 -0
- package/dist/component/people.js.map +1 -0
- package/dist/component/reports.d.ts +10 -4
- package/dist/component/reports.d.ts.map +1 -1
- package/dist/component/reports.js +9 -5
- package/dist/component/reports.js.map +1 -1
- package/dist/component/schema.d.ts +39 -0
- package/dist/component/schema.js +30 -1
- package/dist/component/schema.js.map +1 -1
- package/dist/component/validators.d.ts +50 -0
- package/dist/component/validators.d.ts.map +1 -1
- package/dist/component/validators.js +27 -0
- package/dist/component/validators.js.map +1 -1
- package/dist/component/visitors.d.ts +38 -2
- package/dist/component/visitors.d.ts.map +1 -1
- package/dist/component/visitors.js +162 -42
- package/dist/component/visitors.js.map +1 -1
- package/dist/react/index.d.ts +9 -5
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +36 -5
- package/dist/react/index.js.map +1 -1
- package/dist/tracker/generated.d.ts +6 -6
- package/dist/tracker/generated.d.ts.map +1 -1
- package/dist/tracker/generated.js +6 -6
- package/dist/tracker/generated.js.map +1 -1
- package/dist/tracker/tracker.d.ts +2 -1
- package/dist/tracker/tracker.d.ts.map +1 -1
- package/dist/tracker/tracker.js +41 -2
- package/dist/tracker/tracker.js.map +1 -1
- package/dist/tracker.min.js +1 -1
- package/docs/federation.md +24 -0
- package/docs/identity.md +307 -0
- package/docs/upgrading.md +58 -20
- package/llms.txt +6 -2
- package/package.json +5 -3
- package/src/component/_generated/api.ts +2 -0
- package/src/component/_generated/component.ts +99 -0
- package/src/component/ingest.ts +46 -27
- package/src/component/people.ts +321 -0
- package/src/component/reports.ts +11 -4
- package/src/component/schema.ts +35 -0
- package/src/component/validators.ts +49 -0
- package/src/component/visitors.ts +232 -55
- package/src/tracker/generated.ts +6 -6
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export declare const RASTRO_VERSION = "0.
|
|
2
|
-
export declare const TRACKER_SOURCE = "(()=>{const t=document.currentScript,e=t?.dataset.site,i=t?.dataset.endpoint||t?.src&&new URL(\"events\",t.src).href;if(!e||!i)return;const n=()=>crypto.randomUUID?.()||Math.random()+\"\",
|
|
3
|
-
export declare const TRACKER_GZIP_BASE64 = "
|
|
4
|
-
export declare const TRACKER_RAW_BYTES =
|
|
5
|
-
export declare const TRACKER_GZIP_BYTES =
|
|
6
|
-
export declare const TRACKER_HASH = "
|
|
1
|
+
export declare const RASTRO_VERSION = "0.6.0";
|
|
2
|
+
export declare const TRACKER_SOURCE = "(()=>{const t=document.currentScript,e=t?.dataset.site,i=t?.dataset.endpoint||t?.src&&new URL(\"events\",t.src).href;if(!e||!i)return;const n=()=>crypto.randomUUID?.()||Math.random()+\"\",r=new URLSearchParams(location.search),s=r.get(\"ref\")?.slice(0,64);let o;for(const t of[\"source\",\"medium\",\"campaign\",\"term\",\"content\"]){const e=r.get(\"utm_\"+t)?.slice(0,64);e&&((o??={})[\"utm_\"+t]=e)}const a=\"gclid gbraid wbraid msclkid ttclid twclid li_fat_id ScCid rdt_cid dclid epik srsltid mc_cid mc_eid _hsenc igsh igshid fbclid\".split(\" \").filter(t=>r.has(t)).slice(0,8);let c,d,l,h,f=t.dataset.visitor||\"\",p=Boolean(f);try{f||=localStorage._rv||=n()}catch{}try{d=sessionStorage,l=d._r,c=d._ri==f&&d._rt,h=s||d._a,h&&(d._a=h),o||=d._u&&JSON.parse(d._u),o&&(d._u=JSON.stringify(o))}catch{h=s}let v,g=0;const u=[];let m=document.referrer.split(\"/\",3).join(\"/\")||void 0;const _=t=>{const n=u.splice(0,50);if(!n.length)return;const r=()=>new Blob([JSON.stringify({siteId:e,events:n,sentAt:Date.now()})]);let s=r();for(;s.size>64e3&&n.length>1;)u.unshift(n.pop()),s=r();t&&navigator.sendBeacon(i,s)||fetch(i,{method:\"POST\",body:s,keepalive:1}).catch(()=>{}),u.length&&_(t)},y=(t,e,i)=>{const r=Date.now(),s=r-c;c=r,s<18e5||(l=n(),\"pageview\"!=t&&(S=\"\",w()));try{d._r=l,d._ri=f,d._rt=r}catch{}u.push({eventId:`${l}.${r.toString(36)}.${g}`,sessionId:l,visitorId:f||l,type:t,name:e,path:location.pathname.slice(0,256),referrer:m,timestamp:r,sequence:g++,affiliateSlug:h,...i}),clearTimeout(v),v=setTimeout(_,1200)};let S;const w=()=>{const t=location.pathname;t!=S&&(S=t,y(\"pageview\",void 0,{properties:o,clid:a.length?a:void 0}))};window.rastro=(e,i,r)=>{if(\"context\"==e)return{sessionId:l,visitorId:f||l,identified:p};if(\"identify\"==e||\"reset\"==e){if(\"identify\"==e&&(!i||i.length>128||!/^[A-Za-z0-9][A-Za-z0-9_.:-]*$/.test(i)))return;if(\"identify\"==e&&i==f)return;_();const r=\"reset\"==e||p;if(p=\"identify\"==e,f=\"identify\"==e?i:n(),t.dataset.visitor=\"identify\"==e?f:\"\",r){h=void 0,o=void 0,m=void 0,a.length=0;try{\"reset\"==e&&(localStorage._rv=f),d._a=\"\",d._u=\"\"}catch{}}c=0,g=0,S=\"\",w()}\"event\"==e&&y(\"custom\",`${i||\"event\"}`.slice(0,80),r&&JSON.stringify(r).length>2e4?void 0:{properties:r})},document.addEventListener(\"click\",t=>{const e=t.target?.closest(\"a,button,[data-rastro-event]\");if(!e)return;const i=e.dataset.rastroEvent,n=e.href,r=n&&new URL(n),s=/^https?:$/.test(r?.protocol),o=s&&r.origin!=location.origin;y(i?\"custom\":o?\"outbound\":\"click\",i,{target:(e.dataset.rastroLabel||e.innerText||e.tagName).slice(0,64),href:s?((o?r.origin:\"\")+r.pathname).slice(0,256):void 0})},1);for(const t of[\"pushState\",\"replaceState\"]){const e=history[t];history[t]=(...t)=>{e.apply(history,t),w()}}addEventListener(\"popstate\",w);let b=0;const I=()=>{y(\"heartbeat\"),_()},L=()=>{b&&(clearInterval(b),b=0,y(\"leave\"),_(1))},E=()=>{document.hidden?L():b||(I(),b=setInterval(I,2e4))};addEventListener(\"pagehide\",L),addEventListener(\"pageshow\",E),document.addEventListener(\"visibilitychange\",E),b=setInterval(I,2e4),w(),E()})();";
|
|
3
|
+
export declare const TRACKER_GZIP_BASE64 = "H4sIAAAAAAACA31W23LbOBL9FRmVYgHrNiI7l8pSi6gmO3nwludSq+RlXR4FIpsiNhTAAZrSaET++xRIUYrt1LyQALqBbjTOOQDnQr0/ZM4GmpDKXdZs0JLMGu/R0iLzpiZARXOZa9IBSQZDCObbEbR57YyltqW5DD5LEou7yef/3nGGW7QUGFAcF7L0WMxMwS+wbS+M8EiNt7MhulUxlczva3LSa5u7zefPtz/OJRdt+5Om8jjIxSVj4NUxxgK1z8pftdebwCuXaTLOytCPCgjKyzUSZx4LJuYyVCZDPoW3r8WsQpq4WeE8P25/4op7FlzjM2TANpibZsOAZXpTa7O2DBih70ecJbTEHsSxcjiGaWizZJf0JBImCeduPleHTtyPPg8KRTdM14qts8rkk/XKa5NPdsNvE7Lqq8knRL2Rdv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JmaRtWDkT3dcG0PK+05y5pAbsPgy4uDadujsftyvhamAvxRdc8q5cV4Ajf4ej6knH6LJd+JDk7CqvP8Y1z4zgRCi56zrDLZVwZnBUVFkrRfI81lVrkQj4xpWDVEzsJ9rOfVAL6rPscHNogsPlZXo/BU+8G9DwxWYf9AiW+L8xPGRvl5+VtJVId5OiLFz2XtHbnMVQKcCknipfNmbezFmWDDwGzPzXysYermzDW0co3NWTpu0cBh2FfKn6Z2p1dYtS1KYy36T/gHxQ7p9c96g+LbVwbE3NMwjy+NMZmUMXHpT0wXj1ToRN0OrsWzd1DUxgVpik8hj3WlMxy63zx6ShPI+f09PczOTcWllBR5j1LXdbXnRxuQ6NHVPT/q2tVhiLUbbq3V6RK+HdRrz1mJ2tMKNTEBSy46uBtMqyThvSreWkK/1RVfCVipaRSzCvUWe/9rITr4OMw4ga40eY52fsdFumpbfsvjxIB0WukWbvB11Lbv5KzXWJocGdwJ+L45lG7H4KP4O5RH9q9MZWifldqusff/XhKxdvAx3uxczP4CGKXLCLcLAAA=";
|
|
4
|
+
export declare const TRACKER_RAW_BYTES = 2999;
|
|
5
|
+
export declare const TRACKER_GZIP_BYTES = 1565;
|
|
6
|
+
export declare const TRACKER_HASH = "6246dc584683303a";
|
|
7
7
|
export declare const VITALS_SOURCE = "(()=>{const t=document.currentScript,e=t?.dataset.site,n=t?.dataset.endpoint||t?.src&&new URL(\"events\",t.src).href;if(!e||!n)return;const r=()=>crypto.randomUUID?.()||Math.random()+\"\";let s=t.dataset.visitor||\"\";try{s||=localStorage._rv||=r()}catch{}const o=Date.now();let a;try{a=sessionStorage._ri===s&&o-sessionStorage._rt<18e5&&sessionStorage._r||r(),sessionStorage._r=a,sessionStorage._ri=s,sessionStorage._rt=o}catch{a=r()}const i=s||a,c=location.pathname.slice(0,256),d={},h=[],l=(t,e,n)=>{try{const r=new PerformanceObserver(t=>e(t.getEntries()));r.observe({type:t,buffered:1,...n}),h.push({observer:r,handler:e})}catch{}},f=performance.getEntriesByType?.(\"navigation\")[0];f&&f.responseStart>0&&(d.TTFB=f.responseStart),l(\"paint\",t=>{for(const e of t)\"first-contentful-paint\"===e.name&&(d.FCP=e.startTime)}),l(\"largest-contentful-paint\",t=>{const e=t[t.length-1];e&&(d.LCP=e.startTime)});let m=0,u=0,v=0;l(\"layout-shift\",t=>{for(const e of t)e.hadRecentInput||(m&&e.startTime-v<1e3&&e.startTime-u<5e3?m+=e.value:(m=e.value,u=e.startTime),v=e.startTime,d.CLS=Math.max(d.CLS||0,1e3*m))});const g=[],p=new Set,S=t=>{for(const e of t)e.interactionId&&(p.add(e.interactionId),g.push(e.duration));if(!g.length)return;g.sort((t,e)=>e-t),g.length=Math.min(g.length,10);const e=performance.interactionCount||p.size;d.INP=g[Math.min(g.length-1,Math.floor(e/50))]};l(\"event\",S,{durationThreshold:40}),l(\"first-input\",S);let y=0;const b=()=>{if(y)return;for(const{observer:t,handler:e}of h)e(t.takeRecords()),t.disconnect();const t=Date.now(),r=Object.keys(d).map((e,n)=>({eventId:`${a}.${t.toString(36)}.v${n}`,sessionId:a,visitorId:i,type:\"vital\",name:e,value:Math.round(d[e]),path:c,timestamp:t,sequence:n}));if(!r.length)return;y=1;const s=new Blob([JSON.stringify({siteId:e,events:r,sentAt:t})]),o=navigator.sendBeacon?.bind(navigator);o&&o(n,s)||fetch(n,{method:\"POST\",body:s,keepalive:1}).catch(()=>{})};document.addEventListener(\"visibilitychange\",()=>{\"hidden\"===document.visibilityState&&b()}),addEventListener(\"pagehide\",b)})();";
|
|
8
8
|
export declare const VITALS_GZIP_BASE64 = "H4sIAAAAAAACA3VVbW/bNhD+K6lQCORKc/ayFINcJlj6AnjImqBOPwXBSosniatEauTJnSbpvw+i7MSJ22/SkXf33N1zDwmh4rxLrfF4gkLZtKnAIE8b58DgOnW6RgYCL7iSKD0g9xqBmUMLGFVbbbDv8YJ7l8axgW8nnz9dkQi2YNBHDEc75YWDbKkz8gL6/oWhDrBxZjlld2KEkrq2RsudNMpWnz+v3l1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8BpgUxrKsAC6uS6OZ6fRuxjVVt4tlXgFqWegvJYqA8qB4JAx3osHx4ZKVS70c8V9ojGHAkGju30aXGNi2kySFiwSsqtFJgRnV6cH68ukaJEMcbMurTccxa5lBoBRHb0IESuvwfweV+3/MHAAA=";
|
|
9
9
|
export declare const VITALS_RAW_BYTES = 2035;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generated.d.ts","sourceRoot":"","sources":["../../src/tracker/generated.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,cAAc,UAAU,CAAC;AACtC,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"generated.d.ts","sourceRoot":"","sources":["../../src/tracker/generated.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,cAAc,UAAU,CAAC;AACtC,eAAO,MAAM,cAAc,giGAAgiG,CAAC;AAC5jG,eAAO,MAAM,mBAAmB,6iEAA6iE,CAAC;AAC9kE,eAAO,MAAM,iBAAiB,OAAO,CAAC;AACtC,eAAO,MAAM,kBAAkB,OAAO,CAAC;AACvC,eAAO,MAAM,YAAY,qBAAqB,CAAC;AAC/C,eAAO,MAAM,aAAa,shEAAshE,CAAC;AACjjE,eAAO,MAAM,kBAAkB,67CAA67C,CAAC;AAC79C,eAAO,MAAM,gBAAgB,OAAO,CAAC;AACrC,eAAO,MAAM,iBAAiB,OAAO,CAAC;AACtC,eAAO,MAAM,WAAW,qBAAqB,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Generated by scripts/build-tracker.mjs. Do not edit.
|
|
2
|
-
export const RASTRO_VERSION = "0.
|
|
3
|
-
export const TRACKER_SOURCE = "(()=>{const t=document.currentScript,e=t?.dataset.site,i=t?.dataset.endpoint||t?.src&&new URL(\"events\",t.src).href;if(!e||!i)return;const n=()=>crypto.randomUUID?.()||Math.random()+\"\",
|
|
4
|
-
export const TRACKER_GZIP_BASE64 = "
|
|
5
|
-
export const TRACKER_RAW_BYTES =
|
|
6
|
-
export const TRACKER_GZIP_BYTES =
|
|
7
|
-
export const TRACKER_HASH = "
|
|
2
|
+
export const RASTRO_VERSION = "0.6.0";
|
|
3
|
+
export const TRACKER_SOURCE = "(()=>{const t=document.currentScript,e=t?.dataset.site,i=t?.dataset.endpoint||t?.src&&new URL(\"events\",t.src).href;if(!e||!i)return;const n=()=>crypto.randomUUID?.()||Math.random()+\"\",r=new URLSearchParams(location.search),s=r.get(\"ref\")?.slice(0,64);let o;for(const t of[\"source\",\"medium\",\"campaign\",\"term\",\"content\"]){const e=r.get(\"utm_\"+t)?.slice(0,64);e&&((o??={})[\"utm_\"+t]=e)}const a=\"gclid gbraid wbraid msclkid ttclid twclid li_fat_id ScCid rdt_cid dclid epik srsltid mc_cid mc_eid _hsenc igsh igshid fbclid\".split(\" \").filter(t=>r.has(t)).slice(0,8);let c,d,l,h,f=t.dataset.visitor||\"\",p=Boolean(f);try{f||=localStorage._rv||=n()}catch{}try{d=sessionStorage,l=d._r,c=d._ri==f&&d._rt,h=s||d._a,h&&(d._a=h),o||=d._u&&JSON.parse(d._u),o&&(d._u=JSON.stringify(o))}catch{h=s}let v,g=0;const u=[];let m=document.referrer.split(\"/\",3).join(\"/\")||void 0;const _=t=>{const n=u.splice(0,50);if(!n.length)return;const r=()=>new Blob([JSON.stringify({siteId:e,events:n,sentAt:Date.now()})]);let s=r();for(;s.size>64e3&&n.length>1;)u.unshift(n.pop()),s=r();t&&navigator.sendBeacon(i,s)||fetch(i,{method:\"POST\",body:s,keepalive:1}).catch(()=>{}),u.length&&_(t)},y=(t,e,i)=>{const r=Date.now(),s=r-c;c=r,s<18e5||(l=n(),\"pageview\"!=t&&(S=\"\",w()));try{d._r=l,d._ri=f,d._rt=r}catch{}u.push({eventId:`${l}.${r.toString(36)}.${g}`,sessionId:l,visitorId:f||l,type:t,name:e,path:location.pathname.slice(0,256),referrer:m,timestamp:r,sequence:g++,affiliateSlug:h,...i}),clearTimeout(v),v=setTimeout(_,1200)};let S;const w=()=>{const t=location.pathname;t!=S&&(S=t,y(\"pageview\",void 0,{properties:o,clid:a.length?a:void 0}))};window.rastro=(e,i,r)=>{if(\"context\"==e)return{sessionId:l,visitorId:f||l,identified:p};if(\"identify\"==e||\"reset\"==e){if(\"identify\"==e&&(!i||i.length>128||!/^[A-Za-z0-9][A-Za-z0-9_.:-]*$/.test(i)))return;if(\"identify\"==e&&i==f)return;_();const r=\"reset\"==e||p;if(p=\"identify\"==e,f=\"identify\"==e?i:n(),t.dataset.visitor=\"identify\"==e?f:\"\",r){h=void 0,o=void 0,m=void 0,a.length=0;try{\"reset\"==e&&(localStorage._rv=f),d._a=\"\",d._u=\"\"}catch{}}c=0,g=0,S=\"\",w()}\"event\"==e&&y(\"custom\",`${i||\"event\"}`.slice(0,80),r&&JSON.stringify(r).length>2e4?void 0:{properties:r})},document.addEventListener(\"click\",t=>{const e=t.target?.closest(\"a,button,[data-rastro-event]\");if(!e)return;const i=e.dataset.rastroEvent,n=e.href,r=n&&new URL(n),s=/^https?:$/.test(r?.protocol),o=s&&r.origin!=location.origin;y(i?\"custom\":o?\"outbound\":\"click\",i,{target:(e.dataset.rastroLabel||e.innerText||e.tagName).slice(0,64),href:s?((o?r.origin:\"\")+r.pathname).slice(0,256):void 0})},1);for(const t of[\"pushState\",\"replaceState\"]){const e=history[t];history[t]=(...t)=>{e.apply(history,t),w()}}addEventListener(\"popstate\",w);let b=0;const I=()=>{y(\"heartbeat\"),_()},L=()=>{b&&(clearInterval(b),b=0,y(\"leave\"),_(1))},E=()=>{document.hidden?L():b||(I(),b=setInterval(I,2e4))};addEventListener(\"pagehide\",L),addEventListener(\"pageshow\",E),document.addEventListener(\"visibilitychange\",E),b=setInterval(I,2e4),w(),E()})();";
|
|
4
|
+
export const TRACKER_GZIP_BASE64 = "H4sIAAAAAAACA31W23LbOBL9FRmVYgHrNiI7l8pSi6gmO3nwludSq+RlXR4FIpsiNhTAAZrSaET++xRIUYrt1LyQALqBbjTOOQDnQr0/ZM4GmpDKXdZs0JLMGu/R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4Srm+mU9H1J784ommnHmn8s9RmdKEWffEI9vxcUhigDIfauxo9GQypgygYqT6e31yng1MnRDfbGZu7nfQ6kHeKIxjwMbIp+CCZfxBTCo9YP/xNRU2OlkxhME/rLhKFHUf2cYG2ZR4DDosdnlqThF+YtjUnfN+8a9uLl7/d/3D1P3315/Tqnw/n5lKmVw//ePFSEgbiRoiRiM9XjQI0WpdcnKh6zqVt6zivVo9mQvG4PzdphO4z6XziVaTxlhOHUh2PwY2NzdgYT0FNe7SfE0kS/lRuVSGgF0rGoFdCxkYedJmaRtWDkT3dcG0PK+05y5pAbsPgy4uDadujsftyvhamAvxRdc8q5cV4Ajf4ej6knH6LJd+JDk7CqvP8Y1z4zgRCi56zrDLZVwZnBUVFkrRfI81lVrkQj4xpWDVEzsJ9rOfVAL6rPscHNogsPlZXo/BU+8G9DwxWYf9AiW+L8xPGRvl5+VtJVId5OiLFz2XtHbnMVQKcCknipfNmbezFmWDDwGzPzXysYermzDW0co3NWTpu0cBh2FfKn6Z2p1dYtS1KYy36T/gHxQ7p9c96g+LbVwbE3NMwjy+NMZmUMXHpT0wXj1ToRN0OrsWzd1DUxgVpik8hj3WlMxy63zx6ShPI+f09PczOTcWllBR5j1LXdbXnRxuQ6NHVPT/q2tVhiLUbbq3V6RK+HdRrz1mJ2tMKNTEBSy46uBtMqyThvSreWkK/1RVfCVipaRSzCvUWe/9rITr4OMw4ga40eY52fsdFumpbfsvjxIB0WukWbvB11Lbv5KzXWJocGdwJ+L45lG7H4KP4O5RH9q9MZWifldqusff/XhKxdvAx3uxczP4CGKXLCLcLAAA=";
|
|
5
|
+
export const TRACKER_RAW_BYTES = 2999;
|
|
6
|
+
export const TRACKER_GZIP_BYTES = 1565;
|
|
7
|
+
export const TRACKER_HASH = "6246dc584683303a";
|
|
8
8
|
export const VITALS_SOURCE = "(()=>{const t=document.currentScript,e=t?.dataset.site,n=t?.dataset.endpoint||t?.src&&new URL(\"events\",t.src).href;if(!e||!n)return;const r=()=>crypto.randomUUID?.()||Math.random()+\"\";let s=t.dataset.visitor||\"\";try{s||=localStorage._rv||=r()}catch{}const o=Date.now();let a;try{a=sessionStorage._ri===s&&o-sessionStorage._rt<18e5&&sessionStorage._r||r(),sessionStorage._r=a,sessionStorage._ri=s,sessionStorage._rt=o}catch{a=r()}const i=s||a,c=location.pathname.slice(0,256),d={},h=[],l=(t,e,n)=>{try{const r=new PerformanceObserver(t=>e(t.getEntries()));r.observe({type:t,buffered:1,...n}),h.push({observer:r,handler:e})}catch{}},f=performance.getEntriesByType?.(\"navigation\")[0];f&&f.responseStart>0&&(d.TTFB=f.responseStart),l(\"paint\",t=>{for(const e of t)\"first-contentful-paint\"===e.name&&(d.FCP=e.startTime)}),l(\"largest-contentful-paint\",t=>{const e=t[t.length-1];e&&(d.LCP=e.startTime)});let m=0,u=0,v=0;l(\"layout-shift\",t=>{for(const e of t)e.hadRecentInput||(m&&e.startTime-v<1e3&&e.startTime-u<5e3?m+=e.value:(m=e.value,u=e.startTime),v=e.startTime,d.CLS=Math.max(d.CLS||0,1e3*m))});const g=[],p=new Set,S=t=>{for(const e of t)e.interactionId&&(p.add(e.interactionId),g.push(e.duration));if(!g.length)return;g.sort((t,e)=>e-t),g.length=Math.min(g.length,10);const e=performance.interactionCount||p.size;d.INP=g[Math.min(g.length-1,Math.floor(e/50))]};l(\"event\",S,{durationThreshold:40}),l(\"first-input\",S);let y=0;const b=()=>{if(y)return;for(const{observer:t,handler:e}of h)e(t.takeRecords()),t.disconnect();const t=Date.now(),r=Object.keys(d).map((e,n)=>({eventId:`${a}.${t.toString(36)}.v${n}`,sessionId:a,visitorId:i,type:\"vital\",name:e,value:Math.round(d[e]),path:c,timestamp:t,sequence:n}));if(!r.length)return;y=1;const s=new Blob([JSON.stringify({siteId:e,events:r,sentAt:t})]),o=navigator.sendBeacon?.bind(navigator);o&&o(n,s)||fetch(n,{method:\"POST\",body:s,keepalive:1}).catch(()=>{})};document.addEventListener(\"visibilitychange\",()=>{\"hidden\"===document.visibilityState&&b()}),addEventListener(\"pagehide\",b)})();";
|
|
9
9
|
export const VITALS_GZIP_BASE64 = "H4sIAAAAAAACA3VVbW/bNhD+K6lQCORKc/ayFINcJlj6AnjImqBOPwXBSosniatEauTJnSbpvw+i7MSJ22/SkXf33N1zDwmh4rxLrfF4gkLZtKnAIE8b58DgOnW6RgYCL7iSKD0g9xqBmUMLGFVbbbDv8YJ7l8axgW8nnz9dkQi2YNBHDEc75YWDbKkz8gL6/oWhDrBxZjlld2KEkrq2RsudNMpWnz+v3l1wQvv+T4nFzkjoqyhaloAnXuADhq32Gq3r+yhaoms73/eitKks12idzIH/5bZ9LxyhQyoxLbphymrFO4nAjf1GaAgqg7sUHrzX1jy6ayGEj2M7OzrBN4vf4CyOjw763hHKjsxCsu9E98dGFHaHVk7IA2QtfN9Llob6UFvDa4mFkRVwX+oUyJz9cvaaMiW6gRXi7p6VgiADZsZRj9XtGz6O6QZcZl0lTQrXGw9uC46gOAeCPAd8b9Bp8IRSunTcThdIh20NCbJNk2XgQCULxjk3A2UFrxtfkG530yWOFdKoElwCw0PrB5aJ+jHvQaLL9rat4YKTyMitzkN5Eb2b3y+zOM64A19b42GN0uH5PI6J4re3Hy7FsyPKShLVUhuMGIrzLrOOTEXDic1OkEaZdh5nqTUIBrOmnE23hRDAx1aG0B/e3gjgfox4qyugQ4hbSpfD95xDql0agXfISzA5FrPF/XKKd3UUL1CuEnPWiDnbivkyxG9tgzNf6OxH8IEXUn2CFAyuTN1g35Mqjg9Cz7ZvFnD61NS8OYPTi+qVAL6VZQMJqfafrHmCi20Pf5nib6/WIqxgJf8l4bfv52wBpz9VdKxiApePXKsDq9aAbC1+gF0bBCfTcbYrFcek5lIp8sxOWT5xCbhqXCACpUE78l1f9/KRc28dkpHiVJzDDEfX6coOtDZkb2GL+R4uPOHgQfK3thnFrOZe/wdLxVcfb0R+dxRqtmDBlpXWOgI/n80pvR/GCQbVi9iadXvot4UDX9hSJb/OJxZNBNTj9CK2nojQivkO2yaIYacz0u7LfGjk43LhwXLZ7KSg49ai/AqfILVOjWvLkCvtU2sMpEj2peOB6jEnrjd/Q4r8K7SeKMorWRMyyQXpQi0rlXx52cmBv+yQo12j0yYnp6/pwLcvOzN82WvXSiWS7bR4pRLNglJEW42yjNi4WAmwiX2TpNvGKKLu4J6yUcWSlKGuwKOs6gSZh38aMCkkZtgN3z0bfisWu5p8IN5laTfk7o/19UfuA0qdtaQb36yVSoBN71HimAeDv2OCA72nzIqd2ljHPRh1CTK15oJvtFHk4YgubRxbYpinfZ8BpgUxrKsAC6uS6OZ6fRuxjVVt4tlXgFqWegvJYqA8qB4JAx3osHx4ZKVS70c8V9ojGHAkGju30aXGNi2kySFiwSsqtFJgRnV6cH68ukaJEMcbMurTccxa5lBoBRHb0IESuvwfweV+3/MHAAA=";
|
|
10
10
|
export const VITALS_RAW_BYTES = 2035;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generated.js","sourceRoot":"","sources":["../../src/tracker/generated.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC;AACtC,MAAM,CAAC,MAAM,cAAc,GAAG,
|
|
1
|
+
{"version":3,"file":"generated.js","sourceRoot":"","sources":["../../src/tracker/generated.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC;AACtC,MAAM,CAAC,MAAM,cAAc,GAAG,6hGAA6hG,CAAC;AAC5jG,MAAM,CAAC,MAAM,mBAAmB,GAAG,0iEAA0iE,CAAC;AAC9kE,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AACtC,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC;AACvC,MAAM,CAAC,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAC/C,MAAM,CAAC,MAAM,aAAa,GAAG,mhEAAmhE,CAAC;AACjjE,MAAM,CAAC,MAAM,kBAAkB,GAAG,07CAA07C,CAAC;AAC79C,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AACrC,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AACtC,MAAM,CAAC,MAAM,WAAW,GAAG,kBAAkB,CAAC"}
|
|
@@ -20,8 +20,9 @@ interface RastroEvent {
|
|
|
20
20
|
interface RastroContext {
|
|
21
21
|
sessionId: string;
|
|
22
22
|
visitorId: string;
|
|
23
|
+
identified: boolean;
|
|
23
24
|
}
|
|
24
|
-
type RastroCommand = (command: "event" | "context", value?: string, properties?: RastroProperties) => RastroContext | void;
|
|
25
|
+
type RastroCommand = (command: "event" | "context" | "identify" | "reset", value?: string, properties?: RastroProperties) => RastroContext | void;
|
|
25
26
|
interface RastroWindow extends Window {
|
|
26
27
|
rastro?: RastroCommand;
|
|
27
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracker.d.ts","sourceRoot":"","sources":["../../src/tracker/tracker.ts"],"names":[],"mappings":"AAAA,KAAK,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AACvD,KAAK,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AACvD,KAAK,eAAe,GAChB,UAAU,GACV,OAAO,GACP,QAAQ,GACR,YAAY,GACZ,WAAW,GACX,UAAU,GACV,OAAO,CAAC;AAEZ,UAAU,WAAW;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,eAAe,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE,M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EACnD,KAAK,CAAC,EAAE,MAAM,EACd,UAAU,CAAC,EAAE,gBAAgB,KAC1B,aAAa,GAAG,IAAI,CAAC;AAE1B,UAAU,YAAa,SAAQ,MAAM;IACnC,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB"}
|
package/dist/tracker/tracker.js
CHANGED
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
// localStorage), and, when storage is blocked, the per-tab session id —
|
|
29
29
|
// which the server then counts through its salted daily hash.
|
|
30
30
|
let identity = script.dataset.visitor || "";
|
|
31
|
+
let identified = Boolean(identity);
|
|
31
32
|
try {
|
|
32
33
|
identity ||= localStorage._rv ||= createId();
|
|
33
34
|
}
|
|
@@ -62,7 +63,7 @@
|
|
|
62
63
|
// Scheme and host, never the path or query. Not `new URL().origin`: that is
|
|
63
64
|
// the literal "null" for an app link, which would lose the package that
|
|
64
65
|
// names the app — `android-app://com.instagram.android` survives this.
|
|
65
|
-
|
|
66
|
+
let referrer = document.referrer.split("/", 3).join("/") || undefined;
|
|
66
67
|
const flush = (beacon) => {
|
|
67
68
|
const events = queue.splice(0, 50);
|
|
68
69
|
if (!events.length)
|
|
@@ -133,7 +134,45 @@
|
|
|
133
134
|
};
|
|
134
135
|
window.rastro = (command, value, properties) => {
|
|
135
136
|
if (command == "context") {
|
|
136
|
-
return {
|
|
137
|
+
return {
|
|
138
|
+
sessionId,
|
|
139
|
+
visitorId: identity || sessionId,
|
|
140
|
+
identified,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
if (command == "identify" || command == "reset") {
|
|
144
|
+
if (command == "identify" &&
|
|
145
|
+
(!value ||
|
|
146
|
+
value.length > 128 ||
|
|
147
|
+
!/^[A-Za-z0-9][A-Za-z0-9_.:-]*$/.test(value)))
|
|
148
|
+
return;
|
|
149
|
+
if (command == "identify" && value == identity)
|
|
150
|
+
return;
|
|
151
|
+
flush();
|
|
152
|
+
const clearAttribution = command == "reset" || identified;
|
|
153
|
+
identified = command == "identify";
|
|
154
|
+
identity = command == "identify" ? value : createId();
|
|
155
|
+
script.dataset.visitor = command == "identify" ? identity : "";
|
|
156
|
+
if (clearAttribution) {
|
|
157
|
+
// A shared browser's next person starts with a fresh visitor and campaign.
|
|
158
|
+
affiliate = undefined;
|
|
159
|
+
utm = undefined;
|
|
160
|
+
referrer = undefined;
|
|
161
|
+
clid.length = 0;
|
|
162
|
+
try {
|
|
163
|
+
if (command == "reset")
|
|
164
|
+
localStorage._rv = identity;
|
|
165
|
+
store._a = "";
|
|
166
|
+
store._u = "";
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
/* Storage can be blocked. */
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
last = 0;
|
|
173
|
+
sequence = 0;
|
|
174
|
+
lastPath = "";
|
|
175
|
+
pageview();
|
|
137
176
|
}
|
|
138
177
|
if (command == "event") {
|
|
139
178
|
emit("custom", `${value || "event"}`.slice(0, 80), properties && JSON.stringify(properties).length > 20_000
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracker.js","sourceRoot":"","sources":["../../src/tracker/tracker.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"tracker.js","sourceRoot":"","sources":["../../src/tracker/tracker.ts"],"names":[],"mappings":";AA4CA,CAAC,GAAG,EAAE;IACJ,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAyC,CAAC;IAClE,MAAM,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC;IACpC,MAAM,QAAQ,GACZ,MAAM,EAAE,OAAO,CAAC,QAAQ;QACxB,CAAC,MAAM,EAAE,GAAG,IAAI,IAAI,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;IACtD,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ;QAAE,OAAO;IAEjC,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,IAAI,IAAI,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Q,CAAC,MAAM;YAAE,IAAI,EAAE,CAAC;;YACvB,IAAI,EAAE,CAAC;IACd,CAAC,CAAC;IACF,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACnC,0EAA0E;IAC1E,0EAA0E;IAC1E,yCAAyC;IACzC,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IACrC,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;IACtD,UAAU,GAAG,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACvC,QAAQ,EAAE,CAAC;IACX,sEAAsE;IACtE,MAAM,EAAE,CAAC;AACX,CAAC,CAAC,EAAE,CAAC"}
|
package/dist/tracker.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{const t=document.currentScript,e=t?.dataset.site,i=t?.dataset.endpoint||t?.src&&new URL("events",t.src).href;if(!e||!i)return;const n=()=>crypto.randomUUID?.()||Math.random()+"",
|
|
1
|
+
(()=>{const t=document.currentScript,e=t?.dataset.site,i=t?.dataset.endpoint||t?.src&&new URL("events",t.src).href;if(!e||!i)return;const n=()=>crypto.randomUUID?.()||Math.random()+"",r=new URLSearchParams(location.search),s=r.get("ref")?.slice(0,64);let o;for(const t of["source","medium","campaign","term","content"]){const e=r.get("utm_"+t)?.slice(0,64);e&&((o??={})["utm_"+t]=e)}const a="gclid gbraid wbraid msclkid ttclid twclid li_fat_id ScCid rdt_cid dclid epik srsltid mc_cid mc_eid _hsenc igsh igshid fbclid".split(" ").filter(t=>r.has(t)).slice(0,8);let c,d,l,h,f=t.dataset.visitor||"",p=Boolean(f);try{f||=localStorage._rv||=n()}catch{}try{d=sessionStorage,l=d._r,c=d._ri==f&&d._rt,h=s||d._a,h&&(d._a=h),o||=d._u&&JSON.parse(d._u),o&&(d._u=JSON.stringify(o))}catch{h=s}let v,g=0;const u=[];let m=document.referrer.split("/",3).join("/")||void 0;const _=t=>{const n=u.splice(0,50);if(!n.length)return;const r=()=>new Blob([JSON.stringify({siteId:e,events:n,sentAt:Date.now()})]);let s=r();for(;s.size>64e3&&n.length>1;)u.unshift(n.pop()),s=r();t&&navigator.sendBeacon(i,s)||fetch(i,{method:"POST",body:s,keepalive:1}).catch(()=>{}),u.length&&_(t)},y=(t,e,i)=>{const r=Date.now(),s=r-c;c=r,s<18e5||(l=n(),"pageview"!=t&&(S="",w()));try{d._r=l,d._ri=f,d._rt=r}catch{}u.push({eventId:`${l}.${r.toString(36)}.${g}`,sessionId:l,visitorId:f||l,type:t,name:e,path:location.pathname.slice(0,256),referrer:m,timestamp:r,sequence:g++,affiliateSlug:h,...i}),clearTimeout(v),v=setTimeout(_,1200)};let S;const w=()=>{const t=location.pathname;t!=S&&(S=t,y("pageview",void 0,{properties:o,clid:a.length?a:void 0}))};window.rastro=(e,i,r)=>{if("context"==e)return{sessionId:l,visitorId:f||l,identified:p};if("identify"==e||"reset"==e){if("identify"==e&&(!i||i.length>128||!/^[A-Za-z0-9][A-Za-z0-9_.:-]*$/.test(i)))return;if("identify"==e&&i==f)return;_();const r="reset"==e||p;if(p="identify"==e,f="identify"==e?i:n(),t.dataset.visitor="identify"==e?f:"",r){h=void 0,o=void 0,m=void 0,a.length=0;try{"reset"==e&&(localStorage._rv=f),d._a="",d._u=""}catch{}}c=0,g=0,S="",w()}"event"==e&&y("custom",`${i||"event"}`.slice(0,80),r&&JSON.stringify(r).length>2e4?void 0:{properties:r})},document.addEventListener("click",t=>{const e=t.target?.closest("a,button,[data-rastro-event]");if(!e)return;const i=e.dataset.rastroEvent,n=e.href,r=n&&new URL(n),s=/^https?:$/.test(r?.protocol),o=s&&r.origin!=location.origin;y(i?"custom":o?"outbound":"click",i,{target:(e.dataset.rastroLabel||e.innerText||e.tagName).slice(0,64),href:s?((o?r.origin:"")+r.pathname).slice(0,256):void 0})},1);for(const t of["pushState","replaceState"]){const e=history[t];history[t]=(...t)=>{e.apply(history,t),w()}}addEventListener("popstate",w);let b=0;const I=()=>{y("heartbeat"),_()},L=()=>{b&&(clearInterval(b),b=0,y("leave"),_(1))},E=()=>{document.hidden?L():b||(I(),b=setInterval(I,2e4))};addEventListener("pagehide",L),addEventListener("pageshow",E),document.addEventListener("visibilitychange",E),b=setInterval(I,2e4),w(),E()})();
|
package/docs/federation.md
CHANGED
|
@@ -291,6 +291,8 @@ export const {
|
|
|
291
291
|
overview,
|
|
292
292
|
liveVisitors,
|
|
293
293
|
getSession,
|
|
294
|
+
getVisitorProfile,
|
|
295
|
+
listPeople,
|
|
294
296
|
revenueSummary,
|
|
295
297
|
listSessions,
|
|
296
298
|
sessionJourney,
|
|
@@ -405,3 +407,25 @@ plane write. The customer operator provisions the authoritative grant through an
|
|
|
405
407
|
internal or host-admin mutation. For immediate revocation, revoke that local
|
|
406
408
|
grant before revoking the central connection; otherwise an already-issued token
|
|
407
409
|
remains valid until its ten-minute expiry.
|
|
410
|
+
|
|
411
|
+
## Identified visitor profiles
|
|
412
|
+
|
|
413
|
+
The optional `visitorProfiles` capability adds
|
|
414
|
+
`getVisitorProfile({siteId, visitorId})`. It resolves pre-login aliases and
|
|
415
|
+
returns `{visitorId, name?, email?, attributes?, identifiedAt, updatedAt}` or
|
|
416
|
+
null. `liveVisitors`, `listSessions` and `getSession` include an optional
|
|
417
|
+
`profile` for identified people. These attributes require `analytics:read`;
|
|
418
|
+
public live rows remove `profile`, and public tokens cannot call
|
|
419
|
+
`getVisitorProfile`. Older hosts work without this capability. Profile writes
|
|
420
|
+
stay in the product backend, outside federation. See
|
|
421
|
+
[identity integration](identity.md) for Better Auth, custom auth and external
|
|
422
|
+
servers.
|
|
423
|
+
|
|
424
|
+
The optional `people` capability adds
|
|
425
|
+
`listPeople({siteId, filter?, paginationOpts})`: a directory of current
|
|
426
|
+
profiles, independent of the report period. It supports a name/email/ID prefix
|
|
427
|
+
or an exact typed attribute value, with up to 50 rows per page. Cursors belong
|
|
428
|
+
to one site and filter. This query requires `analytics:read`; public tokens
|
|
429
|
+
cannot list people. Profile writes and the bounded `backfillVisitorProfiles`
|
|
430
|
+
upgrade remain host-authorized operations outside federation. See
|
|
431
|
+
[the directory contract and upgrade steps](identity.md#project-defined-attributes-and-the-people-directory).
|
package/docs/identity.md
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
# Identify people with any authentication
|
|
2
|
+
|
|
3
|
+
Available in `@iann29/rastro@0.6.0` and later. Upgrade and deploy the host
|
|
4
|
+
before using these APIs in the browser or enabling the directory in federation.
|
|
5
|
+
|
|
6
|
+
Rastro connects a person's name and email to their visits, actions and
|
|
7
|
+
conversions. The product's backend resolves the signed-in user; Rastro does not
|
|
8
|
+
require Better Auth or a particular auth provider. Profiles and events stay in
|
|
9
|
+
the product's Rastro component.
|
|
10
|
+
|
|
11
|
+
## Shared contract
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
const profile = await analytics.identifyVisitor(ctx, {
|
|
15
|
+
siteId,
|
|
16
|
+
visitorId: user.analyticsId,
|
|
17
|
+
previousVisitorId, // optional: the browser's pre-login visitor ID
|
|
18
|
+
name: user.name,
|
|
19
|
+
email: user.email,
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
This is a trusted server call. Resolve `user` and authorize `siteId` on the
|
|
24
|
+
server. The result is `{ visitorId, name?, email?, identifiedAt, updatedAt }`.
|
|
25
|
+
Use the returned `visitorId` in the tracker. A repeated call is idempotent;
|
|
26
|
+
omitted attributes keep their values, and `name: null` or `email: null` removes
|
|
27
|
+
that attribute. Names are bounded to 160 characters and emails to 320.
|
|
28
|
+
|
|
29
|
+
Choose one stable ID per product user. Existing tracker IDs can be reused
|
|
30
|
+
unchanged. `visitorIdForUser(userId)` converts arbitrary provider IDs into a
|
|
31
|
+
stable tracker-compatible ID. Use your product's user primary key when auth
|
|
32
|
+
providers can change. With raw Convex JWT identities, use the complete
|
|
33
|
+
`tokenIdentifier`, which includes the issuer, rather than `subject` alone. Do
|
|
34
|
+
not use email as the identity key: it can change or be shared.
|
|
35
|
+
|
|
36
|
+
## Project-defined attributes and the people directory
|
|
37
|
+
|
|
38
|
+
No user table, workspace model, auth provider or business field is required.
|
|
39
|
+
Keep your product's existing user key and map its current attributes on the
|
|
40
|
+
server, in the same resolver used above:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
return {
|
|
44
|
+
siteId: authorizedSiteId,
|
|
45
|
+
visitorId: user.analyticsId,
|
|
46
|
+
name: user.name,
|
|
47
|
+
email: user.email,
|
|
48
|
+
attributes: { language: "pt-BR", level: 3, enrolled: true },
|
|
49
|
+
};
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
An education app may send `level` and `enrolled`; a marketplace may send
|
|
53
|
+
`seller` and `orders`; a SaaS may send `plan` and `seats`. These are examples,
|
|
54
|
+
not built-in columns. Attribute values are strings, finite numbers or booleans.
|
|
55
|
+
Dates can be ISO strings. Attributes describe current state; put historical
|
|
56
|
+
context on the event's existing `properties` instead. Nested objects and arrays
|
|
57
|
+
are not supported in this first version.
|
|
58
|
+
|
|
59
|
+
Updates merge keys. Omitted keys are preserved; a null value deletes one key:
|
|
60
|
+
`attributes: { level: 4, enrolled: null }`. Empty strings, zero and false are
|
|
61
|
+
valid values. Each profile allows 32 keys, keys of up to 64 ASCII characters
|
|
62
|
+
starting with a letter (`A-Z`, `a-z`, digits, `.`, `_`, `-`), strings up to 512
|
|
63
|
+
characters, and at most 4096 UTF-8 bytes for the complete attribute map. Invalid
|
|
64
|
+
updates fail atomically. These limits also bound read and index costs.
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
const page = await analytics.listPeople(ctx, {
|
|
68
|
+
siteId: authorizedSiteId,
|
|
69
|
+
filter: { field: "attribute", key: "level", value: 3 },
|
|
70
|
+
paginationOpts: { cursor: null, numItems: 25 },
|
|
71
|
+
});
|
|
72
|
+
// page: { page: Person[], isDone, continueCursor }
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The optional filter is either one exact typed attribute match, or a prefix:
|
|
76
|
+
`{ field: "name" | "email" | "visitorId", prefix: "Maria" }`. Names and emails
|
|
77
|
+
use case-insensitive Unicode-normalized prefixes; IDs preserve case. Text `"3"`
|
|
78
|
+
differs from number `3`. Each page uses the site's database indexes. Pages allow
|
|
79
|
+
1–50 people; pass `continueCursor` back as the next cursor. Cursors are scoped
|
|
80
|
+
to the site and filter. Clear the cursor when either changes. The directory
|
|
81
|
+
includes all identified profiles, independently of the dashboard's event date
|
|
82
|
+
range.
|
|
83
|
+
|
|
84
|
+
Re-export `listPeople` from `exposeFederatedAnalyticsApi` alongside
|
|
85
|
+
`getVisitorProfile`. The optional `people` capability enables the **Pessoas**
|
|
86
|
+
dashboard view. Existing hosts stay connected without it. People and attributes
|
|
87
|
+
are available only to authorized readers of that site; public links cannot list
|
|
88
|
+
them. The local `exposeAnalyticsApi` authorizer receives `visitor.list`.
|
|
89
|
+
|
|
90
|
+
For profiles created by the earlier unreleased identity implementation, call
|
|
91
|
+
`analytics.backfillVisitorProfiles(ctx, { siteId })` from a site-admin mutation
|
|
92
|
+
or action after deployment. Each call updates at most 64 profiles and returns
|
|
93
|
+
`{ updated, isDone }`; schedule another bounded call if `isDone` is false. The
|
|
94
|
+
local API wrapper uses the `visitor.index` authorization operation; it is not
|
|
95
|
+
exposed through federation. The example `analytics.ts` exports an
|
|
96
|
+
owner-authorized wrapper. Backfill preserves identity timestamps and is safe to
|
|
97
|
+
retry. Until it finishes, name/email search refuses to return partial results;
|
|
98
|
+
unfiltered and ID listings remain available. Fresh installations need no
|
|
99
|
+
backfill.
|
|
100
|
+
|
|
101
|
+
## Funnels across identification
|
|
102
|
+
|
|
103
|
+
Funnel progress resolves the canonical person and their pre-login aliases. Steps
|
|
104
|
+
recorded before login continue after login, including queued events under an
|
|
105
|
+
already-linked browser ID. Repeated identification and another tab do not start
|
|
106
|
+
another attempt inside the active conversion window. The original events and
|
|
107
|
+
their IDs stay intact. When multiple aliases already have progress, the furthest
|
|
108
|
+
attempt inside its conversion window takes precedence; expired attempts restart
|
|
109
|
+
only on the first step, as before.
|
|
110
|
+
|
|
111
|
+
Linking does not retroactively recompute already-counted funnel attempts or
|
|
112
|
+
other historical aggregates. Events must still arrive in step order; this change
|
|
113
|
+
does not add late-event replay.
|
|
114
|
+
|
|
115
|
+
## Convex with Better Auth
|
|
116
|
+
|
|
117
|
+
In the product's `convex/analyticsIdentity.ts`, use its existing auth component:
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import { Rastro } from "@iann29/rastro";
|
|
121
|
+
import { components } from "./_generated/api";
|
|
122
|
+
import type { MutationCtx } from "./_generated/server";
|
|
123
|
+
import { authComponent } from "./auth";
|
|
124
|
+
|
|
125
|
+
const analytics = new Rastro(components.rastroAnalytics);
|
|
126
|
+
|
|
127
|
+
export const identifyVisitor = analytics.identifyVisitorMutation({
|
|
128
|
+
resolveUser: async (ctx: MutationCtx) => {
|
|
129
|
+
const user = await authComponent.safeGetAuthUser(ctx);
|
|
130
|
+
if (!user) return null;
|
|
131
|
+
return {
|
|
132
|
+
siteId: "YOUR_PRODUCT_SITE_ID",
|
|
133
|
+
visitorId: user._id,
|
|
134
|
+
name: user.name,
|
|
135
|
+
email: user.email,
|
|
136
|
+
};
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
`safeGetAuthUser` checks the Better Auth session. Rastro adds no Better Auth
|
|
142
|
+
runtime dependency. With multiple workspaces, resolve the site from the user's
|
|
143
|
+
authorized workspace in this callback instead of accepting a site from the
|
|
144
|
+
browser.
|
|
145
|
+
|
|
146
|
+
## Convex with custom auth or another JWT provider
|
|
147
|
+
|
|
148
|
+
Use the same mutation with your own user lookup:
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
import { Rastro, visitorIdForUser } from "@iann29/rastro";
|
|
152
|
+
import { components } from "./_generated/api";
|
|
153
|
+
import type { MutationCtx } from "./_generated/server";
|
|
154
|
+
|
|
155
|
+
const analytics = new Rastro(components.rastroAnalytics);
|
|
156
|
+
|
|
157
|
+
export const identifyVisitor = analytics.identifyVisitorMutation({
|
|
158
|
+
resolveUser: async (ctx: MutationCtx) => {
|
|
159
|
+
const identity = await ctx.auth.getUserIdentity();
|
|
160
|
+
if (!identity) return null;
|
|
161
|
+
return {
|
|
162
|
+
siteId: "YOUR_PRODUCT_SITE_ID",
|
|
163
|
+
visitorId: await visitorIdForUser(identity.tokenIdentifier),
|
|
164
|
+
name: identity.name,
|
|
165
|
+
email: identity.email,
|
|
166
|
+
};
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
For custom database-backed sessions, replace the resolver body with the
|
|
172
|
+
product's existing authenticated-user lookup. Returning `null` refuses the
|
|
173
|
+
request. The public mutation accepts only `previousVisitorId`; user ID, name,
|
|
174
|
+
email and site scope come from the resolver.
|
|
175
|
+
|
|
176
|
+
## React and browser lifecycle
|
|
177
|
+
|
|
178
|
+
After the login has established the backend session:
|
|
179
|
+
|
|
180
|
+
```tsx
|
|
181
|
+
const identifyVisitor = useMutation(api.analyticsIdentity.identifyVisitor);
|
|
182
|
+
const rastro = useRastro();
|
|
183
|
+
|
|
184
|
+
async function identifyAfterLogin() {
|
|
185
|
+
const before = rastro.context();
|
|
186
|
+
const profile = await identifyVisitor({
|
|
187
|
+
previousVisitorId:
|
|
188
|
+
before && !before.identified ? before.visitorId : undefined,
|
|
189
|
+
});
|
|
190
|
+
rastro.identify(profile.visitorId);
|
|
191
|
+
// Keep this ID in your auth state and pass it to RastroScript on later loads.
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
async function signOut() {
|
|
195
|
+
await yourAuth.signOut();
|
|
196
|
+
rastro.reset();
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Import `useRastro` and `RastroScript` from `@iann29/rastro/react`; use your
|
|
201
|
+
app's existing `useMutation` from `convex/react`. Call identification again
|
|
202
|
+
after restoring a logged-in session. Discard a pending identification response
|
|
203
|
+
if the auth session has changed before it returns.
|
|
204
|
+
|
|
205
|
+
`<RastroScript visitorId={analyticsVisitorId} ... />` also synchronizes ID
|
|
206
|
+
changes and logout (`visitorId` becoming undefined), including a delayed script
|
|
207
|
+
load. Mount one tracker per page. Prefer one lifecycle owner: either the prop or
|
|
208
|
+
the explicit commands, so a logout does not reset twice.
|
|
209
|
+
|
|
210
|
+
For another frontend framework, use the equivalent commands:
|
|
211
|
+
|
|
212
|
+
```js
|
|
213
|
+
const before = window.rastro?.("context");
|
|
214
|
+
// Authenticate with your product backend, then obtain its Rastro profile.
|
|
215
|
+
window.rastro?.("identify", profile.visitorId);
|
|
216
|
+
// After logout:
|
|
217
|
+
window.rastro?.("reset");
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
`context` returns `{ visitorId, sessionId, identified }`. The browser commands
|
|
221
|
+
change the tracker ID, not the stored profile. Identification flushes queued
|
|
222
|
+
events under their original ID and opens a new session without a page reload.
|
|
223
|
+
The first login retains acquisition context. Logout creates a new browser
|
|
224
|
+
visitor; logout and direct account switches clear the previous person's
|
|
225
|
+
campaign/referral context. `identify` and `reset` from `useRastro` return false
|
|
226
|
+
when the deferred tracker is not ready; the `visitorId` prop handles that case.
|
|
227
|
+
|
|
228
|
+
## Other backends: authenticated HTTP
|
|
229
|
+
|
|
230
|
+
Mount an HTTP action on the Convex deployment that owns the Rastro component.
|
|
231
|
+
The external backend can be Node, Python, Go, Rails, or any HTTP client. The
|
|
232
|
+
analytics storage still runs on Convex or Synapse.
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
// convex/http.ts — merge into the product's existing router.
|
|
236
|
+
http.route({
|
|
237
|
+
path: "/analytics/identify",
|
|
238
|
+
method: "POST",
|
|
239
|
+
handler: analytics.identifyVisitorHttpAction({
|
|
240
|
+
authorize: async (_ctx, request, siteId) => {
|
|
241
|
+
const key = env.RASTRO_IDENTITY_SERVER_KEY;
|
|
242
|
+
if (
|
|
243
|
+
!key ||
|
|
244
|
+
request.headers.get("authorization") !== `Bearer ${key}` ||
|
|
245
|
+
siteId !== env.RASTRO_IDENTITY_SITE_ID
|
|
246
|
+
) {
|
|
247
|
+
throw new Error("Not authorized");
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
}),
|
|
251
|
+
});
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Declare the two optional string env vars in `convex/convex.config.ts`. The
|
|
255
|
+
complete router and declarations are in `example/convex/`. Provision a random
|
|
256
|
+
server key and share it only with the authorized backend. If multiple backends
|
|
257
|
+
or sites are served, the authorizer must resolve each credential's site scope.
|
|
258
|
+
Do not expose the key in `VITE_`, `NEXT_PUBLIC_`, or browser code.
|
|
259
|
+
|
|
260
|
+
The external backend first authenticates its own user, then sends:
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
const response = await fetch(process.env.RASTRO_IDENTITY_URL!, {
|
|
264
|
+
method: "POST",
|
|
265
|
+
headers: {
|
|
266
|
+
"Content-Type": "application/json",
|
|
267
|
+
Authorization: `Bearer ${process.env.RASTRO_IDENTITY_SERVER_KEY}`,
|
|
268
|
+
},
|
|
269
|
+
body: JSON.stringify({
|
|
270
|
+
siteId: process.env.RASTRO_IDENTITY_SITE_ID,
|
|
271
|
+
visitorId: user.analyticsId,
|
|
272
|
+
previousVisitorId,
|
|
273
|
+
name: user.name,
|
|
274
|
+
email: user.email,
|
|
275
|
+
}),
|
|
276
|
+
});
|
|
277
|
+
if (!response.ok) throw new Error(`Rastro identify failed: ${response.status}`);
|
|
278
|
+
const profile = await response.json();
|
|
279
|
+
// Return profile.visitorId to the authenticated browser.
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
The endpoint accepts at most 8 KiB of JSON, validates the same fields as the SDK
|
|
283
|
+
and sends `Cache-Control: no-store`. Statuses: 200 success, 400 invalid input,
|
|
284
|
+
403 denied credential/site, 404 unknown site, 409 conflicting identity, 413
|
|
285
|
+
oversized body, 415 wrong content type, 429 alias limit, 500 server failure.
|
|
286
|
+
|
|
287
|
+
## Dashboard and existing history
|
|
288
|
+
|
|
289
|
+
Re-export `getVisitorProfile` from `exposeFederatedAnalyticsApi` in the host's
|
|
290
|
+
`convex/rastroFederation.ts`. It is advertised by the optional `visitorProfiles`
|
|
291
|
+
capability. Private live/session reports include a profile when one exists; old
|
|
292
|
+
hosts and unidentified visitors continue to work without it.
|
|
293
|
+
|
|
294
|
+
The dashboard shows names/emails in **Ao vivo** and **Jornadas**, searches those
|
|
295
|
+
attributes within the loaded session records, and opens the person's history for
|
|
296
|
+
the selected site and period. Existing events retain their original ID; the
|
|
297
|
+
identity link resolves them at read time. A profile is keyed by site and
|
|
298
|
+
visitor, with no email-based merging. An identified person cannot be linked into
|
|
299
|
+
another person. Each identity supports the existing limit of ten pre-login
|
|
300
|
+
aliases. Profile attributes persist independently of event retention and can be
|
|
301
|
+
cleared with explicit null updates.
|
|
302
|
+
|
|
303
|
+
Profile reads require a reader's authorization for that site. Public dashboard
|
|
304
|
+
links omit profiles and cannot call `getVisitorProfile`. The tracking endpoint
|
|
305
|
+
continues to accept browser telemetry; an identity label does not turn
|
|
306
|
+
browser-sent events into authenticated business transactions. Record revenue
|
|
307
|
+
through the existing trusted `trackConversion` server API.
|