@upperz/trackiq-sdk 1.0.1 → 1.0.3
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/dist/chunk-GSAGJBV2.mjs +1 -0
- package/dist/chunk-KJMUMR27.mjs +1 -0
- package/dist/chunk-M4SD4ISL.mjs +1 -0
- package/dist/index.d.mts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/next.d.mts +1 -1
- package/dist/next.d.ts +1 -1
- package/dist/next.js +1 -1
- package/dist/next.mjs +1 -1
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +1 -1
- package/dist/react.mjs +1 -1
- package/dist/types-0H6Dm_6_.d.mts +128 -0
- package/dist/types-0H6Dm_6_.d.ts +128 -0
- package/dist/types-kfDmqmqD.d.mts +142 -0
- package/dist/types-kfDmqmqD.d.ts +142 -0
- package/dist/vue.d.mts +1 -1
- package/dist/vue.d.ts +1 -1
- package/dist/vue.js +1 -1
- package/dist/vue.mjs +1 -1
- package/package.json +21 -13
|
@@ -0,0 +1 @@
|
|
|
1
|
+
async function c(t){let n=new TextEncoder().encode(t),i=await crypto.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(i)).map(o=>o.toString(16).padStart(2,"0")).join("")}async function Z(){try{let t=document.createElement("canvas");t.width=280,t.height=60;let e=t.getContext("2d");return e?(e.textBaseline="top",e.font="14px Arial",e.fillStyle="#f60",e.fillRect(125,1,62,20),e.fillStyle="#069",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",2,15),e.fillStyle="rgba(102, 204, 0, 0.7)",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",4,45),c(t.toDataURL())):"unavailable"}catch{return"unavailable"}}function z(){try{let t=document.createElement("canvas"),e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.getExtension("WEBGL_debug_renderer_info");return n?e.getParameter(n.UNMASKED_RENDERER_WEBGL):"unavailable"}catch{return"unavailable"}}async function ee(){try{let t=document.createElement("canvas");t.width=16,t.height=16;let e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.createShader(e.VERTEX_SHADER),i=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(n,"attribute vec2 p;void main(){gl_Position=vec4(p,0,1);}"),e.shaderSource(i,"void main(){gl_FragColor=vec4(0.2,0.4,0.6,1.0);}"),e.compileShader(n),e.compileShader(i);let r=e.createProgram();e.attachShader(r,n),e.attachShader(r,i),e.linkProgram(r),e.useProgram(r);let o=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,o),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-.5,-.5,.5,-.5,0,.5]),e.STATIC_DRAW);let s=e.getAttribLocation(r,"p");e.enableVertexAttribArray(s),e.vertexAttribPointer(s,2,e.FLOAT,!1,0,0),e.drawArrays(e.TRIANGLES,0,3);let a=new Uint8Array(256*4);return e.readPixels(0,0,16,16,e.RGBA,e.UNSIGNED_BYTE,a),c(a.join(","))}catch{return"unavailable"}}async function te(){try{let t=window.OfflineAudioContext||window.webkitOfflineAudioContext;if(!t)return"unavailable";let e=new t(1,44100,44100),n=e.createOscillator();n.type="triangle",n.frequency.setValueAtTime(1e4,e.currentTime);let i=e.createDynamicsCompressor();i.threshold.setValueAtTime(-50,e.currentTime),i.knee.setValueAtTime(40,e.currentTime),i.ratio.setValueAtTime(12,e.currentTime),i.attack.setValueAtTime(0,e.currentTime),i.release.setValueAtTime(.25,e.currentTime),n.connect(i),i.connect(e.destination),n.start(0);let o=(await e.startRendering()).getChannelData(0),s=0;for(let a=4500;a<5e3;a++)s+=Math.abs(o[a]);return c(s.toFixed(10))}catch{return"blocked"}}var ne=["Arial","Arial Black","Arial Narrow","Calibri","Cambria","Candara","Comic Sans MS","Consolas","Constantia","Corbel","Courier New","Franklin Gothic Medium","Garamond","Georgia","Gill Sans","Helvetica","Impact","Lucida Console","Lucida Sans Unicode","Microsoft Sans Serif","Palatino Linotype","Segoe UI","Tahoma","Times New Roman","Trebuchet MS","Verdana","Adobe Caslon Pro","Adobe Garamond Pro","Myriad Pro","Roboto","Open Sans","Lato","Montserrat","Oswald","Source Sans Pro","SF Pro Display","SF Pro Text","Helvetica Neue","Futura","Segoe Print","Segoe Script","MS Gothic","Liberation Sans","Liberation Serif","Ubuntu","DejaVu Sans","Wingdings","Symbol","Webdings"];function ie(){try{let e=document.createElement("canvas").getContext("2d");if(!e)return[];let n="mmmmmmmmmmlli",i="72px",r="monospace";e.font=`${i} ${r}`;let o=e.measureText(n).width;return ne.filter(s=>(e.font=`${i} '${s}', ${r}`,e.measureText(n).width!==o))}catch{return[]}}function re(){try{return Array.from(navigator.plugins).map(t=>t.name)}catch{return[]}}async function T(){let[t,e,n]=await Promise.all([Z(),ee(),te()]),i=z(),r=ie(),o=re(),s={canvas_hash:t,webgl_renderer:i,webgl_hash:e,audio_hash:n,fonts_detected:r,plugins:o},a=[t,i,e,n,r.join(","),o.join(",")].join("|");return{fpId:await c(a),payload:s}}async function E(t){return c(t)}var k="tiq_vid",_="tiq_sid";function l(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function C(){try{let t=localStorage.getItem(k);return t||(t=l(),localStorage.setItem(k,t)),t}catch{return l()}}function I(){try{let t=sessionStorage.getItem(_);return t||(t=l(),sessionStorage.setItem(_,t)),t}catch{return l()}}function A(){try{let t="__tiq_test__";return localStorage.setItem(t,"1"),localStorage.removeItem(t),!0}catch{return!1}}function P(){try{let t="__tiq_test__";return sessionStorage.setItem(t,"1"),sessionStorage.removeItem(t),!0}catch{return!1}}function L(){try{return typeof indexedDB!="undefined"&&indexedDB!==null}catch{return!1}}function D(){return{user_agent:navigator.userAgent,screen_w:screen.width,screen_h:screen.height,viewport_w:window.innerWidth,viewport_h:window.innerHeight,device_pixel_ratio:window.devicePixelRatio||1,color_depth:screen.colorDepth,cpu_cores:navigator.hardwareConcurrency||0,device_memory:navigator.deviceMemory||0,touch:navigator.maxTouchPoints>0,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}}function M(){return navigator.language||""}function R(){return Array.from(navigator.languages||[navigator.language])}function d(){var t;return(t=navigator.connection)!=null?t:{}}function N(){return d().effectiveType||"unknown"}function O(){var t;return(t=d().downlink)!=null?t:0}function F(){var t;return(t=d().rtt)!=null?t:0}function H(){var t;return(t=d().saveData)!=null?t:!1}function B(){return window.matchMedia("(prefers-color-scheme: dark)").matches}function U(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}function G(){try{let t=performance.getEntriesByType("navigation")[0];return(t==null?void 0:t.type)||"navigate"}catch{return"navigate"}}function V(){return navigator.doNotTrack==="1"||window.doNotTrack==="1"}function Y(){return navigator.cookieEnabled}var oe=[25,50,75,90],u=class{constructor(){this.maxScroll=0;this.milestones=new Set;this.handler=()=>this.onScroll(),window.addEventListener("scroll",this.handler,{passive:!0})}onScroll(){let e=document.body.scrollHeight-window.innerHeight;if(e<=0)return;let n=Math.round(window.scrollY/e*100);n>this.maxScroll&&(this.maxScroll=n);for(let i of oe)n>=i&&this.milestones.add(i)}get maxScrollDepth(){return this.maxScroll}get reachedMilestones(){return Array.from(this.milestones)}destroy(){window.removeEventListener("scroll",this.handler)}},K=["mousemove","scroll","click","keydown","touchstart"],se=3e4,h=class{constructor(){this.accumulated=0;this.lastActiveAt=Date.now();this.idle=!1;this.hidden=!1;this.idleTimer=null;this.activityHandler=()=>this.onActivity(),this.visibilityHandler=()=>this.onVisibilityChange();for(let e of K)window.addEventListener(e,this.activityHandler,{passive:!0});document.addEventListener("visibilitychange",this.visibilityHandler),this.scheduleIdleCheck()}onActivity(){this.hidden||(this.idle?(this.lastActiveAt=Date.now(),this.idle=!1):this.flush(),this.scheduleIdleCheck())}onVisibilityChange(){document.hidden?(this.flush(),this.hidden=!0):(this.hidden=!1,this.lastActiveAt=Date.now())}flush(){!this.idle&&!this.hidden&&(this.accumulated+=Date.now()-this.lastActiveAt,this.lastActiveAt=Date.now())}scheduleIdleCheck(){this.idleTimer&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{this.flush(),this.idle=!0},se)}get activeTimeMs(){return this.flush(),this.accumulated}destroy(){for(let e of K)window.removeEventListener(e,this.activityHandler);document.removeEventListener("visibilitychange",this.visibilityHandler),this.idleTimer&&clearTimeout(this.idleTimer)}},ae=30,ce=1e3,v=class{constructor(){this.path=[];this.lastSampleAt=0;this.handler=e=>this.onMouseMove(e),window.addEventListener("mousemove",this.handler,{passive:!0})}onMouseMove(e){let n=Date.now();this.path.length>=ae||n-this.lastSampleAt<ce||(this.path.push({x:Math.round(e.clientX+window.scrollX),y:Math.round(e.clientY+window.scrollY),t:n}),this.lastSampleAt=n)}get points(){return this.path}destroy(){window.removeEventListener("mousemove",this.handler)}},p=class{constructor(e){this.onExitIntent=e;this.fired=!1;this.handler=n=>{!this.fired&&n.clientY<10&&(this.fired=!0,this.onExitIntent(Math.round(n.clientX+window.scrollX),Math.round(n.clientY+window.scrollY)))},document.addEventListener("mousemove",this.handler,{passive:!0})}destroy(){document.removeEventListener("mousemove",this.handler)}},le=1e3,de=3,f=class{constructor(e){this.onRageClick=e;this.recentClicks=[];this.handler=n=>this.onClick(n),window.addEventListener("click",this.handler,{passive:!0})}onClick(e){let n=Date.now();if(this.recentClicks=this.recentClicks.filter(i=>n-i.ts<le),this.recentClicks.push({ts:n,x:Math.round(e.clientX+window.scrollX),y:Math.round(e.clientY+window.scrollY)}),this.recentClicks.length>=de){let i=w(e.target);this.onRageClick(Math.round(e.clientX+window.scrollX),Math.round(e.clientY+window.scrollY),this.recentClicks.length,i),this.recentClicks=[]}}destroy(){window.removeEventListener("click",this.handler)}},m=class{constructor(e){this.onClick=e;this.handler=n=>{let i=n.target;if(y(i))return;let r=ue(i);this.onClick(Math.round(n.clientX+window.scrollX),Math.round(n.clientY+window.scrollY),Date.now(),w(i),r)},window.addEventListener("click",this.handler,{passive:!0})}destroy(){window.removeEventListener("click",this.handler)}},g=class{constructor(e){this.onSelect=e;this.handler=()=>{var o;let n=window.getSelection();if(!n||n.isCollapsed)return;let i=n.toString().trim();if(!i||i.length<3)return;let r=(o=n.anchorNode)==null?void 0:o.parentElement;r&&y(r)||this.onSelect(i.slice(0,200),w(r||document.body))},document.addEventListener("selectionchange",this.handler,{passive:!0})}destroy(){document.removeEventListener("selectionchange",this.handler)}};function W(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=new PerformanceObserver(n=>{let i=n.getEntries(),r=i[i.length-1];r&&t(Math.round(r.startTime))});return e.observe({type:"largest-contentful-paint",buffered:!0}),()=>e.disconnect()}catch{return()=>{}}}function X(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=0,n=new PerformanceObserver(i=>{for(let r of i.getEntries()){let o=r,s=o.processingStart?o.processingStart-o.startTime+o.duration:o.duration;s>e&&(e=s,t(Math.round(e)))}});return n.observe({type:"event",buffered:!0,durationThreshold:16}),()=>n.disconnect()}catch{return()=>{}}}function $(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=0,n=new PerformanceObserver(i=>{for(let r of i.getEntries()){let o=r;o.hadRecentInput||(e+=o.value,t(parseFloat(e.toFixed(4))))}});return n.observe({type:"layout-shift",buffered:!0}),()=>n.disconnect()}catch{return()=>{}}}function q(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=new PerformanceObserver(n=>{for(let i of n.getEntries())if(i.name==="first-contentful-paint"){t(Math.round(i.startTime)),e.disconnect();return}});return e.observe({type:"paint",buffered:!0}),()=>e.disconnect()}catch{return()=>{}}}function j(){try{let t=performance.getEntriesByType("navigation")[0];return t?Math.round(t.responseStart-t.requestStart):0}catch{return 0}}function y(t){var n;if(!t)return!1;let e=(n=t.tagName)==null?void 0:n.toLowerCase();return["input","textarea","select","option"].includes(e)}function w(t){if(!t||!t.tagName)return"";let e=t.tagName.toLowerCase(),n=t.id?`#${t.id}`:"",i=t.classList.length?`.${Array.from(t.classList).slice(0,2).join(".")}`:"";return`${e}${n}${i}`.slice(0,60)}function ue(t){return!t||y(t)?"":(t.textContent||"").trim().slice(0,50)}var he="https://api.trackiq.io";async function Q(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/pageview`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};if(b(i,n,r),t.selfHosted){let o=await E(t.apiKey),s=JSON.stringify({key_hash:o,type:"pageview"});b(`${he}/v1/consume`,s,{"Content-Type":"application/json"})}}function x(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/event`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};b(i,n,r)}function b(t,e,n){try{fetch(t,{method:"POST",headers:n,body:e,keepalive:!0}).catch(()=>{})}catch{}}var ve="https://api.trackiq.io",J=class{constructor(e){this.fpId="";this.lcp=0;this.inp=0;this.cls=0;this.fcp=0;this.ttfb=0;var n,i;this.config={dataEndpoint:ve,debug:!1,...e},this.beacon={apiKey:this.config.apiKey,dataEndpoint:this.config.dataEndpoint,selfHosted:(n=e.selfHosted)!=null?n:!1},this.pageURL=window.location.href,this.pageReferrer=(i=e.referrer)!=null?i:document.referrer,this.session={visitorId:C(),sessionId:I(),tsStart:Date.now(),firstPageviewSent:!1},this.scroll=new u,this.activeTime=new h,this.mousePath=new v,this.exitIntent=new p((r,o)=>{this.sendBehaviorEvent("exit_intent",{x:r,y:o})}),this.rageClick=new f((r,o,s,a)=>{this.sendBehaviorEvent("rage_click",{x:r,y:o,count:s,element:a})}),this.clickTracker=new m((r,o,s,a,S)=>{this.sendBehaviorEvent("click",{x:r,y:o,ts:s,element:a,text:S})}),this.textSelect=new g((r,o)=>{this.sendBehaviorEvent("text_select",{text:r,element:o})}),this.disconnectLCP=W(r=>{this.lcp=r}),X(r=>{this.inp=r}),$(r=>{this.cls=r}),q(r=>{this.fcp=r}),this.ttfb=j(),this.scheduleFingerprint(),this.unloadHandler=()=>{this.flush()},window.addEventListener("beforeunload",this.unloadHandler),window.trackiq={event:this.event.bind(this)},this.log("TrackIQ initialised",{visitorId:this.session.visitorId})}event(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};x(this.beacon,i),this.log("event sent",{type:e,data:n})}destroy(){this.flush(),window.removeEventListener("beforeunload",this.unloadHandler),this.scroll.destroy(),this.activeTime.destroy(),this.mousePath.destroy(),this.exitIntent.destroy(),this.rageClick.destroy(),this.clickTracker.destroy(),this.textSelect.destroy(),this.disconnectLCP(),this.log("TrackIQ destroyed")}scheduleFingerprint(){let e=async()=>{let{fpId:n,payload:i}=await T();this.fpId=n,this.fpPayload=i,this.log("fingerprint computed",{fpId:n})};"requestIdleCallback"in window?requestIdleCallback(()=>{e().catch(()=>{})},{timeout:3e3}):setTimeout(()=>{e().catch(()=>{})},1)}flush(){let e=Date.now(),n=!this.session.firstPageviewSent;Q(this.beacon,{session_id:this.session.sessionId,visitor_id:this.session.visitorId,url:this.pageURL,referrer:this.pageReferrer,ts_start:this.session.tsStart,ts_end:e,active_time:this.activeTime.activeTimeMs,max_scroll:this.scroll.maxScrollDepth,milestones:this.scroll.reachedMilestones,mouse_path:this.mousePath.points,fp_id:this.fpId,fingerprint:n?this.fpPayload:void 0,device:n?D():void 0,language:M(),languages:R(),connection_type:N(),downlink:O(),rtt:F(),save_data:H(),prefers_dark_mode:B(),prefers_reduced_motion:U(),navigation_type:G(),lcp:this.lcp,inp:this.inp,cls:this.cls,fcp:this.fcp,ttfb:this.ttfb,dnt:V(),cookies_enabled:Y(),local_storage_available:A(),session_storage_available:P(),indexed_db_available:L()}).catch(()=>{}),this.session.firstPageviewSent=!0,this.log("pageview sent")}sendBehaviorEvent(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};x(this.beacon,i)}log(e,n){this.config.debug&&console.log(`[TrackIQ] ${e}`,n!=null?n:"")}};export{J as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
async function c(t){let n=new TextEncoder().encode(t),i=await crypto.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(i)).map(o=>o.toString(16).padStart(2,"0")).join("")}async function W(){try{let t=document.createElement("canvas");t.width=280,t.height=60;let e=t.getContext("2d");return e?(e.textBaseline="top",e.font="14px Arial",e.fillStyle="#f60",e.fillRect(125,1,62,20),e.fillStyle="#069",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",2,15),e.fillStyle="rgba(102, 204, 0, 0.7)",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",4,45),c(t.toDataURL())):"unavailable"}catch{return"unavailable"}}function $(){try{let t=document.createElement("canvas"),e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.getExtension("WEBGL_debug_renderer_info");return n?e.getParameter(n.UNMASKED_RENDERER_WEBGL):"unavailable"}catch{return"unavailable"}}async function Y(){try{let t=document.createElement("canvas");t.width=16,t.height=16;let e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.createShader(e.VERTEX_SHADER),i=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(n,"attribute vec2 p;void main(){gl_Position=vec4(p,0,1);}"),e.shaderSource(i,"void main(){gl_FragColor=vec4(0.2,0.4,0.6,1.0);}"),e.compileShader(n),e.compileShader(i);let r=e.createProgram();e.attachShader(r,n),e.attachShader(r,i),e.linkProgram(r),e.useProgram(r);let o=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,o),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-.5,-.5,.5,-.5,0,.5]),e.STATIC_DRAW);let s=e.getAttribLocation(r,"p");e.enableVertexAttribArray(s),e.vertexAttribPointer(s,2,e.FLOAT,!1,0,0),e.drawArrays(e.TRIANGLES,0,3);let a=new Uint8Array(256*4);return e.readPixels(0,0,16,16,e.RGBA,e.UNSIGNED_BYTE,a),c(a.join(","))}catch{return"unavailable"}}async function q(){try{let t=window.OfflineAudioContext||window.webkitOfflineAudioContext;if(!t)return"unavailable";let e=new t(1,44100,44100),n=e.createOscillator();n.type="triangle",n.frequency.setValueAtTime(1e4,e.currentTime);let i=e.createDynamicsCompressor();i.threshold.setValueAtTime(-50,e.currentTime),i.knee.setValueAtTime(40,e.currentTime),i.ratio.setValueAtTime(12,e.currentTime),i.attack.setValueAtTime(0,e.currentTime),i.release.setValueAtTime(.25,e.currentTime),n.connect(i),i.connect(e.destination),n.start(0);let o=(await e.startRendering()).getChannelData(0),s=0;for(let a=4500;a<5e3;a++)s+=Math.abs(o[a]);return c(s.toFixed(10))}catch{return"blocked"}}var j=["Arial","Arial Black","Arial Narrow","Calibri","Cambria","Candara","Comic Sans MS","Consolas","Constantia","Corbel","Courier New","Franklin Gothic Medium","Garamond","Georgia","Gill Sans","Helvetica","Impact","Lucida Console","Lucida Sans Unicode","Microsoft Sans Serif","Palatino Linotype","Segoe UI","Tahoma","Times New Roman","Trebuchet MS","Verdana","Adobe Caslon Pro","Adobe Garamond Pro","Myriad Pro","Roboto","Open Sans","Lato","Montserrat","Oswald","Source Sans Pro","SF Pro Display","SF Pro Text","Helvetica Neue","Futura","Segoe Print","Segoe Script","MS Gothic","Liberation Sans","Liberation Serif","Ubuntu","DejaVu Sans","Wingdings","Symbol","Webdings"];function X(){try{let e=document.createElement("canvas").getContext("2d");if(!e)return[];let n="mmmmmmmmmmlli",i="72px",r="monospace";e.font=`${i} ${r}`;let o=e.measureText(n).width;return j.filter(s=>(e.font=`${i} '${s}', ${r}`,e.measureText(n).width!==o))}catch{return[]}}function Q(){try{return Array.from(navigator.plugins).map(t=>t.name)}catch{return[]}}async function S(){let[t,e,n]=await Promise.all([W(),Y(),q()]),i=$(),r=X(),o=Q(),s={canvas_hash:t,webgl_renderer:i,webgl_hash:e,audio_hash:n,fonts_detected:r,plugins:o},a=[t,i,e,n,r.join(","),o.join(",")].join("|");return{fpId:await c(a),payload:s}}async function T(t){return c(t)}var E="tiq_vid",_="tiq_sid";function l(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function k(){try{let t=localStorage.getItem(E);return t||(t=l(),localStorage.setItem(E,t)),t}catch{return l()}}function C(){try{let t=sessionStorage.getItem(_);return t||(t=l(),sessionStorage.setItem(_,t)),t}catch{return l()}}function A(){try{let t="__tiq_test__";return localStorage.setItem(t,"1"),localStorage.removeItem(t),!0}catch{return!1}}function I(){try{let t="__tiq_test__";return sessionStorage.setItem(t,"1"),sessionStorage.removeItem(t),!0}catch{return!1}}function P(){try{return typeof indexedDB!="undefined"&&indexedDB!==null}catch{return!1}}function L(){return{user_agent:navigator.userAgent,screen_w:screen.width,screen_h:screen.height,viewport_w:window.innerWidth,viewport_h:window.innerHeight,device_pixel_ratio:window.devicePixelRatio||1,color_depth:screen.colorDepth,cpu_cores:navigator.hardwareConcurrency||0,device_memory:navigator.deviceMemory||0,touch:navigator.maxTouchPoints>0,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}}function D(){return navigator.language||""}function R(){return Array.from(navigator.languages||[navigator.language])}function M(){let t=navigator.connection;return(t==null?void 0:t.effectiveType)||"unknown"}function N(){return window.matchMedia("(prefers-color-scheme: dark)").matches}function H(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}function F(){try{let t=performance.getEntriesByType("navigation")[0];return(t==null?void 0:t.type)||"navigate"}catch{return"navigate"}}function O(){return navigator.doNotTrack==="1"||window.doNotTrack==="1"}function B(){return navigator.cookieEnabled}var J=[25,50,75,90],d=class{constructor(){this.maxScroll=0;this.milestones=new Set;this.handler=()=>this.onScroll(),window.addEventListener("scroll",this.handler,{passive:!0})}onScroll(){let e=document.body.scrollHeight-window.innerHeight;if(e<=0)return;let n=Math.round(window.scrollY/e*100);n>this.maxScroll&&(this.maxScroll=n);for(let i of J)n>=i&&this.milestones.add(i)}get maxScrollDepth(){return this.maxScroll}get reachedMilestones(){return Array.from(this.milestones)}destroy(){window.removeEventListener("scroll",this.handler)}},U=["mousemove","scroll","click","keydown","touchstart"],Z=3e4,u=class{constructor(){this.accumulated=0;this.lastActiveAt=Date.now();this.idle=!1;this.hidden=!1;this.idleTimer=null;this.activityHandler=()=>this.onActivity(),this.visibilityHandler=()=>this.onVisibilityChange();for(let e of U)window.addEventListener(e,this.activityHandler,{passive:!0});document.addEventListener("visibilitychange",this.visibilityHandler),this.scheduleIdleCheck()}onActivity(){this.hidden||(this.idle?(this.lastActiveAt=Date.now(),this.idle=!1):this.flush(),this.scheduleIdleCheck())}onVisibilityChange(){document.hidden?(this.flush(),this.hidden=!0):(this.hidden=!1,this.lastActiveAt=Date.now())}flush(){!this.idle&&!this.hidden&&(this.accumulated+=Date.now()-this.lastActiveAt,this.lastActiveAt=Date.now())}scheduleIdleCheck(){this.idleTimer&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{this.flush(),this.idle=!0},Z)}get activeTimeMs(){return this.flush(),this.accumulated}destroy(){for(let e of U)window.removeEventListener(e,this.activityHandler);document.removeEventListener("visibilitychange",this.visibilityHandler),this.idleTimer&&clearTimeout(this.idleTimer)}},z=30,ee=1e3,h=class{constructor(){this.path=[];this.lastSampleAt=0;this.handler=e=>this.onMouseMove(e),window.addEventListener("mousemove",this.handler,{passive:!0})}onMouseMove(e){let n=Date.now();this.path.length>=z||n-this.lastSampleAt<ee||(this.path.push({x:e.clientX,y:e.clientY,t:n}),this.lastSampleAt=n)}get points(){return this.path}destroy(){window.removeEventListener("mousemove",this.handler)}},v=class{constructor(e){this.onExitIntent=e;this.fired=!1;this.handler=n=>{!this.fired&&n.clientY<10&&(this.fired=!0,this.onExitIntent(n.clientX,n.clientY))},document.addEventListener("mousemove",this.handler,{passive:!0})}destroy(){document.removeEventListener("mousemove",this.handler)}},te=1e3,ne=3,p=class{constructor(e){this.onRageClick=e;this.recentClicks=[];this.handler=n=>this.onClick(n),window.addEventListener("click",this.handler,{passive:!0})}onClick(e){let n=Date.now();if(this.recentClicks=this.recentClicks.filter(i=>n-i.ts<te),this.recentClicks.push({ts:n,x:e.clientX,y:e.clientY}),this.recentClicks.length>=ne){let i=y(e.target);this.onRageClick(e.clientX,e.clientY,this.recentClicks.length,i),this.recentClicks=[]}}destroy(){window.removeEventListener("click",this.handler)}},g=class{constructor(e){this.onClick=e;this.handler=n=>{let i=n.target;if(f(i))return;let r=ie(i);this.onClick(n.clientX,n.clientY,Date.now(),y(i),r)},window.addEventListener("click",this.handler,{passive:!0})}destroy(){window.removeEventListener("click",this.handler)}},m=class{constructor(e){this.onSelect=e;this.handler=()=>{var o;let n=window.getSelection();if(!n||n.isCollapsed)return;let i=n.toString().trim();if(!i||i.length<3)return;let r=(o=n.anchorNode)==null?void 0:o.parentElement;r&&f(r)||this.onSelect(i.slice(0,200),y(r||document.body))},document.addEventListener("selectionchange",this.handler,{passive:!0})}destroy(){document.removeEventListener("selectionchange",this.handler)}};function G(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=new PerformanceObserver(n=>{let i=n.getEntries(),r=i[i.length-1];r&&t(Math.round(r.startTime))});return e.observe({type:"largest-contentful-paint",buffered:!0}),()=>e.disconnect()}catch{return()=>{}}}function f(t){var n;if(!t)return!1;let e=(n=t.tagName)==null?void 0:n.toLowerCase();return["input","textarea","select","option"].includes(e)}function y(t){if(!t||!t.tagName)return"";let e=t.tagName.toLowerCase(),n=t.id?`#${t.id}`:"",i=t.classList.length?`.${Array.from(t.classList).slice(0,2).join(".")}`:"";return`${e}${n}${i}`.slice(0,60)}function ie(t){return!t||f(t)?"":(t.textContent||"").trim().slice(0,50)}var re="https://api.trackiq.io";async function V(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/pageview`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};if(w(i,n,r),t.selfHosted){let o=await T(t.apiKey),s=JSON.stringify({key_hash:o,type:"pageview"});w(`${re}/v1/consume`,s,{"Content-Type":"application/json"})}}function x(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/event`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};w(i,n,r)}function w(t,e,n){try{fetch(t,{method:"POST",headers:n,body:e,keepalive:!0}).catch(()=>{})}catch{}}var oe="https://api.trackiq.io",K=class{constructor(e){this.fpId="";this.lcp=0;var n,i;this.config={dataEndpoint:oe,debug:!1,...e},this.beacon={apiKey:this.config.apiKey,dataEndpoint:this.config.dataEndpoint,selfHosted:(n=e.selfHosted)!=null?n:!1},this.pageURL=window.location.href,this.pageReferrer=(i=e.referrer)!=null?i:document.referrer,this.session={visitorId:k(),sessionId:C(),tsStart:Date.now(),firstPageviewSent:!1},this.scroll=new d,this.activeTime=new u,this.mousePath=new h,this.exitIntent=new v((r,o)=>{this.sendBehaviorEvent("exit_intent",{x:r,y:o})}),this.rageClick=new p((r,o,s,a)=>{this.sendBehaviorEvent("rage_click",{x:r,y:o,count:s,element:a})}),this.clickTracker=new g((r,o,s,a,b)=>{this.sendBehaviorEvent("click",{x:r,y:o,ts:s,element:a,text:b})}),this.textSelect=new m((r,o)=>{this.sendBehaviorEvent("text_select",{text:r,element:o})}),this.disconnectLCP=G(r=>{this.lcp=r}),this.scheduleFingerprint(),this.unloadHandler=()=>{this.flush()},window.addEventListener("beforeunload",this.unloadHandler),window.trackiq={event:this.event.bind(this)},this.log("TrackIQ initialised",{visitorId:this.session.visitorId})}event(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};x(this.beacon,i),this.log("event sent",{type:e,data:n})}destroy(){this.flush(),window.removeEventListener("beforeunload",this.unloadHandler),this.scroll.destroy(),this.activeTime.destroy(),this.mousePath.destroy(),this.exitIntent.destroy(),this.rageClick.destroy(),this.clickTracker.destroy(),this.textSelect.destroy(),this.disconnectLCP(),this.log("TrackIQ destroyed")}scheduleFingerprint(){let e=async()=>{let{fpId:n,payload:i}=await S();this.fpId=n,this.fpPayload=i,this.log("fingerprint computed",{fpId:n})};"requestIdleCallback"in window?requestIdleCallback(()=>{e().catch(()=>{})},{timeout:3e3}):setTimeout(()=>{e().catch(()=>{})},1)}flush(){let e=Date.now(),n=!this.session.firstPageviewSent;V(this.beacon,{session_id:this.session.sessionId,visitor_id:this.session.visitorId,url:this.pageURL,referrer:this.pageReferrer,ts_start:this.session.tsStart,ts_end:e,active_time:this.activeTime.activeTimeMs,max_scroll:this.scroll.maxScrollDepth,milestones:this.scroll.reachedMilestones,mouse_path:this.mousePath.points,fp_id:this.fpId,fingerprint:n?this.fpPayload:void 0,device:n?L():void 0,language:D(),languages:R(),connection_type:M(),prefers_dark_mode:N(),prefers_reduced_motion:H(),navigation_type:F(),lcp:this.lcp,dnt:O(),cookies_enabled:B(),local_storage_available:A(),session_storage_available:I(),indexed_db_available:P()}).catch(()=>{}),this.session.firstPageviewSent=!0,this.log("pageview sent")}sendBehaviorEvent(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};x(this.beacon,i)}log(e,n){this.config.debug&&console.log(`[TrackIQ] ${e}`,n!=null?n:"")}};export{K as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
async function c(t){let n=new TextEncoder().encode(t),i=await crypto.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(i)).map(o=>o.toString(16).padStart(2,"0")).join("")}async function Z(){try{let t=document.createElement("canvas");t.width=280,t.height=60;let e=t.getContext("2d");return e?(e.textBaseline="top",e.font="14px Arial",e.fillStyle="#f60",e.fillRect(125,1,62,20),e.fillStyle="#069",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",2,15),e.fillStyle="rgba(102, 204, 0, 0.7)",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",4,45),c(t.toDataURL())):"unavailable"}catch{return"unavailable"}}function z(){try{let t=document.createElement("canvas"),e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.getExtension("WEBGL_debug_renderer_info");return n?e.getParameter(n.UNMASKED_RENDERER_WEBGL):"unavailable"}catch{return"unavailable"}}async function ee(){try{let t=document.createElement("canvas");t.width=16,t.height=16;let e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.createShader(e.VERTEX_SHADER),i=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(n,"attribute vec2 p;void main(){gl_Position=vec4(p,0,1);}"),e.shaderSource(i,"void main(){gl_FragColor=vec4(0.2,0.4,0.6,1.0);}"),e.compileShader(n),e.compileShader(i);let r=e.createProgram();e.attachShader(r,n),e.attachShader(r,i),e.linkProgram(r),e.useProgram(r);let o=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,o),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-.5,-.5,.5,-.5,0,.5]),e.STATIC_DRAW);let s=e.getAttribLocation(r,"p");e.enableVertexAttribArray(s),e.vertexAttribPointer(s,2,e.FLOAT,!1,0,0),e.drawArrays(e.TRIANGLES,0,3);let a=new Uint8Array(256*4);return e.readPixels(0,0,16,16,e.RGBA,e.UNSIGNED_BYTE,a),c(a.join(","))}catch{return"unavailable"}}async function te(){try{let t=window.OfflineAudioContext||window.webkitOfflineAudioContext;if(!t)return"unavailable";let e=new t(1,44100,44100),n=e.createOscillator();n.type="triangle",n.frequency.setValueAtTime(1e4,e.currentTime);let i=e.createDynamicsCompressor();i.threshold.setValueAtTime(-50,e.currentTime),i.knee.setValueAtTime(40,e.currentTime),i.ratio.setValueAtTime(12,e.currentTime),i.attack.setValueAtTime(0,e.currentTime),i.release.setValueAtTime(.25,e.currentTime),n.connect(i),i.connect(e.destination),n.start(0);let o=(await e.startRendering()).getChannelData(0),s=0;for(let a=4500;a<5e3;a++)s+=Math.abs(o[a]);return c(s.toFixed(10))}catch{return"blocked"}}var ne=["Arial","Arial Black","Arial Narrow","Calibri","Cambria","Candara","Comic Sans MS","Consolas","Constantia","Corbel","Courier New","Franklin Gothic Medium","Garamond","Georgia","Gill Sans","Helvetica","Impact","Lucida Console","Lucida Sans Unicode","Microsoft Sans Serif","Palatino Linotype","Segoe UI","Tahoma","Times New Roman","Trebuchet MS","Verdana","Adobe Caslon Pro","Adobe Garamond Pro","Myriad Pro","Roboto","Open Sans","Lato","Montserrat","Oswald","Source Sans Pro","SF Pro Display","SF Pro Text","Helvetica Neue","Futura","Segoe Print","Segoe Script","MS Gothic","Liberation Sans","Liberation Serif","Ubuntu","DejaVu Sans","Wingdings","Symbol","Webdings"];function ie(){try{let e=document.createElement("canvas").getContext("2d");if(!e)return[];let n="mmmmmmmmmmlli",i="72px",r="monospace";e.font=`${i} ${r}`;let o=e.measureText(n).width;return ne.filter(s=>(e.font=`${i} '${s}', ${r}`,e.measureText(n).width!==o))}catch{return[]}}function re(){try{return Array.from(navigator.plugins).map(t=>t.name)}catch{return[]}}async function T(){let[t,e,n]=await Promise.all([Z(),ee(),te()]),i=z(),r=ie(),o=re(),s={canvas_hash:t,webgl_renderer:i,webgl_hash:e,audio_hash:n,fonts_detected:r,plugins:o},a=[t,i,e,n,r.join(","),o.join(",")].join("|");return{fpId:await c(a),payload:s}}async function E(t){return c(t)}var k="tiq_vid",_="tiq_sid";function l(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function C(){try{let t=localStorage.getItem(k);return t||(t=l(),localStorage.setItem(k,t)),t}catch{return l()}}function I(){try{let t=sessionStorage.getItem(_);return t||(t=l(),sessionStorage.setItem(_,t)),t}catch{return l()}}function A(){try{let t="__tiq_test__";return localStorage.setItem(t,"1"),localStorage.removeItem(t),!0}catch{return!1}}function P(){try{let t="__tiq_test__";return sessionStorage.setItem(t,"1"),sessionStorage.removeItem(t),!0}catch{return!1}}function L(){try{return typeof indexedDB!="undefined"&&indexedDB!==null}catch{return!1}}function D(){return{user_agent:navigator.userAgent,screen_w:screen.width,screen_h:screen.height,viewport_w:window.innerWidth,viewport_h:window.innerHeight,device_pixel_ratio:window.devicePixelRatio||1,color_depth:screen.colorDepth,cpu_cores:navigator.hardwareConcurrency||0,device_memory:navigator.deviceMemory||0,touch:navigator.maxTouchPoints>0,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}}function R(){return navigator.language||""}function M(){return Array.from(navigator.languages||[navigator.language])}function d(){var t;return(t=navigator.connection)!=null?t:{}}function N(){return d().effectiveType||"unknown"}function O(){var t;return(t=d().downlink)!=null?t:0}function F(){var t;return(t=d().rtt)!=null?t:0}function H(){var t;return(t=d().saveData)!=null?t:!1}function B(){return window.matchMedia("(prefers-color-scheme: dark)").matches}function U(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}function G(){try{let t=performance.getEntriesByType("navigation")[0];return(t==null?void 0:t.type)||"navigate"}catch{return"navigate"}}function V(){return navigator.doNotTrack==="1"||window.doNotTrack==="1"}function K(){return navigator.cookieEnabled}var oe=[25,50,75,90],u=class{constructor(){this.maxScroll=0;this.milestones=new Set;this.handler=()=>this.onScroll(),window.addEventListener("scroll",this.handler,{passive:!0})}onScroll(){let e=document.body.scrollHeight-window.innerHeight;if(e<=0)return;let n=Math.round(window.scrollY/e*100);n>this.maxScroll&&(this.maxScroll=n);for(let i of oe)n>=i&&this.milestones.add(i)}get maxScrollDepth(){return this.maxScroll}get reachedMilestones(){return Array.from(this.milestones)}destroy(){window.removeEventListener("scroll",this.handler)}},W=["mousemove","scroll","click","keydown","touchstart"],se=3e4,h=class{constructor(){this.accumulated=0;this.lastActiveAt=Date.now();this.idle=!1;this.hidden=!1;this.idleTimer=null;this.activityHandler=()=>this.onActivity(),this.visibilityHandler=()=>this.onVisibilityChange();for(let e of W)window.addEventListener(e,this.activityHandler,{passive:!0});document.addEventListener("visibilitychange",this.visibilityHandler),this.scheduleIdleCheck()}onActivity(){this.hidden||(this.idle?(this.lastActiveAt=Date.now(),this.idle=!1):this.flush(),this.scheduleIdleCheck())}onVisibilityChange(){document.hidden?(this.flush(),this.hidden=!0):(this.hidden=!1,this.lastActiveAt=Date.now())}flush(){!this.idle&&!this.hidden&&(this.accumulated+=Date.now()-this.lastActiveAt,this.lastActiveAt=Date.now())}scheduleIdleCheck(){this.idleTimer&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{this.flush(),this.idle=!0},se)}get activeTimeMs(){return this.flush(),this.accumulated}destroy(){for(let e of W)window.removeEventListener(e,this.activityHandler);document.removeEventListener("visibilitychange",this.visibilityHandler),this.idleTimer&&clearTimeout(this.idleTimer)}},ae=30,ce=1e3,v=class{constructor(){this.path=[];this.lastSampleAt=0;this.handler=e=>this.onMouseMove(e),window.addEventListener("mousemove",this.handler,{passive:!0})}onMouseMove(e){let n=Date.now();this.path.length>=ae||n-this.lastSampleAt<ce||(this.path.push({x:e.clientX,y:e.clientY,t:n}),this.lastSampleAt=n)}get points(){return this.path}destroy(){window.removeEventListener("mousemove",this.handler)}},p=class{constructor(e){this.onExitIntent=e;this.fired=!1;this.handler=n=>{!this.fired&&n.clientY<10&&(this.fired=!0,this.onExitIntent(n.clientX,n.clientY))},document.addEventListener("mousemove",this.handler,{passive:!0})}destroy(){document.removeEventListener("mousemove",this.handler)}},le=1e3,de=3,f=class{constructor(e){this.onRageClick=e;this.recentClicks=[];this.handler=n=>this.onClick(n),window.addEventListener("click",this.handler,{passive:!0})}onClick(e){let n=Date.now();if(this.recentClicks=this.recentClicks.filter(i=>n-i.ts<le),this.recentClicks.push({ts:n,x:e.clientX,y:e.clientY}),this.recentClicks.length>=de){let i=b(e.target);this.onRageClick(e.clientX,e.clientY,this.recentClicks.length,i),this.recentClicks=[]}}destroy(){window.removeEventListener("click",this.handler)}},m=class{constructor(e){this.onClick=e;this.handler=n=>{let i=n.target;if(y(i))return;let r=ue(i);this.onClick(n.clientX,n.clientY,Date.now(),b(i),r)},window.addEventListener("click",this.handler,{passive:!0})}destroy(){window.removeEventListener("click",this.handler)}},g=class{constructor(e){this.onSelect=e;this.handler=()=>{var o;let n=window.getSelection();if(!n||n.isCollapsed)return;let i=n.toString().trim();if(!i||i.length<3)return;let r=(o=n.anchorNode)==null?void 0:o.parentElement;r&&y(r)||this.onSelect(i.slice(0,200),b(r||document.body))},document.addEventListener("selectionchange",this.handler,{passive:!0})}destroy(){document.removeEventListener("selectionchange",this.handler)}};function $(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=new PerformanceObserver(n=>{let i=n.getEntries(),r=i[i.length-1];r&&t(Math.round(r.startTime))});return e.observe({type:"largest-contentful-paint",buffered:!0}),()=>e.disconnect()}catch{return()=>{}}}function q(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=0,n=new PerformanceObserver(i=>{for(let r of i.getEntries()){let o=r,s=o.processingStart?o.processingStart-o.startTime+o.duration:o.duration;s>e&&(e=s,t(Math.round(e)))}});return n.observe({type:"event",buffered:!0,durationThreshold:16}),()=>n.disconnect()}catch{return()=>{}}}function Y(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=0,n=new PerformanceObserver(i=>{for(let r of i.getEntries()){let o=r;o.hadRecentInput||(e+=o.value,t(parseFloat(e.toFixed(4))))}});return n.observe({type:"layout-shift",buffered:!0}),()=>n.disconnect()}catch{return()=>{}}}function j(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=new PerformanceObserver(n=>{for(let i of n.getEntries())if(i.name==="first-contentful-paint"){t(Math.round(i.startTime)),e.disconnect();return}});return e.observe({type:"paint",buffered:!0}),()=>e.disconnect()}catch{return()=>{}}}function X(){try{let t=performance.getEntriesByType("navigation")[0];return t?Math.round(t.responseStart-t.requestStart):0}catch{return 0}}function y(t){var n;if(!t)return!1;let e=(n=t.tagName)==null?void 0:n.toLowerCase();return["input","textarea","select","option"].includes(e)}function b(t){if(!t||!t.tagName)return"";let e=t.tagName.toLowerCase(),n=t.id?`#${t.id}`:"",i=t.classList.length?`.${Array.from(t.classList).slice(0,2).join(".")}`:"";return`${e}${n}${i}`.slice(0,60)}function ue(t){return!t||y(t)?"":(t.textContent||"").trim().slice(0,50)}var he="https://api.trackiq.io";async function Q(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/pageview`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};if(w(i,n,r),t.selfHosted){let o=await E(t.apiKey),s=JSON.stringify({key_hash:o,type:"pageview"});w(`${he}/v1/consume`,s,{"Content-Type":"application/json"})}}function x(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/event`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};w(i,n,r)}function w(t,e,n){try{fetch(t,{method:"POST",headers:n,body:e,keepalive:!0}).catch(()=>{})}catch{}}var ve="https://api.trackiq.io",J=class{constructor(e){this.fpId="";this.lcp=0;this.inp=0;this.cls=0;this.fcp=0;this.ttfb=0;var n,i;this.config={dataEndpoint:ve,debug:!1,...e},this.beacon={apiKey:this.config.apiKey,dataEndpoint:this.config.dataEndpoint,selfHosted:(n=e.selfHosted)!=null?n:!1},this.pageURL=window.location.href,this.pageReferrer=(i=e.referrer)!=null?i:document.referrer,this.session={visitorId:C(),sessionId:I(),tsStart:Date.now(),firstPageviewSent:!1},this.scroll=new u,this.activeTime=new h,this.mousePath=new v,this.exitIntent=new p((r,o)=>{this.sendBehaviorEvent("exit_intent",{x:r,y:o})}),this.rageClick=new f((r,o,s,a)=>{this.sendBehaviorEvent("rage_click",{x:r,y:o,count:s,element:a})}),this.clickTracker=new m((r,o,s,a,S)=>{this.sendBehaviorEvent("click",{x:r,y:o,ts:s,element:a,text:S})}),this.textSelect=new g((r,o)=>{this.sendBehaviorEvent("text_select",{text:r,element:o})}),this.disconnectLCP=$(r=>{this.lcp=r}),q(r=>{this.inp=r}),Y(r=>{this.cls=r}),j(r=>{this.fcp=r}),this.ttfb=X(),this.scheduleFingerprint(),this.unloadHandler=()=>{this.flush()},window.addEventListener("beforeunload",this.unloadHandler),window.trackiq={event:this.event.bind(this)},this.log("TrackIQ initialised",{visitorId:this.session.visitorId})}event(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};x(this.beacon,i),this.log("event sent",{type:e,data:n})}destroy(){this.flush(),window.removeEventListener("beforeunload",this.unloadHandler),this.scroll.destroy(),this.activeTime.destroy(),this.mousePath.destroy(),this.exitIntent.destroy(),this.rageClick.destroy(),this.clickTracker.destroy(),this.textSelect.destroy(),this.disconnectLCP(),this.log("TrackIQ destroyed")}scheduleFingerprint(){let e=async()=>{let{fpId:n,payload:i}=await T();this.fpId=n,this.fpPayload=i,this.log("fingerprint computed",{fpId:n})};"requestIdleCallback"in window?requestIdleCallback(()=>{e().catch(()=>{})},{timeout:3e3}):setTimeout(()=>{e().catch(()=>{})},1)}flush(){let e=Date.now(),n=!this.session.firstPageviewSent;Q(this.beacon,{session_id:this.session.sessionId,visitor_id:this.session.visitorId,url:this.pageURL,referrer:this.pageReferrer,ts_start:this.session.tsStart,ts_end:e,active_time:this.activeTime.activeTimeMs,max_scroll:this.scroll.maxScrollDepth,milestones:this.scroll.reachedMilestones,mouse_path:this.mousePath.points,fp_id:this.fpId,fingerprint:n?this.fpPayload:void 0,device:n?D():void 0,language:R(),languages:M(),connection_type:N(),downlink:O(),rtt:F(),save_data:H(),prefers_dark_mode:B(),prefers_reduced_motion:U(),navigation_type:G(),lcp:this.lcp,inp:this.inp,cls:this.cls,fcp:this.fcp,ttfb:this.ttfb,dnt:V(),cookies_enabled:K(),local_storage_available:A(),session_storage_available:P(),indexed_db_available:L()}).catch(()=>{}),this.session.firstPageviewSent=!0,this.log("pageview sent")}sendBehaviorEvent(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};x(this.beacon,i)}log(e,n){this.config.debug&&console.log(`[TrackIQ] ${e}`,n!=null?n:"")}};export{J as a};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as TrackIQConfig } from './types-
|
|
2
|
-
export { D as DevicePayload, E as EventPayload, F as FingerprintPayload, M as MousePoint, P as PageviewPayload, S as SessionState } from './types-
|
|
1
|
+
import { T as TrackIQConfig } from './types-kfDmqmqD.mjs';
|
|
2
|
+
export { D as DevicePayload, E as EventPayload, F as FingerprintPayload, M as MousePoint, P as PageviewPayload, S as SessionState } from './types-kfDmqmqD.mjs';
|
|
3
3
|
|
|
4
4
|
declare class TrackIQ {
|
|
5
5
|
private readonly config;
|
|
@@ -16,6 +16,10 @@ declare class TrackIQ {
|
|
|
16
16
|
private textSelect;
|
|
17
17
|
private disconnectLCP;
|
|
18
18
|
private lcp;
|
|
19
|
+
private inp;
|
|
20
|
+
private cls;
|
|
21
|
+
private fcp;
|
|
22
|
+
private ttfb;
|
|
19
23
|
private readonly pageURL;
|
|
20
24
|
private readonly pageReferrer;
|
|
21
25
|
private unloadHandler;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as TrackIQConfig } from './types-
|
|
2
|
-
export { D as DevicePayload, E as EventPayload, F as FingerprintPayload, M as MousePoint, P as PageviewPayload, S as SessionState } from './types-
|
|
1
|
+
import { T as TrackIQConfig } from './types-kfDmqmqD.js';
|
|
2
|
+
export { D as DevicePayload, E as EventPayload, F as FingerprintPayload, M as MousePoint, P as PageviewPayload, S as SessionState } from './types-kfDmqmqD.js';
|
|
3
3
|
|
|
4
4
|
declare class TrackIQ {
|
|
5
5
|
private readonly config;
|
|
@@ -16,6 +16,10 @@ declare class TrackIQ {
|
|
|
16
16
|
private textSelect;
|
|
17
17
|
private disconnectLCP;
|
|
18
18
|
private lcp;
|
|
19
|
+
private inp;
|
|
20
|
+
private cls;
|
|
21
|
+
private fcp;
|
|
22
|
+
private ttfb;
|
|
19
23
|
private readonly pageURL;
|
|
20
24
|
private readonly pageReferrer;
|
|
21
25
|
private unloadHandler;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var y=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var j=(t,e)=>{for(var n in e)y(t,n,{get:e[n],enumerable:!0})},Q=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Y(e))!q.call(t,r)&&r!==n&&y(t,r,{get:()=>e[r],enumerable:!(i=W(e,r))||i.enumerable});return t};var X=t=>Q(y({},"__esModule",{value:!0}),t);var he={};j(he,{TrackIQ:()=>f});module.exports=X(he);async function c(t){let n=new TextEncoder().encode(t),i=await crypto.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(i)).map(o=>o.toString(16).padStart(2,"0")).join("")}async function J(){try{let t=document.createElement("canvas");t.width=280,t.height=60;let e=t.getContext("2d");return e?(e.textBaseline="top",e.font="14px Arial",e.fillStyle="#f60",e.fillRect(125,1,62,20),e.fillStyle="#069",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",2,15),e.fillStyle="rgba(102, 204, 0, 0.7)",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",4,45),c(t.toDataURL())):"unavailable"}catch{return"unavailable"}}function Z(){try{let t=document.createElement("canvas"),e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.getExtension("WEBGL_debug_renderer_info");return n?e.getParameter(n.UNMASKED_RENDERER_WEBGL):"unavailable"}catch{return"unavailable"}}async function z(){try{let t=document.createElement("canvas");t.width=16,t.height=16;let e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.createShader(e.VERTEX_SHADER),i=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(n,"attribute vec2 p;void main(){gl_Position=vec4(p,0,1);}"),e.shaderSource(i,"void main(){gl_FragColor=vec4(0.2,0.4,0.6,1.0);}"),e.compileShader(n),e.compileShader(i);let r=e.createProgram();e.attachShader(r,n),e.attachShader(r,i),e.linkProgram(r),e.useProgram(r);let o=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,o),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-.5,-.5,.5,-.5,0,.5]),e.STATIC_DRAW);let s=e.getAttribLocation(r,"p");e.enableVertexAttribArray(s),e.vertexAttribPointer(s,2,e.FLOAT,!1,0,0),e.drawArrays(e.TRIANGLES,0,3);let a=new Uint8Array(256*4);return e.readPixels(0,0,16,16,e.RGBA,e.UNSIGNED_BYTE,a),c(a.join(","))}catch{return"unavailable"}}async function ee(){try{let t=window.OfflineAudioContext||window.webkitOfflineAudioContext;if(!t)return"unavailable";let e=new t(1,44100,44100),n=e.createOscillator();n.type="triangle",n.frequency.setValueAtTime(1e4,e.currentTime);let i=e.createDynamicsCompressor();i.threshold.setValueAtTime(-50,e.currentTime),i.knee.setValueAtTime(40,e.currentTime),i.ratio.setValueAtTime(12,e.currentTime),i.attack.setValueAtTime(0,e.currentTime),i.release.setValueAtTime(.25,e.currentTime),n.connect(i),i.connect(e.destination),n.start(0);let o=(await e.startRendering()).getChannelData(0),s=0;for(let a=4500;a<5e3;a++)s+=Math.abs(o[a]);return c(s.toFixed(10))}catch{return"blocked"}}var te=["Arial","Arial Black","Arial Narrow","Calibri","Cambria","Candara","Comic Sans MS","Consolas","Constantia","Corbel","Courier New","Franklin Gothic Medium","Garamond","Georgia","Gill Sans","Helvetica","Impact","Lucida Console","Lucida Sans Unicode","Microsoft Sans Serif","Palatino Linotype","Segoe UI","Tahoma","Times New Roman","Trebuchet MS","Verdana","Adobe Caslon Pro","Adobe Garamond Pro","Myriad Pro","Roboto","Open Sans","Lato","Montserrat","Oswald","Source Sans Pro","SF Pro Display","SF Pro Text","Helvetica Neue","Futura","Segoe Print","Segoe Script","MS Gothic","Liberation Sans","Liberation Serif","Ubuntu","DejaVu Sans","Wingdings","Symbol","Webdings"];function ne(){try{let e=document.createElement("canvas").getContext("2d");if(!e)return[];let n="mmmmmmmmmmlli",i="72px",r="monospace";e.font=`${i} ${r}`;let o=e.measureText(n).width;return te.filter(s=>(e.font=`${i} '${s}', ${r}`,e.measureText(n).width!==o))}catch{return[]}}function ie(){try{return Array.from(navigator.plugins).map(t=>t.name)}catch{return[]}}async function T(){let[t,e,n]=await Promise.all([J(),z(),ee()]),i=Z(),r=ne(),o=ie(),s={canvas_hash:t,webgl_renderer:i,webgl_hash:e,audio_hash:n,fonts_detected:r,plugins:o},a=[t,i,e,n,r.join(","),o.join(",")].join("|");return{fpId:await c(a),payload:s}}async function E(t){return c(t)}var k="tiq_vid",_="tiq_sid";function l(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function C(){try{let t=localStorage.getItem(k);return t||(t=l(),localStorage.setItem(k,t)),t}catch{return l()}}function A(){try{let t=sessionStorage.getItem(_);return t||(t=l(),sessionStorage.setItem(_,t)),t}catch{return l()}}function I(){try{let t="__tiq_test__";return localStorage.setItem(t,"1"),localStorage.removeItem(t),!0}catch{return!1}}function P(){try{let t="__tiq_test__";return sessionStorage.setItem(t,"1"),sessionStorage.removeItem(t),!0}catch{return!1}}function L(){try{return typeof indexedDB!="undefined"&&indexedDB!==null}catch{return!1}}function D(){return{user_agent:navigator.userAgent,screen_w:screen.width,screen_h:screen.height,viewport_w:window.innerWidth,viewport_h:window.innerHeight,device_pixel_ratio:window.devicePixelRatio||1,color_depth:screen.colorDepth,cpu_cores:navigator.hardwareConcurrency||0,device_memory:navigator.deviceMemory||0,touch:navigator.maxTouchPoints>0,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}}function R(){return navigator.language||""}function M(){return Array.from(navigator.languages||[navigator.language])}function N(){let t=navigator.connection;return(t==null?void 0:t.effectiveType)||"unknown"}function F(){return window.matchMedia("(prefers-color-scheme: dark)").matches}function H(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}function O(){try{let t=performance.getEntriesByType("navigation")[0];return(t==null?void 0:t.type)||"navigate"}catch{return"navigate"}}function B(){return navigator.doNotTrack==="1"||window.doNotTrack==="1"}function U(){return navigator.cookieEnabled}var re=[25,50,75,90],d=class{constructor(){this.maxScroll=0;this.milestones=new Set;this.handler=()=>this.onScroll(),window.addEventListener("scroll",this.handler,{passive:!0})}onScroll(){let e=document.body.scrollHeight-window.innerHeight;if(e<=0)return;let n=Math.round(window.scrollY/e*100);n>this.maxScroll&&(this.maxScroll=n);for(let i of re)n>=i&&this.milestones.add(i)}get maxScrollDepth(){return this.maxScroll}get reachedMilestones(){return Array.from(this.milestones)}destroy(){window.removeEventListener("scroll",this.handler)}},G=["mousemove","scroll","click","keydown","touchstart"],oe=3e4,u=class{constructor(){this.accumulated=0;this.lastActiveAt=Date.now();this.idle=!1;this.hidden=!1;this.idleTimer=null;this.activityHandler=()=>this.onActivity(),this.visibilityHandler=()=>this.onVisibilityChange();for(let e of G)window.addEventListener(e,this.activityHandler,{passive:!0});document.addEventListener("visibilitychange",this.visibilityHandler),this.scheduleIdleCheck()}onActivity(){this.hidden||(this.idle?(this.lastActiveAt=Date.now(),this.idle=!1):this.flush(),this.scheduleIdleCheck())}onVisibilityChange(){document.hidden?(this.flush(),this.hidden=!0):(this.hidden=!1,this.lastActiveAt=Date.now())}flush(){!this.idle&&!this.hidden&&(this.accumulated+=Date.now()-this.lastActiveAt,this.lastActiveAt=Date.now())}scheduleIdleCheck(){this.idleTimer&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{this.flush(),this.idle=!0},oe)}get activeTimeMs(){return this.flush(),this.accumulated}destroy(){for(let e of G)window.removeEventListener(e,this.activityHandler);document.removeEventListener("visibilitychange",this.visibilityHandler),this.idleTimer&&clearTimeout(this.idleTimer)}},se=30,ae=1e3,h=class{constructor(){this.path=[];this.lastSampleAt=0;this.handler=e=>this.onMouseMove(e),window.addEventListener("mousemove",this.handler,{passive:!0})}onMouseMove(e){let n=Date.now();this.path.length>=se||n-this.lastSampleAt<ae||(this.path.push({x:e.clientX,y:e.clientY,t:n}),this.lastSampleAt=n)}get points(){return this.path}destroy(){window.removeEventListener("mousemove",this.handler)}},v=class{constructor(e){this.onExitIntent=e;this.fired=!1;this.handler=n=>{!this.fired&&n.clientY<10&&(this.fired=!0,this.onExitIntent(n.clientX,n.clientY))},document.addEventListener("mousemove",this.handler,{passive:!0})}destroy(){document.removeEventListener("mousemove",this.handler)}},ce=1e3,le=3,p=class{constructor(e){this.onRageClick=e;this.recentClicks=[];this.handler=n=>this.onClick(n),window.addEventListener("click",this.handler,{passive:!0})}onClick(e){let n=Date.now();if(this.recentClicks=this.recentClicks.filter(i=>n-i.ts<ce),this.recentClicks.push({ts:n,x:e.clientX,y:e.clientY}),this.recentClicks.length>=le){let i=x(e.target);this.onRageClick(e.clientX,e.clientY,this.recentClicks.length,i),this.recentClicks=[]}}destroy(){window.removeEventListener("click",this.handler)}},g=class{constructor(e){this.onClick=e;this.handler=n=>{let i=n.target;if(w(i))return;let r=de(i);this.onClick(n.clientX,n.clientY,Date.now(),x(i),r)},window.addEventListener("click",this.handler,{passive:!0})}destroy(){window.removeEventListener("click",this.handler)}},m=class{constructor(e){this.onSelect=e;this.handler=()=>{var o;let n=window.getSelection();if(!n||n.isCollapsed)return;let i=n.toString().trim();if(!i||i.length<3)return;let r=(o=n.anchorNode)==null?void 0:o.parentElement;r&&w(r)||this.onSelect(i.slice(0,200),x(r||document.body))},document.addEventListener("selectionchange",this.handler,{passive:!0})}destroy(){document.removeEventListener("selectionchange",this.handler)}};function V(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=new PerformanceObserver(n=>{let i=n.getEntries(),r=i[i.length-1];r&&t(Math.round(r.startTime))});return e.observe({type:"largest-contentful-paint",buffered:!0}),()=>e.disconnect()}catch{return()=>{}}}function w(t){var n;if(!t)return!1;let e=(n=t.tagName)==null?void 0:n.toLowerCase();return["input","textarea","select","option"].includes(e)}function x(t){if(!t||!t.tagName)return"";let e=t.tagName.toLowerCase(),n=t.id?`#${t.id}`:"",i=t.classList.length?`.${Array.from(t.classList).slice(0,2).join(".")}`:"";return`${e}${n}${i}`.slice(0,60)}function de(t){return!t||w(t)?"":(t.textContent||"").trim().slice(0,50)}var K="https://api.trackiq.io";async function $(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/pageview`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};if(b(i,n,r),!(t.dataEndpoint.replace(/\/$/,"")===K.replace(/\/$/,""))){let s=await E(t.apiKey),a=JSON.stringify({key_hash:s,type:"pageview"});b(`${K}/v1/consume`,a,{"Content-Type":"application/json"})}}function S(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/event`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};b(i,n,r)}function b(t,e,n){try{fetch(t,{method:"POST",headers:n,body:e,keepalive:!0}).catch(()=>{})}catch{}}var ue="https://api.trackiq.io",f=class{constructor(e){this.fpId="";this.lcp=0;var n;this.config={dataEndpoint:ue,debug:!1,...e},this.beacon={apiKey:this.config.apiKey,dataEndpoint:this.config.dataEndpoint},this.pageURL=window.location.href,this.pageReferrer=(n=e.referrer)!=null?n:document.referrer,this.session={visitorId:C(),sessionId:A(),tsStart:Date.now(),firstPageviewSent:!1},this.scroll=new d,this.activeTime=new u,this.mousePath=new h,this.exitIntent=new v((i,r)=>{this.sendBehaviorEvent("exit_intent",{x:i,y:r})}),this.rageClick=new p((i,r,o,s)=>{this.sendBehaviorEvent("rage_click",{x:i,y:r,count:o,element:s})}),this.clickTracker=new g((i,r,o,s,a)=>{this.sendBehaviorEvent("click",{x:i,y:r,ts:o,element:s,text:a})}),this.textSelect=new m((i,r)=>{this.sendBehaviorEvent("text_select",{text:i,element:r})}),this.disconnectLCP=V(i=>{this.lcp=i}),this.scheduleFingerprint(),this.unloadHandler=()=>{this.flush()},window.addEventListener("beforeunload",this.unloadHandler),window.trackiq={event:this.event.bind(this)},this.log("TrackIQ initialised",{visitorId:this.session.visitorId})}event(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};S(this.beacon,i),this.log("event sent",{type:e,data:n})}destroy(){this.flush(),window.removeEventListener("beforeunload",this.unloadHandler),this.scroll.destroy(),this.activeTime.destroy(),this.mousePath.destroy(),this.exitIntent.destroy(),this.rageClick.destroy(),this.clickTracker.destroy(),this.textSelect.destroy(),this.disconnectLCP(),this.log("TrackIQ destroyed")}scheduleFingerprint(){let e=async()=>{let{fpId:n,payload:i}=await T();this.fpId=n,this.fpPayload=i,this.log("fingerprint computed",{fpId:n})};"requestIdleCallback"in window?requestIdleCallback(()=>{e().catch(()=>{})},{timeout:3e3}):setTimeout(()=>{e().catch(()=>{})},1)}flush(){let e=Date.now(),n=!this.session.firstPageviewSent;$(this.beacon,{session_id:this.session.sessionId,visitor_id:this.session.visitorId,url:this.pageURL,referrer:this.pageReferrer,ts_start:this.session.tsStart,ts_end:e,active_time:this.activeTime.activeTimeMs,max_scroll:this.scroll.maxScrollDepth,milestones:this.scroll.reachedMilestones,mouse_path:this.mousePath.points,fp_id:this.fpId,fingerprint:n?this.fpPayload:void 0,device:n?D():void 0,language:R(),languages:M(),connection_type:N(),prefers_dark_mode:F(),prefers_reduced_motion:H(),navigation_type:O(),lcp:this.lcp,dnt:B(),cookies_enabled:U(),local_storage_available:I(),session_storage_available:P(),indexed_db_available:L()}).catch(()=>{}),this.session.firstPageviewSent=!0,this.log("pageview sent")}sendBehaviorEvent(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};S(this.beacon,i)}log(e,n){this.config.debug&&console.log(`[TrackIQ] ${e}`,n!=null?n:"")}};0&&(module.exports={TrackIQ});
|
|
1
|
+
"use strict";var w=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var ne=(t,e)=>{for(var n in e)w(t,n,{get:e[n],enumerable:!0})},ie=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ee(e))!te.call(t,r)&&r!==n&&w(t,r,{get:()=>e[r],enumerable:!(i=z(e,r))||i.enumerable});return t};var re=t=>ie(w({},"__esModule",{value:!0}),t);var xe={};ne(xe,{TrackIQ:()=>y});module.exports=re(xe);async function c(t){let n=new TextEncoder().encode(t),i=await crypto.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(i)).map(o=>o.toString(16).padStart(2,"0")).join("")}async function oe(){try{let t=document.createElement("canvas");t.width=280,t.height=60;let e=t.getContext("2d");return e?(e.textBaseline="top",e.font="14px Arial",e.fillStyle="#f60",e.fillRect(125,1,62,20),e.fillStyle="#069",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",2,15),e.fillStyle="rgba(102, 204, 0, 0.7)",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",4,45),c(t.toDataURL())):"unavailable"}catch{return"unavailable"}}function se(){try{let t=document.createElement("canvas"),e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.getExtension("WEBGL_debug_renderer_info");return n?e.getParameter(n.UNMASKED_RENDERER_WEBGL):"unavailable"}catch{return"unavailable"}}async function ae(){try{let t=document.createElement("canvas");t.width=16,t.height=16;let e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.createShader(e.VERTEX_SHADER),i=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(n,"attribute vec2 p;void main(){gl_Position=vec4(p,0,1);}"),e.shaderSource(i,"void main(){gl_FragColor=vec4(0.2,0.4,0.6,1.0);}"),e.compileShader(n),e.compileShader(i);let r=e.createProgram();e.attachShader(r,n),e.attachShader(r,i),e.linkProgram(r),e.useProgram(r);let o=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,o),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-.5,-.5,.5,-.5,0,.5]),e.STATIC_DRAW);let s=e.getAttribLocation(r,"p");e.enableVertexAttribArray(s),e.vertexAttribPointer(s,2,e.FLOAT,!1,0,0),e.drawArrays(e.TRIANGLES,0,3);let a=new Uint8Array(256*4);return e.readPixels(0,0,16,16,e.RGBA,e.UNSIGNED_BYTE,a),c(a.join(","))}catch{return"unavailable"}}async function ce(){try{let t=window.OfflineAudioContext||window.webkitOfflineAudioContext;if(!t)return"unavailable";let e=new t(1,44100,44100),n=e.createOscillator();n.type="triangle",n.frequency.setValueAtTime(1e4,e.currentTime);let i=e.createDynamicsCompressor();i.threshold.setValueAtTime(-50,e.currentTime),i.knee.setValueAtTime(40,e.currentTime),i.ratio.setValueAtTime(12,e.currentTime),i.attack.setValueAtTime(0,e.currentTime),i.release.setValueAtTime(.25,e.currentTime),n.connect(i),i.connect(e.destination),n.start(0);let o=(await e.startRendering()).getChannelData(0),s=0;for(let a=4500;a<5e3;a++)s+=Math.abs(o[a]);return c(s.toFixed(10))}catch{return"blocked"}}var le=["Arial","Arial Black","Arial Narrow","Calibri","Cambria","Candara","Comic Sans MS","Consolas","Constantia","Corbel","Courier New","Franklin Gothic Medium","Garamond","Georgia","Gill Sans","Helvetica","Impact","Lucida Console","Lucida Sans Unicode","Microsoft Sans Serif","Palatino Linotype","Segoe UI","Tahoma","Times New Roman","Trebuchet MS","Verdana","Adobe Caslon Pro","Adobe Garamond Pro","Myriad Pro","Roboto","Open Sans","Lato","Montserrat","Oswald","Source Sans Pro","SF Pro Display","SF Pro Text","Helvetica Neue","Futura","Segoe Print","Segoe Script","MS Gothic","Liberation Sans","Liberation Serif","Ubuntu","DejaVu Sans","Wingdings","Symbol","Webdings"];function de(){try{let e=document.createElement("canvas").getContext("2d");if(!e)return[];let n="mmmmmmmmmmlli",i="72px",r="monospace";e.font=`${i} ${r}`;let o=e.measureText(n).width;return le.filter(s=>(e.font=`${i} '${s}', ${r}`,e.measureText(n).width!==o))}catch{return[]}}function ue(){try{return Array.from(navigator.plugins).map(t=>t.name)}catch{return[]}}async function k(){let[t,e,n]=await Promise.all([oe(),ae(),ce()]),i=se(),r=de(),o=ue(),s={canvas_hash:t,webgl_renderer:i,webgl_hash:e,audio_hash:n,fonts_detected:r,plugins:o},a=[t,i,e,n,r.join(","),o.join(",")].join("|");return{fpId:await c(a),payload:s}}async function _(t){return c(t)}var C="tiq_vid",P="tiq_sid";function l(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function I(){try{let t=localStorage.getItem(C);return t||(t=l(),localStorage.setItem(C,t)),t}catch{return l()}}function A(){try{let t=sessionStorage.getItem(P);return t||(t=l(),sessionStorage.setItem(P,t)),t}catch{return l()}}function L(){try{let t="__tiq_test__";return localStorage.setItem(t,"1"),localStorage.removeItem(t),!0}catch{return!1}}function D(){try{let t="__tiq_test__";return sessionStorage.setItem(t,"1"),sessionStorage.removeItem(t),!0}catch{return!1}}function M(){try{return typeof indexedDB!="undefined"&&indexedDB!==null}catch{return!1}}function R(){return{user_agent:navigator.userAgent,screen_w:screen.width,screen_h:screen.height,viewport_w:window.innerWidth,viewport_h:window.innerHeight,device_pixel_ratio:window.devicePixelRatio||1,color_depth:screen.colorDepth,cpu_cores:navigator.hardwareConcurrency||0,device_memory:navigator.deviceMemory||0,touch:navigator.maxTouchPoints>0,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}}function N(){return navigator.language||""}function F(){return Array.from(navigator.languages||[navigator.language])}function d(){var t;return(t=navigator.connection)!=null?t:{}}function O(){return d().effectiveType||"unknown"}function H(){var t;return(t=d().downlink)!=null?t:0}function B(){var t;return(t=d().rtt)!=null?t:0}function U(){var t;return(t=d().saveData)!=null?t:!1}function G(){return window.matchMedia("(prefers-color-scheme: dark)").matches}function V(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}function Y(){try{let t=performance.getEntriesByType("navigation")[0];return(t==null?void 0:t.type)||"navigate"}catch{return"navigate"}}function K(){return navigator.doNotTrack==="1"||window.doNotTrack==="1"}function W(){return navigator.cookieEnabled}var he=[25,50,75,90],u=class{constructor(){this.maxScroll=0;this.milestones=new Set;this.handler=()=>this.onScroll(),window.addEventListener("scroll",this.handler,{passive:!0})}onScroll(){let e=document.body.scrollHeight-window.innerHeight;if(e<=0)return;let n=Math.round(window.scrollY/e*100);n>this.maxScroll&&(this.maxScroll=n);for(let i of he)n>=i&&this.milestones.add(i)}get maxScrollDepth(){return this.maxScroll}get reachedMilestones(){return Array.from(this.milestones)}destroy(){window.removeEventListener("scroll",this.handler)}},X=["mousemove","scroll","click","keydown","touchstart"],ve=3e4,h=class{constructor(){this.accumulated=0;this.lastActiveAt=Date.now();this.idle=!1;this.hidden=!1;this.idleTimer=null;this.activityHandler=()=>this.onActivity(),this.visibilityHandler=()=>this.onVisibilityChange();for(let e of X)window.addEventListener(e,this.activityHandler,{passive:!0});document.addEventListener("visibilitychange",this.visibilityHandler),this.scheduleIdleCheck()}onActivity(){this.hidden||(this.idle?(this.lastActiveAt=Date.now(),this.idle=!1):this.flush(),this.scheduleIdleCheck())}onVisibilityChange(){document.hidden?(this.flush(),this.hidden=!0):(this.hidden=!1,this.lastActiveAt=Date.now())}flush(){!this.idle&&!this.hidden&&(this.accumulated+=Date.now()-this.lastActiveAt,this.lastActiveAt=Date.now())}scheduleIdleCheck(){this.idleTimer&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{this.flush(),this.idle=!0},ve)}get activeTimeMs(){return this.flush(),this.accumulated}destroy(){for(let e of X)window.removeEventListener(e,this.activityHandler);document.removeEventListener("visibilitychange",this.visibilityHandler),this.idleTimer&&clearTimeout(this.idleTimer)}},pe=30,fe=1e3,v=class{constructor(){this.path=[];this.lastSampleAt=0;this.handler=e=>this.onMouseMove(e),window.addEventListener("mousemove",this.handler,{passive:!0})}onMouseMove(e){let n=Date.now();this.path.length>=pe||n-this.lastSampleAt<fe||(this.path.push({x:Math.round(e.clientX+window.scrollX),y:Math.round(e.clientY+window.scrollY),t:n}),this.lastSampleAt=n)}get points(){return this.path}destroy(){window.removeEventListener("mousemove",this.handler)}},p=class{constructor(e){this.onExitIntent=e;this.fired=!1;this.handler=n=>{!this.fired&&n.clientY<10&&(this.fired=!0,this.onExitIntent(Math.round(n.clientX+window.scrollX),Math.round(n.clientY+window.scrollY)))},document.addEventListener("mousemove",this.handler,{passive:!0})}destroy(){document.removeEventListener("mousemove",this.handler)}},me=1e3,ge=3,f=class{constructor(e){this.onRageClick=e;this.recentClicks=[];this.handler=n=>this.onClick(n),window.addEventListener("click",this.handler,{passive:!0})}onClick(e){let n=Date.now();if(this.recentClicks=this.recentClicks.filter(i=>n-i.ts<me),this.recentClicks.push({ts:n,x:Math.round(e.clientX+window.scrollX),y:Math.round(e.clientY+window.scrollY)}),this.recentClicks.length>=ge){let i=x(e.target);this.onRageClick(Math.round(e.clientX+window.scrollX),Math.round(e.clientY+window.scrollY),this.recentClicks.length,i),this.recentClicks=[]}}destroy(){window.removeEventListener("click",this.handler)}},m=class{constructor(e){this.onClick=e;this.handler=n=>{let i=n.target;if(b(i))return;let r=ye(i);this.onClick(Math.round(n.clientX+window.scrollX),Math.round(n.clientY+window.scrollY),Date.now(),x(i),r)},window.addEventListener("click",this.handler,{passive:!0})}destroy(){window.removeEventListener("click",this.handler)}},g=class{constructor(e){this.onSelect=e;this.handler=()=>{var o;let n=window.getSelection();if(!n||n.isCollapsed)return;let i=n.toString().trim();if(!i||i.length<3)return;let r=(o=n.anchorNode)==null?void 0:o.parentElement;r&&b(r)||this.onSelect(i.slice(0,200),x(r||document.body))},document.addEventListener("selectionchange",this.handler,{passive:!0})}destroy(){document.removeEventListener("selectionchange",this.handler)}};function $(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=new PerformanceObserver(n=>{let i=n.getEntries(),r=i[i.length-1];r&&t(Math.round(r.startTime))});return e.observe({type:"largest-contentful-paint",buffered:!0}),()=>e.disconnect()}catch{return()=>{}}}function q(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=0,n=new PerformanceObserver(i=>{for(let r of i.getEntries()){let o=r,s=o.processingStart?o.processingStart-o.startTime+o.duration:o.duration;s>e&&(e=s,t(Math.round(e)))}});return n.observe({type:"event",buffered:!0,durationThreshold:16}),()=>n.disconnect()}catch{return()=>{}}}function j(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=0,n=new PerformanceObserver(i=>{for(let r of i.getEntries()){let o=r;o.hadRecentInput||(e+=o.value,t(parseFloat(e.toFixed(4))))}});return n.observe({type:"layout-shift",buffered:!0}),()=>n.disconnect()}catch{return()=>{}}}function Q(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=new PerformanceObserver(n=>{for(let i of n.getEntries())if(i.name==="first-contentful-paint"){t(Math.round(i.startTime)),e.disconnect();return}});return e.observe({type:"paint",buffered:!0}),()=>e.disconnect()}catch{return()=>{}}}function J(){try{let t=performance.getEntriesByType("navigation")[0];return t?Math.round(t.responseStart-t.requestStart):0}catch{return 0}}function b(t){var n;if(!t)return!1;let e=(n=t.tagName)==null?void 0:n.toLowerCase();return["input","textarea","select","option"].includes(e)}function x(t){if(!t||!t.tagName)return"";let e=t.tagName.toLowerCase(),n=t.id?`#${t.id}`:"",i=t.classList.length?`.${Array.from(t.classList).slice(0,2).join(".")}`:"";return`${e}${n}${i}`.slice(0,60)}function ye(t){return!t||b(t)?"":(t.textContent||"").trim().slice(0,50)}var we="https://api.trackiq.io";async function Z(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/pageview`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};if(S(i,n,r),t.selfHosted){let o=await _(t.apiKey),s=JSON.stringify({key_hash:o,type:"pageview"});S(`${we}/v1/consume`,s,{"Content-Type":"application/json"})}}function T(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/event`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};S(i,n,r)}function S(t,e,n){try{fetch(t,{method:"POST",headers:n,body:e,keepalive:!0}).catch(()=>{})}catch{}}var be="https://api.trackiq.io",y=class{constructor(e){this.fpId="";this.lcp=0;this.inp=0;this.cls=0;this.fcp=0;this.ttfb=0;var n,i;this.config={dataEndpoint:be,debug:!1,...e},this.beacon={apiKey:this.config.apiKey,dataEndpoint:this.config.dataEndpoint,selfHosted:(n=e.selfHosted)!=null?n:!1},this.pageURL=window.location.href,this.pageReferrer=(i=e.referrer)!=null?i:document.referrer,this.session={visitorId:I(),sessionId:A(),tsStart:Date.now(),firstPageviewSent:!1},this.scroll=new u,this.activeTime=new h,this.mousePath=new v,this.exitIntent=new p((r,o)=>{this.sendBehaviorEvent("exit_intent",{x:r,y:o})}),this.rageClick=new f((r,o,s,a)=>{this.sendBehaviorEvent("rage_click",{x:r,y:o,count:s,element:a})}),this.clickTracker=new m((r,o,s,a,E)=>{this.sendBehaviorEvent("click",{x:r,y:o,ts:s,element:a,text:E})}),this.textSelect=new g((r,o)=>{this.sendBehaviorEvent("text_select",{text:r,element:o})}),this.disconnectLCP=$(r=>{this.lcp=r}),q(r=>{this.inp=r}),j(r=>{this.cls=r}),Q(r=>{this.fcp=r}),this.ttfb=J(),this.scheduleFingerprint(),this.unloadHandler=()=>{this.flush()},window.addEventListener("beforeunload",this.unloadHandler),window.trackiq={event:this.event.bind(this)},this.log("TrackIQ initialised",{visitorId:this.session.visitorId})}event(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};T(this.beacon,i),this.log("event sent",{type:e,data:n})}destroy(){this.flush(),window.removeEventListener("beforeunload",this.unloadHandler),this.scroll.destroy(),this.activeTime.destroy(),this.mousePath.destroy(),this.exitIntent.destroy(),this.rageClick.destroy(),this.clickTracker.destroy(),this.textSelect.destroy(),this.disconnectLCP(),this.log("TrackIQ destroyed")}scheduleFingerprint(){let e=async()=>{let{fpId:n,payload:i}=await k();this.fpId=n,this.fpPayload=i,this.log("fingerprint computed",{fpId:n})};"requestIdleCallback"in window?requestIdleCallback(()=>{e().catch(()=>{})},{timeout:3e3}):setTimeout(()=>{e().catch(()=>{})},1)}flush(){let e=Date.now(),n=!this.session.firstPageviewSent;Z(this.beacon,{session_id:this.session.sessionId,visitor_id:this.session.visitorId,url:this.pageURL,referrer:this.pageReferrer,ts_start:this.session.tsStart,ts_end:e,active_time:this.activeTime.activeTimeMs,max_scroll:this.scroll.maxScrollDepth,milestones:this.scroll.reachedMilestones,mouse_path:this.mousePath.points,fp_id:this.fpId,fingerprint:n?this.fpPayload:void 0,device:n?R():void 0,language:N(),languages:F(),connection_type:O(),downlink:H(),rtt:B(),save_data:U(),prefers_dark_mode:G(),prefers_reduced_motion:V(),navigation_type:Y(),lcp:this.lcp,inp:this.inp,cls:this.cls,fcp:this.fcp,ttfb:this.ttfb,dnt:K(),cookies_enabled:W(),local_storage_available:L(),session_storage_available:D(),indexed_db_available:M()}).catch(()=>{}),this.session.firstPageviewSent=!0,this.log("pageview sent")}sendBehaviorEvent(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};T(this.beacon,i)}log(e,n){this.config.debug&&console.log(`[TrackIQ] ${e}`,n!=null?n:"")}};0&&(module.exports={TrackIQ});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./chunk-
|
|
1
|
+
import{a as e}from"./chunk-GSAGJBV2.mjs";export{e as TrackIQ};
|
package/dist/next.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { T as TrackIQConfig } from './types-
|
|
3
|
+
import { T as TrackIQConfig } from './types-kfDmqmqD.mjs';
|
|
4
4
|
|
|
5
5
|
interface TrackIQProviderProps extends TrackIQConfig {
|
|
6
6
|
children: ReactNode;
|
package/dist/next.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { T as TrackIQConfig } from './types-
|
|
3
|
+
import { T as TrackIQConfig } from './types-kfDmqmqD.js';
|
|
4
4
|
|
|
5
5
|
interface TrackIQProviderProps extends TrackIQConfig {
|
|
6
6
|
children: ReactNode;
|
package/dist/next.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var w=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var X=(t,e)=>{for(var n in e)w(t,n,{get:e[n],enumerable:!0})},J=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of q(e))!j.call(t,r)&&r!==n&&w(t,r,{get:()=>e[r],enumerable:!(i=Y(e,r))||i.enumerable});return t};var Z=t=>J(w({},"__esModule",{value:!0}),t);var ge={};X(ge,{TrackIQProvider:()=>pe});module.exports=Z(ge);var Q=require("react");async function c(t){let n=new TextEncoder().encode(t),i=await crypto.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(i)).map(o=>o.toString(16).padStart(2,"0")).join("")}async function z(){try{let t=document.createElement("canvas");t.width=280,t.height=60;let e=t.getContext("2d");return e?(e.textBaseline="top",e.font="14px Arial",e.fillStyle="#f60",e.fillRect(125,1,62,20),e.fillStyle="#069",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",2,15),e.fillStyle="rgba(102, 204, 0, 0.7)",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",4,45),c(t.toDataURL())):"unavailable"}catch{return"unavailable"}}function ee(){try{let t=document.createElement("canvas"),e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.getExtension("WEBGL_debug_renderer_info");return n?e.getParameter(n.UNMASKED_RENDERER_WEBGL):"unavailable"}catch{return"unavailable"}}async function te(){try{let t=document.createElement("canvas");t.width=16,t.height=16;let e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.createShader(e.VERTEX_SHADER),i=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(n,"attribute vec2 p;void main(){gl_Position=vec4(p,0,1);}"),e.shaderSource(i,"void main(){gl_FragColor=vec4(0.2,0.4,0.6,1.0);}"),e.compileShader(n),e.compileShader(i);let r=e.createProgram();e.attachShader(r,n),e.attachShader(r,i),e.linkProgram(r),e.useProgram(r);let o=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,o),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-.5,-.5,.5,-.5,0,.5]),e.STATIC_DRAW);let s=e.getAttribLocation(r,"p");e.enableVertexAttribArray(s),e.vertexAttribPointer(s,2,e.FLOAT,!1,0,0),e.drawArrays(e.TRIANGLES,0,3);let a=new Uint8Array(256*4);return e.readPixels(0,0,16,16,e.RGBA,e.UNSIGNED_BYTE,a),c(a.join(","))}catch{return"unavailable"}}async function ne(){try{let t=window.OfflineAudioContext||window.webkitOfflineAudioContext;if(!t)return"unavailable";let e=new t(1,44100,44100),n=e.createOscillator();n.type="triangle",n.frequency.setValueAtTime(1e4,e.currentTime);let i=e.createDynamicsCompressor();i.threshold.setValueAtTime(-50,e.currentTime),i.knee.setValueAtTime(40,e.currentTime),i.ratio.setValueAtTime(12,e.currentTime),i.attack.setValueAtTime(0,e.currentTime),i.release.setValueAtTime(.25,e.currentTime),n.connect(i),i.connect(e.destination),n.start(0);let o=(await e.startRendering()).getChannelData(0),s=0;for(let a=4500;a<5e3;a++)s+=Math.abs(o[a]);return c(s.toFixed(10))}catch{return"blocked"}}var ie=["Arial","Arial Black","Arial Narrow","Calibri","Cambria","Candara","Comic Sans MS","Consolas","Constantia","Corbel","Courier New","Franklin Gothic Medium","Garamond","Georgia","Gill Sans","Helvetica","Impact","Lucida Console","Lucida Sans Unicode","Microsoft Sans Serif","Palatino Linotype","Segoe UI","Tahoma","Times New Roman","Trebuchet MS","Verdana","Adobe Caslon Pro","Adobe Garamond Pro","Myriad Pro","Roboto","Open Sans","Lato","Montserrat","Oswald","Source Sans Pro","SF Pro Display","SF Pro Text","Helvetica Neue","Futura","Segoe Print","Segoe Script","MS Gothic","Liberation Sans","Liberation Serif","Ubuntu","DejaVu Sans","Wingdings","Symbol","Webdings"];function re(){try{let e=document.createElement("canvas").getContext("2d");if(!e)return[];let n="mmmmmmmmmmlli",i="72px",r="monospace";e.font=`${i} ${r}`;let o=e.measureText(n).width;return ie.filter(s=>(e.font=`${i} '${s}', ${r}`,e.measureText(n).width!==o))}catch{return[]}}function oe(){try{return Array.from(navigator.plugins).map(t=>t.name)}catch{return[]}}async function E(){let[t,e,n]=await Promise.all([z(),te(),ne()]),i=ee(),r=re(),o=oe(),s={canvas_hash:t,webgl_renderer:i,webgl_hash:e,audio_hash:n,fonts_detected:r,plugins:o},a=[t,i,e,n,r.join(","),o.join(",")].join("|");return{fpId:await c(a),payload:s}}async function k(t){return c(t)}var _="tiq_vid",C="tiq_sid";function l(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function A(){try{let t=localStorage.getItem(_);return t||(t=l(),localStorage.setItem(_,t)),t}catch{return l()}}function I(){try{let t=sessionStorage.getItem(C);return t||(t=l(),sessionStorage.setItem(C,t)),t}catch{return l()}}function P(){try{let t="__tiq_test__";return localStorage.setItem(t,"1"),localStorage.removeItem(t),!0}catch{return!1}}function L(){try{let t="__tiq_test__";return sessionStorage.setItem(t,"1"),sessionStorage.removeItem(t),!0}catch{return!1}}function R(){try{return typeof indexedDB!="undefined"&&indexedDB!==null}catch{return!1}}function D(){return{user_agent:navigator.userAgent,screen_w:screen.width,screen_h:screen.height,viewport_w:window.innerWidth,viewport_h:window.innerHeight,device_pixel_ratio:window.devicePixelRatio||1,color_depth:screen.colorDepth,cpu_cores:navigator.hardwareConcurrency||0,device_memory:navigator.deviceMemory||0,touch:navigator.maxTouchPoints>0,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}}function M(){return navigator.language||""}function N(){return Array.from(navigator.languages||[navigator.language])}function H(){let t=navigator.connection;return(t==null?void 0:t.effectiveType)||"unknown"}function F(){return window.matchMedia("(prefers-color-scheme: dark)").matches}function O(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}function B(){try{let t=performance.getEntriesByType("navigation")[0];return(t==null?void 0:t.type)||"navigate"}catch{return"navigate"}}function U(){return navigator.doNotTrack==="1"||window.doNotTrack==="1"}function G(){return navigator.cookieEnabled}var se=[25,50,75,90],d=class{constructor(){this.maxScroll=0;this.milestones=new Set;this.handler=()=>this.onScroll(),window.addEventListener("scroll",this.handler,{passive:!0})}onScroll(){let e=document.body.scrollHeight-window.innerHeight;if(e<=0)return;let n=Math.round(window.scrollY/e*100);n>this.maxScroll&&(this.maxScroll=n);for(let i of se)n>=i&&this.milestones.add(i)}get maxScrollDepth(){return this.maxScroll}get reachedMilestones(){return Array.from(this.milestones)}destroy(){window.removeEventListener("scroll",this.handler)}},V=["mousemove","scroll","click","keydown","touchstart"],ae=3e4,u=class{constructor(){this.accumulated=0;this.lastActiveAt=Date.now();this.idle=!1;this.hidden=!1;this.idleTimer=null;this.activityHandler=()=>this.onActivity(),this.visibilityHandler=()=>this.onVisibilityChange();for(let e of V)window.addEventListener(e,this.activityHandler,{passive:!0});document.addEventListener("visibilitychange",this.visibilityHandler),this.scheduleIdleCheck()}onActivity(){this.hidden||(this.idle?(this.lastActiveAt=Date.now(),this.idle=!1):this.flush(),this.scheduleIdleCheck())}onVisibilityChange(){document.hidden?(this.flush(),this.hidden=!0):(this.hidden=!1,this.lastActiveAt=Date.now())}flush(){!this.idle&&!this.hidden&&(this.accumulated+=Date.now()-this.lastActiveAt,this.lastActiveAt=Date.now())}scheduleIdleCheck(){this.idleTimer&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{this.flush(),this.idle=!0},ae)}get activeTimeMs(){return this.flush(),this.accumulated}destroy(){for(let e of V)window.removeEventListener(e,this.activityHandler);document.removeEventListener("visibilitychange",this.visibilityHandler),this.idleTimer&&clearTimeout(this.idleTimer)}},ce=30,le=1e3,h=class{constructor(){this.path=[];this.lastSampleAt=0;this.handler=e=>this.onMouseMove(e),window.addEventListener("mousemove",this.handler,{passive:!0})}onMouseMove(e){let n=Date.now();this.path.length>=ce||n-this.lastSampleAt<le||(this.path.push({x:e.clientX,y:e.clientY,t:n}),this.lastSampleAt=n)}get points(){return this.path}destroy(){window.removeEventListener("mousemove",this.handler)}},v=class{constructor(e){this.onExitIntent=e;this.fired=!1;this.handler=n=>{!this.fired&&n.clientY<10&&(this.fired=!0,this.onExitIntent(n.clientX,n.clientY))},document.addEventListener("mousemove",this.handler,{passive:!0})}destroy(){document.removeEventListener("mousemove",this.handler)}},de=1e3,ue=3,p=class{constructor(e){this.onRageClick=e;this.recentClicks=[];this.handler=n=>this.onClick(n),window.addEventListener("click",this.handler,{passive:!0})}onClick(e){let n=Date.now();if(this.recentClicks=this.recentClicks.filter(i=>n-i.ts<de),this.recentClicks.push({ts:n,x:e.clientX,y:e.clientY}),this.recentClicks.length>=ue){let i=b(e.target);this.onRageClick(e.clientX,e.clientY,this.recentClicks.length,i),this.recentClicks=[]}}destroy(){window.removeEventListener("click",this.handler)}},g=class{constructor(e){this.onClick=e;this.handler=n=>{let i=n.target;if(x(i))return;let r=he(i);this.onClick(n.clientX,n.clientY,Date.now(),b(i),r)},window.addEventListener("click",this.handler,{passive:!0})}destroy(){window.removeEventListener("click",this.handler)}},m=class{constructor(e){this.onSelect=e;this.handler=()=>{var o;let n=window.getSelection();if(!n||n.isCollapsed)return;let i=n.toString().trim();if(!i||i.length<3)return;let r=(o=n.anchorNode)==null?void 0:o.parentElement;r&&x(r)||this.onSelect(i.slice(0,200),b(r||document.body))},document.addEventListener("selectionchange",this.handler,{passive:!0})}destroy(){document.removeEventListener("selectionchange",this.handler)}};function $(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=new PerformanceObserver(n=>{let i=n.getEntries(),r=i[i.length-1];r&&t(Math.round(r.startTime))});return e.observe({type:"largest-contentful-paint",buffered:!0}),()=>e.disconnect()}catch{return()=>{}}}function x(t){var n;if(!t)return!1;let e=(n=t.tagName)==null?void 0:n.toLowerCase();return["input","textarea","select","option"].includes(e)}function b(t){if(!t||!t.tagName)return"";let e=t.tagName.toLowerCase(),n=t.id?`#${t.id}`:"",i=t.classList.length?`.${Array.from(t.classList).slice(0,2).join(".")}`:"";return`${e}${n}${i}`.slice(0,60)}function he(t){return!t||x(t)?"":(t.textContent||"").trim().slice(0,50)}var K="https://api.trackiq.io";async function W(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/pageview`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};if(S(i,n,r),!(t.dataEndpoint.replace(/\/$/,"")===K.replace(/\/$/,""))){let s=await k(t.apiKey),a=JSON.stringify({key_hash:s,type:"pageview"});S(`${K}/v1/consume`,a,{"Content-Type":"application/json"})}}function T(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/event`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};S(i,n,r)}function S(t,e,n){try{fetch(t,{method:"POST",headers:n,body:e,keepalive:!0}).catch(()=>{})}catch{}}var ve="https://api.trackiq.io",f=class{constructor(e){this.fpId="";this.lcp=0;var n;this.config={dataEndpoint:ve,debug:!1,...e},this.beacon={apiKey:this.config.apiKey,dataEndpoint:this.config.dataEndpoint},this.pageURL=window.location.href,this.pageReferrer=(n=e.referrer)!=null?n:document.referrer,this.session={visitorId:A(),sessionId:I(),tsStart:Date.now(),firstPageviewSent:!1},this.scroll=new d,this.activeTime=new u,this.mousePath=new h,this.exitIntent=new v((i,r)=>{this.sendBehaviorEvent("exit_intent",{x:i,y:r})}),this.rageClick=new p((i,r,o,s)=>{this.sendBehaviorEvent("rage_click",{x:i,y:r,count:o,element:s})}),this.clickTracker=new g((i,r,o,s,a)=>{this.sendBehaviorEvent("click",{x:i,y:r,ts:o,element:s,text:a})}),this.textSelect=new m((i,r)=>{this.sendBehaviorEvent("text_select",{text:i,element:r})}),this.disconnectLCP=$(i=>{this.lcp=i}),this.scheduleFingerprint(),this.unloadHandler=()=>{this.flush()},window.addEventListener("beforeunload",this.unloadHandler),window.trackiq={event:this.event.bind(this)},this.log("TrackIQ initialised",{visitorId:this.session.visitorId})}event(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};T(this.beacon,i),this.log("event sent",{type:e,data:n})}destroy(){this.flush(),window.removeEventListener("beforeunload",this.unloadHandler),this.scroll.destroy(),this.activeTime.destroy(),this.mousePath.destroy(),this.exitIntent.destroy(),this.rageClick.destroy(),this.clickTracker.destroy(),this.textSelect.destroy(),this.disconnectLCP(),this.log("TrackIQ destroyed")}scheduleFingerprint(){let e=async()=>{let{fpId:n,payload:i}=await E();this.fpId=n,this.fpPayload=i,this.log("fingerprint computed",{fpId:n})};"requestIdleCallback"in window?requestIdleCallback(()=>{e().catch(()=>{})},{timeout:3e3}):setTimeout(()=>{e().catch(()=>{})},1)}flush(){let e=Date.now(),n=!this.session.firstPageviewSent;W(this.beacon,{session_id:this.session.sessionId,visitor_id:this.session.visitorId,url:this.pageURL,referrer:this.pageReferrer,ts_start:this.session.tsStart,ts_end:e,active_time:this.activeTime.activeTimeMs,max_scroll:this.scroll.maxScrollDepth,milestones:this.scroll.reachedMilestones,mouse_path:this.mousePath.points,fp_id:this.fpId,fingerprint:n?this.fpPayload:void 0,device:n?D():void 0,language:M(),languages:N(),connection_type:H(),prefers_dark_mode:F(),prefers_reduced_motion:O(),navigation_type:B(),lcp:this.lcp,dnt:U(),cookies_enabled:G(),local_storage_available:P(),session_storage_available:L(),indexed_db_available:R()}).catch(()=>{}),this.session.firstPageviewSent=!0,this.log("pageview sent")}sendBehaviorEvent(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};T(this.beacon,i)}log(e,n){this.config.debug&&console.log(`[TrackIQ] ${e}`,n!=null?n:"")}};var y=require("react/jsx-runtime");function pe({apiKey:t,dataEndpoint:e,debug:n,children:i}){return(0,Q.useEffect)(()=>{if(typeof window=="undefined")return;let r=new f({apiKey:t,dataEndpoint:e,debug:n});return()=>r.destroy()},[t,e,n]),(0,y.jsx)(y.Fragment,{children:i})}0&&(module.exports={TrackIQProvider});
|
|
1
|
+
"use strict";"use client";var b=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var ie=Object.prototype.hasOwnProperty;var re=(t,e)=>{for(var n in e)b(t,n,{get:e[n],enumerable:!0})},oe=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ne(e))!ie.call(t,r)&&r!==n&&b(t,r,{get:()=>e[r],enumerable:!(i=te(e,r))||i.enumerable});return t};var se=t=>oe(b({},"__esModule",{value:!0}),t);var Ee={};re(Ee,{TrackIQProvider:()=>Se});module.exports=se(Ee);var ee=require("react");async function c(t){let n=new TextEncoder().encode(t),i=await crypto.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(i)).map(o=>o.toString(16).padStart(2,"0")).join("")}async function ae(){try{let t=document.createElement("canvas");t.width=280,t.height=60;let e=t.getContext("2d");return e?(e.textBaseline="top",e.font="14px Arial",e.fillStyle="#f60",e.fillRect(125,1,62,20),e.fillStyle="#069",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",2,15),e.fillStyle="rgba(102, 204, 0, 0.7)",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",4,45),c(t.toDataURL())):"unavailable"}catch{return"unavailable"}}function ce(){try{let t=document.createElement("canvas"),e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.getExtension("WEBGL_debug_renderer_info");return n?e.getParameter(n.UNMASKED_RENDERER_WEBGL):"unavailable"}catch{return"unavailable"}}async function le(){try{let t=document.createElement("canvas");t.width=16,t.height=16;let e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.createShader(e.VERTEX_SHADER),i=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(n,"attribute vec2 p;void main(){gl_Position=vec4(p,0,1);}"),e.shaderSource(i,"void main(){gl_FragColor=vec4(0.2,0.4,0.6,1.0);}"),e.compileShader(n),e.compileShader(i);let r=e.createProgram();e.attachShader(r,n),e.attachShader(r,i),e.linkProgram(r),e.useProgram(r);let o=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,o),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-.5,-.5,.5,-.5,0,.5]),e.STATIC_DRAW);let s=e.getAttribLocation(r,"p");e.enableVertexAttribArray(s),e.vertexAttribPointer(s,2,e.FLOAT,!1,0,0),e.drawArrays(e.TRIANGLES,0,3);let a=new Uint8Array(256*4);return e.readPixels(0,0,16,16,e.RGBA,e.UNSIGNED_BYTE,a),c(a.join(","))}catch{return"unavailable"}}async function de(){try{let t=window.OfflineAudioContext||window.webkitOfflineAudioContext;if(!t)return"unavailable";let e=new t(1,44100,44100),n=e.createOscillator();n.type="triangle",n.frequency.setValueAtTime(1e4,e.currentTime);let i=e.createDynamicsCompressor();i.threshold.setValueAtTime(-50,e.currentTime),i.knee.setValueAtTime(40,e.currentTime),i.ratio.setValueAtTime(12,e.currentTime),i.attack.setValueAtTime(0,e.currentTime),i.release.setValueAtTime(.25,e.currentTime),n.connect(i),i.connect(e.destination),n.start(0);let o=(await e.startRendering()).getChannelData(0),s=0;for(let a=4500;a<5e3;a++)s+=Math.abs(o[a]);return c(s.toFixed(10))}catch{return"blocked"}}var ue=["Arial","Arial Black","Arial Narrow","Calibri","Cambria","Candara","Comic Sans MS","Consolas","Constantia","Corbel","Courier New","Franklin Gothic Medium","Garamond","Georgia","Gill Sans","Helvetica","Impact","Lucida Console","Lucida Sans Unicode","Microsoft Sans Serif","Palatino Linotype","Segoe UI","Tahoma","Times New Roman","Trebuchet MS","Verdana","Adobe Caslon Pro","Adobe Garamond Pro","Myriad Pro","Roboto","Open Sans","Lato","Montserrat","Oswald","Source Sans Pro","SF Pro Display","SF Pro Text","Helvetica Neue","Futura","Segoe Print","Segoe Script","MS Gothic","Liberation Sans","Liberation Serif","Ubuntu","DejaVu Sans","Wingdings","Symbol","Webdings"];function he(){try{let e=document.createElement("canvas").getContext("2d");if(!e)return[];let n="mmmmmmmmmmlli",i="72px",r="monospace";e.font=`${i} ${r}`;let o=e.measureText(n).width;return ue.filter(s=>(e.font=`${i} '${s}', ${r}`,e.measureText(n).width!==o))}catch{return[]}}function ve(){try{return Array.from(navigator.plugins).map(t=>t.name)}catch{return[]}}async function C(){let[t,e,n]=await Promise.all([ae(),le(),de()]),i=ce(),r=he(),o=ve(),s={canvas_hash:t,webgl_renderer:i,webgl_hash:e,audio_hash:n,fonts_detected:r,plugins:o},a=[t,i,e,n,r.join(","),o.join(",")].join("|");return{fpId:await c(a),payload:s}}async function _(t){return c(t)}var I="tiq_vid",P="tiq_sid";function l(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function A(){try{let t=localStorage.getItem(I);return t||(t=l(),localStorage.setItem(I,t)),t}catch{return l()}}function L(){try{let t=sessionStorage.getItem(P);return t||(t=l(),sessionStorage.setItem(P,t)),t}catch{return l()}}function D(){try{let t="__tiq_test__";return localStorage.setItem(t,"1"),localStorage.removeItem(t),!0}catch{return!1}}function M(){try{let t="__tiq_test__";return sessionStorage.setItem(t,"1"),sessionStorage.removeItem(t),!0}catch{return!1}}function R(){try{return typeof indexedDB!="undefined"&&indexedDB!==null}catch{return!1}}function N(){return{user_agent:navigator.userAgent,screen_w:screen.width,screen_h:screen.height,viewport_w:window.innerWidth,viewport_h:window.innerHeight,device_pixel_ratio:window.devicePixelRatio||1,color_depth:screen.colorDepth,cpu_cores:navigator.hardwareConcurrency||0,device_memory:navigator.deviceMemory||0,touch:navigator.maxTouchPoints>0,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}}function O(){return navigator.language||""}function F(){return Array.from(navigator.languages||[navigator.language])}function d(){var t;return(t=navigator.connection)!=null?t:{}}function H(){return d().effectiveType||"unknown"}function B(){var t;return(t=d().downlink)!=null?t:0}function U(){var t;return(t=d().rtt)!=null?t:0}function G(){var t;return(t=d().saveData)!=null?t:!1}function V(){return window.matchMedia("(prefers-color-scheme: dark)").matches}function Y(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}function K(){try{let t=performance.getEntriesByType("navigation")[0];return(t==null?void 0:t.type)||"navigate"}catch{return"navigate"}}function W(){return navigator.doNotTrack==="1"||window.doNotTrack==="1"}function Q(){return navigator.cookieEnabled}var pe=[25,50,75,90],u=class{constructor(){this.maxScroll=0;this.milestones=new Set;this.handler=()=>this.onScroll(),window.addEventListener("scroll",this.handler,{passive:!0})}onScroll(){let e=document.body.scrollHeight-window.innerHeight;if(e<=0)return;let n=Math.round(window.scrollY/e*100);n>this.maxScroll&&(this.maxScroll=n);for(let i of pe)n>=i&&this.milestones.add(i)}get maxScrollDepth(){return this.maxScroll}get reachedMilestones(){return Array.from(this.milestones)}destroy(){window.removeEventListener("scroll",this.handler)}},X=["mousemove","scroll","click","keydown","touchstart"],fe=3e4,h=class{constructor(){this.accumulated=0;this.lastActiveAt=Date.now();this.idle=!1;this.hidden=!1;this.idleTimer=null;this.activityHandler=()=>this.onActivity(),this.visibilityHandler=()=>this.onVisibilityChange();for(let e of X)window.addEventListener(e,this.activityHandler,{passive:!0});document.addEventListener("visibilitychange",this.visibilityHandler),this.scheduleIdleCheck()}onActivity(){this.hidden||(this.idle?(this.lastActiveAt=Date.now(),this.idle=!1):this.flush(),this.scheduleIdleCheck())}onVisibilityChange(){document.hidden?(this.flush(),this.hidden=!0):(this.hidden=!1,this.lastActiveAt=Date.now())}flush(){!this.idle&&!this.hidden&&(this.accumulated+=Date.now()-this.lastActiveAt,this.lastActiveAt=Date.now())}scheduleIdleCheck(){this.idleTimer&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{this.flush(),this.idle=!0},fe)}get activeTimeMs(){return this.flush(),this.accumulated}destroy(){for(let e of X)window.removeEventListener(e,this.activityHandler);document.removeEventListener("visibilitychange",this.visibilityHandler),this.idleTimer&&clearTimeout(this.idleTimer)}},me=30,ge=1e3,v=class{constructor(){this.path=[];this.lastSampleAt=0;this.handler=e=>this.onMouseMove(e),window.addEventListener("mousemove",this.handler,{passive:!0})}onMouseMove(e){let n=Date.now();this.path.length>=me||n-this.lastSampleAt<ge||(this.path.push({x:Math.round(e.clientX+window.scrollX),y:Math.round(e.clientY+window.scrollY),t:n}),this.lastSampleAt=n)}get points(){return this.path}destroy(){window.removeEventListener("mousemove",this.handler)}},p=class{constructor(e){this.onExitIntent=e;this.fired=!1;this.handler=n=>{!this.fired&&n.clientY<10&&(this.fired=!0,this.onExitIntent(Math.round(n.clientX+window.scrollX),Math.round(n.clientY+window.scrollY)))},document.addEventListener("mousemove",this.handler,{passive:!0})}destroy(){document.removeEventListener("mousemove",this.handler)}},ye=1e3,we=3,f=class{constructor(e){this.onRageClick=e;this.recentClicks=[];this.handler=n=>this.onClick(n),window.addEventListener("click",this.handler,{passive:!0})}onClick(e){let n=Date.now();if(this.recentClicks=this.recentClicks.filter(i=>n-i.ts<ye),this.recentClicks.push({ts:n,x:Math.round(e.clientX+window.scrollX),y:Math.round(e.clientY+window.scrollY)}),this.recentClicks.length>=we){let i=T(e.target);this.onRageClick(Math.round(e.clientX+window.scrollX),Math.round(e.clientY+window.scrollY),this.recentClicks.length,i),this.recentClicks=[]}}destroy(){window.removeEventListener("click",this.handler)}},m=class{constructor(e){this.onClick=e;this.handler=n=>{let i=n.target;if(x(i))return;let r=be(i);this.onClick(Math.round(n.clientX+window.scrollX),Math.round(n.clientY+window.scrollY),Date.now(),T(i),r)},window.addEventListener("click",this.handler,{passive:!0})}destroy(){window.removeEventListener("click",this.handler)}},g=class{constructor(e){this.onSelect=e;this.handler=()=>{var o;let n=window.getSelection();if(!n||n.isCollapsed)return;let i=n.toString().trim();if(!i||i.length<3)return;let r=(o=n.anchorNode)==null?void 0:o.parentElement;r&&x(r)||this.onSelect(i.slice(0,200),T(r||document.body))},document.addEventListener("selectionchange",this.handler,{passive:!0})}destroy(){document.removeEventListener("selectionchange",this.handler)}};function $(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=new PerformanceObserver(n=>{let i=n.getEntries(),r=i[i.length-1];r&&t(Math.round(r.startTime))});return e.observe({type:"largest-contentful-paint",buffered:!0}),()=>e.disconnect()}catch{return()=>{}}}function q(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=0,n=new PerformanceObserver(i=>{for(let r of i.getEntries()){let o=r,s=o.processingStart?o.processingStart-o.startTime+o.duration:o.duration;s>e&&(e=s,t(Math.round(e)))}});return n.observe({type:"event",buffered:!0,durationThreshold:16}),()=>n.disconnect()}catch{return()=>{}}}function j(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=0,n=new PerformanceObserver(i=>{for(let r of i.getEntries()){let o=r;o.hadRecentInput||(e+=o.value,t(parseFloat(e.toFixed(4))))}});return n.observe({type:"layout-shift",buffered:!0}),()=>n.disconnect()}catch{return()=>{}}}function J(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=new PerformanceObserver(n=>{for(let i of n.getEntries())if(i.name==="first-contentful-paint"){t(Math.round(i.startTime)),e.disconnect();return}});return e.observe({type:"paint",buffered:!0}),()=>e.disconnect()}catch{return()=>{}}}function Z(){try{let t=performance.getEntriesByType("navigation")[0];return t?Math.round(t.responseStart-t.requestStart):0}catch{return 0}}function x(t){var n;if(!t)return!1;let e=(n=t.tagName)==null?void 0:n.toLowerCase();return["input","textarea","select","option"].includes(e)}function T(t){if(!t||!t.tagName)return"";let e=t.tagName.toLowerCase(),n=t.id?`#${t.id}`:"",i=t.classList.length?`.${Array.from(t.classList).slice(0,2).join(".")}`:"";return`${e}${n}${i}`.slice(0,60)}function be(t){return!t||x(t)?"":(t.textContent||"").trim().slice(0,50)}var xe="https://api.trackiq.io";async function z(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/pageview`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};if(S(i,n,r),t.selfHosted){let o=await _(t.apiKey),s=JSON.stringify({key_hash:o,type:"pageview"});S(`${xe}/v1/consume`,s,{"Content-Type":"application/json"})}}function E(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/event`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};S(i,n,r)}function S(t,e,n){try{fetch(t,{method:"POST",headers:n,body:e,keepalive:!0}).catch(()=>{})}catch{}}var Te="https://api.trackiq.io",y=class{constructor(e){this.fpId="";this.lcp=0;this.inp=0;this.cls=0;this.fcp=0;this.ttfb=0;var n,i;this.config={dataEndpoint:Te,debug:!1,...e},this.beacon={apiKey:this.config.apiKey,dataEndpoint:this.config.dataEndpoint,selfHosted:(n=e.selfHosted)!=null?n:!1},this.pageURL=window.location.href,this.pageReferrer=(i=e.referrer)!=null?i:document.referrer,this.session={visitorId:A(),sessionId:L(),tsStart:Date.now(),firstPageviewSent:!1},this.scroll=new u,this.activeTime=new h,this.mousePath=new v,this.exitIntent=new p((r,o)=>{this.sendBehaviorEvent("exit_intent",{x:r,y:o})}),this.rageClick=new f((r,o,s,a)=>{this.sendBehaviorEvent("rage_click",{x:r,y:o,count:s,element:a})}),this.clickTracker=new m((r,o,s,a,k)=>{this.sendBehaviorEvent("click",{x:r,y:o,ts:s,element:a,text:k})}),this.textSelect=new g((r,o)=>{this.sendBehaviorEvent("text_select",{text:r,element:o})}),this.disconnectLCP=$(r=>{this.lcp=r}),q(r=>{this.inp=r}),j(r=>{this.cls=r}),J(r=>{this.fcp=r}),this.ttfb=Z(),this.scheduleFingerprint(),this.unloadHandler=()=>{this.flush()},window.addEventListener("beforeunload",this.unloadHandler),window.trackiq={event:this.event.bind(this)},this.log("TrackIQ initialised",{visitorId:this.session.visitorId})}event(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};E(this.beacon,i),this.log("event sent",{type:e,data:n})}destroy(){this.flush(),window.removeEventListener("beforeunload",this.unloadHandler),this.scroll.destroy(),this.activeTime.destroy(),this.mousePath.destroy(),this.exitIntent.destroy(),this.rageClick.destroy(),this.clickTracker.destroy(),this.textSelect.destroy(),this.disconnectLCP(),this.log("TrackIQ destroyed")}scheduleFingerprint(){let e=async()=>{let{fpId:n,payload:i}=await C();this.fpId=n,this.fpPayload=i,this.log("fingerprint computed",{fpId:n})};"requestIdleCallback"in window?requestIdleCallback(()=>{e().catch(()=>{})},{timeout:3e3}):setTimeout(()=>{e().catch(()=>{})},1)}flush(){let e=Date.now(),n=!this.session.firstPageviewSent;z(this.beacon,{session_id:this.session.sessionId,visitor_id:this.session.visitorId,url:this.pageURL,referrer:this.pageReferrer,ts_start:this.session.tsStart,ts_end:e,active_time:this.activeTime.activeTimeMs,max_scroll:this.scroll.maxScrollDepth,milestones:this.scroll.reachedMilestones,mouse_path:this.mousePath.points,fp_id:this.fpId,fingerprint:n?this.fpPayload:void 0,device:n?N():void 0,language:O(),languages:F(),connection_type:H(),downlink:B(),rtt:U(),save_data:G(),prefers_dark_mode:V(),prefers_reduced_motion:Y(),navigation_type:K(),lcp:this.lcp,inp:this.inp,cls:this.cls,fcp:this.fcp,ttfb:this.ttfb,dnt:W(),cookies_enabled:Q(),local_storage_available:D(),session_storage_available:M(),indexed_db_available:R()}).catch(()=>{}),this.session.firstPageviewSent=!0,this.log("pageview sent")}sendBehaviorEvent(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};E(this.beacon,i)}log(e,n){this.config.debug&&console.log(`[TrackIQ] ${e}`,n!=null?n:"")}};var w=require("react/jsx-runtime");function Se({apiKey:t,dataEndpoint:e,debug:n,children:i}){return(0,ee.useEffect)(()=>{if(typeof window=="undefined")return;let r=new y({apiKey:t,dataEndpoint:e,debug:n});return()=>r.destroy()},[t,e,n]),(0,w.jsx)(w.Fragment,{children:i})}0&&(module.exports={TrackIQProvider});
|
package/dist/next.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{a as t}from"./chunk-
|
|
1
|
+
"use client";import{a as t}from"./chunk-GSAGJBV2.mjs";import{useEffect as f}from"react";import{Fragment as i,jsx as p}from"react/jsx-runtime";function s({apiKey:r,dataEndpoint:e,debug:o,children:c}){return f(()=>{if(typeof window=="undefined")return;let n=new t({apiKey:r,dataEndpoint:e,debug:o});return()=>n.destroy()},[r,e,o]),p(i,{children:c})}export{s as TrackIQProvider};
|
package/dist/react.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { T as TrackIQConfig } from './types-
|
|
3
|
+
import { T as TrackIQConfig } from './types-kfDmqmqD.mjs';
|
|
4
4
|
|
|
5
5
|
interface TrackIQProviderProps extends TrackIQConfig {
|
|
6
6
|
children: ReactNode;
|
package/dist/react.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { T as TrackIQConfig } from './types-
|
|
3
|
+
import { T as TrackIQConfig } from './types-kfDmqmqD.js';
|
|
4
4
|
|
|
5
5
|
interface TrackIQProviderProps extends TrackIQConfig {
|
|
6
6
|
children: ReactNode;
|
package/dist/react.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var w=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var X=(t,e)=>{for(var n in e)w(t,n,{get:e[n],enumerable:!0})},J=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of q(e))!j.call(t,r)&&r!==n&&w(t,r,{get:()=>e[r],enumerable:!(i=Y(e,r))||i.enumerable});return t};var Z=t=>J(w({},"__esModule",{value:!0}),t);var ge={};X(ge,{TrackIQProvider:()=>pe});module.exports=Z(ge);var Q=require("react");async function c(t){let n=new TextEncoder().encode(t),i=await crypto.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(i)).map(o=>o.toString(16).padStart(2,"0")).join("")}async function z(){try{let t=document.createElement("canvas");t.width=280,t.height=60;let e=t.getContext("2d");return e?(e.textBaseline="top",e.font="14px Arial",e.fillStyle="#f60",e.fillRect(125,1,62,20),e.fillStyle="#069",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",2,15),e.fillStyle="rgba(102, 204, 0, 0.7)",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",4,45),c(t.toDataURL())):"unavailable"}catch{return"unavailable"}}function ee(){try{let t=document.createElement("canvas"),e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.getExtension("WEBGL_debug_renderer_info");return n?e.getParameter(n.UNMASKED_RENDERER_WEBGL):"unavailable"}catch{return"unavailable"}}async function te(){try{let t=document.createElement("canvas");t.width=16,t.height=16;let e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.createShader(e.VERTEX_SHADER),i=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(n,"attribute vec2 p;void main(){gl_Position=vec4(p,0,1);}"),e.shaderSource(i,"void main(){gl_FragColor=vec4(0.2,0.4,0.6,1.0);}"),e.compileShader(n),e.compileShader(i);let r=e.createProgram();e.attachShader(r,n),e.attachShader(r,i),e.linkProgram(r),e.useProgram(r);let o=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,o),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-.5,-.5,.5,-.5,0,.5]),e.STATIC_DRAW);let s=e.getAttribLocation(r,"p");e.enableVertexAttribArray(s),e.vertexAttribPointer(s,2,e.FLOAT,!1,0,0),e.drawArrays(e.TRIANGLES,0,3);let a=new Uint8Array(256*4);return e.readPixels(0,0,16,16,e.RGBA,e.UNSIGNED_BYTE,a),c(a.join(","))}catch{return"unavailable"}}async function ne(){try{let t=window.OfflineAudioContext||window.webkitOfflineAudioContext;if(!t)return"unavailable";let e=new t(1,44100,44100),n=e.createOscillator();n.type="triangle",n.frequency.setValueAtTime(1e4,e.currentTime);let i=e.createDynamicsCompressor();i.threshold.setValueAtTime(-50,e.currentTime),i.knee.setValueAtTime(40,e.currentTime),i.ratio.setValueAtTime(12,e.currentTime),i.attack.setValueAtTime(0,e.currentTime),i.release.setValueAtTime(.25,e.currentTime),n.connect(i),i.connect(e.destination),n.start(0);let o=(await e.startRendering()).getChannelData(0),s=0;for(let a=4500;a<5e3;a++)s+=Math.abs(o[a]);return c(s.toFixed(10))}catch{return"blocked"}}var ie=["Arial","Arial Black","Arial Narrow","Calibri","Cambria","Candara","Comic Sans MS","Consolas","Constantia","Corbel","Courier New","Franklin Gothic Medium","Garamond","Georgia","Gill Sans","Helvetica","Impact","Lucida Console","Lucida Sans Unicode","Microsoft Sans Serif","Palatino Linotype","Segoe UI","Tahoma","Times New Roman","Trebuchet MS","Verdana","Adobe Caslon Pro","Adobe Garamond Pro","Myriad Pro","Roboto","Open Sans","Lato","Montserrat","Oswald","Source Sans Pro","SF Pro Display","SF Pro Text","Helvetica Neue","Futura","Segoe Print","Segoe Script","MS Gothic","Liberation Sans","Liberation Serif","Ubuntu","DejaVu Sans","Wingdings","Symbol","Webdings"];function re(){try{let e=document.createElement("canvas").getContext("2d");if(!e)return[];let n="mmmmmmmmmmlli",i="72px",r="monospace";e.font=`${i} ${r}`;let o=e.measureText(n).width;return ie.filter(s=>(e.font=`${i} '${s}', ${r}`,e.measureText(n).width!==o))}catch{return[]}}function oe(){try{return Array.from(navigator.plugins).map(t=>t.name)}catch{return[]}}async function E(){let[t,e,n]=await Promise.all([z(),te(),ne()]),i=ee(),r=re(),o=oe(),s={canvas_hash:t,webgl_renderer:i,webgl_hash:e,audio_hash:n,fonts_detected:r,plugins:o},a=[t,i,e,n,r.join(","),o.join(",")].join("|");return{fpId:await c(a),payload:s}}async function k(t){return c(t)}var _="tiq_vid",C="tiq_sid";function l(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function A(){try{let t=localStorage.getItem(_);return t||(t=l(),localStorage.setItem(_,t)),t}catch{return l()}}function I(){try{let t=sessionStorage.getItem(C);return t||(t=l(),sessionStorage.setItem(C,t)),t}catch{return l()}}function P(){try{let t="__tiq_test__";return localStorage.setItem(t,"1"),localStorage.removeItem(t),!0}catch{return!1}}function L(){try{let t="__tiq_test__";return sessionStorage.setItem(t,"1"),sessionStorage.removeItem(t),!0}catch{return!1}}function R(){try{return typeof indexedDB!="undefined"&&indexedDB!==null}catch{return!1}}function D(){return{user_agent:navigator.userAgent,screen_w:screen.width,screen_h:screen.height,viewport_w:window.innerWidth,viewport_h:window.innerHeight,device_pixel_ratio:window.devicePixelRatio||1,color_depth:screen.colorDepth,cpu_cores:navigator.hardwareConcurrency||0,device_memory:navigator.deviceMemory||0,touch:navigator.maxTouchPoints>0,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}}function M(){return navigator.language||""}function N(){return Array.from(navigator.languages||[navigator.language])}function H(){let t=navigator.connection;return(t==null?void 0:t.effectiveType)||"unknown"}function F(){return window.matchMedia("(prefers-color-scheme: dark)").matches}function O(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}function B(){try{let t=performance.getEntriesByType("navigation")[0];return(t==null?void 0:t.type)||"navigate"}catch{return"navigate"}}function U(){return navigator.doNotTrack==="1"||window.doNotTrack==="1"}function G(){return navigator.cookieEnabled}var se=[25,50,75,90],d=class{constructor(){this.maxScroll=0;this.milestones=new Set;this.handler=()=>this.onScroll(),window.addEventListener("scroll",this.handler,{passive:!0})}onScroll(){let e=document.body.scrollHeight-window.innerHeight;if(e<=0)return;let n=Math.round(window.scrollY/e*100);n>this.maxScroll&&(this.maxScroll=n);for(let i of se)n>=i&&this.milestones.add(i)}get maxScrollDepth(){return this.maxScroll}get reachedMilestones(){return Array.from(this.milestones)}destroy(){window.removeEventListener("scroll",this.handler)}},V=["mousemove","scroll","click","keydown","touchstart"],ae=3e4,u=class{constructor(){this.accumulated=0;this.lastActiveAt=Date.now();this.idle=!1;this.hidden=!1;this.idleTimer=null;this.activityHandler=()=>this.onActivity(),this.visibilityHandler=()=>this.onVisibilityChange();for(let e of V)window.addEventListener(e,this.activityHandler,{passive:!0});document.addEventListener("visibilitychange",this.visibilityHandler),this.scheduleIdleCheck()}onActivity(){this.hidden||(this.idle?(this.lastActiveAt=Date.now(),this.idle=!1):this.flush(),this.scheduleIdleCheck())}onVisibilityChange(){document.hidden?(this.flush(),this.hidden=!0):(this.hidden=!1,this.lastActiveAt=Date.now())}flush(){!this.idle&&!this.hidden&&(this.accumulated+=Date.now()-this.lastActiveAt,this.lastActiveAt=Date.now())}scheduleIdleCheck(){this.idleTimer&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{this.flush(),this.idle=!0},ae)}get activeTimeMs(){return this.flush(),this.accumulated}destroy(){for(let e of V)window.removeEventListener(e,this.activityHandler);document.removeEventListener("visibilitychange",this.visibilityHandler),this.idleTimer&&clearTimeout(this.idleTimer)}},ce=30,le=1e3,h=class{constructor(){this.path=[];this.lastSampleAt=0;this.handler=e=>this.onMouseMove(e),window.addEventListener("mousemove",this.handler,{passive:!0})}onMouseMove(e){let n=Date.now();this.path.length>=ce||n-this.lastSampleAt<le||(this.path.push({x:e.clientX,y:e.clientY,t:n}),this.lastSampleAt=n)}get points(){return this.path}destroy(){window.removeEventListener("mousemove",this.handler)}},v=class{constructor(e){this.onExitIntent=e;this.fired=!1;this.handler=n=>{!this.fired&&n.clientY<10&&(this.fired=!0,this.onExitIntent(n.clientX,n.clientY))},document.addEventListener("mousemove",this.handler,{passive:!0})}destroy(){document.removeEventListener("mousemove",this.handler)}},de=1e3,ue=3,p=class{constructor(e){this.onRageClick=e;this.recentClicks=[];this.handler=n=>this.onClick(n),window.addEventListener("click",this.handler,{passive:!0})}onClick(e){let n=Date.now();if(this.recentClicks=this.recentClicks.filter(i=>n-i.ts<de),this.recentClicks.push({ts:n,x:e.clientX,y:e.clientY}),this.recentClicks.length>=ue){let i=b(e.target);this.onRageClick(e.clientX,e.clientY,this.recentClicks.length,i),this.recentClicks=[]}}destroy(){window.removeEventListener("click",this.handler)}},g=class{constructor(e){this.onClick=e;this.handler=n=>{let i=n.target;if(x(i))return;let r=he(i);this.onClick(n.clientX,n.clientY,Date.now(),b(i),r)},window.addEventListener("click",this.handler,{passive:!0})}destroy(){window.removeEventListener("click",this.handler)}},m=class{constructor(e){this.onSelect=e;this.handler=()=>{var o;let n=window.getSelection();if(!n||n.isCollapsed)return;let i=n.toString().trim();if(!i||i.length<3)return;let r=(o=n.anchorNode)==null?void 0:o.parentElement;r&&x(r)||this.onSelect(i.slice(0,200),b(r||document.body))},document.addEventListener("selectionchange",this.handler,{passive:!0})}destroy(){document.removeEventListener("selectionchange",this.handler)}};function $(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=new PerformanceObserver(n=>{let i=n.getEntries(),r=i[i.length-1];r&&t(Math.round(r.startTime))});return e.observe({type:"largest-contentful-paint",buffered:!0}),()=>e.disconnect()}catch{return()=>{}}}function x(t){var n;if(!t)return!1;let e=(n=t.tagName)==null?void 0:n.toLowerCase();return["input","textarea","select","option"].includes(e)}function b(t){if(!t||!t.tagName)return"";let e=t.tagName.toLowerCase(),n=t.id?`#${t.id}`:"",i=t.classList.length?`.${Array.from(t.classList).slice(0,2).join(".")}`:"";return`${e}${n}${i}`.slice(0,60)}function he(t){return!t||x(t)?"":(t.textContent||"").trim().slice(0,50)}var K="https://api.trackiq.io";async function W(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/pageview`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};if(S(i,n,r),!(t.dataEndpoint.replace(/\/$/,"")===K.replace(/\/$/,""))){let s=await k(t.apiKey),a=JSON.stringify({key_hash:s,type:"pageview"});S(`${K}/v1/consume`,a,{"Content-Type":"application/json"})}}function T(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/event`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};S(i,n,r)}function S(t,e,n){try{fetch(t,{method:"POST",headers:n,body:e,keepalive:!0}).catch(()=>{})}catch{}}var ve="https://api.trackiq.io",f=class{constructor(e){this.fpId="";this.lcp=0;var n;this.config={dataEndpoint:ve,debug:!1,...e},this.beacon={apiKey:this.config.apiKey,dataEndpoint:this.config.dataEndpoint},this.pageURL=window.location.href,this.pageReferrer=(n=e.referrer)!=null?n:document.referrer,this.session={visitorId:A(),sessionId:I(),tsStart:Date.now(),firstPageviewSent:!1},this.scroll=new d,this.activeTime=new u,this.mousePath=new h,this.exitIntent=new v((i,r)=>{this.sendBehaviorEvent("exit_intent",{x:i,y:r})}),this.rageClick=new p((i,r,o,s)=>{this.sendBehaviorEvent("rage_click",{x:i,y:r,count:o,element:s})}),this.clickTracker=new g((i,r,o,s,a)=>{this.sendBehaviorEvent("click",{x:i,y:r,ts:o,element:s,text:a})}),this.textSelect=new m((i,r)=>{this.sendBehaviorEvent("text_select",{text:i,element:r})}),this.disconnectLCP=$(i=>{this.lcp=i}),this.scheduleFingerprint(),this.unloadHandler=()=>{this.flush()},window.addEventListener("beforeunload",this.unloadHandler),window.trackiq={event:this.event.bind(this)},this.log("TrackIQ initialised",{visitorId:this.session.visitorId})}event(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};T(this.beacon,i),this.log("event sent",{type:e,data:n})}destroy(){this.flush(),window.removeEventListener("beforeunload",this.unloadHandler),this.scroll.destroy(),this.activeTime.destroy(),this.mousePath.destroy(),this.exitIntent.destroy(),this.rageClick.destroy(),this.clickTracker.destroy(),this.textSelect.destroy(),this.disconnectLCP(),this.log("TrackIQ destroyed")}scheduleFingerprint(){let e=async()=>{let{fpId:n,payload:i}=await E();this.fpId=n,this.fpPayload=i,this.log("fingerprint computed",{fpId:n})};"requestIdleCallback"in window?requestIdleCallback(()=>{e().catch(()=>{})},{timeout:3e3}):setTimeout(()=>{e().catch(()=>{})},1)}flush(){let e=Date.now(),n=!this.session.firstPageviewSent;W(this.beacon,{session_id:this.session.sessionId,visitor_id:this.session.visitorId,url:this.pageURL,referrer:this.pageReferrer,ts_start:this.session.tsStart,ts_end:e,active_time:this.activeTime.activeTimeMs,max_scroll:this.scroll.maxScrollDepth,milestones:this.scroll.reachedMilestones,mouse_path:this.mousePath.points,fp_id:this.fpId,fingerprint:n?this.fpPayload:void 0,device:n?D():void 0,language:M(),languages:N(),connection_type:H(),prefers_dark_mode:F(),prefers_reduced_motion:O(),navigation_type:B(),lcp:this.lcp,dnt:U(),cookies_enabled:G(),local_storage_available:P(),session_storage_available:L(),indexed_db_available:R()}).catch(()=>{}),this.session.firstPageviewSent=!0,this.log("pageview sent")}sendBehaviorEvent(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};T(this.beacon,i)}log(e,n){this.config.debug&&console.log(`[TrackIQ] ${e}`,n!=null?n:"")}};var y=require("react/jsx-runtime");function pe({apiKey:t,dataEndpoint:e,debug:n,children:i}){return(0,Q.useEffect)(()=>{if(typeof window=="undefined")return;let r=new f({apiKey:t,dataEndpoint:e,debug:n});return()=>r.destroy()},[t,e,n]),(0,y.jsx)(y.Fragment,{children:i})}0&&(module.exports={TrackIQProvider});
|
|
1
|
+
"use strict";var b=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var ie=Object.prototype.hasOwnProperty;var re=(t,e)=>{for(var n in e)b(t,n,{get:e[n],enumerable:!0})},oe=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ne(e))!ie.call(t,r)&&r!==n&&b(t,r,{get:()=>e[r],enumerable:!(i=te(e,r))||i.enumerable});return t};var se=t=>oe(b({},"__esModule",{value:!0}),t);var Ee={};re(Ee,{TrackIQProvider:()=>Se});module.exports=se(Ee);var ee=require("react");async function c(t){let n=new TextEncoder().encode(t),i=await crypto.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(i)).map(o=>o.toString(16).padStart(2,"0")).join("")}async function ae(){try{let t=document.createElement("canvas");t.width=280,t.height=60;let e=t.getContext("2d");return e?(e.textBaseline="top",e.font="14px Arial",e.fillStyle="#f60",e.fillRect(125,1,62,20),e.fillStyle="#069",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",2,15),e.fillStyle="rgba(102, 204, 0, 0.7)",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",4,45),c(t.toDataURL())):"unavailable"}catch{return"unavailable"}}function ce(){try{let t=document.createElement("canvas"),e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.getExtension("WEBGL_debug_renderer_info");return n?e.getParameter(n.UNMASKED_RENDERER_WEBGL):"unavailable"}catch{return"unavailable"}}async function le(){try{let t=document.createElement("canvas");t.width=16,t.height=16;let e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.createShader(e.VERTEX_SHADER),i=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(n,"attribute vec2 p;void main(){gl_Position=vec4(p,0,1);}"),e.shaderSource(i,"void main(){gl_FragColor=vec4(0.2,0.4,0.6,1.0);}"),e.compileShader(n),e.compileShader(i);let r=e.createProgram();e.attachShader(r,n),e.attachShader(r,i),e.linkProgram(r),e.useProgram(r);let o=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,o),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-.5,-.5,.5,-.5,0,.5]),e.STATIC_DRAW);let s=e.getAttribLocation(r,"p");e.enableVertexAttribArray(s),e.vertexAttribPointer(s,2,e.FLOAT,!1,0,0),e.drawArrays(e.TRIANGLES,0,3);let a=new Uint8Array(256*4);return e.readPixels(0,0,16,16,e.RGBA,e.UNSIGNED_BYTE,a),c(a.join(","))}catch{return"unavailable"}}async function de(){try{let t=window.OfflineAudioContext||window.webkitOfflineAudioContext;if(!t)return"unavailable";let e=new t(1,44100,44100),n=e.createOscillator();n.type="triangle",n.frequency.setValueAtTime(1e4,e.currentTime);let i=e.createDynamicsCompressor();i.threshold.setValueAtTime(-50,e.currentTime),i.knee.setValueAtTime(40,e.currentTime),i.ratio.setValueAtTime(12,e.currentTime),i.attack.setValueAtTime(0,e.currentTime),i.release.setValueAtTime(.25,e.currentTime),n.connect(i),i.connect(e.destination),n.start(0);let o=(await e.startRendering()).getChannelData(0),s=0;for(let a=4500;a<5e3;a++)s+=Math.abs(o[a]);return c(s.toFixed(10))}catch{return"blocked"}}var ue=["Arial","Arial Black","Arial Narrow","Calibri","Cambria","Candara","Comic Sans MS","Consolas","Constantia","Corbel","Courier New","Franklin Gothic Medium","Garamond","Georgia","Gill Sans","Helvetica","Impact","Lucida Console","Lucida Sans Unicode","Microsoft Sans Serif","Palatino Linotype","Segoe UI","Tahoma","Times New Roman","Trebuchet MS","Verdana","Adobe Caslon Pro","Adobe Garamond Pro","Myriad Pro","Roboto","Open Sans","Lato","Montserrat","Oswald","Source Sans Pro","SF Pro Display","SF Pro Text","Helvetica Neue","Futura","Segoe Print","Segoe Script","MS Gothic","Liberation Sans","Liberation Serif","Ubuntu","DejaVu Sans","Wingdings","Symbol","Webdings"];function he(){try{let e=document.createElement("canvas").getContext("2d");if(!e)return[];let n="mmmmmmmmmmlli",i="72px",r="monospace";e.font=`${i} ${r}`;let o=e.measureText(n).width;return ue.filter(s=>(e.font=`${i} '${s}', ${r}`,e.measureText(n).width!==o))}catch{return[]}}function ve(){try{return Array.from(navigator.plugins).map(t=>t.name)}catch{return[]}}async function C(){let[t,e,n]=await Promise.all([ae(),le(),de()]),i=ce(),r=he(),o=ve(),s={canvas_hash:t,webgl_renderer:i,webgl_hash:e,audio_hash:n,fonts_detected:r,plugins:o},a=[t,i,e,n,r.join(","),o.join(",")].join("|");return{fpId:await c(a),payload:s}}async function _(t){return c(t)}var I="tiq_vid",P="tiq_sid";function l(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function A(){try{let t=localStorage.getItem(I);return t||(t=l(),localStorage.setItem(I,t)),t}catch{return l()}}function L(){try{let t=sessionStorage.getItem(P);return t||(t=l(),sessionStorage.setItem(P,t)),t}catch{return l()}}function D(){try{let t="__tiq_test__";return localStorage.setItem(t,"1"),localStorage.removeItem(t),!0}catch{return!1}}function M(){try{let t="__tiq_test__";return sessionStorage.setItem(t,"1"),sessionStorage.removeItem(t),!0}catch{return!1}}function R(){try{return typeof indexedDB!="undefined"&&indexedDB!==null}catch{return!1}}function N(){return{user_agent:navigator.userAgent,screen_w:screen.width,screen_h:screen.height,viewport_w:window.innerWidth,viewport_h:window.innerHeight,device_pixel_ratio:window.devicePixelRatio||1,color_depth:screen.colorDepth,cpu_cores:navigator.hardwareConcurrency||0,device_memory:navigator.deviceMemory||0,touch:navigator.maxTouchPoints>0,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}}function O(){return navigator.language||""}function F(){return Array.from(navigator.languages||[navigator.language])}function d(){var t;return(t=navigator.connection)!=null?t:{}}function H(){return d().effectiveType||"unknown"}function B(){var t;return(t=d().downlink)!=null?t:0}function U(){var t;return(t=d().rtt)!=null?t:0}function G(){var t;return(t=d().saveData)!=null?t:!1}function V(){return window.matchMedia("(prefers-color-scheme: dark)").matches}function Y(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}function K(){try{let t=performance.getEntriesByType("navigation")[0];return(t==null?void 0:t.type)||"navigate"}catch{return"navigate"}}function W(){return navigator.doNotTrack==="1"||window.doNotTrack==="1"}function Q(){return navigator.cookieEnabled}var pe=[25,50,75,90],u=class{constructor(){this.maxScroll=0;this.milestones=new Set;this.handler=()=>this.onScroll(),window.addEventListener("scroll",this.handler,{passive:!0})}onScroll(){let e=document.body.scrollHeight-window.innerHeight;if(e<=0)return;let n=Math.round(window.scrollY/e*100);n>this.maxScroll&&(this.maxScroll=n);for(let i of pe)n>=i&&this.milestones.add(i)}get maxScrollDepth(){return this.maxScroll}get reachedMilestones(){return Array.from(this.milestones)}destroy(){window.removeEventListener("scroll",this.handler)}},X=["mousemove","scroll","click","keydown","touchstart"],fe=3e4,h=class{constructor(){this.accumulated=0;this.lastActiveAt=Date.now();this.idle=!1;this.hidden=!1;this.idleTimer=null;this.activityHandler=()=>this.onActivity(),this.visibilityHandler=()=>this.onVisibilityChange();for(let e of X)window.addEventListener(e,this.activityHandler,{passive:!0});document.addEventListener("visibilitychange",this.visibilityHandler),this.scheduleIdleCheck()}onActivity(){this.hidden||(this.idle?(this.lastActiveAt=Date.now(),this.idle=!1):this.flush(),this.scheduleIdleCheck())}onVisibilityChange(){document.hidden?(this.flush(),this.hidden=!0):(this.hidden=!1,this.lastActiveAt=Date.now())}flush(){!this.idle&&!this.hidden&&(this.accumulated+=Date.now()-this.lastActiveAt,this.lastActiveAt=Date.now())}scheduleIdleCheck(){this.idleTimer&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{this.flush(),this.idle=!0},fe)}get activeTimeMs(){return this.flush(),this.accumulated}destroy(){for(let e of X)window.removeEventListener(e,this.activityHandler);document.removeEventListener("visibilitychange",this.visibilityHandler),this.idleTimer&&clearTimeout(this.idleTimer)}},me=30,ge=1e3,v=class{constructor(){this.path=[];this.lastSampleAt=0;this.handler=e=>this.onMouseMove(e),window.addEventListener("mousemove",this.handler,{passive:!0})}onMouseMove(e){let n=Date.now();this.path.length>=me||n-this.lastSampleAt<ge||(this.path.push({x:Math.round(e.clientX+window.scrollX),y:Math.round(e.clientY+window.scrollY),t:n}),this.lastSampleAt=n)}get points(){return this.path}destroy(){window.removeEventListener("mousemove",this.handler)}},p=class{constructor(e){this.onExitIntent=e;this.fired=!1;this.handler=n=>{!this.fired&&n.clientY<10&&(this.fired=!0,this.onExitIntent(Math.round(n.clientX+window.scrollX),Math.round(n.clientY+window.scrollY)))},document.addEventListener("mousemove",this.handler,{passive:!0})}destroy(){document.removeEventListener("mousemove",this.handler)}},ye=1e3,we=3,f=class{constructor(e){this.onRageClick=e;this.recentClicks=[];this.handler=n=>this.onClick(n),window.addEventListener("click",this.handler,{passive:!0})}onClick(e){let n=Date.now();if(this.recentClicks=this.recentClicks.filter(i=>n-i.ts<ye),this.recentClicks.push({ts:n,x:Math.round(e.clientX+window.scrollX),y:Math.round(e.clientY+window.scrollY)}),this.recentClicks.length>=we){let i=T(e.target);this.onRageClick(Math.round(e.clientX+window.scrollX),Math.round(e.clientY+window.scrollY),this.recentClicks.length,i),this.recentClicks=[]}}destroy(){window.removeEventListener("click",this.handler)}},m=class{constructor(e){this.onClick=e;this.handler=n=>{let i=n.target;if(x(i))return;let r=be(i);this.onClick(Math.round(n.clientX+window.scrollX),Math.round(n.clientY+window.scrollY),Date.now(),T(i),r)},window.addEventListener("click",this.handler,{passive:!0})}destroy(){window.removeEventListener("click",this.handler)}},g=class{constructor(e){this.onSelect=e;this.handler=()=>{var o;let n=window.getSelection();if(!n||n.isCollapsed)return;let i=n.toString().trim();if(!i||i.length<3)return;let r=(o=n.anchorNode)==null?void 0:o.parentElement;r&&x(r)||this.onSelect(i.slice(0,200),T(r||document.body))},document.addEventListener("selectionchange",this.handler,{passive:!0})}destroy(){document.removeEventListener("selectionchange",this.handler)}};function $(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=new PerformanceObserver(n=>{let i=n.getEntries(),r=i[i.length-1];r&&t(Math.round(r.startTime))});return e.observe({type:"largest-contentful-paint",buffered:!0}),()=>e.disconnect()}catch{return()=>{}}}function q(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=0,n=new PerformanceObserver(i=>{for(let r of i.getEntries()){let o=r,s=o.processingStart?o.processingStart-o.startTime+o.duration:o.duration;s>e&&(e=s,t(Math.round(e)))}});return n.observe({type:"event",buffered:!0,durationThreshold:16}),()=>n.disconnect()}catch{return()=>{}}}function j(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=0,n=new PerformanceObserver(i=>{for(let r of i.getEntries()){let o=r;o.hadRecentInput||(e+=o.value,t(parseFloat(e.toFixed(4))))}});return n.observe({type:"layout-shift",buffered:!0}),()=>n.disconnect()}catch{return()=>{}}}function J(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=new PerformanceObserver(n=>{for(let i of n.getEntries())if(i.name==="first-contentful-paint"){t(Math.round(i.startTime)),e.disconnect();return}});return e.observe({type:"paint",buffered:!0}),()=>e.disconnect()}catch{return()=>{}}}function Z(){try{let t=performance.getEntriesByType("navigation")[0];return t?Math.round(t.responseStart-t.requestStart):0}catch{return 0}}function x(t){var n;if(!t)return!1;let e=(n=t.tagName)==null?void 0:n.toLowerCase();return["input","textarea","select","option"].includes(e)}function T(t){if(!t||!t.tagName)return"";let e=t.tagName.toLowerCase(),n=t.id?`#${t.id}`:"",i=t.classList.length?`.${Array.from(t.classList).slice(0,2).join(".")}`:"";return`${e}${n}${i}`.slice(0,60)}function be(t){return!t||x(t)?"":(t.textContent||"").trim().slice(0,50)}var xe="https://api.trackiq.io";async function z(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/pageview`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};if(S(i,n,r),t.selfHosted){let o=await _(t.apiKey),s=JSON.stringify({key_hash:o,type:"pageview"});S(`${xe}/v1/consume`,s,{"Content-Type":"application/json"})}}function E(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/event`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};S(i,n,r)}function S(t,e,n){try{fetch(t,{method:"POST",headers:n,body:e,keepalive:!0}).catch(()=>{})}catch{}}var Te="https://api.trackiq.io",y=class{constructor(e){this.fpId="";this.lcp=0;this.inp=0;this.cls=0;this.fcp=0;this.ttfb=0;var n,i;this.config={dataEndpoint:Te,debug:!1,...e},this.beacon={apiKey:this.config.apiKey,dataEndpoint:this.config.dataEndpoint,selfHosted:(n=e.selfHosted)!=null?n:!1},this.pageURL=window.location.href,this.pageReferrer=(i=e.referrer)!=null?i:document.referrer,this.session={visitorId:A(),sessionId:L(),tsStart:Date.now(),firstPageviewSent:!1},this.scroll=new u,this.activeTime=new h,this.mousePath=new v,this.exitIntent=new p((r,o)=>{this.sendBehaviorEvent("exit_intent",{x:r,y:o})}),this.rageClick=new f((r,o,s,a)=>{this.sendBehaviorEvent("rage_click",{x:r,y:o,count:s,element:a})}),this.clickTracker=new m((r,o,s,a,k)=>{this.sendBehaviorEvent("click",{x:r,y:o,ts:s,element:a,text:k})}),this.textSelect=new g((r,o)=>{this.sendBehaviorEvent("text_select",{text:r,element:o})}),this.disconnectLCP=$(r=>{this.lcp=r}),q(r=>{this.inp=r}),j(r=>{this.cls=r}),J(r=>{this.fcp=r}),this.ttfb=Z(),this.scheduleFingerprint(),this.unloadHandler=()=>{this.flush()},window.addEventListener("beforeunload",this.unloadHandler),window.trackiq={event:this.event.bind(this)},this.log("TrackIQ initialised",{visitorId:this.session.visitorId})}event(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};E(this.beacon,i),this.log("event sent",{type:e,data:n})}destroy(){this.flush(),window.removeEventListener("beforeunload",this.unloadHandler),this.scroll.destroy(),this.activeTime.destroy(),this.mousePath.destroy(),this.exitIntent.destroy(),this.rageClick.destroy(),this.clickTracker.destroy(),this.textSelect.destroy(),this.disconnectLCP(),this.log("TrackIQ destroyed")}scheduleFingerprint(){let e=async()=>{let{fpId:n,payload:i}=await C();this.fpId=n,this.fpPayload=i,this.log("fingerprint computed",{fpId:n})};"requestIdleCallback"in window?requestIdleCallback(()=>{e().catch(()=>{})},{timeout:3e3}):setTimeout(()=>{e().catch(()=>{})},1)}flush(){let e=Date.now(),n=!this.session.firstPageviewSent;z(this.beacon,{session_id:this.session.sessionId,visitor_id:this.session.visitorId,url:this.pageURL,referrer:this.pageReferrer,ts_start:this.session.tsStart,ts_end:e,active_time:this.activeTime.activeTimeMs,max_scroll:this.scroll.maxScrollDepth,milestones:this.scroll.reachedMilestones,mouse_path:this.mousePath.points,fp_id:this.fpId,fingerprint:n?this.fpPayload:void 0,device:n?N():void 0,language:O(),languages:F(),connection_type:H(),downlink:B(),rtt:U(),save_data:G(),prefers_dark_mode:V(),prefers_reduced_motion:Y(),navigation_type:K(),lcp:this.lcp,inp:this.inp,cls:this.cls,fcp:this.fcp,ttfb:this.ttfb,dnt:W(),cookies_enabled:Q(),local_storage_available:D(),session_storage_available:M(),indexed_db_available:R()}).catch(()=>{}),this.session.firstPageviewSent=!0,this.log("pageview sent")}sendBehaviorEvent(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};E(this.beacon,i)}log(e,n){this.config.debug&&console.log(`[TrackIQ] ${e}`,n!=null?n:"")}};var w=require("react/jsx-runtime");function Se({apiKey:t,dataEndpoint:e,debug:n,children:i}){return(0,ee.useEffect)(()=>{if(typeof window=="undefined")return;let r=new y({apiKey:t,dataEndpoint:e,debug:n});return()=>r.destroy()},[t,e,n]),(0,w.jsx)(w.Fragment,{children:i})}0&&(module.exports={TrackIQProvider});
|
package/dist/react.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as t}from"./chunk-
|
|
1
|
+
import{a as t}from"./chunk-GSAGJBV2.mjs";import{useEffect as n}from"react";import{Fragment as i,jsx as p}from"react/jsx-runtime";function a({apiKey:r,dataEndpoint:e,debug:o,children:c}){return n(()=>{if(typeof window=="undefined")return;let f=new t({apiKey:r,dataEndpoint:e,debug:o});return()=>f.destroy()},[r,e,o]),p(i,{children:c})}export{a as TrackIQProvider};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/** Configuration passed to the TrackIQ constructor. */
|
|
2
|
+
interface TrackIQConfig {
|
|
3
|
+
/** Raw API key shown once at creation (format: tk_live_...). */
|
|
4
|
+
apiKey: string;
|
|
5
|
+
/**
|
|
6
|
+
* The ingestion API endpoint for behavioral data.
|
|
7
|
+
* Defaults to https://api.trackiq.io.
|
|
8
|
+
*/
|
|
9
|
+
dataEndpoint?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Set to true only for enterprise self-hosted deployments where behavioral
|
|
12
|
+
* data goes to the customer's own server. Enables the dual consumption ping
|
|
13
|
+
* to TrackIQ cloud for license billing. Default: false.
|
|
14
|
+
*/
|
|
15
|
+
selfHosted?: boolean;
|
|
16
|
+
/** Enable verbose console logging for debugging. Default: false. */
|
|
17
|
+
debug?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Referrer URL to use for this page, overriding document.referrer.
|
|
20
|
+
* Required for correct SPA tracking: pass the previous page's URL so
|
|
21
|
+
* each pageview records where the user came from within the app.
|
|
22
|
+
*/
|
|
23
|
+
referrer?: string;
|
|
24
|
+
}
|
|
25
|
+
/** Full pageview payload sent via sendBeacon on page close. */
|
|
26
|
+
interface PageviewPayload {
|
|
27
|
+
session_id: string;
|
|
28
|
+
visitor_id: string;
|
|
29
|
+
url: string;
|
|
30
|
+
/** Empty string if the browser blocked the referrer. */
|
|
31
|
+
referrer: string;
|
|
32
|
+
ts_start: number;
|
|
33
|
+
ts_end: number;
|
|
34
|
+
/** Real engagement time in ms — idle > 30s and background tabs excluded. */
|
|
35
|
+
active_time: number;
|
|
36
|
+
max_scroll: number;
|
|
37
|
+
milestones: number[];
|
|
38
|
+
/** Throttled mouse positions — max 30 points at 1 sample/sec. */
|
|
39
|
+
mouse_path: MousePoint[];
|
|
40
|
+
fp_id: string;
|
|
41
|
+
/** Only sent on first pageview of a session to reduce payload size. */
|
|
42
|
+
fingerprint?: FingerprintPayload;
|
|
43
|
+
/** Only sent on first pageview of a session. */
|
|
44
|
+
device?: DevicePayload;
|
|
45
|
+
language: string;
|
|
46
|
+
languages: string[];
|
|
47
|
+
connection_type: string;
|
|
48
|
+
prefers_dark_mode: boolean;
|
|
49
|
+
prefers_reduced_motion: boolean;
|
|
50
|
+
navigation_type: string;
|
|
51
|
+
/** Largest Contentful Paint in milliseconds. */
|
|
52
|
+
lcp: number;
|
|
53
|
+
/** Do Not Track browser setting. */
|
|
54
|
+
dnt: boolean;
|
|
55
|
+
cookies_enabled: boolean;
|
|
56
|
+
local_storage_available: boolean;
|
|
57
|
+
session_storage_available: boolean;
|
|
58
|
+
indexed_db_available: boolean;
|
|
59
|
+
}
|
|
60
|
+
/** A single throttled mouse position sample. */
|
|
61
|
+
interface MousePoint {
|
|
62
|
+
x: number;
|
|
63
|
+
y: number;
|
|
64
|
+
/** Unix timestamp in milliseconds. */
|
|
65
|
+
t: number;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Browser fingerprinting signals used to compute the composite fp_id.
|
|
69
|
+
* Weighted scores: GPU 0.25 | Canvas 0.20 | Audio 0.15 | Fonts 0.15 | ...
|
|
70
|
+
*/
|
|
71
|
+
interface FingerprintPayload {
|
|
72
|
+
/** SHA-256 of a Canvas 2D render — varies by GPU driver and antialiasing. */
|
|
73
|
+
canvas_hash: string;
|
|
74
|
+
/** GPU model from WEBGL_debug_renderer_info — most stable signal (weight 0.25). */
|
|
75
|
+
webgl_renderer: string;
|
|
76
|
+
/** SHA-256 of a 3D WebGL scene — captures float precision differences between GPUs. */
|
|
77
|
+
webgl_hash: string;
|
|
78
|
+
/** SHA-256 derived from OfflineAudioContext oscillator output (samples 4500–5000). */
|
|
79
|
+
audio_hash: string;
|
|
80
|
+
/** System fonts detected by canvas width comparison against 50 reference fonts. */
|
|
81
|
+
fonts_detected: string[];
|
|
82
|
+
/** Active browser plugins (navigator.plugins). */
|
|
83
|
+
plugins: string[];
|
|
84
|
+
}
|
|
85
|
+
/** Hardware and browser capability signals. */
|
|
86
|
+
interface DevicePayload {
|
|
87
|
+
user_agent: string;
|
|
88
|
+
/** Physical screen dimensions in pixels. */
|
|
89
|
+
screen_w: number;
|
|
90
|
+
screen_h: number;
|
|
91
|
+
/** Visible browser window dimensions — different from screen resolution. */
|
|
92
|
+
viewport_w: number;
|
|
93
|
+
viewport_h: number;
|
|
94
|
+
/** > 1.0 indicates Retina / OLED / 4K display. */
|
|
95
|
+
device_pixel_ratio: number;
|
|
96
|
+
color_depth: number;
|
|
97
|
+
cpu_cores: number;
|
|
98
|
+
/** Approximate RAM in GB — rounded to 0.5/1/2/4/8. */
|
|
99
|
+
device_memory: number;
|
|
100
|
+
touch: boolean;
|
|
101
|
+
/** IANA timezone string e.g. "Africa/Kinshasa". */
|
|
102
|
+
timezone: string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Event payload for discrete user actions.
|
|
106
|
+
* Built-in types: click | rage_click | scroll_milestone | exit_intent |
|
|
107
|
+
* text_select | element_visible
|
|
108
|
+
* Custom types: any string via window.trackiq.event(type, data)
|
|
109
|
+
*/
|
|
110
|
+
interface EventPayload {
|
|
111
|
+
session_id: string;
|
|
112
|
+
visitor_id: string;
|
|
113
|
+
type: string;
|
|
114
|
+
url: string;
|
|
115
|
+
/** Unix timestamp in milliseconds. */
|
|
116
|
+
ts: number;
|
|
117
|
+
data?: Record<string, unknown>;
|
|
118
|
+
}
|
|
119
|
+
/** Internal state tracked per page session. */
|
|
120
|
+
interface SessionState {
|
|
121
|
+
visitorId: string;
|
|
122
|
+
sessionId: string;
|
|
123
|
+
tsStart: number;
|
|
124
|
+
/** Whether device + fingerprint have been sent in this session. */
|
|
125
|
+
firstPageviewSent: boolean;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export type { DevicePayload as D, EventPayload as E, FingerprintPayload as F, MousePoint as M, PageviewPayload as P, SessionState as S, TrackIQConfig as T };
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/** Configuration passed to the TrackIQ constructor. */
|
|
2
|
+
interface TrackIQConfig {
|
|
3
|
+
/** Raw API key shown once at creation (format: tk_live_...). */
|
|
4
|
+
apiKey: string;
|
|
5
|
+
/**
|
|
6
|
+
* The ingestion API endpoint for behavioral data.
|
|
7
|
+
* Defaults to https://api.trackiq.io.
|
|
8
|
+
*/
|
|
9
|
+
dataEndpoint?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Set to true only for enterprise self-hosted deployments where behavioral
|
|
12
|
+
* data goes to the customer's own server. Enables the dual consumption ping
|
|
13
|
+
* to TrackIQ cloud for license billing. Default: false.
|
|
14
|
+
*/
|
|
15
|
+
selfHosted?: boolean;
|
|
16
|
+
/** Enable verbose console logging for debugging. Default: false. */
|
|
17
|
+
debug?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Referrer URL to use for this page, overriding document.referrer.
|
|
20
|
+
* Required for correct SPA tracking: pass the previous page's URL so
|
|
21
|
+
* each pageview records where the user came from within the app.
|
|
22
|
+
*/
|
|
23
|
+
referrer?: string;
|
|
24
|
+
}
|
|
25
|
+
/** Full pageview payload sent via sendBeacon on page close. */
|
|
26
|
+
interface PageviewPayload {
|
|
27
|
+
session_id: string;
|
|
28
|
+
visitor_id: string;
|
|
29
|
+
url: string;
|
|
30
|
+
/** Empty string if the browser blocked the referrer. */
|
|
31
|
+
referrer: string;
|
|
32
|
+
ts_start: number;
|
|
33
|
+
ts_end: number;
|
|
34
|
+
/** Real engagement time in ms — idle > 30s and background tabs excluded. */
|
|
35
|
+
active_time: number;
|
|
36
|
+
max_scroll: number;
|
|
37
|
+
milestones: number[];
|
|
38
|
+
/** Throttled mouse positions — max 30 points at 1 sample/sec. */
|
|
39
|
+
mouse_path: MousePoint[];
|
|
40
|
+
fp_id: string;
|
|
41
|
+
/** Only sent on first pageview of a session to reduce payload size. */
|
|
42
|
+
fingerprint?: FingerprintPayload;
|
|
43
|
+
/** Only sent on first pageview of a session. */
|
|
44
|
+
device?: DevicePayload;
|
|
45
|
+
language: string;
|
|
46
|
+
languages: string[];
|
|
47
|
+
connection_type: string;
|
|
48
|
+
prefers_dark_mode: boolean;
|
|
49
|
+
prefers_reduced_motion: boolean;
|
|
50
|
+
navigation_type: string;
|
|
51
|
+
/** Largest Contentful Paint in milliseconds. */
|
|
52
|
+
lcp: number;
|
|
53
|
+
/** Do Not Track browser setting. */
|
|
54
|
+
dnt: boolean;
|
|
55
|
+
cookies_enabled: boolean;
|
|
56
|
+
local_storage_available: boolean;
|
|
57
|
+
session_storage_available: boolean;
|
|
58
|
+
indexed_db_available: boolean;
|
|
59
|
+
}
|
|
60
|
+
/** A single throttled mouse position sample. */
|
|
61
|
+
interface MousePoint {
|
|
62
|
+
x: number;
|
|
63
|
+
y: number;
|
|
64
|
+
/** Unix timestamp in milliseconds. */
|
|
65
|
+
t: number;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Browser fingerprinting signals used to compute the composite fp_id.
|
|
69
|
+
* Weighted scores: GPU 0.25 | Canvas 0.20 | Audio 0.15 | Fonts 0.15 | ...
|
|
70
|
+
*/
|
|
71
|
+
interface FingerprintPayload {
|
|
72
|
+
/** SHA-256 of a Canvas 2D render — varies by GPU driver and antialiasing. */
|
|
73
|
+
canvas_hash: string;
|
|
74
|
+
/** GPU model from WEBGL_debug_renderer_info — most stable signal (weight 0.25). */
|
|
75
|
+
webgl_renderer: string;
|
|
76
|
+
/** SHA-256 of a 3D WebGL scene — captures float precision differences between GPUs. */
|
|
77
|
+
webgl_hash: string;
|
|
78
|
+
/** SHA-256 derived from OfflineAudioContext oscillator output (samples 4500–5000). */
|
|
79
|
+
audio_hash: string;
|
|
80
|
+
/** System fonts detected by canvas width comparison against 50 reference fonts. */
|
|
81
|
+
fonts_detected: string[];
|
|
82
|
+
/** Active browser plugins (navigator.plugins). */
|
|
83
|
+
plugins: string[];
|
|
84
|
+
}
|
|
85
|
+
/** Hardware and browser capability signals. */
|
|
86
|
+
interface DevicePayload {
|
|
87
|
+
user_agent: string;
|
|
88
|
+
/** Physical screen dimensions in pixels. */
|
|
89
|
+
screen_w: number;
|
|
90
|
+
screen_h: number;
|
|
91
|
+
/** Visible browser window dimensions — different from screen resolution. */
|
|
92
|
+
viewport_w: number;
|
|
93
|
+
viewport_h: number;
|
|
94
|
+
/** > 1.0 indicates Retina / OLED / 4K display. */
|
|
95
|
+
device_pixel_ratio: number;
|
|
96
|
+
color_depth: number;
|
|
97
|
+
cpu_cores: number;
|
|
98
|
+
/** Approximate RAM in GB — rounded to 0.5/1/2/4/8. */
|
|
99
|
+
device_memory: number;
|
|
100
|
+
touch: boolean;
|
|
101
|
+
/** IANA timezone string e.g. "Africa/Kinshasa". */
|
|
102
|
+
timezone: string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Event payload for discrete user actions.
|
|
106
|
+
* Built-in types: click | rage_click | scroll_milestone | exit_intent |
|
|
107
|
+
* text_select | element_visible
|
|
108
|
+
* Custom types: any string via window.trackiq.event(type, data)
|
|
109
|
+
*/
|
|
110
|
+
interface EventPayload {
|
|
111
|
+
session_id: string;
|
|
112
|
+
visitor_id: string;
|
|
113
|
+
type: string;
|
|
114
|
+
url: string;
|
|
115
|
+
/** Unix timestamp in milliseconds. */
|
|
116
|
+
ts: number;
|
|
117
|
+
data?: Record<string, unknown>;
|
|
118
|
+
}
|
|
119
|
+
/** Internal state tracked per page session. */
|
|
120
|
+
interface SessionState {
|
|
121
|
+
visitorId: string;
|
|
122
|
+
sessionId: string;
|
|
123
|
+
tsStart: number;
|
|
124
|
+
/** Whether device + fingerprint have been sent in this session. */
|
|
125
|
+
firstPageviewSent: boolean;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export type { DevicePayload as D, EventPayload as E, FingerprintPayload as F, MousePoint as M, PageviewPayload as P, SessionState as S, TrackIQConfig as T };
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/** Configuration passed to the TrackIQ constructor. */
|
|
2
|
+
interface TrackIQConfig {
|
|
3
|
+
/** Raw API key shown once at creation (format: tk_live_...). */
|
|
4
|
+
apiKey: string;
|
|
5
|
+
/**
|
|
6
|
+
* The ingestion API endpoint for behavioral data.
|
|
7
|
+
* Defaults to https://api.trackiq.io.
|
|
8
|
+
*/
|
|
9
|
+
dataEndpoint?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Set to true only for enterprise self-hosted deployments where behavioral
|
|
12
|
+
* data goes to the customer's own server. Enables the dual consumption ping
|
|
13
|
+
* to TrackIQ cloud for license billing. Default: false.
|
|
14
|
+
*/
|
|
15
|
+
selfHosted?: boolean;
|
|
16
|
+
/** Enable verbose console logging for debugging. Default: false. */
|
|
17
|
+
debug?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Referrer URL to use for this page, overriding document.referrer.
|
|
20
|
+
* Required for correct SPA tracking: pass the previous page's URL so
|
|
21
|
+
* each pageview records where the user came from within the app.
|
|
22
|
+
*/
|
|
23
|
+
referrer?: string;
|
|
24
|
+
}
|
|
25
|
+
/** Full pageview payload sent via sendBeacon on page close. */
|
|
26
|
+
interface PageviewPayload {
|
|
27
|
+
session_id: string;
|
|
28
|
+
visitor_id: string;
|
|
29
|
+
url: string;
|
|
30
|
+
/** Empty string if the browser blocked the referrer. */
|
|
31
|
+
referrer: string;
|
|
32
|
+
ts_start: number;
|
|
33
|
+
ts_end: number;
|
|
34
|
+
/** Real engagement time in ms — idle > 30s and background tabs excluded. */
|
|
35
|
+
active_time: number;
|
|
36
|
+
max_scroll: number;
|
|
37
|
+
milestones: number[];
|
|
38
|
+
/** Throttled mouse positions — max 30 points at 1 sample/sec. */
|
|
39
|
+
mouse_path: MousePoint[];
|
|
40
|
+
fp_id: string;
|
|
41
|
+
/** Only sent on first pageview of a session to reduce payload size. */
|
|
42
|
+
fingerprint?: FingerprintPayload;
|
|
43
|
+
/** Only sent on first pageview of a session. */
|
|
44
|
+
device?: DevicePayload;
|
|
45
|
+
language: string;
|
|
46
|
+
languages: string[];
|
|
47
|
+
connection_type: string;
|
|
48
|
+
/** Downlink throughput estimate in Mbps (Network Information API). 0 if unavailable. */
|
|
49
|
+
downlink: number;
|
|
50
|
+
/** Round-trip time estimate in ms. 0 if unavailable. */
|
|
51
|
+
rtt: number;
|
|
52
|
+
/** True if the user enabled data-saving mode. */
|
|
53
|
+
save_data: boolean;
|
|
54
|
+
prefers_dark_mode: boolean;
|
|
55
|
+
prefers_reduced_motion: boolean;
|
|
56
|
+
navigation_type: string;
|
|
57
|
+
/** Largest Contentful Paint in milliseconds. */
|
|
58
|
+
lcp: number;
|
|
59
|
+
/** Interaction to Next Paint in milliseconds (Core Web Vital since Mar 2024). */
|
|
60
|
+
inp: number;
|
|
61
|
+
/** Cumulative Layout Shift score (unitless, 0–1 range). */
|
|
62
|
+
cls: number;
|
|
63
|
+
/** First Contentful Paint in milliseconds. */
|
|
64
|
+
fcp: number;
|
|
65
|
+
/** Time to First Byte in milliseconds. */
|
|
66
|
+
ttfb: number;
|
|
67
|
+
/** Do Not Track browser setting. */
|
|
68
|
+
dnt: boolean;
|
|
69
|
+
cookies_enabled: boolean;
|
|
70
|
+
local_storage_available: boolean;
|
|
71
|
+
session_storage_available: boolean;
|
|
72
|
+
indexed_db_available: boolean;
|
|
73
|
+
}
|
|
74
|
+
/** A single throttled mouse position sample. */
|
|
75
|
+
interface MousePoint {
|
|
76
|
+
x: number;
|
|
77
|
+
y: number;
|
|
78
|
+
/** Unix timestamp in milliseconds. */
|
|
79
|
+
t: number;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Browser fingerprinting signals used to compute the composite fp_id.
|
|
83
|
+
* Weighted scores: GPU 0.25 | Canvas 0.20 | Audio 0.15 | Fonts 0.15 | ...
|
|
84
|
+
*/
|
|
85
|
+
interface FingerprintPayload {
|
|
86
|
+
/** SHA-256 of a Canvas 2D render — varies by GPU driver and antialiasing. */
|
|
87
|
+
canvas_hash: string;
|
|
88
|
+
/** GPU model from WEBGL_debug_renderer_info — most stable signal (weight 0.25). */
|
|
89
|
+
webgl_renderer: string;
|
|
90
|
+
/** SHA-256 of a 3D WebGL scene — captures float precision differences between GPUs. */
|
|
91
|
+
webgl_hash: string;
|
|
92
|
+
/** SHA-256 derived from OfflineAudioContext oscillator output (samples 4500–5000). */
|
|
93
|
+
audio_hash: string;
|
|
94
|
+
/** System fonts detected by canvas width comparison against 50 reference fonts. */
|
|
95
|
+
fonts_detected: string[];
|
|
96
|
+
/** Active browser plugins (navigator.plugins). */
|
|
97
|
+
plugins: string[];
|
|
98
|
+
}
|
|
99
|
+
/** Hardware and browser capability signals. */
|
|
100
|
+
interface DevicePayload {
|
|
101
|
+
user_agent: string;
|
|
102
|
+
/** Physical screen dimensions in pixels. */
|
|
103
|
+
screen_w: number;
|
|
104
|
+
screen_h: number;
|
|
105
|
+
/** Visible browser window dimensions — different from screen resolution. */
|
|
106
|
+
viewport_w: number;
|
|
107
|
+
viewport_h: number;
|
|
108
|
+
/** > 1.0 indicates Retina / OLED / 4K display. */
|
|
109
|
+
device_pixel_ratio: number;
|
|
110
|
+
color_depth: number;
|
|
111
|
+
cpu_cores: number;
|
|
112
|
+
/** Approximate RAM in GB — rounded to 0.5/1/2/4/8. */
|
|
113
|
+
device_memory: number;
|
|
114
|
+
touch: boolean;
|
|
115
|
+
/** IANA timezone string e.g. "Africa/Kinshasa". */
|
|
116
|
+
timezone: string;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Event payload for discrete user actions.
|
|
120
|
+
* Built-in types: click | rage_click | scroll_milestone | exit_intent |
|
|
121
|
+
* text_select | element_visible
|
|
122
|
+
* Custom types: any string via window.trackiq.event(type, data)
|
|
123
|
+
*/
|
|
124
|
+
interface EventPayload {
|
|
125
|
+
session_id: string;
|
|
126
|
+
visitor_id: string;
|
|
127
|
+
type: string;
|
|
128
|
+
url: string;
|
|
129
|
+
/** Unix timestamp in milliseconds. */
|
|
130
|
+
ts: number;
|
|
131
|
+
data?: Record<string, unknown>;
|
|
132
|
+
}
|
|
133
|
+
/** Internal state tracked per page session. */
|
|
134
|
+
interface SessionState {
|
|
135
|
+
visitorId: string;
|
|
136
|
+
sessionId: string;
|
|
137
|
+
tsStart: number;
|
|
138
|
+
/** Whether device + fingerprint have been sent in this session. */
|
|
139
|
+
firstPageviewSent: boolean;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export type { DevicePayload as D, EventPayload as E, FingerprintPayload as F, MousePoint as M, PageviewPayload as P, SessionState as S, TrackIQConfig as T };
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/** Configuration passed to the TrackIQ constructor. */
|
|
2
|
+
interface TrackIQConfig {
|
|
3
|
+
/** Raw API key shown once at creation (format: tk_live_...). */
|
|
4
|
+
apiKey: string;
|
|
5
|
+
/**
|
|
6
|
+
* The ingestion API endpoint for behavioral data.
|
|
7
|
+
* Defaults to https://api.trackiq.io.
|
|
8
|
+
*/
|
|
9
|
+
dataEndpoint?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Set to true only for enterprise self-hosted deployments where behavioral
|
|
12
|
+
* data goes to the customer's own server. Enables the dual consumption ping
|
|
13
|
+
* to TrackIQ cloud for license billing. Default: false.
|
|
14
|
+
*/
|
|
15
|
+
selfHosted?: boolean;
|
|
16
|
+
/** Enable verbose console logging for debugging. Default: false. */
|
|
17
|
+
debug?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Referrer URL to use for this page, overriding document.referrer.
|
|
20
|
+
* Required for correct SPA tracking: pass the previous page's URL so
|
|
21
|
+
* each pageview records where the user came from within the app.
|
|
22
|
+
*/
|
|
23
|
+
referrer?: string;
|
|
24
|
+
}
|
|
25
|
+
/** Full pageview payload sent via sendBeacon on page close. */
|
|
26
|
+
interface PageviewPayload {
|
|
27
|
+
session_id: string;
|
|
28
|
+
visitor_id: string;
|
|
29
|
+
url: string;
|
|
30
|
+
/** Empty string if the browser blocked the referrer. */
|
|
31
|
+
referrer: string;
|
|
32
|
+
ts_start: number;
|
|
33
|
+
ts_end: number;
|
|
34
|
+
/** Real engagement time in ms — idle > 30s and background tabs excluded. */
|
|
35
|
+
active_time: number;
|
|
36
|
+
max_scroll: number;
|
|
37
|
+
milestones: number[];
|
|
38
|
+
/** Throttled mouse positions — max 30 points at 1 sample/sec. */
|
|
39
|
+
mouse_path: MousePoint[];
|
|
40
|
+
fp_id: string;
|
|
41
|
+
/** Only sent on first pageview of a session to reduce payload size. */
|
|
42
|
+
fingerprint?: FingerprintPayload;
|
|
43
|
+
/** Only sent on first pageview of a session. */
|
|
44
|
+
device?: DevicePayload;
|
|
45
|
+
language: string;
|
|
46
|
+
languages: string[];
|
|
47
|
+
connection_type: string;
|
|
48
|
+
/** Downlink throughput estimate in Mbps (Network Information API). 0 if unavailable. */
|
|
49
|
+
downlink: number;
|
|
50
|
+
/** Round-trip time estimate in ms. 0 if unavailable. */
|
|
51
|
+
rtt: number;
|
|
52
|
+
/** True if the user enabled data-saving mode. */
|
|
53
|
+
save_data: boolean;
|
|
54
|
+
prefers_dark_mode: boolean;
|
|
55
|
+
prefers_reduced_motion: boolean;
|
|
56
|
+
navigation_type: string;
|
|
57
|
+
/** Largest Contentful Paint in milliseconds. */
|
|
58
|
+
lcp: number;
|
|
59
|
+
/** Interaction to Next Paint in milliseconds (Core Web Vital since Mar 2024). */
|
|
60
|
+
inp: number;
|
|
61
|
+
/** Cumulative Layout Shift score (unitless, 0–1 range). */
|
|
62
|
+
cls: number;
|
|
63
|
+
/** First Contentful Paint in milliseconds. */
|
|
64
|
+
fcp: number;
|
|
65
|
+
/** Time to First Byte in milliseconds. */
|
|
66
|
+
ttfb: number;
|
|
67
|
+
/** Do Not Track browser setting. */
|
|
68
|
+
dnt: boolean;
|
|
69
|
+
cookies_enabled: boolean;
|
|
70
|
+
local_storage_available: boolean;
|
|
71
|
+
session_storage_available: boolean;
|
|
72
|
+
indexed_db_available: boolean;
|
|
73
|
+
}
|
|
74
|
+
/** A single throttled mouse position sample. */
|
|
75
|
+
interface MousePoint {
|
|
76
|
+
x: number;
|
|
77
|
+
y: number;
|
|
78
|
+
/** Unix timestamp in milliseconds. */
|
|
79
|
+
t: number;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Browser fingerprinting signals used to compute the composite fp_id.
|
|
83
|
+
* Weighted scores: GPU 0.25 | Canvas 0.20 | Audio 0.15 | Fonts 0.15 | ...
|
|
84
|
+
*/
|
|
85
|
+
interface FingerprintPayload {
|
|
86
|
+
/** SHA-256 of a Canvas 2D render — varies by GPU driver and antialiasing. */
|
|
87
|
+
canvas_hash: string;
|
|
88
|
+
/** GPU model from WEBGL_debug_renderer_info — most stable signal (weight 0.25). */
|
|
89
|
+
webgl_renderer: string;
|
|
90
|
+
/** SHA-256 of a 3D WebGL scene — captures float precision differences between GPUs. */
|
|
91
|
+
webgl_hash: string;
|
|
92
|
+
/** SHA-256 derived from OfflineAudioContext oscillator output (samples 4500–5000). */
|
|
93
|
+
audio_hash: string;
|
|
94
|
+
/** System fonts detected by canvas width comparison against 50 reference fonts. */
|
|
95
|
+
fonts_detected: string[];
|
|
96
|
+
/** Active browser plugins (navigator.plugins). */
|
|
97
|
+
plugins: string[];
|
|
98
|
+
}
|
|
99
|
+
/** Hardware and browser capability signals. */
|
|
100
|
+
interface DevicePayload {
|
|
101
|
+
user_agent: string;
|
|
102
|
+
/** Physical screen dimensions in pixels. */
|
|
103
|
+
screen_w: number;
|
|
104
|
+
screen_h: number;
|
|
105
|
+
/** Visible browser window dimensions — different from screen resolution. */
|
|
106
|
+
viewport_w: number;
|
|
107
|
+
viewport_h: number;
|
|
108
|
+
/** > 1.0 indicates Retina / OLED / 4K display. */
|
|
109
|
+
device_pixel_ratio: number;
|
|
110
|
+
color_depth: number;
|
|
111
|
+
cpu_cores: number;
|
|
112
|
+
/** Approximate RAM in GB — rounded to 0.5/1/2/4/8. */
|
|
113
|
+
device_memory: number;
|
|
114
|
+
touch: boolean;
|
|
115
|
+
/** IANA timezone string e.g. "Africa/Kinshasa". */
|
|
116
|
+
timezone: string;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Event payload for discrete user actions.
|
|
120
|
+
* Built-in types: click | rage_click | scroll_milestone | exit_intent |
|
|
121
|
+
* text_select | element_visible
|
|
122
|
+
* Custom types: any string via window.trackiq.event(type, data)
|
|
123
|
+
*/
|
|
124
|
+
interface EventPayload {
|
|
125
|
+
session_id: string;
|
|
126
|
+
visitor_id: string;
|
|
127
|
+
type: string;
|
|
128
|
+
url: string;
|
|
129
|
+
/** Unix timestamp in milliseconds. */
|
|
130
|
+
ts: number;
|
|
131
|
+
data?: Record<string, unknown>;
|
|
132
|
+
}
|
|
133
|
+
/** Internal state tracked per page session. */
|
|
134
|
+
interface SessionState {
|
|
135
|
+
visitorId: string;
|
|
136
|
+
sessionId: string;
|
|
137
|
+
tsStart: number;
|
|
138
|
+
/** Whether device + fingerprint have been sent in this session. */
|
|
139
|
+
firstPageviewSent: boolean;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export type { DevicePayload as D, EventPayload as E, FingerprintPayload as F, MousePoint as M, PageviewPayload as P, SessionState as S, TrackIQConfig as T };
|
package/dist/vue.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { App } from 'vue';
|
|
2
2
|
export { TrackIQ } from './index.mjs';
|
|
3
|
-
import { T as TrackIQConfig } from './types-
|
|
3
|
+
import { T as TrackIQConfig } from './types-kfDmqmqD.mjs';
|
|
4
4
|
|
|
5
5
|
declare const TrackIQPlugin: {
|
|
6
6
|
install(app: App, options: TrackIQConfig): void;
|
package/dist/vue.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { App } from 'vue';
|
|
2
2
|
export { TrackIQ } from './index.js';
|
|
3
|
-
import { T as TrackIQConfig } from './types-
|
|
3
|
+
import { T as TrackIQConfig } from './types-kfDmqmqD.js';
|
|
4
4
|
|
|
5
5
|
declare const TrackIQPlugin: {
|
|
6
6
|
install(app: App, options: TrackIQConfig): void;
|
package/dist/vue.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var y=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var Y=(t,e)=>{for(var n in e)y(t,n,{get:e[n],enumerable:!0})},j=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of q(e))!Q.call(t,r)&&r!==n&&y(t,r,{get:()=>e[r],enumerable:!(i=W(e,r))||i.enumerable});return t};var X=t=>j(y({},"__esModule",{value:!0}),t);var ve={};Y(ve,{TrackIQPlugin:()=>he});module.exports=X(ve);async function c(t){let n=new TextEncoder().encode(t),i=await crypto.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(i)).map(o=>o.toString(16).padStart(2,"0")).join("")}async function J(){try{let t=document.createElement("canvas");t.width=280,t.height=60;let e=t.getContext("2d");return e?(e.textBaseline="top",e.font="14px Arial",e.fillStyle="#f60",e.fillRect(125,1,62,20),e.fillStyle="#069",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",2,15),e.fillStyle="rgba(102, 204, 0, 0.7)",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",4,45),c(t.toDataURL())):"unavailable"}catch{return"unavailable"}}function Z(){try{let t=document.createElement("canvas"),e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.getExtension("WEBGL_debug_renderer_info");return n?e.getParameter(n.UNMASKED_RENDERER_WEBGL):"unavailable"}catch{return"unavailable"}}async function z(){try{let t=document.createElement("canvas");t.width=16,t.height=16;let e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.createShader(e.VERTEX_SHADER),i=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(n,"attribute vec2 p;void main(){gl_Position=vec4(p,0,1);}"),e.shaderSource(i,"void main(){gl_FragColor=vec4(0.2,0.4,0.6,1.0);}"),e.compileShader(n),e.compileShader(i);let r=e.createProgram();e.attachShader(r,n),e.attachShader(r,i),e.linkProgram(r),e.useProgram(r);let o=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,o),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-.5,-.5,.5,-.5,0,.5]),e.STATIC_DRAW);let s=e.getAttribLocation(r,"p");e.enableVertexAttribArray(s),e.vertexAttribPointer(s,2,e.FLOAT,!1,0,0),e.drawArrays(e.TRIANGLES,0,3);let a=new Uint8Array(256*4);return e.readPixels(0,0,16,16,e.RGBA,e.UNSIGNED_BYTE,a),c(a.join(","))}catch{return"unavailable"}}async function ee(){try{let t=window.OfflineAudioContext||window.webkitOfflineAudioContext;if(!t)return"unavailable";let e=new t(1,44100,44100),n=e.createOscillator();n.type="triangle",n.frequency.setValueAtTime(1e4,e.currentTime);let i=e.createDynamicsCompressor();i.threshold.setValueAtTime(-50,e.currentTime),i.knee.setValueAtTime(40,e.currentTime),i.ratio.setValueAtTime(12,e.currentTime),i.attack.setValueAtTime(0,e.currentTime),i.release.setValueAtTime(.25,e.currentTime),n.connect(i),i.connect(e.destination),n.start(0);let o=(await e.startRendering()).getChannelData(0),s=0;for(let a=4500;a<5e3;a++)s+=Math.abs(o[a]);return c(s.toFixed(10))}catch{return"blocked"}}var te=["Arial","Arial Black","Arial Narrow","Calibri","Cambria","Candara","Comic Sans MS","Consolas","Constantia","Corbel","Courier New","Franklin Gothic Medium","Garamond","Georgia","Gill Sans","Helvetica","Impact","Lucida Console","Lucida Sans Unicode","Microsoft Sans Serif","Palatino Linotype","Segoe UI","Tahoma","Times New Roman","Trebuchet MS","Verdana","Adobe Caslon Pro","Adobe Garamond Pro","Myriad Pro","Roboto","Open Sans","Lato","Montserrat","Oswald","Source Sans Pro","SF Pro Display","SF Pro Text","Helvetica Neue","Futura","Segoe Print","Segoe Script","MS Gothic","Liberation Sans","Liberation Serif","Ubuntu","DejaVu Sans","Wingdings","Symbol","Webdings"];function ne(){try{let e=document.createElement("canvas").getContext("2d");if(!e)return[];let n="mmmmmmmmmmlli",i="72px",r="monospace";e.font=`${i} ${r}`;let o=e.measureText(n).width;return te.filter(s=>(e.font=`${i} '${s}', ${r}`,e.measureText(n).width!==o))}catch{return[]}}function ie(){try{return Array.from(navigator.plugins).map(t=>t.name)}catch{return[]}}async function T(){let[t,e,n]=await Promise.all([J(),z(),ee()]),i=Z(),r=ne(),o=ie(),s={canvas_hash:t,webgl_renderer:i,webgl_hash:e,audio_hash:n,fonts_detected:r,plugins:o},a=[t,i,e,n,r.join(","),o.join(",")].join("|");return{fpId:await c(a),payload:s}}async function E(t){return c(t)}var k="tiq_vid",C="tiq_sid";function l(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function _(){try{let t=localStorage.getItem(k);return t||(t=l(),localStorage.setItem(k,t)),t}catch{return l()}}function A(){try{let t=sessionStorage.getItem(C);return t||(t=l(),sessionStorage.setItem(C,t)),t}catch{return l()}}function I(){try{let t="__tiq_test__";return localStorage.setItem(t,"1"),localStorage.removeItem(t),!0}catch{return!1}}function P(){try{let t="__tiq_test__";return sessionStorage.setItem(t,"1"),sessionStorage.removeItem(t),!0}catch{return!1}}function L(){try{return typeof indexedDB!="undefined"&&indexedDB!==null}catch{return!1}}function D(){return{user_agent:navigator.userAgent,screen_w:screen.width,screen_h:screen.height,viewport_w:window.innerWidth,viewport_h:window.innerHeight,device_pixel_ratio:window.devicePixelRatio||1,color_depth:screen.colorDepth,cpu_cores:navigator.hardwareConcurrency||0,device_memory:navigator.deviceMemory||0,touch:navigator.maxTouchPoints>0,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}}function R(){return navigator.language||""}function M(){return Array.from(navigator.languages||[navigator.language])}function N(){let t=navigator.connection;return(t==null?void 0:t.effectiveType)||"unknown"}function H(){return window.matchMedia("(prefers-color-scheme: dark)").matches}function F(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}function O(){try{let t=performance.getEntriesByType("navigation")[0];return(t==null?void 0:t.type)||"navigate"}catch{return"navigate"}}function B(){return navigator.doNotTrack==="1"||window.doNotTrack==="1"}function U(){return navigator.cookieEnabled}var re=[25,50,75,90],d=class{constructor(){this.maxScroll=0;this.milestones=new Set;this.handler=()=>this.onScroll(),window.addEventListener("scroll",this.handler,{passive:!0})}onScroll(){let e=document.body.scrollHeight-window.innerHeight;if(e<=0)return;let n=Math.round(window.scrollY/e*100);n>this.maxScroll&&(this.maxScroll=n);for(let i of re)n>=i&&this.milestones.add(i)}get maxScrollDepth(){return this.maxScroll}get reachedMilestones(){return Array.from(this.milestones)}destroy(){window.removeEventListener("scroll",this.handler)}},G=["mousemove","scroll","click","keydown","touchstart"],oe=3e4,u=class{constructor(){this.accumulated=0;this.lastActiveAt=Date.now();this.idle=!1;this.hidden=!1;this.idleTimer=null;this.activityHandler=()=>this.onActivity(),this.visibilityHandler=()=>this.onVisibilityChange();for(let e of G)window.addEventListener(e,this.activityHandler,{passive:!0});document.addEventListener("visibilitychange",this.visibilityHandler),this.scheduleIdleCheck()}onActivity(){this.hidden||(this.idle?(this.lastActiveAt=Date.now(),this.idle=!1):this.flush(),this.scheduleIdleCheck())}onVisibilityChange(){document.hidden?(this.flush(),this.hidden=!0):(this.hidden=!1,this.lastActiveAt=Date.now())}flush(){!this.idle&&!this.hidden&&(this.accumulated+=Date.now()-this.lastActiveAt,this.lastActiveAt=Date.now())}scheduleIdleCheck(){this.idleTimer&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{this.flush(),this.idle=!0},oe)}get activeTimeMs(){return this.flush(),this.accumulated}destroy(){for(let e of G)window.removeEventListener(e,this.activityHandler);document.removeEventListener("visibilitychange",this.visibilityHandler),this.idleTimer&&clearTimeout(this.idleTimer)}},se=30,ae=1e3,h=class{constructor(){this.path=[];this.lastSampleAt=0;this.handler=e=>this.onMouseMove(e),window.addEventListener("mousemove",this.handler,{passive:!0})}onMouseMove(e){let n=Date.now();this.path.length>=se||n-this.lastSampleAt<ae||(this.path.push({x:e.clientX,y:e.clientY,t:n}),this.lastSampleAt=n)}get points(){return this.path}destroy(){window.removeEventListener("mousemove",this.handler)}},v=class{constructor(e){this.onExitIntent=e;this.fired=!1;this.handler=n=>{!this.fired&&n.clientY<10&&(this.fired=!0,this.onExitIntent(n.clientX,n.clientY))},document.addEventListener("mousemove",this.handler,{passive:!0})}destroy(){document.removeEventListener("mousemove",this.handler)}},ce=1e3,le=3,p=class{constructor(e){this.onRageClick=e;this.recentClicks=[];this.handler=n=>this.onClick(n),window.addEventListener("click",this.handler,{passive:!0})}onClick(e){let n=Date.now();if(this.recentClicks=this.recentClicks.filter(i=>n-i.ts<ce),this.recentClicks.push({ts:n,x:e.clientX,y:e.clientY}),this.recentClicks.length>=le){let i=x(e.target);this.onRageClick(e.clientX,e.clientY,this.recentClicks.length,i),this.recentClicks=[]}}destroy(){window.removeEventListener("click",this.handler)}},g=class{constructor(e){this.onClick=e;this.handler=n=>{let i=n.target;if(w(i))return;let r=de(i);this.onClick(n.clientX,n.clientY,Date.now(),x(i),r)},window.addEventListener("click",this.handler,{passive:!0})}destroy(){window.removeEventListener("click",this.handler)}},m=class{constructor(e){this.onSelect=e;this.handler=()=>{var o;let n=window.getSelection();if(!n||n.isCollapsed)return;let i=n.toString().trim();if(!i||i.length<3)return;let r=(o=n.anchorNode)==null?void 0:o.parentElement;r&&w(r)||this.onSelect(i.slice(0,200),x(r||document.body))},document.addEventListener("selectionchange",this.handler,{passive:!0})}destroy(){document.removeEventListener("selectionchange",this.handler)}};function V(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=new PerformanceObserver(n=>{let i=n.getEntries(),r=i[i.length-1];r&&t(Math.round(r.startTime))});return e.observe({type:"largest-contentful-paint",buffered:!0}),()=>e.disconnect()}catch{return()=>{}}}function w(t){var n;if(!t)return!1;let e=(n=t.tagName)==null?void 0:n.toLowerCase();return["input","textarea","select","option"].includes(e)}function x(t){if(!t||!t.tagName)return"";let e=t.tagName.toLowerCase(),n=t.id?`#${t.id}`:"",i=t.classList.length?`.${Array.from(t.classList).slice(0,2).join(".")}`:"";return`${e}${n}${i}`.slice(0,60)}function de(t){return!t||w(t)?"":(t.textContent||"").trim().slice(0,50)}var $="https://api.trackiq.io";async function K(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/pageview`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};if(b(i,n,r),!(t.dataEndpoint.replace(/\/$/,"")===$.replace(/\/$/,""))){let s=await E(t.apiKey),a=JSON.stringify({key_hash:s,type:"pageview"});b(`${$}/v1/consume`,a,{"Content-Type":"application/json"})}}function S(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/event`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};b(i,n,r)}function b(t,e,n){try{fetch(t,{method:"POST",headers:n,body:e,keepalive:!0}).catch(()=>{})}catch{}}var ue="https://api.trackiq.io",f=class{constructor(e){this.fpId="";this.lcp=0;var n;this.config={dataEndpoint:ue,debug:!1,...e},this.beacon={apiKey:this.config.apiKey,dataEndpoint:this.config.dataEndpoint},this.pageURL=window.location.href,this.pageReferrer=(n=e.referrer)!=null?n:document.referrer,this.session={visitorId:_(),sessionId:A(),tsStart:Date.now(),firstPageviewSent:!1},this.scroll=new d,this.activeTime=new u,this.mousePath=new h,this.exitIntent=new v((i,r)=>{this.sendBehaviorEvent("exit_intent",{x:i,y:r})}),this.rageClick=new p((i,r,o,s)=>{this.sendBehaviorEvent("rage_click",{x:i,y:r,count:o,element:s})}),this.clickTracker=new g((i,r,o,s,a)=>{this.sendBehaviorEvent("click",{x:i,y:r,ts:o,element:s,text:a})}),this.textSelect=new m((i,r)=>{this.sendBehaviorEvent("text_select",{text:i,element:r})}),this.disconnectLCP=V(i=>{this.lcp=i}),this.scheduleFingerprint(),this.unloadHandler=()=>{this.flush()},window.addEventListener("beforeunload",this.unloadHandler),window.trackiq={event:this.event.bind(this)},this.log("TrackIQ initialised",{visitorId:this.session.visitorId})}event(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};S(this.beacon,i),this.log("event sent",{type:e,data:n})}destroy(){this.flush(),window.removeEventListener("beforeunload",this.unloadHandler),this.scroll.destroy(),this.activeTime.destroy(),this.mousePath.destroy(),this.exitIntent.destroy(),this.rageClick.destroy(),this.clickTracker.destroy(),this.textSelect.destroy(),this.disconnectLCP(),this.log("TrackIQ destroyed")}scheduleFingerprint(){let e=async()=>{let{fpId:n,payload:i}=await T();this.fpId=n,this.fpPayload=i,this.log("fingerprint computed",{fpId:n})};"requestIdleCallback"in window?requestIdleCallback(()=>{e().catch(()=>{})},{timeout:3e3}):setTimeout(()=>{e().catch(()=>{})},1)}flush(){let e=Date.now(),n=!this.session.firstPageviewSent;K(this.beacon,{session_id:this.session.sessionId,visitor_id:this.session.visitorId,url:this.pageURL,referrer:this.pageReferrer,ts_start:this.session.tsStart,ts_end:e,active_time:this.activeTime.activeTimeMs,max_scroll:this.scroll.maxScrollDepth,milestones:this.scroll.reachedMilestones,mouse_path:this.mousePath.points,fp_id:this.fpId,fingerprint:n?this.fpPayload:void 0,device:n?D():void 0,language:R(),languages:M(),connection_type:N(),prefers_dark_mode:H(),prefers_reduced_motion:F(),navigation_type:O(),lcp:this.lcp,dnt:B(),cookies_enabled:U(),local_storage_available:I(),session_storage_available:P(),indexed_db_available:L()}).catch(()=>{}),this.session.firstPageviewSent=!0,this.log("pageview sent")}sendBehaviorEvent(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};S(this.beacon,i)}log(e,n){this.config.debug&&console.log(`[TrackIQ] ${e}`,n!=null?n:"")}};var he={install(t,e){if(typeof window=="undefined")return;let n=new f(e);t.config.globalProperties.$trackiq=n,t.provide("trackiq",n);let i=t.unmount.bind(t);t.unmount=()=>{n.destroy(),i()}}};0&&(module.exports={TrackIQPlugin});
|
|
1
|
+
"use strict";var w=Object.defineProperty;var z=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var ne=(t,e)=>{for(var n in e)w(t,n,{get:e[n],enumerable:!0})},ie=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ee(e))!te.call(t,r)&&r!==n&&w(t,r,{get:()=>e[r],enumerable:!(i=z(e,r))||i.enumerable});return t};var re=t=>ie(w({},"__esModule",{value:!0}),t);var Te={};ne(Te,{TrackIQPlugin:()=>xe});module.exports=re(Te);async function c(t){let n=new TextEncoder().encode(t),i=await crypto.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(i)).map(o=>o.toString(16).padStart(2,"0")).join("")}async function oe(){try{let t=document.createElement("canvas");t.width=280,t.height=60;let e=t.getContext("2d");return e?(e.textBaseline="top",e.font="14px Arial",e.fillStyle="#f60",e.fillRect(125,1,62,20),e.fillStyle="#069",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",2,15),e.fillStyle="rgba(102, 204, 0, 0.7)",e.fillText("TrackIQ canvas fp \u2014 \u0398\u03B1",4,45),c(t.toDataURL())):"unavailable"}catch{return"unavailable"}}function se(){try{let t=document.createElement("canvas"),e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.getExtension("WEBGL_debug_renderer_info");return n?e.getParameter(n.UNMASKED_RENDERER_WEBGL):"unavailable"}catch{return"unavailable"}}async function ae(){try{let t=document.createElement("canvas");t.width=16,t.height=16;let e=t.getContext("webgl")||t.getContext("experimental-webgl");if(!e)return"unavailable";let n=e.createShader(e.VERTEX_SHADER),i=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(n,"attribute vec2 p;void main(){gl_Position=vec4(p,0,1);}"),e.shaderSource(i,"void main(){gl_FragColor=vec4(0.2,0.4,0.6,1.0);}"),e.compileShader(n),e.compileShader(i);let r=e.createProgram();e.attachShader(r,n),e.attachShader(r,i),e.linkProgram(r),e.useProgram(r);let o=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,o),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-.5,-.5,.5,-.5,0,.5]),e.STATIC_DRAW);let s=e.getAttribLocation(r,"p");e.enableVertexAttribArray(s),e.vertexAttribPointer(s,2,e.FLOAT,!1,0,0),e.drawArrays(e.TRIANGLES,0,3);let a=new Uint8Array(256*4);return e.readPixels(0,0,16,16,e.RGBA,e.UNSIGNED_BYTE,a),c(a.join(","))}catch{return"unavailable"}}async function ce(){try{let t=window.OfflineAudioContext||window.webkitOfflineAudioContext;if(!t)return"unavailable";let e=new t(1,44100,44100),n=e.createOscillator();n.type="triangle",n.frequency.setValueAtTime(1e4,e.currentTime);let i=e.createDynamicsCompressor();i.threshold.setValueAtTime(-50,e.currentTime),i.knee.setValueAtTime(40,e.currentTime),i.ratio.setValueAtTime(12,e.currentTime),i.attack.setValueAtTime(0,e.currentTime),i.release.setValueAtTime(.25,e.currentTime),n.connect(i),i.connect(e.destination),n.start(0);let o=(await e.startRendering()).getChannelData(0),s=0;for(let a=4500;a<5e3;a++)s+=Math.abs(o[a]);return c(s.toFixed(10))}catch{return"blocked"}}var le=["Arial","Arial Black","Arial Narrow","Calibri","Cambria","Candara","Comic Sans MS","Consolas","Constantia","Corbel","Courier New","Franklin Gothic Medium","Garamond","Georgia","Gill Sans","Helvetica","Impact","Lucida Console","Lucida Sans Unicode","Microsoft Sans Serif","Palatino Linotype","Segoe UI","Tahoma","Times New Roman","Trebuchet MS","Verdana","Adobe Caslon Pro","Adobe Garamond Pro","Myriad Pro","Roboto","Open Sans","Lato","Montserrat","Oswald","Source Sans Pro","SF Pro Display","SF Pro Text","Helvetica Neue","Futura","Segoe Print","Segoe Script","MS Gothic","Liberation Sans","Liberation Serif","Ubuntu","DejaVu Sans","Wingdings","Symbol","Webdings"];function de(){try{let e=document.createElement("canvas").getContext("2d");if(!e)return[];let n="mmmmmmmmmmlli",i="72px",r="monospace";e.font=`${i} ${r}`;let o=e.measureText(n).width;return le.filter(s=>(e.font=`${i} '${s}', ${r}`,e.measureText(n).width!==o))}catch{return[]}}function ue(){try{return Array.from(navigator.plugins).map(t=>t.name)}catch{return[]}}async function k(){let[t,e,n]=await Promise.all([oe(),ae(),ce()]),i=se(),r=de(),o=ue(),s={canvas_hash:t,webgl_renderer:i,webgl_hash:e,audio_hash:n,fonts_detected:r,plugins:o},a=[t,i,e,n,r.join(","),o.join(",")].join("|");return{fpId:await c(a),payload:s}}async function C(t){return c(t)}var _="tiq_vid",I="tiq_sid";function l(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function A(){try{let t=localStorage.getItem(_);return t||(t=l(),localStorage.setItem(_,t)),t}catch{return l()}}function P(){try{let t=sessionStorage.getItem(I);return t||(t=l(),sessionStorage.setItem(I,t)),t}catch{return l()}}function L(){try{let t="__tiq_test__";return localStorage.setItem(t,"1"),localStorage.removeItem(t),!0}catch{return!1}}function D(){try{let t="__tiq_test__";return sessionStorage.setItem(t,"1"),sessionStorage.removeItem(t),!0}catch{return!1}}function M(){try{return typeof indexedDB!="undefined"&&indexedDB!==null}catch{return!1}}function R(){return{user_agent:navigator.userAgent,screen_w:screen.width,screen_h:screen.height,viewport_w:window.innerWidth,viewport_h:window.innerHeight,device_pixel_ratio:window.devicePixelRatio||1,color_depth:screen.colorDepth,cpu_cores:navigator.hardwareConcurrency||0,device_memory:navigator.deviceMemory||0,touch:navigator.maxTouchPoints>0,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone}}function N(){return navigator.language||""}function O(){return Array.from(navigator.languages||[navigator.language])}function d(){var t;return(t=navigator.connection)!=null?t:{}}function F(){return d().effectiveType||"unknown"}function H(){var t;return(t=d().downlink)!=null?t:0}function B(){var t;return(t=d().rtt)!=null?t:0}function U(){var t;return(t=d().saveData)!=null?t:!1}function G(){return window.matchMedia("(prefers-color-scheme: dark)").matches}function V(){return window.matchMedia("(prefers-reduced-motion: reduce)").matches}function Y(){try{let t=performance.getEntriesByType("navigation")[0];return(t==null?void 0:t.type)||"navigate"}catch{return"navigate"}}function K(){return navigator.doNotTrack==="1"||window.doNotTrack==="1"}function q(){return navigator.cookieEnabled}var he=[25,50,75,90],u=class{constructor(){this.maxScroll=0;this.milestones=new Set;this.handler=()=>this.onScroll(),window.addEventListener("scroll",this.handler,{passive:!0})}onScroll(){let e=document.body.scrollHeight-window.innerHeight;if(e<=0)return;let n=Math.round(window.scrollY/e*100);n>this.maxScroll&&(this.maxScroll=n);for(let i of he)n>=i&&this.milestones.add(i)}get maxScrollDepth(){return this.maxScroll}get reachedMilestones(){return Array.from(this.milestones)}destroy(){window.removeEventListener("scroll",this.handler)}},W=["mousemove","scroll","click","keydown","touchstart"],ve=3e4,h=class{constructor(){this.accumulated=0;this.lastActiveAt=Date.now();this.idle=!1;this.hidden=!1;this.idleTimer=null;this.activityHandler=()=>this.onActivity(),this.visibilityHandler=()=>this.onVisibilityChange();for(let e of W)window.addEventListener(e,this.activityHandler,{passive:!0});document.addEventListener("visibilitychange",this.visibilityHandler),this.scheduleIdleCheck()}onActivity(){this.hidden||(this.idle?(this.lastActiveAt=Date.now(),this.idle=!1):this.flush(),this.scheduleIdleCheck())}onVisibilityChange(){document.hidden?(this.flush(),this.hidden=!0):(this.hidden=!1,this.lastActiveAt=Date.now())}flush(){!this.idle&&!this.hidden&&(this.accumulated+=Date.now()-this.lastActiveAt,this.lastActiveAt=Date.now())}scheduleIdleCheck(){this.idleTimer&&clearTimeout(this.idleTimer),this.idleTimer=setTimeout(()=>{this.flush(),this.idle=!0},ve)}get activeTimeMs(){return this.flush(),this.accumulated}destroy(){for(let e of W)window.removeEventListener(e,this.activityHandler);document.removeEventListener("visibilitychange",this.visibilityHandler),this.idleTimer&&clearTimeout(this.idleTimer)}},pe=30,fe=1e3,v=class{constructor(){this.path=[];this.lastSampleAt=0;this.handler=e=>this.onMouseMove(e),window.addEventListener("mousemove",this.handler,{passive:!0})}onMouseMove(e){let n=Date.now();this.path.length>=pe||n-this.lastSampleAt<fe||(this.path.push({x:Math.round(e.clientX+window.scrollX),y:Math.round(e.clientY+window.scrollY),t:n}),this.lastSampleAt=n)}get points(){return this.path}destroy(){window.removeEventListener("mousemove",this.handler)}},p=class{constructor(e){this.onExitIntent=e;this.fired=!1;this.handler=n=>{!this.fired&&n.clientY<10&&(this.fired=!0,this.onExitIntent(Math.round(n.clientX+window.scrollX),Math.round(n.clientY+window.scrollY)))},document.addEventListener("mousemove",this.handler,{passive:!0})}destroy(){document.removeEventListener("mousemove",this.handler)}},me=1e3,ge=3,f=class{constructor(e){this.onRageClick=e;this.recentClicks=[];this.handler=n=>this.onClick(n),window.addEventListener("click",this.handler,{passive:!0})}onClick(e){let n=Date.now();if(this.recentClicks=this.recentClicks.filter(i=>n-i.ts<me),this.recentClicks.push({ts:n,x:Math.round(e.clientX+window.scrollX),y:Math.round(e.clientY+window.scrollY)}),this.recentClicks.length>=ge){let i=x(e.target);this.onRageClick(Math.round(e.clientX+window.scrollX),Math.round(e.clientY+window.scrollY),this.recentClicks.length,i),this.recentClicks=[]}}destroy(){window.removeEventListener("click",this.handler)}},m=class{constructor(e){this.onClick=e;this.handler=n=>{let i=n.target;if(b(i))return;let r=ye(i);this.onClick(Math.round(n.clientX+window.scrollX),Math.round(n.clientY+window.scrollY),Date.now(),x(i),r)},window.addEventListener("click",this.handler,{passive:!0})}destroy(){window.removeEventListener("click",this.handler)}},g=class{constructor(e){this.onSelect=e;this.handler=()=>{var o;let n=window.getSelection();if(!n||n.isCollapsed)return;let i=n.toString().trim();if(!i||i.length<3)return;let r=(o=n.anchorNode)==null?void 0:o.parentElement;r&&b(r)||this.onSelect(i.slice(0,200),x(r||document.body))},document.addEventListener("selectionchange",this.handler,{passive:!0})}destroy(){document.removeEventListener("selectionchange",this.handler)}};function $(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=new PerformanceObserver(n=>{let i=n.getEntries(),r=i[i.length-1];r&&t(Math.round(r.startTime))});return e.observe({type:"largest-contentful-paint",buffered:!0}),()=>e.disconnect()}catch{return()=>{}}}function Q(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=0,n=new PerformanceObserver(i=>{for(let r of i.getEntries()){let o=r,s=o.processingStart?o.processingStart-o.startTime+o.duration:o.duration;s>e&&(e=s,t(Math.round(e)))}});return n.observe({type:"event",buffered:!0,durationThreshold:16}),()=>n.disconnect()}catch{return()=>{}}}function X(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=0,n=new PerformanceObserver(i=>{for(let r of i.getEntries()){let o=r;o.hadRecentInput||(e+=o.value,t(parseFloat(e.toFixed(4))))}});return n.observe({type:"layout-shift",buffered:!0}),()=>n.disconnect()}catch{return()=>{}}}function j(t){if(!("PerformanceObserver"in window))return()=>{};try{let e=new PerformanceObserver(n=>{for(let i of n.getEntries())if(i.name==="first-contentful-paint"){t(Math.round(i.startTime)),e.disconnect();return}});return e.observe({type:"paint",buffered:!0}),()=>e.disconnect()}catch{return()=>{}}}function J(){try{let t=performance.getEntriesByType("navigation")[0];return t?Math.round(t.responseStart-t.requestStart):0}catch{return 0}}function b(t){var n;if(!t)return!1;let e=(n=t.tagName)==null?void 0:n.toLowerCase();return["input","textarea","select","option"].includes(e)}function x(t){if(!t||!t.tagName)return"";let e=t.tagName.toLowerCase(),n=t.id?`#${t.id}`:"",i=t.classList.length?`.${Array.from(t.classList).slice(0,2).join(".")}`:"";return`${e}${n}${i}`.slice(0,60)}function ye(t){return!t||b(t)?"":(t.textContent||"").trim().slice(0,50)}var we="https://api.trackiq.io";async function Z(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/pageview`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};if(T(i,n,r),t.selfHosted){let o=await C(t.apiKey),s=JSON.stringify({key_hash:o,type:"pageview"});T(`${we}/v1/consume`,s,{"Content-Type":"application/json"})}}function S(t,e){let n=JSON.stringify(e),i=`${t.dataEndpoint}/v1/track/event`,r={"X-Api-Key":t.apiKey,"Content-Type":"application/json"};T(i,n,r)}function T(t,e,n){try{fetch(t,{method:"POST",headers:n,body:e,keepalive:!0}).catch(()=>{})}catch{}}var be="https://api.trackiq.io",y=class{constructor(e){this.fpId="";this.lcp=0;this.inp=0;this.cls=0;this.fcp=0;this.ttfb=0;var n,i;this.config={dataEndpoint:be,debug:!1,...e},this.beacon={apiKey:this.config.apiKey,dataEndpoint:this.config.dataEndpoint,selfHosted:(n=e.selfHosted)!=null?n:!1},this.pageURL=window.location.href,this.pageReferrer=(i=e.referrer)!=null?i:document.referrer,this.session={visitorId:A(),sessionId:P(),tsStart:Date.now(),firstPageviewSent:!1},this.scroll=new u,this.activeTime=new h,this.mousePath=new v,this.exitIntent=new p((r,o)=>{this.sendBehaviorEvent("exit_intent",{x:r,y:o})}),this.rageClick=new f((r,o,s,a)=>{this.sendBehaviorEvent("rage_click",{x:r,y:o,count:s,element:a})}),this.clickTracker=new m((r,o,s,a,E)=>{this.sendBehaviorEvent("click",{x:r,y:o,ts:s,element:a,text:E})}),this.textSelect=new g((r,o)=>{this.sendBehaviorEvent("text_select",{text:r,element:o})}),this.disconnectLCP=$(r=>{this.lcp=r}),Q(r=>{this.inp=r}),X(r=>{this.cls=r}),j(r=>{this.fcp=r}),this.ttfb=J(),this.scheduleFingerprint(),this.unloadHandler=()=>{this.flush()},window.addEventListener("beforeunload",this.unloadHandler),window.trackiq={event:this.event.bind(this)},this.log("TrackIQ initialised",{visitorId:this.session.visitorId})}event(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};S(this.beacon,i),this.log("event sent",{type:e,data:n})}destroy(){this.flush(),window.removeEventListener("beforeunload",this.unloadHandler),this.scroll.destroy(),this.activeTime.destroy(),this.mousePath.destroy(),this.exitIntent.destroy(),this.rageClick.destroy(),this.clickTracker.destroy(),this.textSelect.destroy(),this.disconnectLCP(),this.log("TrackIQ destroyed")}scheduleFingerprint(){let e=async()=>{let{fpId:n,payload:i}=await k();this.fpId=n,this.fpPayload=i,this.log("fingerprint computed",{fpId:n})};"requestIdleCallback"in window?requestIdleCallback(()=>{e().catch(()=>{})},{timeout:3e3}):setTimeout(()=>{e().catch(()=>{})},1)}flush(){let e=Date.now(),n=!this.session.firstPageviewSent;Z(this.beacon,{session_id:this.session.sessionId,visitor_id:this.session.visitorId,url:this.pageURL,referrer:this.pageReferrer,ts_start:this.session.tsStart,ts_end:e,active_time:this.activeTime.activeTimeMs,max_scroll:this.scroll.maxScrollDepth,milestones:this.scroll.reachedMilestones,mouse_path:this.mousePath.points,fp_id:this.fpId,fingerprint:n?this.fpPayload:void 0,device:n?R():void 0,language:N(),languages:O(),connection_type:F(),downlink:H(),rtt:B(),save_data:U(),prefers_dark_mode:G(),prefers_reduced_motion:V(),navigation_type:Y(),lcp:this.lcp,inp:this.inp,cls:this.cls,fcp:this.fcp,ttfb:this.ttfb,dnt:K(),cookies_enabled:q(),local_storage_available:L(),session_storage_available:D(),indexed_db_available:M()}).catch(()=>{}),this.session.firstPageviewSent=!0,this.log("pageview sent")}sendBehaviorEvent(e,n){let i={session_id:this.session.sessionId,visitor_id:this.session.visitorId,type:e,url:window.location.href,ts:Date.now(),data:n};S(this.beacon,i)}log(e,n){this.config.debug&&console.log(`[TrackIQ] ${e}`,n!=null?n:"")}};var xe={install(t,e){if(typeof window=="undefined")return;let n=new y(e);t.config.globalProperties.$trackiq=n,t.provide("trackiq",n);let i=t.unmount.bind(t);t.unmount=()=>{n.destroy(),i()}}};0&&(module.exports={TrackIQPlugin});
|
package/dist/vue.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as t}from"./chunk-
|
|
1
|
+
import{a as t}from"./chunk-GSAGJBV2.mjs";var c={install(o,n){if(typeof window=="undefined")return;let r=new t(n);o.config.globalProperties.$trackiq=r,o.provide("trackiq",r);let i=o.unmount.bind(o);o.unmount=()=>{r.destroy(),i()}}};export{c as TrackIQPlugin};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upperz/trackiq-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Privacy-first analytics SDK for TrackIQ",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -16,27 +16,29 @@
|
|
|
16
16
|
"types": "./dist/index.d.ts",
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
19
|
-
"types":
|
|
20
|
-
"import":
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
21
|
"require": "./dist/index.cjs"
|
|
22
22
|
},
|
|
23
23
|
"./react": {
|
|
24
|
-
"types":
|
|
25
|
-
"import":
|
|
24
|
+
"types": "./dist/react.d.ts",
|
|
25
|
+
"import": "./dist/react.js",
|
|
26
26
|
"require": "./dist/react.cjs"
|
|
27
27
|
},
|
|
28
28
|
"./next": {
|
|
29
|
-
"types":
|
|
30
|
-
"import":
|
|
29
|
+
"types": "./dist/next.d.ts",
|
|
30
|
+
"import": "./dist/next.js",
|
|
31
31
|
"require": "./dist/next.cjs"
|
|
32
32
|
},
|
|
33
33
|
"./vue": {
|
|
34
|
-
"types":
|
|
35
|
-
"import":
|
|
34
|
+
"types": "./dist/vue.d.ts",
|
|
35
|
+
"import": "./dist/vue.js",
|
|
36
36
|
"require": "./dist/vue.cjs"
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
|
-
"files": [
|
|
39
|
+
"files": [
|
|
40
|
+
"dist"
|
|
41
|
+
],
|
|
40
42
|
"sideEffects": false,
|
|
41
43
|
"scripts": {
|
|
42
44
|
"build": "tsup",
|
|
@@ -50,9 +52,15 @@
|
|
|
50
52
|
"vue": ">=3"
|
|
51
53
|
},
|
|
52
54
|
"peerDependenciesMeta": {
|
|
53
|
-
"react": {
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
"react": {
|
|
56
|
+
"optional": true
|
|
57
|
+
},
|
|
58
|
+
"react-dom": {
|
|
59
|
+
"optional": true
|
|
60
|
+
},
|
|
61
|
+
"vue": {
|
|
62
|
+
"optional": true
|
|
63
|
+
}
|
|
56
64
|
},
|
|
57
65
|
"devDependencies": {
|
|
58
66
|
"@types/react": "^18",
|