@generazioneai/analytics-web 0.0.0-stage → 0.3.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/CHANGELOG.md +29 -0
- package/LICENSE +201 -0
- package/README.md +191 -2
- package/bin/analytics-web.cjs +76 -0
- package/dist/autocapture.d.ts +57 -0
- package/dist/browser.d.ts +3 -0
- package/dist/cmp.d.ts +7 -0
- package/dist/cmp.js +1 -0
- package/dist/consent/cookiebot.d.ts +11 -0
- package/dist/consent/gcm.d.ts +10 -0
- package/dist/consent/index.d.ts +6 -0
- package/dist/consent/iubenda.d.ts +20 -0
- package/dist/consent/onetrust.d.ts +12 -0
- package/dist/consent/tcf.d.ts +43 -0
- package/dist/consent/test-env.d.ts +13 -0
- package/dist/consent/types.d.ts +60 -0
- package/dist/core.d.ts +165 -0
- package/dist/errors.d.ts +60 -0
- package/dist/extensions.d.ts +1 -0
- package/dist/flags.d.ts +96 -0
- package/dist/frustration.d.ts +62 -0
- package/dist/index.cjs +1380 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +1359 -0
- package/dist/plugins.d.ts +16 -0
- package/dist/s.js +1 -0
- package/dist/scrub.d.ts +7 -0
- package/dist/snippet.d.ts +1 -0
- package/dist/vitals.d.ts +28 -0
- package/dist/x.js +3 -0
- package/package.json +45 -4
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type AutocaptureOptions, type EnhancedOptions } from './autocapture';
|
|
2
|
+
import { type ErrorsOptions, type Tracker } from './errors';
|
|
3
|
+
import { type VitalsOptions } from './vitals';
|
|
4
|
+
/** Le estensioni dell'SDK web (W2, W3): tutte spente di serie, si accendono una per una. */
|
|
5
|
+
export interface PluginOptions {
|
|
6
|
+
errors?: boolean | ErrorsOptions;
|
|
7
|
+
webVitals?: boolean | VitalsOptions;
|
|
8
|
+
enhanced?: boolean | EnhancedOptions;
|
|
9
|
+
autocapture?: boolean | AutocaptureOptions;
|
|
10
|
+
}
|
|
11
|
+
export interface Plugins {
|
|
12
|
+
/** Manda un errore gestito (`$exception` con `handled: true`); senza `errors` acceso non fa niente. */
|
|
13
|
+
captureException(err: unknown): void;
|
|
14
|
+
uninstall(): void;
|
|
15
|
+
}
|
|
16
|
+
export declare function installPlugins(client: Tracker, win: Window, opts: PluginOptions): Plugins;
|
package/dist/s.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(()=>{var v=["analytics_storage","ad_storage","ad_user_data","ad_personalization"];function m(o,t){let e={};for(let n of v){let i=String(o?.[n]).toLowerCase();i==="granted"||i==="denied"?e[n]=i:t&&(e[n]=t)}return e}var x={name:"auralytics-web",version:"0.3.0"},d="_au_id",y="_au_s",g="_au_q",w=395,A=30*6e4,p=500,I=7*864e5,_=20,T=/^\$?[a-z][a-z0-9_]{0,39}$/;function k(o){let t="";for(let e of o)t+=(e<16?"0":"")+e.toString(16);return t}function b(o,t){let e=t.slice(0,16),n=o;for(let s=5;s>=0;s--)e[s]=n%256,n=Math.floor(n/256);e[6]=e[6]&15|112,e[8]=e[8]&63|128;let i=k(e);return`${i.slice(0,8)}-${i.slice(8,12)}-${i.slice(12,16)}-${i.slice(16,20)}-${i.slice(20,32)}`}var h=class{constructor(t,e){this.opts=t;this.env=e;this.endpoint=(t.endpoint??"https://api.auralytics.it").replace(/\/+$/,"")+"/c/v1/batch",this.disabled=(t.respectDnt??!0)&&e.dnt(),this.cookieAge=Math.min(w,Math.max(1,Math.round(Number(t.cookieMaxAgeDays))||w))*86400,this.cs=m({...t.consentDefaults,analytics_storage:t.consent!=="unknown"&&t.consent||t.consentDefaults?.analytics_storage},"denied"),this.explicitDenial=t.consent==="denied",this.identityToken(t.identityToken??null),this.granted&&this.loadOffline(),e.onHide(()=>void this.flush(!0)),e.setInterval(()=>void this.flush(!1),5e3),(t.autoPageviews??!0)&&(this.page(),e.onNavigate(()=>this.page()));for(let n of[].concat(t.cmp??[]))try{this.unsubs.push(n.subscribe(i=>this.consentUpdate(i)))}catch{}}wt="";idt="";off=!1;closing=!1;cs;explicitDenial=!1;cookieAge;unsubs=[];consentListeners=new Set;queue=[];userId="";sending=!1;retryAt=0;failures=0;lastUrl="";endpoint;disabled;get granted(){return this.cs.analytics_storage==="granted"}get none(){return!this.granted&&this.opts.withoutConsent==="none"}get consentValue(){return this.granted?"granted":this.explicitDenial?"denied":"unknown"}onConsentChange(t){return this.consentListeners.add(t),()=>this.consentListeners.delete(t)}get distinctIdValue(){if(!this.granted)return null;let t=this.env.getCookie(d);return t&&/^[A-Za-z0-9._:-]{8,64}$/.test(t)?t:null}get userIdValue(){return this.granted&&this.userId?this.userId:null}bucketingId(){return!this.granted||this.disabled||this.off?null:this.userId||this.deviceId()}get collectorEndpoint(){return this.endpoint.replace(/\/c\/v1\/batch$/,"")}consentState(){return{...this.cs,mode:this.granted?"full":this.none?"none":"cookieless"}}consent(t){this.applyConsent({analytics_storage:t==="granted"?"granted":"denied"},t==="denied")}consentUpdate(t){let e=m(t);this.applyConsent(e,e.analytics_storage==="denied")}applyConsent(t,e){if(this.off)return;let n=this.granted,i=!1;for(let s of v){let r=t[s];r&&r!==this.cs[s]&&(this.cs[s]=r,i=!0)}if(t.analytics_storage&&(this.explicitDenial=e),this.granted)n||this.deviceId();else{this.env.setCookie(d,"",0);try{let s=this.env.storage();s?.removeItem(y),s?.removeItem(g)}catch{}this.userId="",this.none&&(this.queue=[])}if(i&&this.track("$consent",{state:this.cs.analytics_storage,...this.cs}),i||t.analytics_storage){let s=this.consentValue;for(let r of[...this.consentListeners])try{r(s)}catch{}}this.granted&&!n&&this.opts.withoutConsent==="none"&&(this.opts.autoPageviews??!0)&&(this.lastUrl="",this.page())}identify(t){!this.granted||!t||t.includes("@")||t.length>128||(this.userId=t,this.track("$identify"))}identityToken(t){this.idt=t&&t.startsWith("it1.")&&t.length<=1024?t:""}workforceTicket(t){this.wt=t&&t.startsWith("wt1.")&&t.length<=512?t:""}reset(){this.userId="",this.wt="",this.idt="",this.granted&&(this.env.setCookie(d,"",0),this.deviceId())}page(t){let e=this.env.location().href;e===this.lastUrl&&!t||(this.lastUrl=e,this.clean(e)!==null&&this.track("page_view",t,{url:e,title:this.opts.pageTitle===!1?"":this.env.title(),referrer:this.env.referrer()}))}shutdown(){this.closing=!0;for(let t of this.unsubs.splice(0))try{t()}catch{}this.flush(!0).then(()=>this.off=!0)}clean(t){let e=this.opts.sanitizeUrl;return e&&t?e(t):t}track(t,e,n={}){if(this.disabled||this.off||this.closing||!T.test(t)||this.none)return;let i=this.env.now(),s=this.clean(typeof n.url=="string"?n.url:this.env.location().href)??"",r=typeof this.opts.module=="function"?this.opts.module(s):this.opts.module,c=this.granted,l=this.env.screen(),a={event_id:b(i,this.env.random(16)),event:t,ts:i,consent:this.consentValue,url:s,screen_w:l.w,screen_h:l.h,language:this.env.language(),...c?{distinct_id:this.deviceId(),session_id:this.session(i)}:{},...c&&this.userId?{user_id:this.userId}:{},...this.opts.product?{product:this.opts.product}:{},...this.opts.appName?{app_name:this.opts.appName}:{},...r?{module:r}:{},...this.opts.debug?{debug:!0}:{},...e?{properties:e}:{},...n};a.url=s,typeof a.referrer=="string"&&(a.referrer=this.clean(a.referrer)??""),this.queue.push({e:a,idt:this.idt,wt:this.wt}),this.queue.length>=_&&this.flush(!1)}async flush(t){if(this.off||this.sending||!this.queue.length)return;let e=this.env.now();if(!t&&e<this.retryAt||(this.queue=this.queue.filter(a=>e-a.e.ts<I),!this.queue.length))return;let{idt:n,wt:i}=this.queue[0],s=0;for(;s<_*2&&s<this.queue.length&&this.queue[s].idt===n&&this.queue[s].wt===i;)s++;let r=this.queue.slice(0,s),c=JSON.stringify({stream:this.opts.stream,sent_at:e,sdk:x,...i?{wt:i}:{},...n?{idt:n}:{},events:r.map(a=>a.e)});this.sending=!0;let l=!1;try{l=await this.env.send(this.endpoint,c,t)}catch{l=!1}this.sending=!1,l?(this.queue=this.queue.slice(r.length),this.failures=0,this.retryAt=0):(this.failures++,this.retryAt=e+Math.min(3e5,5e3*2**Math.min(this.failures,6)),this.queue.length>p&&(this.queue=this.queue.slice(-p))),this.granted&&this.saveOffline(),l&&this.queue.length&&await this.flush(t)}deviceId(){let t=this.env.getCookie(d);return(!t||!/^[A-Za-z0-9._:-]{8,64}$/.test(t))&&(t="au."+k(this.env.random(12))),this.env.setCookie(d,t,this.cookieAge),t}session(t){let e=this.env.storage(),n=null;try{n=JSON.parse(e?.getItem(y)??"null")}catch{n=null}(!n||t-n.last>A)&&(n={id:b(t,this.env.random(16)),last:t}),n.last=t;try{e?.setItem(y,JSON.stringify(n))}catch{}return n.id}saveOffline(){try{let t=this.env.storage();if(!t)return;this.queue.length?t.setItem(g,JSON.stringify(this.queue.slice(-p).map(e=>e.e))):t.removeItem(g)}catch{}}loadOffline(){try{let t=JSON.parse(this.env.storage()?.getItem(g)??"[]");Array.isArray(t)&&(this.queue=t.slice(-p).map(e=>({e,idt:"",wt:""})))}catch{}}};function S(o=window){let t=o.document;return{now:()=>Date.now(),random:e=>o.crypto.getRandomValues(new Uint8Array(e)),location:()=>({href:o.location.href,host:o.location.host}),referrer:()=>t.referrer,title:()=>t.title,screen:()=>({w:o.screen?.width??0,h:o.screen?.height??0}),language:()=>o.navigator.language??"",dnt:()=>o.navigator.doNotTrack==="1"||o.navigator.globalPrivacyControl===!0,getCookie:e=>{let n=t.cookie.match(new RegExp("(?:^|; )"+e+"=([^;]*)"));return n?decodeURIComponent(n[1]):null},setCookie:(e,n,i)=>{let s=o.location.protocol==="https:"?"; Secure":"";t.cookie=`${e}=${encodeURIComponent(n)}; Max-Age=${i}; Path=/; SameSite=Lax${s}`},storage:()=>{try{return o.localStorage}catch{return null}},send:async(e,n,i)=>{if(i&&o.navigator.sendBeacon)return o.navigator.sendBeacon(e,new Blob([n],{type:"text/plain"}));let s=await o.fetch(e,{method:"POST",body:n,headers:{"content-type":"text/plain"},keepalive:!0,credentials:"omit"});return s.ok||s.status>=400&&s.status<500&&s.status!==429},onHide:e=>{t.addEventListener("visibilitychange",()=>t.visibilityState==="hidden"&&e()),o.addEventListener("pagehide",e)},onNavigate:e=>{let n=o.history;for(let i of["pushState","replaceState"]){let s=n[i];n[i]=function(...r){let c=s.apply(this,r);return setTimeout(e,0),c}}o.addEventListener("popstate",()=>setTimeout(e,0))},setInterval:(e,n)=>o.setInterval(e,n)}}var f=window,C=document.currentScript,u=C?.dataset??{},E=u.stream;if(E&&!(f.auralytics instanceof h)){let o=Array.isArray(f.auralytics)?f.auralytics:[],t=C?.src?new URL(C.src).origin:void 0,e=new h({stream:E,endpoint:u.endpoint??t,consent:u.consent??"unknown",withoutConsent:u.withoutConsent==="none"?"none":"cookieless",autoPageviews:u.auto!=="false",debug:u.debug==="true"},S());f.auralytics=e;for(let[n,...i]of o){let s=e[n];typeof s=="function"&&s.apply(e,i)}if(u.cmp&&t){let n=document.createElement("script");n.src=t+"/cmp.js",n.async=!0,n.dataset.cmp=u.cmp,document.head.appendChild(n)}}})();
|
package/dist/scrub.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pulizia dei testi che l'SDK raccoglie da solo (messaggi d'errore, stack, testo dei pulsanti, termini di ricerca): niente email, numeri
|
|
3
|
+
* lunghi (telefoni, codici, carte), UUID, token né query string degli indirizzi. Il collector ripulisce di nuovo: qui è la prima difesa.
|
|
4
|
+
*/
|
|
5
|
+
export declare function scrubText(s: string, max?: number): string;
|
|
6
|
+
/** Un indirizzo ridotto a origine e percorso (niente query né frammento); vuoto se non è http(s). */
|
|
7
|
+
export declare function originPath(href: string, base?: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/vitals.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Tracker } from './errors';
|
|
2
|
+
/**
|
|
3
|
+
* Web Vitals (W2), implementazione propria e leggera (niente dipendenze): LCP, CLS (finestre di sessione di 5 s), INP (approssimato come
|
|
4
|
+
* il 98° percentile delle interazioni, come la definizione di Chrome) e TTFB, da `PerformanceObserver`. Un solo evento `$web_vitals` per
|
|
5
|
+
* pagina, quando la pagina si nasconde, con i valori nelle colonne `perf_*` e il giudizio in `vital_rating`. Campionamento per pagina
|
|
6
|
+
* (`sampleRate`, di serie 10%). Nei browser senza le API mancano i valori (null), mai un errore.
|
|
7
|
+
*/
|
|
8
|
+
export interface VitalsOptions {
|
|
9
|
+
sampleRate?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface VitalsValues {
|
|
12
|
+
lcp: number | null;
|
|
13
|
+
inp: number | null;
|
|
14
|
+
cls: number | null;
|
|
15
|
+
ttfb: number | null;
|
|
16
|
+
}
|
|
17
|
+
export declare function rateVitals(v: VitalsValues): 'good' | 'needs-improvement' | 'poor' | null;
|
|
18
|
+
/** CLS con le finestre di sessione: spostamenti a meno di 1 s l'uno dall'altro e in al più 5 s; vale la finestra peggiore. */
|
|
19
|
+
export declare class ClsWindow {
|
|
20
|
+
private current;
|
|
21
|
+
private first;
|
|
22
|
+
private last;
|
|
23
|
+
value: number;
|
|
24
|
+
add(time: number, shift: number): void;
|
|
25
|
+
}
|
|
26
|
+
/** INP: con meno di 50 interazioni la peggiore, poi si salta una ogni 50 (98° percentile). */
|
|
27
|
+
export declare function inpOf(durations: number[]): number | null;
|
|
28
|
+
export declare function installWebVitals(client: Tracker, win: Window, opts?: VitalsOptions, random?: () => number): () => void;
|
package/dist/x.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";(()=>{function d(e,t=300){return e.replace(/(https?:\/\/[^\s?#)'"]*)[?#][^\s)'":]*/g,"$1").replace(/[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}(?![\w:/.-])/g,"<email>").replace(/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi,"<id>").replace(/\b[A-Za-z0-9_-]{32,}\b/g,"<token>").replace(/\d[\d\s.-]{4,}\d/g,"<n>").slice(0,t)}function E(e,t){try{let n=new URL(e,t);return n.protocol==="http:"||n.protocol==="https:"?`${n.origin}${n.pathname}`:""}catch{return""}}var N=/\.(pdf|zip|rar|7z|gz|tgz|docx?|xlsx?|pptx?|odt|ods|odp|csv|txt|rtf|exe|msi|dmg|pkg|apk|mp3|wav|mp4|mov|avi|mkv|epub)$/i,j=new Set(["a","button"]),C=new Set(["input","textarea","select","option"]);function x(e){for(let t=e;t;t=t.parentElement??null)if(t.getAttribute("data-au-no-capture")!==null)return!0;return!1}function I(e){return/^[A-Za-z][A-Za-z_-]{1,40}$/.test(e)&&!/(^css-|^sc-|^jsx-|__[a-z0-9]{5,}$)/.test(e)}function W(e){let t=[];for(let n=e,r=0;n&&r<4;n=n.parentElement,r++){let o=n.tagName.toLowerCase();if(o==="html"||o==="body")break;if(n.id&&/^[A-Za-z][A-Za-z0-9_-]{0,40}$/.test(n.id)&&!/\d{3,}/.test(n.id)){t.unshift(`${o}#${n.id}`);break}let s=typeof n.className=="string"?n.className.split(/\s+/).filter(I).slice(0,2):[];t.unshift(o+s.map(c=>`.${c}`).join(""))}return t.join(" > ").slice(0,300)}function Z(e){for(let t=e,n=0;t&&n<5;t=t.parentElement??null,n++){let r=t.tagName.toLowerCase();if(C.has(r)){let o=(t.getAttribute("type")??"").toLowerCase();return r==="input"&&["submit","button","reset","checkbox","radio"].includes(o)?t:null}if(t.getAttribute("contenteditable")!==null)return null;if(j.has(r)||t.getAttribute("role")==="button"||t.getAttribute("data-au-capture")!==null)return t}return null}function F(e,t){let n=Z(e);if(!n||x(n))return null;let r=n.tagName.toLowerCase(),o=r==="input"?"":d((n.textContent??"").replace(/\s+/g," ").trim(),64),s=r==="a"?E(n.getAttribute("href")??"",t):"";return{selector:W(n),tag:r,...o?{text:o}:{},...s?{href:s}:{},...n.getAttribute("data-au-name")?{name:d(n.getAttribute("data-au-name")??"",64)}:{}}}function U(e,t,n){let r,o;try{r=new URL(e,t),o=new URL(t)}catch{return null}if(r.protocol!=="http:"&&r.protocol!=="https:")return null;let s=N.exec(r.pathname);return n.downloads&&s?{event:"$file_download",props:{file_name:d(decodeURIComponent(r.pathname.split("/").pop()??""),100),file_extension:s[1].toLowerCase(),link_url:`${r.origin}${r.pathname}`}}:n.outbound&&r.hostname!==o.hostname?{event:"$outbound_click",props:{link_domain:r.hostname,link_url:`${r.origin}${r.pathname}`}}:null}function H(e,t=["q","s","search","query"]){try{let n=new URL(e);for(let r of t){let o=n.searchParams.get(r);if(o&&o.trim())return d(o.trim(),100)}}catch{}return null}function D(e,t){return[25,50,75,90].filter(n=>e*100>=n&&!t.has(n))}function w(e){return e&&typeof e.tagName=="string"?e:null}function T(e,t,n={}){let r=t.document,o=a=>n[a]!==!1,s=[],c=(a,i,l,p=!0)=>{a.addEventListener(i,l,{capture:p,passive:!0}),s.push(()=>a.removeEventListener(i,l,{capture:p}))},u=t.location.href,m=new Set,h=new WeakSet,f=()=>{t.location.href!==u&&(u=t.location.href,m=new Set,v())},v=()=>{if(!o("siteSearch"))return;let a=typeof n.siteSearch=="object"?n.siteSearch.params:void 0,i=H(t.location.href,a);i&&e.track("$site_search",{search_term:i})};v(),c(t,"popstate",()=>setTimeout(f,0));let y=t.setInterval(f,1e3);if(s.push(()=>t.clearInterval(y)),o("scroll")&&c(t,"scroll",()=>{let a=r.documentElement,i=Math.max(a.scrollHeight,1);for(let l of D((t.scrollY+t.innerHeight)/i,m))m.add(l),e.track("$scroll",{percent_scrolled:l})}),(o("outbound")||o("downloads"))&&c(r,"click",a=>{let i=w(a.target);for(;i&&i.tagName.toLowerCase()!=="a";)i=i.parentElement??null;if(!i||x(i))return;let l=U(i.getAttribute("href")??"",t.location.href,{outbound:o("outbound"),downloads:o("downloads")});l&&e.track(l.event,l.props)}),o("forms")){let a=i=>({...i.id?{form_id:d(i.id,64)}:{},...i.getAttribute("name")?{form_name:d(i.getAttribute("name")??"",64)}:{},form_destination:E(i.getAttribute("action")??"",t.location.href)});c(r,"focusin",i=>{let l=w(i.target);for(;l&&l.tagName.toLowerCase()!=="form";)l=l.parentElement??null;!l||h.has(l)||x(l)||(h.add(l),e.track("$form_start",a(l)))}),c(r,"submit",i=>{let l=w(i.target);l&&!x(l)&&e.track("$form_submit",a(l))})}if(o("video")){let a=new WeakMap,i=p=>({video_url:E(p.currentSrc||p.src,t.location.href),...p.title?{video_title:d(p.title,100)}:{}}),l=p=>!!p&&p.tagName==="VIDEO"&&!x(p);c(r,"play",p=>{l(p.target)&&!a.has(p.target)&&(a.set(p.target,new Set),e.track("$video_start",i(p.target)))}),c(r,"timeupdate",p=>{let g=p.target;if(!l(g)||!g.duration||!Number.isFinite(g.duration))return;let k=a.get(g)??new Set;a.set(g,k);for(let L of[10,25,50,75])g.currentTime/g.duration*100>=L&&!k.has(L)&&(k.add(L),e.track("$video_progress",{...i(g),video_percent:L}))}),c(r,"ended",p=>l(p.target)&&e.track("$video_complete",i(p.target)))}return()=>s.forEach(a=>a())}function S(e,t,n={}){let r=o=>{let s=w(o.target);if(s&&n.ignore?.length){let u=s;if(n.ignore.some(m=>typeof u.closest=="function"&&u.closest(m)))return}let c=F(s,t.location.href);c&&e.track("$autocapture",c)};return t.document.addEventListener("click",r,{capture:!0,passive:!0}),()=>t.document.removeEventListener("click",r,{capture:!0})}var q=/^\s*at\s+(?:(.*?)\s+\()?(.+?):(\d+):(\d+)\)?\s*$/,B=/^\s*(.*?)@(.+?):(\d+):(\d+)\s*$/;function K(e){let t=[];for(let n of(e??"").split(`
|
|
2
|
+
`)){let r=q.exec(n)??B.exec(n);if(!r)continue;let o=/^https?:/.test(r[2])?E(r[2]):r[2].split(/[?#]/)[0];if(t.push({fn:d(r[1]??"",100),file:o.slice(0,300),line:Number(r[3]),col:Number(r[4])}),t.length>=30)break}return t}function G(e){return e.map(t=>` at ${t.fn||"<anonima>"} (${t.file}:${t.line}:${t.col})`).join(`
|
|
3
|
+
`)}function J(e){let t=2166136261,n=2671212586;for(let r=0;r<e.length;r++){let o=e.charCodeAt(r);t=Math.imul(t^o,16777619)>>>0,n=Math.imul(n^o,16777619)>>>0}return t.toString(16).padStart(8,"0")+n.toString(16).padStart(8,"0")}function X(e){return d(e,200).replace(/(["'`]).*?\1/g,"<s>").replace(/\d+/g,"<n>").trim()}function Y(e,t,n){let r=n.slice(0,3).map(o=>`${o.file.split("/").pop()?.replace(/[.-][0-9a-f]{6,}(?=\.)/g,"")??""}:${o.fn}`).join("|");return J(`${e}|${X(t)}|${r}`)}function Q(e,t,n){let r=e instanceof Error?e:null,o=(r?.name||(typeof e=="object"&&e?"Object":typeof e)||"Error").slice(0,100),s=r?r.message:typeof e=="string"?e:(()=>{try{return JSON.stringify(e)??String(e)}catch{return String(e)}})(),c=d(s??"",300),u=K(r?.stack);return{type:o,message:c,stack:G(u).slice(0,4e3),fingerprint:Y(o,c,u),handled:t,...n?{release:n.slice(0,100)}:{}}}var A=class{constructor(t,n){this.opts=t;this.sampled=n}seen=new Set;count=0;admit(t){if(!this.sampled)return!1;let n=String(t.fingerprint??""),r=String(t.message??"");return(this.opts.ignore??[]).some(o=>o.test(r))||this.seen.has(n)||this.count>=(this.opts.maxPerPage??10)?!1:(this.seen.add(n),this.count++,!0)}};function O(e,t,n,r=!0,o){let s=Q(n,r,o);t.admit(s)&&e.track("$exception",s)}function _(e,t,n={},r=Math.random){let o=new A(n,r()<(n.sampleRate??1)),s=u=>{!u.error&&/^Script error\.?$/.test(u.message??"")||O(e,o,u.error??u.message,!1,n.release)},c=u=>O(e,o,u.reason,!1,n.release);return t.addEventListener("error",s),t.addEventListener("unhandledrejection",c),{capture:u=>O(e,o,u,!0,n.release),uninstall:()=>{t.removeEventListener("error",s),t.removeEventListener("unhandledrejection",c)}}}var P={lcp:[2500,4e3],inp:[200,500],cls:[.1,.25]};function tt(e){let t=-1;for(let n of["lcp","inp","cls"]){let r=e[n];r!==null&&(t=Math.max(t,r<=P[n][0]?0:r<=P[n][1]?1:2))}return t<0?null:["good","needs-improvement","poor"][t]}var $=class{current=0;first=0;last=0;value=0;add(t,n){this.current&&t-this.last<1e3&&t-this.first<5e3?this.current+=n:(this.current=n,this.first=t),this.last=t,this.value=Math.max(this.value,this.current)}};function et(e){if(!e.length)return null;let t=[...e].sort((n,r)=>r-n);return t[Math.min(t.length-1,Math.floor(e.length/50))]}function R(e,t,n={},r=Math.random){let o=t.PerformanceObserver;if(!o||r()>=(n.sampleRate??.1))return()=>{};let s={lcp:null,inp:null,cls:null,ttfb:null},c=new $,u=new Map,m=[],h=(a,i,l={})=>{try{let p=new o(g=>g.getEntries().forEach(k=>i(k)));p.observe({type:a,buffered:!0,...l}),m.push(p)}catch{}};h("largest-contentful-paint",a=>s.lcp=Math.round(a.startTime)),h("layout-shift",a=>{!a.hadRecentInput&&typeof a.value=="number"&&(c.add(a.startTime,a.value),s.cls=Math.round(c.value*1e4)/1e4)}),h("event",a=>{a.interactionId&&(u.set(a.interactionId,Math.max(u.get(a.interactionId)??0,a.duration)),u.size>500&&u.delete(u.keys().next().value),s.inp=et([...u.values()]))},{durationThreshold:40});try{let a=t.performance?.getEntriesByType?.("navigation")?.[0];a&&typeof a.responseStart=="number"&&a.responseStart>0&&(s.ttfb=Math.round(a.responseStart))}catch{}let f=!1,v=()=>{if(f||s.lcp===null&&s.cls===null&&s.inp===null&&s.ttfb===null)return;f=!0;let a=tt(s);e.track("$web_vitals",a?{vital_rating:a}:void 0,{perf:{...s}})},y=()=>t.document.visibilityState==="hidden"&&v();return t.document.addEventListener("visibilitychange",y),t.addEventListener("pagehide",v),()=>{m.forEach(a=>a.disconnect()),t.document.removeEventListener("visibilitychange",y),t.removeEventListener("pagehide",v)}}function M(e,t,n){let r=[],o=()=>{},s=f=>f?f===!0?{}:f:null,c=s(n.errors);if(c){let f=_(e,t,c);o=f.capture,r.push(f.uninstall)}let u=s(n.webVitals);u&&r.push(R(e,t,u));let m=s(n.enhanced);m&&r.push(T(e,t,m));let h=s(n.autocapture);return h&&r.push(S(e,t,h)),{captureException:f=>o(f),uninstall:()=>r.forEach(f=>f())}}var nt=document.currentScript,b=nt?.dataset??{},rt={errors:b.errors==="true"?{...b.release?{release:b.release}:{}}:!1,webVitals:b.vitals?{sampleRate:Math.min(1,Math.max(0,Number(b.vitals)||.1))}:!1,enhanced:b.enhanced==="true",autocapture:b.autocapture==="true"},V=window,ot=0,z=()=>{let e=V.auralytics;if(e&&typeof e.track=="function"&&!Array.isArray(e)){V.auralyticsPlugins=M(e,window,rt);return}++ot<50&&setTimeout(z,200)};z();})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@generazioneai/analytics-web",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "SDK web di Auralytics (GenAI Analytics): eventi, pagine, consenso (Consent Mode v2, IAB TCF 2.2, iubenda, Cookiebot, OneTrust), identità verificata, invio a lotti, errori, Web Vitals, misurazione avanzata e autocattura. Nessuna dipendenza.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "Generazione AI S.r.l.",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/GenerazioneAI-SRL/GENAI-ANALYTICS-BE.git",
|
|
10
|
+
"directory": "sdk/web"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/GenerazioneAI-SRL/GENAI-ANALYTICS-BE/tree/main/sdk/web#readme",
|
|
13
|
+
"bugs": "https://github.com/GenerazioneAI-SRL/GENAI-ANALYTICS-BE/issues",
|
|
14
|
+
"keywords": ["analytics", "privacy", "consent", "consent-mode", "tcf", "telemetry", "auralytics"],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"main": "./dist/index.cjs",
|
|
18
|
+
"module": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js",
|
|
24
|
+
"require": "./dist/index.cjs"
|
|
25
|
+
},
|
|
26
|
+
"./s.js": "./dist/s.js",
|
|
27
|
+
"./cmp.js": "./dist/cmp.js",
|
|
28
|
+
"./x.js": "./dist/x.js",
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"bin": { "analytics-web": "./bin/analytics-web.cjs" },
|
|
32
|
+
"files": ["dist", "bin", "README.md", "CHANGELOG.md", "LICENSE"],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"clean": "rm -rf dist",
|
|
35
|
+
"build": "npm run clean && esbuild src/index.ts --bundle --format=esm --target=es2019 --outfile=dist/index.js && esbuild src/index.ts --bundle --format=cjs --target=es2019 --outfile=dist/index.cjs && esbuild src/snippet.ts --bundle --minify --format=iife --target=es2022 --outfile=dist/s.js && esbuild src/cmp.ts --bundle --minify --format=iife --target=es2022 --outfile=dist/cmp.js && esbuild src/extensions.ts --bundle --minify --format=iife --target=es2022 --outfile=dist/x.js && tsc -p tsconfig.build.json",
|
|
36
|
+
"typecheck": "tsc -p tsconfig.build.json --noEmit",
|
|
37
|
+
"prepublishOnly": "npm run build"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"esbuild": "^0.25.0",
|
|
41
|
+
"typescript": "^6.0.0"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public",
|
|
45
|
+
"registry": "https://registry.npmjs.org"
|
|
46
|
+
}
|
|
47
|
+
}
|