@cnv-vn/track 0.2.0-alpha.4 → 0.2.0-alpha.5

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.
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @cnv-vn/track v0.2.0-alpha.4
2
+ * @cnv-vn/track v0.2.0-alpha.5
3
3
  * (c) 2026 CNV
4
4
  * Released under the UNLICENSED license.
5
5
  */
6
- const t=["pdf","doc","docx","xls","xlsx","ppt","pptx","txt","csv","rtf","zip","rar","7z","tar","gz","mp3","mp4","mov","wav","avi","mkv","dmg","exe","pkg","apk","msi","svg"];function n(t){return!!t&&"object"==typeof t&&1===t.nodeType&&"A"===t.tagName}function e(t){const n=t.lastIndexOf("/");return-1===n?t:t.slice(n+1)}function r(t){var n,e,r;let o=(null!==(n=t.textContent)&&void 0!==n?n:"").trim();return o||(o=(null!==(e=t.getAttribute("aria-label"))&&void 0!==e?e:"").trim()),o||(o=(null!==(r=t.getAttribute("title"))&&void 0!==r?r:"").trim()),o.length>200?o.slice(0,200):o}const o="__cnvPatched";function i(){try{return"undefined"!=typeof location?location.href:""}catch(t){return""}}const c=["q","s","query","search","keyword"],u={spa:!0,outboundClicks:!0,scroll:!0,downloads:!0,siteSearch:!0},s={spa:!1,outboundClicks:!1,scroll:!1,downloads:!1,siteSearch:!1};function a(t){try{t()}catch(t){}}const l=["gclid","fbclid","ttclid","msclkid","dclid"],d=[["utm_source","source"],["utm_medium","medium"],["utm_campaign","name"],["utm_term","term"],["utm_content","content"],["utm_id","id"]];function f(t,n){try{return t()}catch(t){return n}}function h(){const t=f(()=>window.location.href,"");let n="",e="",r="";if(t)try{const o=new URL(t);n=o.pathname,e=o.search,r=o.hash}catch(t){}return{url:t,path:n,search:e,hash:r,title:f(()=>document.title,""),referrer:f(()=>document.referrer,"")}}function y(t){var n,e;let r="@cnv-vn/track",o="0.0.0-dev";try{r="@cnv-vn/track"}catch(t){}try{o="0.2.0-alpha.4"}catch(t){}return{name:null!==(n=null==t?void 0:t.name)&&void 0!==n?n:r,version:null!==(e=null==t?void 0:t.version)&&void 0!==e?e:o}}const v="0123456789abcdef";function p(t){return v[t>>>4&15]+v[15&t]}function m(){if("undefined"!=typeof crypto){if("function"==typeof crypto.randomUUID)return crypto.randomUUID();if("function"==typeof crypto.getRandomValues){const t=new Uint8Array(16);return crypto.getRandomValues(t),t[6]=15&t[6]|64,t[8]=63&t[8]|128,p(t[0])+p(t[1])+p(t[2])+p(t[3])+"-"+p(t[4])+p(t[5])+"-"+p(t[6])+p(t[7])+"-"+p(t[8])+p(t[9])+"-"+p(t[10])+p(t[11])+p(t[12])+p(t[13])+p(t[14])+p(t[15])}}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const n=16*Math.random()|0;return("x"===t?n:3&n|8).toString(16)})}const b=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function w(t){return"string"==typeof t&&b.test(t)}const g="undefined"!=typeof window&&"undefined"!=typeof document;function x(t){if(!g)return null;try{const n=document.cookie;if(!n)return null;const e=encodeURIComponent(t),r=n.split(";");for(let n=0;n<r.length;n++){const o=r[n].indexOf("=");if(o<0)continue;const i=r[n].slice(0,o).trim();if(i===e||i===t)try{return decodeURIComponent(r[n].slice(o+1))}catch(t){return r[n].slice(o+1)}}return null}catch(t){return null}}function k(t,n,e={}){var r,o,i;if(!g)return!1;try{let c=`${encodeURIComponent(t)}=${encodeURIComponent(n)}`;if(c+=`; path=${null!==(r=e.path)&&void 0!==r?r:"/"}`,e.domain&&(c+=`; domain=${e.domain}`),"number"==typeof e.maxAgeDays){const t=Math.floor(86400*e.maxAgeDays);c+=`; max-age=${t}`,c+=`; expires=${new Date(Date.now()+1e3*t).toUTCString()}`}return c+=`; SameSite=${null!==(o=e.sameSite)&&void 0!==o?o:"Lax"}`,(null!==(i=e.secure)&&void 0!==i?i:"undefined"!=typeof location&&"https:"===location.protocol)&&(c+="; Secure"),document.cookie=c,x(t)===n}catch(t){return!1}}function j(){if(!g)return!1;try{const t="__cnv_probe__";return localStorage.setItem(t,"1"),localStorage.removeItem(t),!0}catch(t){return!1}}function O(t){if(!j())return null;try{return localStorage.getItem(t)}catch(t){return null}}function S(t,n){if(!j())return!1;try{return localStorage.setItem(t,n),!0}catch(t){return!1}}function _(t){if(!j())return!1;try{return localStorage.removeItem(t),!0}catch(t){return!1}}function A(){if(!g)return!1;try{const t="__cnv_probe__";return sessionStorage.setItem(t,"1"),sessionStorage.removeItem(t),!0}catch(t){return!1}}const P="_cnv_cid";function D(t={}){const n=x(P),e=O(P);let r=null;return w(n)?r=n:w(e)&&(r=e),r||(r=m()),I(r,t),r}function I(t,n={}){var e;k(P,t,{domain:n.cookieDomain,maxAgeDays:null!==(e=n.cookieMaxAgeDays)&&void 0!==e?e:730,sameSite:"Lax"}),S(P,t)}const M="1.0";function U(){return(new Date).toISOString()}function C(t,n){var e;const r=null!==(e=n.timestamp)&&void 0!==e?e:U(),o=Object.assign(Object.assign({},n.context),{projectId:n.projectId,schemaVersion:M}),i={type:t,messageId:m(),anonymousId:n.anonymousId,timestamp:r,originalTimestamp:r,context:o};return n.userId&&(i.userId=n.userId),n.sessionId&&(i.sessionId=n.sessionId),n.integrations&&(i.integrations=n.integrations),i}const T="_cnv_sid";function $(t){if(!t)return null;const n=t.lastIndexOf(".");if(n<0)return null;const e=t.slice(0,n),r=Number(t.slice(n+1));return!w(e)||!Number.isFinite(r)||r<=0?null:{id:e,lastActivity:r}}function L(t={}){const n=Date.now(),e=(t=>{var n;return 6e4*(null!==(n=t.timeoutMinutes)&&void 0!==n?n:30)})(t),r=$(x(T)),o=$((t=>{if(!A())return null;try{return sessionStorage.getItem(t)}catch(t){return null}})(T));let i=null;for(const t of[r,o])t&&(n-t.lastActivity>e||(!i||t.lastActivity>i.lastActivity)&&(i=t));const c=i?{id:i.id,lastActivity:n}:{id:m(),lastActivity:n};return R(c,t),c.id}function R(t,n={}){var e;const r=(t=>`${t.id}.${t.lastActivity}`)(t),o=null!==(e=n.timeoutMinutes)&&void 0!==e?e:30;k(T,r,{domain:n.cookieDomain,maxAgeDays:o/1440,sameSite:"Lax"}),((t,n)=>{if(!A())return!1;try{return sessionStorage.setItem(t,n),!0}catch(t){return!1}})(T,r)}class q{constructor(t){var n,e;Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"storageKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"maxMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"flushing",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"onlineHandler",{enumerable:!0,configurable:!0,writable:!0,value:null}),this.storageKey=null!==(n=t.storageKey)&&void 0!==n?n:"_cnv_rq",this.maxMessages=null!==(e=t.maxMessages)&&void 0!==e?e:100,this.installOnlineListener()}stash(t){if(t&&0!==t.length)try{const n=this.read();for(n.push(t);n.length>1&&N(n)>this.maxMessages;)n.shift();this.write(n),this.config.debug&&console.log("[cnv-track] retry queued",t.length,"buffered",N(n))}catch(t){}}flush(){if(this.flushing||"undefined"!=typeof navigator&&!1===navigator.onLine)return Promise.resolve();const t=this.read();if(0===t.length)return Promise.resolve();this.flushing=!0,this.write([]);const n=()=>{this.flushing=!1};return t.reduce((t,n)=>t.then(()=>this.config.resend(n)),Promise.resolve()).then(n,n)}size(){return N(this.read())}clear(){try{_(this.storageKey)}catch(t){}}destroy(){if(this.onlineHandler){try{window.removeEventListener("online",this.onlineHandler)}catch(t){}this.onlineHandler=null}}installOnlineListener(){if("undefined"==typeof window)return;const t=()=>{this.flush()};try{window.addEventListener("online",t),this.onlineHandler=t}catch(t){}}read(){const t=O(this.storageKey);if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.filter(t=>Array.isArray(t)&&t.length>0):[]}catch(t){return[]}}write(t){0!==t.length?S(this.storageKey,JSON.stringify(t)):_(this.storageKey)}}function N(t){let n=0;for(const e of t)n+=e.length;return n}class B{constructor(t){Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"buffer",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"timer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"handlers",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"retryQueue",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.retryQueue=new q({debug:t.debug,resend:t=>this.send(t)}),this.installPageLifecycleHandlers(),this.retryQueue.flush()}setConfig(t){this.config=Object.assign(Object.assign({},this.config),t)}enqueue(t){this.destroyed||(this.buffer.push(t),this.buffer.length>=this.config.flushAt?this.flush():this.timer||(this.timer=setTimeout(()=>{this.timer=null,this.flush()},this.config.flushInterval)))}flush(){if(this.timer&&(clearTimeout(this.timer),this.timer=null),0===this.buffer.length)return Promise.resolve();const t=this.buffer;return this.buffer=[],this.send(t)}bufferedCount(){return this.buffer.length}destroy(){this.destroyed||(this.destroyed=!0,this.timer&&(clearTimeout(this.timer),this.timer=null),this.uninstallPageLifecycleHandlers(),this.retryQueue.destroy())}send(t){try{return this.config.useBatch?this.sendBatch(t):Promise.all(t.map(t=>this.sendSingle(t))).then(()=>{})}catch(t){return this.config.debug&&console.warn("[cnv-track] send failed synchronously; dropped batch",t),Promise.resolve()}}sendBatch(t){var n;const e=U(),r={batch:t.map(t=>z(t,e)),context:Object.assign(Object.assign({},null!==(n=this.config.batchContext)&&void 0!==n?n:{}),{projectId:this.config.projectId,sentAt:e}),sentAt:e};return this.post(this.batchUrl(),r,t)}sendSingle(t){const n=z(t,U());return this.post(this.singleUrl(t.type),n,[t])}batchUrl(){return this.config.endpoint+this.config.batchPath+"?projectId="+encodeURIComponent(this.config.projectId)}singleUrl(t){const n=this.config.singlePath.replace("{type}",t);return this.config.endpoint+n+"?projectId="+encodeURIComponent(this.config.projectId)}post(t,n,e){const r=JSON.stringify(n),o=((t,n)=>{try{return new Blob([t],{type:n})}catch(t){return null}})(r,this.config.contentType),i=o?o.size:(t=>{try{return new Blob([t]).size}catch(n){return t.length}})(r),c=i>65536?null:e;return c&&"undefined"!=typeof navigator&&!1===navigator.onLine?(this.retryQueue.stash(c),this.config.debug&&console.log("[cnv-track] offline; queued for retry",t),Promise.resolve()):o&&this.sendViaBeacon(t,o)?(this.config.debug&&console.log("[cnv-track] beacon",t),Promise.resolve()):this.sendViaFetch(t,r,c)}sendViaBeacon(t,n){if("undefined"==typeof navigator||"function"!=typeof navigator.sendBeacon)return!1;if(n.size>65536)return!1;try{return navigator.sendBeacon(t,n)}catch(t){return!1}}sendViaFetch(t,n,e){return"function"!=typeof fetch?(this.config.debug&&console.warn("[cnv-track] no transport available; queued for retry"),e&&this.retryQueue.stash(e),Promise.resolve()):fetch(t,{method:"POST",headers:{"Content-Type":this.config.contentType},body:n,keepalive:!0,credentials:"omit",mode:"cors"}).then(n=>{this.config.debug&&console.log("[cnv-track] fetch flushed",t,n.status)}).catch(n=>{this.config.debug&&console.warn("[cnv-track] flush failed; queued for retry",t,n),e&&this.retryQueue.stash(e)})}installPageLifecycleHandlers(){if("undefined"==typeof window||"undefined"==typeof document)return;const t=()=>{this.flush()},n=()=>{"hidden"===document.visibilityState&&this.flush()};try{window.addEventListener("pagehide",t),document.addEventListener("visibilitychange",n),this.handlers={pagehide:t,visibility:n}}catch(t){}}uninstallPageLifecycleHandlers(){if(this.handlers){try{window.removeEventListener("pagehide",this.handlers.pagehide),document.removeEventListener("visibilitychange",this.handlers.visibility)}catch(t){}this.handlers=null}}}function z(t,n){return Object.assign(Object.assign({},t),{sentAt:n})}const J="_cnv_uid",V="_cnv_traits",E={endpoint:"http://localhost:8090/v1",batchPath:"/batch",singlePath:"/{type}",useBatch:!0,contentType:"text/plain",debug:!1,allowAdTracking:!0,cookieMaxAgeDays:730,sessionTimeoutMinutes:30,flushAt:20,flushInterval:5e3,autoPageview:!0,autotrack:!1,integrations:{}},H={analytics:!0,marketing:!0};function F(t,n){if(!Array.isArray(n)||0===n.length)return;const e=n;try{switch(e[0]){case"init":t.init(e[1],e[2]);break;case"pageview":t.pageview(e[1],e[2]);break;case"page":t.page(e[1],e[2]);break;case"screen":t.screen(e[1],e[2]);break;case"track":t.track(e[1],e[2]);break;case"identify":t.identify(e[1],e[2]);break;case"alias":t.alias(e[1],e[2]);break;case"group":t.group(e[1],e[2]);break;case"reset":t.reset();break;case"flush":t.flush();break;case"consent":t.consent(e[1]);break;case"set":t.set(e[1])}}catch(t){}}const G="0.2.0-alpha.4",K="@cnv-vn/track",Q=(()=>{let v=null,p=Object.assign({},E),b=Object.assign({},H),w=null,j=!1,A=null;function P(t){const n=Object.assign({},p);return t?(void 0!==t.endpoint&&(n.endpoint=(e=t.endpoint).endsWith("/")?e.slice(0,-1):e),void 0!==t.batchPath&&(n.batchPath=t.batchPath),void 0!==t.singlePath&&(n.singlePath=t.singlePath),void 0!==t.useBatch&&(n.useBatch=t.useBatch),void 0!==t.contentType&&(n.contentType=t.contentType),void 0!==t.debug&&(n.debug=t.debug),void 0!==t.allowAdTracking&&(n.allowAdTracking=t.allowAdTracking),void 0!==t.cookieDomain&&(n.cookieDomain=t.cookieDomain),void 0!==t.cookieMaxAgeDays&&(n.cookieMaxAgeDays=t.cookieMaxAgeDays),void 0!==t.sessionTimeoutMinutes&&(n.sessionTimeoutMinutes=t.sessionTimeoutMinutes),void 0!==t.flushAt&&(n.flushAt=t.flushAt),void 0!==t.flushInterval&&(n.flushInterval=t.flushInterval),void 0!==t.autoPageview&&(n.autoPageview=t.autoPageview),void 0!==t.autotrack&&(n.autotrack=t.autotrack),void 0!==t.integrations&&(n.integrations=t.integrations),n):n;var e}function M(){return w||(w=new B({endpoint:p.endpoint,batchPath:p.batchPath,singlePath:p.singlePath,useBatch:p.useBatch,contentType:p.contentType,flushAt:p.flushAt,flushInterval:p.flushInterval,projectId:null!=v?v:"",debug:p.debug}),w)}function U(){var t;if(!v)return null;const n=((t={})=>{var n;const e={page:h(),screen:{width:f(()=>window.screen.width,0),height:f(()=>window.screen.height,0),density:f(()=>window.devicePixelRatio||1,1)},locale:f(()=>navigator.language||"",""),timezone:f(()=>Intl.DateTimeFormat().resolvedOptions().timeZone||"",""),userAgent:f(()=>navigator.userAgent||"",""),library:y(t.library)},r=((t,n=!0)=>{const e=f(()=>window.location.search,"");if(!e)return;let r;try{r=new URLSearchParams(e)}catch(t){return}const o={};let i=!1;for(const[t,n]of d){const e=r.get(t);e&&e.length>0&&(o[n]=e,i=!0)}if(n){const t={};for(const n of l){const e=r.get(n);e&&e.length>0&&(t[n]=e)}Object.keys(t).length>0&&(o.clickIds=t,i=!0)}return i?o:void 0})(0,null===(n=t.allowAdTracking)||void 0===n||n);return r&&(e.campaign=r),e})({allowAdTracking:p.allowAdTracking});return b.analytics&&b.marketing||(n.consent=Object.assign({},b)),{anonymousId:D({cookieDomain:p.cookieDomain,cookieMaxAgeDays:p.cookieMaxAgeDays}),sessionId:L({cookieDomain:p.cookieDomain,timeoutMinutes:p.sessionTimeoutMinutes}),userId:null!==(t=x(J)||O(J))&&void 0!==t?t:void 0,context:n,projectId:v,integrations:Object.keys(p.integrations).length>0?p.integrations:void 0}}function T(t){p.debug&&console.warn(`[cnv-track] ${t}() called before init()`)}function $(t,n){try{const e=U();if(!e)return T("pageview");const r=((t,n,e)=>{const r=C("page",e);return t&&(r.name=t),r.properties=null!=n?n:{},r})(null!=t?t:(()=>{try{return"undefined"!=typeof document&&document.title||void 0}catch(t){return}})(),n,e);M().enqueue(r)}catch(t){}}function q(t,n){$(t,n)}function N(t,n){try{if("string"!=typeof t||0===t.length)return;const e=U();if(!e)return T("track");const r=((t,n,e)=>{const r=C("track",e);return r.event=t,r.properties=null!=n?n:{},r})(t,n,e);M().enqueue(r)}catch(t){}}return{get initialized(){return j},get projectId(){return v},init(l,d){try{if(!l||"string"!=typeof l)return;if(p=P(d),(null==d?void 0:d.consent)&&(b=Object.assign(Object.assign({},b),d.consent)),v=l,w&&w.destroy(),w=null,M(),j=!0,D({cookieDomain:p.cookieDomain,cookieMaxAgeDays:p.cookieMaxAgeDays}),L({cookieDomain:p.cookieDomain,timeoutMinutes:p.sessionTimeoutMinutes}),p.autoPageview&&$(),A){try{A()}catch(t){}A=null}p.autotrack&&(A=function(l,d){const f=void 0===(h=d)||!1===h?Object.assign(Object.assign({},s),{searchParams:c}):!0===h?Object.assign(Object.assign({},u),{searchParams:c}):{spa:null===(y=h.spa)||void 0===y||y,outboundClicks:null===(v=h.outboundClicks)||void 0===v||v,scroll:null===(p=h.scroll)||void 0===p||p,downloads:null===(m=h.downloads)||void 0===m||m,siteSearch:null===(b=h.siteSearch)||void 0===b||b,downloadExtensions:h.downloadExtensions,searchParams:null!==(w=h.searchParams)&&void 0!==w?w:c};var h,y,v,p,m,b,w;const g=[];let x=null;function k(t){if(f.siteSearch)try{const n=null!=t?t:(()=>{try{return"undefined"!=typeof location?location.href:""}catch(t){return""}})();if(n===x)return;x=n;const e=((t,n=c)=>{try{if(!t){if("undefined"==typeof location)return null;t=location.href}const e=t instanceof URL?t:new URL(t,(()=>{try{return"undefined"!=typeof location?location.href:"http://localhost/"}catch(t){return"http://localhost/"}})());if(!e.search)return null;for(const t of n){const n=e.searchParams.get(t);if(null===n)continue;const r=n.trim();if(0!==r.length)return{query:r,param:t}}return null}catch(t){return null}})(n,f.searchParams);e&&a(()=>l.track("Site Searched",{query:e.query,param:e.param}))}catch(t){}}if(f.outboundClicks||f.downloads){const o=(o=>{var i;if("undefined"==typeof document)return()=>{};const c=new Set((null!==(i=o.downloadExtensions)&&void 0!==i?i:t).map(t=>t.toLowerCase())),u=!!o.onOutbound,s=!!o.onDownload;if(!u&&!s)return()=>{};function a(t){var i,a;try{if(0!==t.button)return;if(t.defaultPrevented)return;const l=(t=>{const e="function"==typeof t.composedPath?t.composedPath():[];if(e.length>0)for(const t of e)if(n(t))return t;let r=t.target;for(;r;){if(n(r))return r;r=r.parentNode}return null})(t);if(!l)return;const d=l.getAttribute("href");if(!d)return;if(/^(javascript:|mailto:|tel:|sms:)/i.test(d))return;if(d.startsWith("#"))return;const f=(t=>{try{return new URL(t,location.href)}catch(t){return null}})(d);if(!f)return;let h=!1;if(s){const t=l.hasAttribute("download"),n=(t=>{const n=e(t),r=n.lastIndexOf(".");return r<=0||r===n.length-1?null:n.slice(r+1).toLowerCase()})(f.pathname);(t||n&&c.has(n))&&(h=!0,null===(i=o.onDownload)||void 0===i||i.call(o,{url:f.href,fileName:e(f.pathname),fileExtension:null!=n?n:"",text:r(l)}))}u&&!h&&f.host!==(()=>{try{return"undefined"!=typeof location?location.hostname:""}catch(t){return""}})()&&f.host&&(null===(a=o.onOutbound)||void 0===a||a.call(o,{url:f.href,host:f.host,text:r(l),target:l.target||"_self"}))}catch(t){}}try{document.addEventListener("click",a,!0)}catch(t){return()=>{}}return()=>{try{document.removeEventListener("click",a,!0)}catch(t){}}})({downloadExtensions:f.downloadExtensions,onOutbound:f.outboundClicks?t=>a(()=>l.track("Outbound Link Clicked",t)):void 0,onDownload:f.downloads?t=>a(()=>l.track("File Downloaded",t)):void 0});g.push(o)}let j=null;if(f.scroll&&(j=(t=>{if("undefined"==typeof window||"undefined"==typeof document)return{destroy(){},reset(){}};let n=!1,e=null,r=!1;function o(){if(e=null,!r&&!n)try{const e=document.documentElement,r=document.body,o=Math.max(e?e.scrollHeight:0,r?r.scrollHeight:0),i=Math.max(e?e.clientHeight:0,window.innerHeight||0);if(o<=i)return n=!0,c(),void t(90);((window.scrollY||(e?e.scrollTop:0)||0)+i)/o>=.9&&(n=!0,c(),t(90))}catch(t){}}function i(){if(null===e)try{e=window.requestAnimationFrame(o)}catch(t){o()}}function c(){try{window.removeEventListener("scroll",i),null!==e&&window.cancelAnimationFrame(e),e=null}catch(t){}}try{window.addEventListener("scroll",i,{passive:!0})}catch(t){try{window.addEventListener("scroll",i)}catch(t){}}try{window.requestAnimationFrame(o)}catch(t){o()}return{destroy(){r=!0,c()},reset(){if(!r){n=!1;try{window.addEventListener("scroll",i,{passive:!0})}catch(t){try{window.addEventListener("scroll",i)}catch(t){}}try{window.requestAnimationFrame(o)}catch(t){o()}}}}})(t=>{a(()=>l.track("Scrolled",{percent:t}))}),g.push(()=>null==j?void 0:j.destroy())),f.spa){const t=function(){if("undefined"==typeof window||"undefined"==typeof history)return()=>{};let t=i();function n(){try{const n=i();if(n===t)return;t=n,(t=>{a(()=>l.page()),null==j||j.reset(),k(t)})(n)}catch(t){}}const e=history.pushState,r=history.replaceState,c=!0===e[o],u=!0===r[o];if(!c){function f(...t){e.apply(this,t),n()}f[o]=!0,history.pushState=f}if(!u){function h(...t){r.apply(this,t),n()}h[o]=!0,history.replaceState=h}const s=()=>n(),d=()=>n();try{window.addEventListener("popstate",s),window.addEventListener("hashchange",d)}catch(y){}return()=>{try{window.removeEventListener("popstate",s),window.removeEventListener("hashchange",d)}catch(t){}try{!c&&history.pushState[o]&&(history.pushState=e),!u&&history.replaceState[o]&&(history.replaceState=r)}catch(t){}}}();g.push(t)}return k(),()=>{for(;g.length>0;){const t=g.pop();try{null==t||t()}catch(t){}}x=null}}({page(t,n){return q(t,n)},track(t,n){return N(t,n)}},p.autotrack))}catch(t){}},pageview:$,page:q,screen(t,n){try{const e=U();if(!e)return T("screen");const r=((t,n,e)=>{const r=C("screen",e);return t&&(r.name=t),r.properties=null!=n?n:{},r})(t,n,e);M().enqueue(r)}catch(t){}},track:N,identify(t,n){try{if("string"!=typeof t||0===t.length)return;((t,n,e={})=>{var r,o;if(t&&(k(J,t,{domain:e.cookieDomain,maxAgeDays:null!==(r=e.cookieMaxAgeDays)&&void 0!==r?r:730,sameSite:"Lax"}),S(J,t),null!=n)){const t=null!==(o=(()=>{const t=O(V);if(!t)return null;try{const n=JSON.parse(t);return n&&"object"==typeof n&&!Array.isArray(n)?n:null}catch(t){return null}})())&&void 0!==o?o:{},e=Object.assign(Object.assign({},t),n);try{S(V,JSON.stringify(e))}catch(t){}}})(t,n,{cookieDomain:p.cookieDomain,cookieMaxAgeDays:p.cookieMaxAgeDays});const e=U();if(!e)return T("identify");const r=((t,n,e)=>{var r;const o=C("identify",e);return t&&(o.userId=t),o.traits=null!==(r=n)&&void 0!==r?r:{},o})(t,n,e);M().enqueue(r)}catch(t){}},alias(t,n){try{if("string"!=typeof t||0===t.length)return;const e=U();if(!e)return T("alias");const r=((t,n,e)=>{const r=C("alias",e);return t&&(r.userId=t),r.previousId=null!=n?n:e.anonymousId,r})(t,n,e);M().enqueue(r)}catch(t){}},group(t,n){try{if("string"!=typeof t||0===t.length)return;const e=U();if(!e)return T("group");const r=((t,n,e)=>{const r=C("group",e);return r.groupId=t,r.traits=null!=n?n:{},r})(t,n,e);M().enqueue(r)}catch(t){}},reset(){try{((t={})=>{((t,n={})=>{var e;if(!g)return!1;try{let r=`${encodeURIComponent(t)}=`;return r+=`; path=${null!==(e=n.path)&&void 0!==e?e:"/"}`,n.domain&&(r+=`; domain=${n.domain}`),r+="; max-age=0",r+="; expires=Thu, 01 Jan 1970 00:00:00 GMT",document.cookie=r,null===x(t)}catch(t){return!1}})(J,{domain:t.cookieDomain}),_(J),_(V)})({cookieDomain:p.cookieDomain}),((t={})=>{I(m(),t)})({cookieDomain:p.cookieDomain,cookieMaxAgeDays:p.cookieMaxAgeDays}),((t={})=>{R({id:m(),lastActivity:Date.now()},t)})({cookieDomain:p.cookieDomain,timeoutMinutes:p.sessionTimeoutMinutes})}catch(t){}},flush(){try{w&&w.flush()}catch(t){}},consent(t){try{b=Object.assign(Object.assign({},b),t)}catch(t){}},set(t){try{p=P(t),t.consent&&(b=Object.assign(Object.assign({},b),t.consent)),w&&w.setConfig({endpoint:p.endpoint,batchPath:p.batchPath,singlePath:p.singlePath,useBatch:p.useBatch,contentType:p.contentType,flushAt:p.flushAt,flushInterval:p.flushInterval,debug:p.debug})}catch(t){}},destroy(){if(A){try{A()}catch(t){}A=null}w&&w.destroy(),w=null,j=!1,v=null,p=Object.assign({},E),b=Object.assign({},H)}}})();"undefined"!=typeof window&&(t=>{if("undefined"==typeof window)return()=>{};const n=window.cnvQ;if(n&&n.__loaded)return()=>{};const e=window.cnvQ=null!=n?n:[],r=e.splice(0,e.length);e.push.bind(e),e.push=(...n)=>{for(const e of n)F(t,e);return e.length},e.__loaded=!0;for(const n of r)F(t,n)})(Q);const W=Object.assign(Q,{version:G,name:K,schemaVersion:M});export{K as NAME,M as SCHEMA_VERSION,G as VERSION,W as default};
6
+ const t=["pdf","doc","docx","xls","xlsx","ppt","pptx","txt","csv","rtf","zip","rar","7z","tar","gz","mp3","mp4","mov","wav","avi","mkv","dmg","exe","pkg","apk","msi","svg"];function n(t){return!!t&&"object"==typeof t&&1===t.nodeType&&"A"===t.tagName}function e(t){const n=t.lastIndexOf("/");return-1===n?t:t.slice(n+1)}function r(t){var n,e,r;let o=(null!==(n=t.textContent)&&void 0!==n?n:"").trim();return o||(o=(null!==(e=t.getAttribute("aria-label"))&&void 0!==e?e:"").trim()),o||(o=(null!==(r=t.getAttribute("title"))&&void 0!==r?r:"").trim()),o.length>200?o.slice(0,200):o}const o=200;function i(t){let n="";try{n=(t.textContent||"").replace(/\s+/g," ").trim(),n||(n=(t.getAttribute("aria-label")||"").trim()),n||(n=(t.getAttribute("title")||"").trim())}catch(t){return""}return n.length>o?n.slice(0,o):n}function c(t){const n=!1!==t.caseInsensitive;return"regex"===t.mode?{mode:"regex",needle:t.value,ci:n,re:p(t.value,n)}:{mode:t.mode,needle:n?t.value.toLowerCase():t.value,ci:n,re:null}}function u(t,n){try{return t.matches(n)}catch(t){return!1}}function s(t){try{if("A"===t.tagName){const n=t.getAttribute("href");return n?m(n):null}const n=t.getAttribute("formaction");if(n)return m(n);const e=t.getAttribute("data-href");if(e)return m(e);const r=t.closest("form");if(r){const t=r.getAttribute("action");if(t)return m(t)}return null}catch(t){return null}}function a(t){return"regex"===t.mode?{mode:"regex",needle:t.value,re:p(t.value,!0)}:{mode:t.mode,needle:t.value.toLowerCase(),re:null}}function l(t){if("startsWith"===t.mode)return{mode:"startsWith",needle:t.value,re:null};const n="glob"===t.mode?"^"+t.value.replace(/[.+^${}()|[\]\\?]/g,"\\$&").replace(/\*/g,".*")+"$":t.value;return{mode:t.mode,needle:t.value,re:p(n,!1)}}function f(t,n){return"startsWith"===t.mode?0===n.indexOf(t.needle):!t.re||b(t.re,n)}const d=/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g,h=/\+?\d[\d\s().-]{7,}\d/g;function y(t){if(!t)return t;try{return t.replace(d,"[email]").replace(h,"[phone]")}catch(n){return t}}function v(t){return!!t&&"object"==typeof t&&1===t.nodeType}function m(t){try{return new URL(t,location.href).href}catch(n){return t}}function p(t,n){try{return!t||t.length>1e3?null:new RegExp(t,n?"i":"")}catch(t){return null}}function b(t,n){try{return t.test(n)}catch(t){return!1}}function g(t){const n=t.match;return n.element?n.element:n.selector||n.id||n.dataAttr||n.classes&&n.classes.length>0||n.destinationUrl?"any":void 0}function w(t,n){if(!((t,n)=>{if(!n)return(t=>{const n=t.tagName;if("BUTTON"===n||"A"===n)return!0;if("INPUT"===n){const n=(t.getAttribute("type")||"").toLowerCase();return"submit"===n||"button"===n||"reset"===n}return"button"===t.getAttribute("role")})(t);if("any"===n)return!0;if("button"===n){const n=t.tagName;if("BUTTON"===n)return!0;if("INPUT"===n){const n=(t.getAttribute("type")||"").toLowerCase();return"submit"===n||"button"===n||"reset"===n}return"button"===t.getAttribute("role")}return"link"===n?"A"===t.tagName:u(t,n)})(n,t.elementSpec))return!1;const e=t.rule.match;return!(t.selector&&!u(n,t.selector)||void 0!==e.id&&!((t,n)=>t.id===n)(n,e.id)||e.classes&&e.classes.length>0&&!((t,n)=>{try{for(let e=0;e<n.length;e++)if(!t.classList.contains(n[e]))return!1;return!0}catch(t){return!1}})(n,e.classes)||e.dataAttr&&!((t,n,e)=>{try{return!!t.hasAttribute(n)&&(void 0===e||t.getAttribute(n)===e)}catch(t){return!1}})(n,e.dataAttr.name,e.dataAttr.value)||t.text&&!((t,n)=>{const e=i(t);if("regex"===n.mode)return!!n.re&&b(n.re,e);const r=n.ci?e.toLowerCase():e;return"exact"===n.mode?r===n.needle:"startsWith"===n.mode?0===r.indexOf(n.needle):-1!==r.indexOf(n.needle)})(n,t.text)||t.dest&&!((t,n)=>{const e=s(t);if(!e)return!1;if("regex"===n.mode)return!!n.re&&b(n.re,e);if("domain"===n.mode)try{return new URL(e).host.toLowerCase()===n.needle}catch(t){return!1}const r=e.toLowerCase();return"exact"===n.mode?r===n.needle:"startsWith"===n.mode?0===r.indexOf(n.needle):-1!==r.indexOf(n.needle)})(n,t.dest))}function x(t,n,e){const r={},c=t.event.staticProps;if(c)for(const t of Object.keys(c))r[t]=c[t];const u=t.capture;if(u)try{if(u.text){const t=y(i(n));t&&(r.text=t)}if(u.href){const t=s(n);t&&(r.href=t)}if(u.elementId&&n.id&&(r.element_id=n.id),u.classes&&(r.element_classes=Array.from(n.classList)),u.dataAttrs&&u.dataAttrs.length>0)for(let t=0;t<u.dataAttrs.length;t++){const e=u.dataAttrs[t],o=n.getAttribute(e);null!==o&&(r[e]=y(o))}if(u.valueFrom){const t=((t,n)=>{try{const e=t.querySelector(n.selector)||(t.parentElement?t.parentElement.querySelector(n.selector):null);if(!e)return null;const r=n.attr?e.getAttribute(n.attr):e.textContent||"";if(null===r)return null;const i=y(r.replace(/\s+/g," ").trim());return i.length>o?i.slice(0,o):i}catch(t){return null}})(n,u.valueFrom);null!==t&&(r[u.valueFrom.as]=t)}u.selectorPath&&(r.selector_path=((t,n=5)=>{try{const e=[];let r=t,o=0;for(;r&&1===r.nodeType&&o<n;){let t=r.tagName.toLowerCase();if(r.id){e.unshift(t+"#"+r.id);break}const n=Array.from(r.classList).slice(0,2).join(".");n&&(t+="."+n),e.unshift(t),r=r.parentElement,o++}return e.join(" > ")}catch(t){return""}})(n)),u.position&&(r.x=e.clientX,r.y=e.clientY)}catch(t){}return r.rule_id=t.id,t.name&&(r.rule_name=t.name),r.tag=n.tagName.toLowerCase(),r}function k(t){try{t()}catch(t){}}function j(){try{return"undefined"!=typeof location?location.href:""}catch(t){return""}}function O(t,n){return"number"!=typeof t||isNaN(t)?n:t}function A(t){return t<0?0:t>1?1:t}const S="__cnvPatched";function _(){try{return"undefined"!=typeof location?location.href:""}catch(t){return""}}const P=["q","s","query","search","keyword"],I={spa:!0,outboundClicks:!0,scroll:!0,downloads:!0,siteSearch:!0},D={spa:!1,outboundClicks:!1,scroll:!1,downloads:!1,siteSearch:!1};function T(t){try{t()}catch(t){}}const U=["gclid","fbclid","ttclid","msclkid","dclid"],M=[["utm_source","source"],["utm_medium","medium"],["utm_campaign","name"],["utm_term","term"],["utm_content","content"],["utm_id","id"]];function $(t,n){try{return t()}catch(t){return n}}function R(){const t=$(()=>window.location.href,"");let n="",e="",r="";if(t)try{const o=new URL(t);n=o.pathname,e=o.search,r=o.hash}catch(t){}return{url:t,path:n,search:e,hash:r,title:$(()=>document.title,""),referrer:$(()=>document.referrer,"")}}function C(t){var n,e;let r="@cnv-vn/track",o="0.0.0-dev";try{r="@cnv-vn/track"}catch(t){}try{o="0.2.0-alpha.5"}catch(t){}return{name:null!==(n=null==t?void 0:t.name)&&void 0!==n?n:r,version:null!==(e=null==t?void 0:t.version)&&void 0!==e?e:o}}const L="0123456789abcdef";function N(t){return L[t>>>4&15]+L[15&t]}function q(){if("undefined"!=typeof crypto){if("function"==typeof crypto.randomUUID)return crypto.randomUUID();if("function"==typeof crypto.getRandomValues){const t=new Uint8Array(16);return crypto.getRandomValues(t),t[6]=15&t[6]|64,t[8]=63&t[8]|128,N(t[0])+N(t[1])+N(t[2])+N(t[3])+"-"+N(t[4])+N(t[5])+"-"+N(t[6])+N(t[7])+"-"+N(t[8])+N(t[9])+"-"+N(t[10])+N(t[11])+N(t[12])+N(t[13])+N(t[14])+N(t[15])}}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const n=16*Math.random()|0;return("x"===t?n:3&n|8).toString(16)})}const B=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function z(t){return"string"==typeof t&&B.test(t)}const W="undefined"!=typeof window&&"undefined"!=typeof document;function J(t){if(!W)return null;try{const n=document.cookie;if(!n)return null;const e=encodeURIComponent(t),r=n.split(";");for(let n=0;n<r.length;n++){const o=r[n].indexOf("=");if(o<0)continue;const i=r[n].slice(0,o).trim();if(i===e||i===t)try{return decodeURIComponent(r[n].slice(o+1))}catch(t){return r[n].slice(o+1)}}return null}catch(t){return null}}function E(t,n,e={}){var r,o,i;if(!W)return!1;try{let c=`${encodeURIComponent(t)}=${encodeURIComponent(n)}`;if(c+=`; path=${null!==(r=e.path)&&void 0!==r?r:"/"}`,e.domain&&(c+=`; domain=${e.domain}`),"number"==typeof e.maxAgeDays){const t=Math.floor(86400*e.maxAgeDays);c+=`; max-age=${t}`,c+=`; expires=${new Date(Date.now()+1e3*t).toUTCString()}`}return c+=`; SameSite=${null!==(o=e.sameSite)&&void 0!==o?o:"Lax"}`,(null!==(i=e.secure)&&void 0!==i?i:"undefined"!=typeof location&&"https:"===location.protocol)&&(c+="; Secure"),document.cookie=c,J(t)===n}catch(t){return!1}}function V(){if(!W)return!1;try{const t="__cnv_probe__";return localStorage.setItem(t,"1"),localStorage.removeItem(t),!0}catch(t){return!1}}function H(t){if(!V())return null;try{return localStorage.getItem(t)}catch(t){return null}}function Z(t,n){if(!V())return!1;try{return localStorage.setItem(t,n),!0}catch(t){return!1}}function F(t){if(!V())return!1;try{return localStorage.removeItem(t),!0}catch(t){return!1}}function G(){if(!W)return!1;try{const t="__cnv_probe__";return sessionStorage.setItem(t,"1"),sessionStorage.removeItem(t),!0}catch(t){return!1}}const K="_cnv_cid";function Q(t={}){const n=J(K),e=H(K);let r=null;return z(n)?r=n:z(e)&&(r=e),r||(r=q()),X(r,t),r}function X(t,n={}){var e;E(K,t,{domain:n.cookieDomain,maxAgeDays:null!==(e=n.cookieMaxAgeDays)&&void 0!==e?e:730,sameSite:"Lax"}),Z(K,t)}const Y="1.0";function tt(){return(new Date).toISOString()}function nt(t,n){var e;const r=null!==(e=n.timestamp)&&void 0!==e?e:tt(),o=Object.assign(Object.assign({},n.context),{projectId:n.projectId,schemaVersion:Y}),i={type:t,messageId:q(),anonymousId:n.anonymousId,timestamp:r,originalTimestamp:r,context:o};return n.userId&&(i.userId=n.userId),n.sessionId&&(i.sessionId=n.sessionId),n.integrations&&(i.integrations=n.integrations),i}const et="_cnv_sid";function rt(t){if(!t)return null;const n=t.lastIndexOf(".");if(n<0)return null;const e=t.slice(0,n),r=Number(t.slice(n+1));return!z(e)||!Number.isFinite(r)||r<=0?null:{id:e,lastActivity:r}}function ot(t={}){const n=Date.now(),e=(t=>{var n;return 6e4*(null!==(n=t.timeoutMinutes)&&void 0!==n?n:30)})(t),r=rt(J(et)),o=rt((t=>{if(!G())return null;try{return sessionStorage.getItem(t)}catch(t){return null}})(et));let i=null;for(const t of[r,o])t&&(n-t.lastActivity>e||(!i||t.lastActivity>i.lastActivity)&&(i=t));const c=i?{id:i.id,lastActivity:n}:{id:q(),lastActivity:n};return it(c,t),c.id}function it(t,n={}){var e;const r=(t=>`${t.id}.${t.lastActivity}`)(t),o=null!==(e=n.timeoutMinutes)&&void 0!==e?e:30;E(et,r,{domain:n.cookieDomain,maxAgeDays:o/1440,sameSite:"Lax"}),((t,n)=>{if(!G())return!1;try{return sessionStorage.setItem(t,n),!0}catch(t){return!1}})(et,r)}class ct{constructor(t){var n,e;Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"storageKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"maxMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"flushing",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"onlineHandler",{enumerable:!0,configurable:!0,writable:!0,value:null}),this.storageKey=null!==(n=t.storageKey)&&void 0!==n?n:"_cnv_rq",this.maxMessages=null!==(e=t.maxMessages)&&void 0!==e?e:100,this.installOnlineListener()}stash(t){if(t&&0!==t.length)try{const n=this.read();for(n.push(t);n.length>1&&ut(n)>this.maxMessages;)n.shift();this.write(n),this.config.debug&&console.log("[cnv-track] retry queued",t.length,"buffered",ut(n))}catch(t){}}flush(){if(this.flushing||"undefined"!=typeof navigator&&!1===navigator.onLine)return Promise.resolve();const t=this.read();if(0===t.length)return Promise.resolve();this.flushing=!0,this.write([]);const n=()=>{this.flushing=!1};return t.reduce((t,n)=>t.then(()=>this.config.resend(n)),Promise.resolve()).then(n,n)}size(){return ut(this.read())}clear(){try{F(this.storageKey)}catch(t){}}destroy(){if(this.onlineHandler){try{window.removeEventListener("online",this.onlineHandler)}catch(t){}this.onlineHandler=null}}installOnlineListener(){if("undefined"==typeof window)return;const t=()=>{this.flush()};try{window.addEventListener("online",t),this.onlineHandler=t}catch(t){}}read(){const t=H(this.storageKey);if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.filter(t=>Array.isArray(t)&&t.length>0):[]}catch(t){return[]}}write(t){0!==t.length?Z(this.storageKey,JSON.stringify(t)):F(this.storageKey)}}function ut(t){let n=0;for(const e of t)n+=e.length;return n}class st{constructor(t){Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"buffer",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"timer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"handlers",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"retryQueue",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.retryQueue=new ct({debug:t.debug,resend:t=>this.send(t)}),this.installPageLifecycleHandlers(),this.retryQueue.flush()}setConfig(t){this.config=Object.assign(Object.assign({},this.config),t)}enqueue(t){this.destroyed||(this.buffer.push(t),this.buffer.length>=this.config.flushAt?this.flush():this.timer||(this.timer=setTimeout(()=>{this.timer=null,this.flush()},this.config.flushInterval)))}flush(){if(this.timer&&(clearTimeout(this.timer),this.timer=null),0===this.buffer.length)return Promise.resolve();const t=this.buffer;return this.buffer=[],this.send(t)}bufferedCount(){return this.buffer.length}destroy(){this.destroyed||(this.destroyed=!0,this.timer&&(clearTimeout(this.timer),this.timer=null),this.uninstallPageLifecycleHandlers(),this.retryQueue.destroy())}send(t){try{return this.config.useBatch?this.sendBatch(t):Promise.all(t.map(t=>this.sendSingle(t))).then(()=>{})}catch(t){return this.config.debug&&console.warn("[cnv-track] send failed synchronously; dropped batch",t),Promise.resolve()}}sendBatch(t){var n;const e=tt(),r={batch:t.map(t=>at(t,e)),context:Object.assign(Object.assign({},null!==(n=this.config.batchContext)&&void 0!==n?n:{}),{projectId:this.config.projectId,sentAt:e}),sentAt:e};return this.post(this.batchUrl(),r,t)}sendSingle(t){const n=at(t,tt());return this.post(this.singleUrl(t.type),n,[t])}batchUrl(){return this.config.endpoint+this.config.batchPath+"?projectId="+encodeURIComponent(this.config.projectId)}singleUrl(t){const n=this.config.singlePath.replace("{type}",t);return this.config.endpoint+n+"?projectId="+encodeURIComponent(this.config.projectId)}post(t,n,e){const r=JSON.stringify(n),o=((t,n)=>{try{return new Blob([t],{type:n})}catch(t){return null}})(r,this.config.contentType),i=o?o.size:(t=>{try{return new Blob([t]).size}catch(n){return t.length}})(r),c=i>65536?null:e;return c&&"undefined"!=typeof navigator&&!1===navigator.onLine?(this.retryQueue.stash(c),this.config.debug&&console.log("[cnv-track] offline; queued for retry",t),Promise.resolve()):o&&this.sendViaBeacon(t,o)?(this.config.debug&&console.log("[cnv-track] beacon",t),Promise.resolve()):this.sendViaFetch(t,r,c)}sendViaBeacon(t,n){if("undefined"==typeof navigator||"function"!=typeof navigator.sendBeacon)return!1;if(n.size>65536)return!1;try{return navigator.sendBeacon(t,n)}catch(t){return!1}}sendViaFetch(t,n,e){return"function"!=typeof fetch?(this.config.debug&&console.warn("[cnv-track] no transport available; queued for retry"),e&&this.retryQueue.stash(e),Promise.resolve()):fetch(t,{method:"POST",headers:{"Content-Type":this.config.contentType},body:n,keepalive:!0,credentials:"omit",mode:"cors"}).then(n=>{this.config.debug&&console.log("[cnv-track] fetch flushed",t,n.status)}).catch(n=>{this.config.debug&&console.warn("[cnv-track] flush failed; queued for retry",t,n),e&&this.retryQueue.stash(e)})}installPageLifecycleHandlers(){if("undefined"==typeof window||"undefined"==typeof document)return;const t=()=>{this.flush()},n=()=>{"hidden"===document.visibilityState&&this.flush()};try{window.addEventListener("pagehide",t),document.addEventListener("visibilitychange",n),this.handlers={pagehide:t,visibility:n}}catch(t){}}uninstallPageLifecycleHandlers(){if(this.handlers){try{window.removeEventListener("pagehide",this.handlers.pagehide),document.removeEventListener("visibilitychange",this.handlers.visibility)}catch(t){}this.handlers=null}}}function at(t,n){return Object.assign(Object.assign({},t),{sentAt:n})}const lt="_cnv_uid",ft="_cnv_traits",dt={endpoint:"http://localhost:8090/v1",batchPath:"/batch",singlePath:"/{type}",useBatch:!0,contentType:"text/plain",debug:!1,allowAdTracking:!0,cookieMaxAgeDays:730,sessionTimeoutMinutes:30,flushAt:20,flushInterval:5e3,autoPageview:!0,autotrack:!1,integrations:{}},ht={analytics:!0,marketing:!0};function yt(t,n){if(!Array.isArray(n)||0===n.length)return;const e=n;try{switch(e[0]){case"init":t.init(e[1],e[2]);break;case"pageview":t.pageview(e[1],e[2]);break;case"page":t.page(e[1],e[2]);break;case"screen":t.screen(e[1],e[2]);break;case"track":t.track(e[1],e[2]);break;case"identify":t.identify(e[1],e[2]);break;case"alias":t.alias(e[1],e[2]);break;case"group":t.group(e[1],e[2]);break;case"reset":t.reset();break;case"flush":t.flush();break;case"consent":t.consent(e[1]);break;case"set":t.set(e[1])}}catch(t){}}const vt="0.2.0-alpha.5",mt="@cnv-vn/track",pt=(()=>{let o=null,i=Object.assign({},dt),u=Object.assign({},ht),s=null,d=!1,h=null;function y(t){const n=Object.assign({},i);return t?(void 0!==t.endpoint&&(n.endpoint=(e=t.endpoint).endsWith("/")?e.slice(0,-1):e),void 0!==t.batchPath&&(n.batchPath=t.batchPath),void 0!==t.singlePath&&(n.singlePath=t.singlePath),void 0!==t.useBatch&&(n.useBatch=t.useBatch),void 0!==t.contentType&&(n.contentType=t.contentType),void 0!==t.debug&&(n.debug=t.debug),void 0!==t.allowAdTracking&&(n.allowAdTracking=t.allowAdTracking),void 0!==t.cookieDomain&&(n.cookieDomain=t.cookieDomain),void 0!==t.cookieMaxAgeDays&&(n.cookieMaxAgeDays=t.cookieMaxAgeDays),void 0!==t.sessionTimeoutMinutes&&(n.sessionTimeoutMinutes=t.sessionTimeoutMinutes),void 0!==t.flushAt&&(n.flushAt=t.flushAt),void 0!==t.flushInterval&&(n.flushInterval=t.flushInterval),void 0!==t.autoPageview&&(n.autoPageview=t.autoPageview),void 0!==t.autotrack&&(n.autotrack=t.autotrack),void 0!==t.integrations&&(n.integrations=t.integrations),n):n;var e}function m(){return s||(s=new st({endpoint:i.endpoint,batchPath:i.batchPath,singlePath:i.singlePath,useBatch:i.useBatch,contentType:i.contentType,flushAt:i.flushAt,flushInterval:i.flushInterval,projectId:null!=o?o:"",debug:i.debug}),s)}function p(){var t;if(!o)return null;const n=((t={})=>{var n;const e={page:R(),screen:{width:$(()=>window.screen.width,0),height:$(()=>window.screen.height,0),density:$(()=>window.devicePixelRatio||1,1)},locale:$(()=>navigator.language||"",""),timezone:$(()=>Intl.DateTimeFormat().resolvedOptions().timeZone||"",""),userAgent:$(()=>navigator.userAgent||"",""),library:C(t.library)},r=((t,n=!0)=>{const e=$(()=>window.location.search,"");if(!e)return;let r;try{r=new URLSearchParams(e)}catch(t){return}const o={};let i=!1;for(const[t,n]of M){const e=r.get(t);e&&e.length>0&&(o[n]=e,i=!0)}if(n){const t={};for(const n of U){const e=r.get(n);e&&e.length>0&&(t[n]=e)}Object.keys(t).length>0&&(o.clickIds=t,i=!0)}return i?o:void 0})(0,null===(n=t.allowAdTracking)||void 0===n||n);return r&&(e.campaign=r),e})({allowAdTracking:i.allowAdTracking});return u.analytics&&u.marketing||(n.consent=Object.assign({},u)),{anonymousId:Q({cookieDomain:i.cookieDomain,cookieMaxAgeDays:i.cookieMaxAgeDays}),sessionId:ot({cookieDomain:i.cookieDomain,timeoutMinutes:i.sessionTimeoutMinutes}),userId:null!==(t=J(lt)||H(lt))&&void 0!==t?t:void 0,context:n,projectId:o,integrations:Object.keys(i.integrations).length>0?i.integrations:void 0}}function b(t){i.debug&&console.warn(`[cnv-track] ${t}() called before init()`)}function L(t,n){try{const e=p();if(!e)return b("pageview");const r=((t,n,e)=>{const r=nt("page",e);return t&&(r.name=t),r.properties=null!=n?n:{},r})(null!=t?t:(()=>{try{return"undefined"!=typeof document&&document.title||void 0}catch(t){return}})(),n,e);m().enqueue(r)}catch(t){}}function N(t,n){L(t,n)}function B(t,n){try{if("string"!=typeof t||0===t.length)return;const e=p();if(!e)return b("track");const r=((t,n,e)=>{const r=nt("track",e);return r.event=t,r.properties=null!=n?n:{},r})(t,n,e);m().enqueue(r)}catch(t){}}return{get initialized(){return d},get projectId(){return o},init(p,b){try{if(!p||"string"!=typeof p)return;if(i=y(b),(null==b?void 0:b.consent)&&(u=Object.assign(Object.assign({},u),b.consent)),o=p,s&&s.destroy(),s=null,m(),d=!0,Q({cookieDomain:i.cookieDomain,cookieMaxAgeDays:i.cookieMaxAgeDays}),ot({cookieDomain:i.cookieDomain,timeoutMinutes:i.sessionTimeoutMinutes}),i.autoPageview&&L(),h){try{h()}catch(t){}h=null}i.autotrack&&(h=function(o,i){const u=void 0===(s=i)||!1===s?Object.assign(Object.assign({},D),{searchParams:P}):!0===s?Object.assign(Object.assign({},I),{searchParams:P}):{spa:null===(d=s.spa)||void 0===d||d,outboundClicks:null===(h=s.outboundClicks)||void 0===h||h,scroll:null===(y=s.scroll)||void 0===y||y,downloads:null===(m=s.downloads)||void 0===m||m,siteSearch:null===(p=s.siteSearch)||void 0===p||p,downloadExtensions:s.downloadExtensions,searchParams:null!==(b=s.searchParams)&&void 0!==b?b:P,buttonTracking:s.buttonTracking};var s,d,h,y,m,p,b;const U=[];let M=null;function $(t){if(u.siteSearch)try{const n=null!=t?t:(()=>{try{return"undefined"!=typeof location?location.href:""}catch(t){return""}})();if(n===M)return;M=n;const e=((t,n=P)=>{try{if(!t){if("undefined"==typeof location)return null;t=location.href}const e=t instanceof URL?t:new URL(t,(()=>{try{return"undefined"!=typeof location?location.href:"http://localhost/"}catch(t){return"http://localhost/"}})());if(!e.search)return null;for(const t of n){const n=e.searchParams.get(t);if(null===n)continue;const r=n.trim();if(0!==r.length)return{query:r,param:t}}return null}catch(t){return null}})(n,u.searchParams);e&&T(()=>o.track("Site Searched",{query:e.query,param:e.param}))}catch(t){}}if(u.outboundClicks||u.downloads){const i=(o=>{var i;if("undefined"==typeof document)return()=>{};const c=new Set((null!==(i=o.downloadExtensions)&&void 0!==i?i:t).map(t=>t.toLowerCase())),u=!!o.onOutbound,s=!!o.onDownload;if(!u&&!s)return()=>{};function a(t){var i,a;try{if(0!==t.button)return;if(t.defaultPrevented)return;const l=(t=>{const e="function"==typeof t.composedPath?t.composedPath():[];if(e.length>0)for(const t of e)if(n(t))return t;let r=t.target;for(;r;){if(n(r))return r;r=r.parentNode}return null})(t);if(!l)return;const f=l.getAttribute("href");if(!f)return;if(/^(javascript:|mailto:|tel:|sms:)/i.test(f))return;if(f.startsWith("#"))return;const d=(t=>{try{return new URL(t,location.href)}catch(t){return null}})(f);if(!d)return;let h=!1;if(s){const t=l.hasAttribute("download"),n=(t=>{const n=e(t),r=n.lastIndexOf(".");return r<=0||r===n.length-1?null:n.slice(r+1).toLowerCase()})(d.pathname);(t||n&&c.has(n))&&(h=!0,null===(i=o.onDownload)||void 0===i||i.call(o,{url:d.href,fileName:e(d.pathname),fileExtension:null!=n?n:"",text:r(l)}))}u&&!h&&d.host!==(()=>{try{return"undefined"!=typeof location?location.hostname:""}catch(t){return""}})()&&d.host&&(null===(a=o.onOutbound)||void 0===a||a.call(o,{url:d.href,host:d.host,text:r(l),target:l.target||"_self"}))}catch(t){}}try{document.addEventListener("click",a,!0)}catch(t){return()=>{}}return()=>{try{document.removeEventListener("click",a,!0)}catch(t){}}})({downloadExtensions:u.downloadExtensions,onOutbound:u.outboundClicks?t=>T(()=>o.track("Outbound Link Clicked",t)):void 0,onDownload:u.downloads?t=>T(()=>o.track("File Downloaded",t)):void 0});U.push(i)}u.buttonTracking&&u.buttonTracking.rules&&u.buttonTracking.rules.length>0&&U.push(((t,n)=>{if("undefined"==typeof document)return()=>{};const e=(t=>{const n=t.globalThrottle||{},e=[],r=t.rules||[];for(let t=0;t<r.length;t++){const o=r[t];if(!o||!1===o.enabled)continue;if(!o.match||!o.event||!o.event.name)continue;const i=o.match,u=o.throttle||{};e.push({rule:o,elementSpec:g(o),selector:i.selector||null,text:i.text?c(i.text):null,dest:i.destinationUrl?a(i.destinationUrl):null,urlScope:o.urlScope?l(o.urlScope):null,dedupeWindowMs:O(u.dedupeWindowMs,O(n.dedupeWindowMs,500)),maxPerPageview:O(u.maxPerPageview,O(n.maxPerPageview,1/0)),samplingRate:A(O(u.samplingRate,O(n.samplingRate,1)))})}return e.sort((t,n)=>(t.rule.priority||0)-(n.rule.priority||0)),e})(n);if(0===e.length)return()=>{};const r=new WeakMap;let o=0;const i=t=>{let n=r.get(t);return void 0===n&&(n=++o,r.set(t,n)),String(n)},u=new Map,s=new Map;let d=j();function h(n){try{if(0!==n.button)return;const r=j();r!==d&&(d=r,s.clear(),u.clear());const o=(t=>{const n=[];try{const e="function"==typeof t.composedPath?t.composedPath():[];if(e&&e.length>0){for(const t of e)v(t)&&n.push(t);return n}let r=t.target;for(;r;)v(r)&&n.push(r),r=r.parentNode}catch(t){}return n})(n);if(0===o.length)return;const c=(()=>{try{return"undefined"!=typeof location?location.pathname+location.search:""}catch(t){return""}})();for(let r=0;r<e.length;r++){const a=e[r];if(a.urlScope&&!f(a.urlScope,c))continue;let l=null;for(let t=0;t<o.length;t++)if(w(a,o[t])){l=o[t];break}if(!l)continue;const d=a.rule.id;if((s.get(d)||0)>=a.maxPerPageview)return;const h=d+"#"+i(l),y=Date.now(),v=u.get(h);if(void 0!==v&&y-v<a.dedupeWindowMs)return;if(a.samplingRate<1&&Math.random()>=a.samplingRate)return;u.set(h,y),s.set(d,(s.get(d)||0)+1);const m=a.rule.event.name||"Button Clicked",p=x(a.rule,l,n);return void k(()=>t.track(m,p))}}catch(t){}}try{document.addEventListener("click",h,!0)}catch(t){return()=>{}}return()=>{try{document.removeEventListener("click",h,!0)}catch(t){}u.clear(),s.clear()}})(o,u.buttonTracking));let R=null;if(u.scroll&&(R=(t=>{if("undefined"==typeof window||"undefined"==typeof document)return{destroy(){},reset(){}};let n=!1,e=null,r=!1;function o(){if(e=null,!r&&!n)try{const e=document.documentElement,r=document.body,o=Math.max(e?e.scrollHeight:0,r?r.scrollHeight:0),i=Math.max(e?e.clientHeight:0,window.innerHeight||0);if(o<=i)return n=!0,c(),void t(90);((window.scrollY||(e?e.scrollTop:0)||0)+i)/o>=.9&&(n=!0,c(),t(90))}catch(t){}}function i(){if(null===e)try{e=window.requestAnimationFrame(o)}catch(t){o()}}function c(){try{window.removeEventListener("scroll",i),null!==e&&window.cancelAnimationFrame(e),e=null}catch(t){}}try{window.addEventListener("scroll",i,{passive:!0})}catch(t){try{window.addEventListener("scroll",i)}catch(t){}}try{window.requestAnimationFrame(o)}catch(t){o()}return{destroy(){r=!0,c()},reset(){if(!r){n=!1;try{window.addEventListener("scroll",i,{passive:!0})}catch(t){try{window.addEventListener("scroll",i)}catch(t){}}try{window.requestAnimationFrame(o)}catch(t){o()}}}}})(t=>{T(()=>o.track("Scrolled",{percent:t}))}),U.push(()=>null==R?void 0:R.destroy())),u.spa){const t=function(){if("undefined"==typeof window||"undefined"==typeof history)return()=>{};let t=_();function n(){try{const n=_();if(n===t)return;t=n,(t=>{T(()=>o.page()),null==R||R.reset(),$(t)})(n)}catch(t){}}const e=history.pushState,r=history.replaceState,i=!0===e[S],c=!0===r[S];if(!i){function a(...t){e.apply(this,t),n()}a[S]=!0,history.pushState=a}if(!c){function l(...t){r.apply(this,t),n()}l[S]=!0,history.replaceState=l}const u=()=>n(),s=()=>n();try{window.addEventListener("popstate",u),window.addEventListener("hashchange",s)}catch(f){}return()=>{try{window.removeEventListener("popstate",u),window.removeEventListener("hashchange",s)}catch(t){}try{!i&&history.pushState[S]&&(history.pushState=e),!c&&history.replaceState[S]&&(history.replaceState=r)}catch(t){}}}();U.push(t)}return $(),()=>{for(;U.length>0;){const t=U.pop();try{null==t||t()}catch(t){}}M=null}}({page(t,n){return N(t,n)},track(t,n){return B(t,n)}},i.autotrack))}catch(t){}},pageview:L,page:N,screen(t,n){try{const e=p();if(!e)return b("screen");const r=((t,n,e)=>{const r=nt("screen",e);return t&&(r.name=t),r.properties=null!=n?n:{},r})(t,n,e);m().enqueue(r)}catch(t){}},track:B,identify(t,n){try{if("string"!=typeof t||0===t.length)return;((t,n,e={})=>{var r,o;if(t&&(E(lt,t,{domain:e.cookieDomain,maxAgeDays:null!==(r=e.cookieMaxAgeDays)&&void 0!==r?r:730,sameSite:"Lax"}),Z(lt,t),null!=n)){const t=null!==(o=(()=>{const t=H(ft);if(!t)return null;try{const n=JSON.parse(t);return n&&"object"==typeof n&&!Array.isArray(n)?n:null}catch(t){return null}})())&&void 0!==o?o:{},e=Object.assign(Object.assign({},t),n);try{Z(ft,JSON.stringify(e))}catch(t){}}})(t,n,{cookieDomain:i.cookieDomain,cookieMaxAgeDays:i.cookieMaxAgeDays});const e=p();if(!e)return b("identify");const r=((t,n,e)=>{var r;const o=nt("identify",e);return t&&(o.userId=t),o.traits=null!==(r=n)&&void 0!==r?r:{},o})(t,n,e);m().enqueue(r)}catch(t){}},alias(t,n){try{if("string"!=typeof t||0===t.length)return;const e=p();if(!e)return b("alias");const r=((t,n,e)=>{const r=nt("alias",e);return t&&(r.userId=t),r.previousId=null!=n?n:e.anonymousId,r})(t,n,e);m().enqueue(r)}catch(t){}},group(t,n){try{if("string"!=typeof t||0===t.length)return;const e=p();if(!e)return b("group");const r=((t,n,e)=>{const r=nt("group",e);return r.groupId=t,r.traits=null!=n?n:{},r})(t,n,e);m().enqueue(r)}catch(t){}},reset(){try{((t={})=>{((t,n={})=>{var e;if(!W)return!1;try{let r=`${encodeURIComponent(t)}=`;return r+=`; path=${null!==(e=n.path)&&void 0!==e?e:"/"}`,n.domain&&(r+=`; domain=${n.domain}`),r+="; max-age=0",r+="; expires=Thu, 01 Jan 1970 00:00:00 GMT",document.cookie=r,null===J(t)}catch(t){return!1}})(lt,{domain:t.cookieDomain}),F(lt),F(ft)})({cookieDomain:i.cookieDomain}),((t={})=>{X(q(),t)})({cookieDomain:i.cookieDomain,cookieMaxAgeDays:i.cookieMaxAgeDays}),((t={})=>{it({id:q(),lastActivity:Date.now()},t)})({cookieDomain:i.cookieDomain,timeoutMinutes:i.sessionTimeoutMinutes})}catch(t){}},flush(){try{s&&s.flush()}catch(t){}},consent(t){try{u=Object.assign(Object.assign({},u),t)}catch(t){}},set(t){try{i=y(t),t.consent&&(u=Object.assign(Object.assign({},u),t.consent)),s&&s.setConfig({endpoint:i.endpoint,batchPath:i.batchPath,singlePath:i.singlePath,useBatch:i.useBatch,contentType:i.contentType,flushAt:i.flushAt,flushInterval:i.flushInterval,debug:i.debug})}catch(t){}},destroy(){if(h){try{h()}catch(t){}h=null}s&&s.destroy(),s=null,d=!1,o=null,i=Object.assign({},dt),u=Object.assign({},ht)}}})();"undefined"!=typeof window&&(t=>{if("undefined"==typeof window)return()=>{};const n=window.cnvQ;if(n&&n.__loaded)return()=>{};const e=window.cnvQ=null!=n?n:[],r=e.splice(0,e.length);e.push.bind(e),e.push=(...n)=>{for(const e of n)yt(t,e);return e.length},e.__loaded=!0;for(const n of r)yt(t,n)})(pt);const bt=Object.assign(pt,{version:vt,name:mt,schemaVersion:Y});export{mt as NAME,Y as SCHEMA_VERSION,vt as VERSION,bt as default};
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @cnv-vn/track v0.2.0-alpha.4
2
+ * @cnv-vn/track v0.2.0-alpha.5
3
3
  * (c) 2026 CNV
4
4
  * Released under the UNLICENSED license.
5
5
  */
6
- !function(t){const n=["pdf","doc","docx","xls","xlsx","ppt","pptx","txt","csv","rtf","zip","rar","7z","tar","gz","mp3","mp4","mov","wav","avi","mkv","dmg","exe","pkg","apk","msi","svg"];function e(t){return!!t&&"object"==typeof t&&1===t.nodeType&&"A"===t.tagName}function r(t){const n=t.lastIndexOf("/");return-1===n?t:t.slice(n+1)}function o(t){var n,e,r;let o=(null!==(n=t.textContent)&&void 0!==n?n:"").trim();return o||(o=(null!==(e=t.getAttribute("aria-label"))&&void 0!==e?e:"").trim()),o||(o=(null!==(r=t.getAttribute("title"))&&void 0!==r?r:"").trim()),o.length>200?o.slice(0,200):o}const i="__cnvPatched";function c(){try{return"undefined"!=typeof location?location.href:""}catch(t){return""}}const u=["q","s","query","search","keyword"],s={spa:!0,outboundClicks:!0,scroll:!0,downloads:!0,siteSearch:!0},a={spa:!1,outboundClicks:!1,scroll:!1,downloads:!1,siteSearch:!1};function l(t){try{t()}catch(t){}}const d=["gclid","fbclid","ttclid","msclkid","dclid"],f=[["utm_source","source"],["utm_medium","medium"],["utm_campaign","name"],["utm_term","term"],["utm_content","content"],["utm_id","id"]];function h(t,n){try{return t()}catch(t){return n}}function y(){const t=h(()=>window.location.href,"");let n="",e="",r="";if(t)try{const o=new URL(t);n=o.pathname,e=o.search,r=o.hash}catch(t){}return{url:t,path:n,search:e,hash:r,title:h(()=>document.title,""),referrer:h(()=>document.referrer,"")}}function v(t){var n,e;let r="@cnv-vn/track",o="0.0.0-dev";try{r="@cnv-vn/track"}catch(t){}try{o="0.2.0-alpha.4"}catch(t){}return{name:null!==(n=null==t?void 0:t.name)&&void 0!==n?n:r,version:null!==(e=null==t?void 0:t.version)&&void 0!==e?e:o}}const p="0123456789abcdef";function m(t){return p[t>>>4&15]+p[15&t]}function b(){if("undefined"!=typeof crypto){if("function"==typeof crypto.randomUUID)return crypto.randomUUID();if("function"==typeof crypto.getRandomValues){const t=new Uint8Array(16);return crypto.getRandomValues(t),t[6]=15&t[6]|64,t[8]=63&t[8]|128,m(t[0])+m(t[1])+m(t[2])+m(t[3])+"-"+m(t[4])+m(t[5])+"-"+m(t[6])+m(t[7])+"-"+m(t[8])+m(t[9])+"-"+m(t[10])+m(t[11])+m(t[12])+m(t[13])+m(t[14])+m(t[15])}}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const n=16*Math.random()|0;return("x"===t?n:3&n|8).toString(16)})}const w=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function g(t){return"string"==typeof t&&w.test(t)}const x="undefined"!=typeof window&&"undefined"!=typeof document;function k(t){if(!x)return null;try{const n=document.cookie;if(!n)return null;const e=encodeURIComponent(t),r=n.split(";");for(let n=0;n<r.length;n++){const o=r[n].indexOf("=");if(o<0)continue;const i=r[n].slice(0,o).trim();if(i===e||i===t)try{return decodeURIComponent(r[n].slice(o+1))}catch(t){return r[n].slice(o+1)}}return null}catch(t){return null}}function j(t,n,e={}){var r,o,i;if(!x)return!1;try{let c=`${encodeURIComponent(t)}=${encodeURIComponent(n)}`;if(c+=`; path=${null!==(r=e.path)&&void 0!==r?r:"/"}`,e.domain&&(c+=`; domain=${e.domain}`),"number"==typeof e.maxAgeDays){const t=Math.floor(86400*e.maxAgeDays);c+=`; max-age=${t}`,c+=`; expires=${new Date(Date.now()+1e3*t).toUTCString()}`}return c+=`; SameSite=${null!==(o=e.sameSite)&&void 0!==o?o:"Lax"}`,(null!==(i=e.secure)&&void 0!==i?i:"undefined"!=typeof location&&"https:"===location.protocol)&&(c+="; Secure"),document.cookie=c,k(t)===n}catch(t){return!1}}function O(){if(!x)return!1;try{const t="__cnv_probe__";return localStorage.setItem(t,"1"),localStorage.removeItem(t),!0}catch(t){return!1}}function _(t){if(!O())return null;try{return localStorage.getItem(t)}catch(t){return null}}function S(t,n){if(!O())return!1;try{return localStorage.setItem(t,n),!0}catch(t){return!1}}function A(t){if(!O())return!1;try{return localStorage.removeItem(t),!0}catch(t){return!1}}function P(){if(!x)return!1;try{const t="__cnv_probe__";return sessionStorage.setItem(t,"1"),sessionStorage.removeItem(t),!0}catch(t){return!1}}const D="_cnv_cid";function I(t={}){const n=k(D),e=_(D);let r=null;return g(n)?r=n:g(e)&&(r=e),r||(r=b()),M(r,t),r}function M(t,n={}){var e;j(D,t,{domain:n.cookieDomain,maxAgeDays:null!==(e=n.cookieMaxAgeDays)&&void 0!==e?e:730,sameSite:"Lax"}),S(D,t)}const U="1.0";function C(){return(new Date).toISOString()}function T(t,n){var e;const r=null!==(e=n.timestamp)&&void 0!==e?e:C(),o=Object.assign(Object.assign({},n.context),{projectId:n.projectId,schemaVersion:U}),i={type:t,messageId:b(),anonymousId:n.anonymousId,timestamp:r,originalTimestamp:r,context:o};return n.userId&&(i.userId=n.userId),n.sessionId&&(i.sessionId=n.sessionId),n.integrations&&(i.integrations=n.integrations),i}const $="_cnv_sid";function L(t){if(!t)return null;const n=t.lastIndexOf(".");if(n<0)return null;const e=t.slice(0,n),r=Number(t.slice(n+1));return!g(e)||!Number.isFinite(r)||r<=0?null:{id:e,lastActivity:r}}function R(t={}){const n=Date.now(),e=(t=>{var n;return 6e4*(null!==(n=t.timeoutMinutes)&&void 0!==n?n:30)})(t),r=L(k($)),o=L((t=>{if(!P())return null;try{return sessionStorage.getItem(t)}catch(t){return null}})($));let i=null;for(const t of[r,o])t&&(n-t.lastActivity>e||(!i||t.lastActivity>i.lastActivity)&&(i=t));const c=i?{id:i.id,lastActivity:n}:{id:b(),lastActivity:n};return q(c,t),c.id}function q(t,n={}){var e;const r=(t=>`${t.id}.${t.lastActivity}`)(t),o=null!==(e=n.timeoutMinutes)&&void 0!==e?e:30;j($,r,{domain:n.cookieDomain,maxAgeDays:o/1440,sameSite:"Lax"}),((t,n)=>{if(!P())return!1;try{return sessionStorage.setItem(t,n),!0}catch(t){return!1}})($,r)}class N{constructor(t){var n,e;Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"storageKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"maxMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"flushing",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"onlineHandler",{enumerable:!0,configurable:!0,writable:!0,value:null}),this.storageKey=null!==(n=t.storageKey)&&void 0!==n?n:"_cnv_rq",this.maxMessages=null!==(e=t.maxMessages)&&void 0!==e?e:100,this.installOnlineListener()}stash(t){if(t&&0!==t.length)try{const n=this.read();for(n.push(t);n.length>1&&B(n)>this.maxMessages;)n.shift();this.write(n),this.config.debug&&console.log("[cnv-track] retry queued",t.length,"buffered",B(n))}catch(t){}}flush(){if(this.flushing||"undefined"!=typeof navigator&&!1===navigator.onLine)return Promise.resolve();const t=this.read();if(0===t.length)return Promise.resolve();this.flushing=!0,this.write([]);const n=()=>{this.flushing=!1};return t.reduce((t,n)=>t.then(()=>this.config.resend(n)),Promise.resolve()).then(n,n)}size(){return B(this.read())}clear(){try{A(this.storageKey)}catch(t){}}destroy(){if(this.onlineHandler){try{window.removeEventListener("online",this.onlineHandler)}catch(t){}this.onlineHandler=null}}installOnlineListener(){if("undefined"==typeof window)return;const t=()=>{this.flush()};try{window.addEventListener("online",t),this.onlineHandler=t}catch(t){}}read(){const t=_(this.storageKey);if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.filter(t=>Array.isArray(t)&&t.length>0):[]}catch(t){return[]}}write(t){0!==t.length?S(this.storageKey,JSON.stringify(t)):A(this.storageKey)}}function B(t){let n=0;for(const e of t)n+=e.length;return n}class z{constructor(t){Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"buffer",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"timer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"handlers",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"retryQueue",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.retryQueue=new N({debug:t.debug,resend:t=>this.send(t)}),this.installPageLifecycleHandlers(),this.retryQueue.flush()}setConfig(t){this.config=Object.assign(Object.assign({},this.config),t)}enqueue(t){this.destroyed||(this.buffer.push(t),this.buffer.length>=this.config.flushAt?this.flush():this.timer||(this.timer=setTimeout(()=>{this.timer=null,this.flush()},this.config.flushInterval)))}flush(){if(this.timer&&(clearTimeout(this.timer),this.timer=null),0===this.buffer.length)return Promise.resolve();const t=this.buffer;return this.buffer=[],this.send(t)}bufferedCount(){return this.buffer.length}destroy(){this.destroyed||(this.destroyed=!0,this.timer&&(clearTimeout(this.timer),this.timer=null),this.uninstallPageLifecycleHandlers(),this.retryQueue.destroy())}send(t){try{return this.config.useBatch?this.sendBatch(t):Promise.all(t.map(t=>this.sendSingle(t))).then(()=>{})}catch(t){return this.config.debug&&console.warn("[cnv-track] send failed synchronously; dropped batch",t),Promise.resolve()}}sendBatch(t){var n;const e=C(),r={batch:t.map(t=>J(t,e)),context:Object.assign(Object.assign({},null!==(n=this.config.batchContext)&&void 0!==n?n:{}),{projectId:this.config.projectId,sentAt:e}),sentAt:e};return this.post(this.batchUrl(),r,t)}sendSingle(t){const n=J(t,C());return this.post(this.singleUrl(t.type),n,[t])}batchUrl(){return this.config.endpoint+this.config.batchPath+"?projectId="+encodeURIComponent(this.config.projectId)}singleUrl(t){const n=this.config.singlePath.replace("{type}",t);return this.config.endpoint+n+"?projectId="+encodeURIComponent(this.config.projectId)}post(t,n,e){const r=JSON.stringify(n),o=((t,n)=>{try{return new Blob([t],{type:n})}catch(t){return null}})(r,this.config.contentType),i=o?o.size:(t=>{try{return new Blob([t]).size}catch(n){return t.length}})(r),c=i>65536?null:e;return c&&"undefined"!=typeof navigator&&!1===navigator.onLine?(this.retryQueue.stash(c),this.config.debug&&console.log("[cnv-track] offline; queued for retry",t),Promise.resolve()):o&&this.sendViaBeacon(t,o)?(this.config.debug&&console.log("[cnv-track] beacon",t),Promise.resolve()):this.sendViaFetch(t,r,c)}sendViaBeacon(t,n){if("undefined"==typeof navigator||"function"!=typeof navigator.sendBeacon)return!1;if(n.size>65536)return!1;try{return navigator.sendBeacon(t,n)}catch(t){return!1}}sendViaFetch(t,n,e){return"function"!=typeof fetch?(this.config.debug&&console.warn("[cnv-track] no transport available; queued for retry"),e&&this.retryQueue.stash(e),Promise.resolve()):fetch(t,{method:"POST",headers:{"Content-Type":this.config.contentType},body:n,keepalive:!0,credentials:"omit",mode:"cors"}).then(n=>{this.config.debug&&console.log("[cnv-track] fetch flushed",t,n.status)}).catch(n=>{this.config.debug&&console.warn("[cnv-track] flush failed; queued for retry",t,n),e&&this.retryQueue.stash(e)})}installPageLifecycleHandlers(){if("undefined"==typeof window||"undefined"==typeof document)return;const t=()=>{this.flush()},n=()=>{"hidden"===document.visibilityState&&this.flush()};try{window.addEventListener("pagehide",t),document.addEventListener("visibilitychange",n),this.handlers={pagehide:t,visibility:n}}catch(t){}}uninstallPageLifecycleHandlers(){if(this.handlers){try{window.removeEventListener("pagehide",this.handlers.pagehide),document.removeEventListener("visibilitychange",this.handlers.visibility)}catch(t){}this.handlers=null}}}function J(t,n){return Object.assign(Object.assign({},t),{sentAt:n})}const V="_cnv_uid",E="_cnv_traits",H={endpoint:"http://localhost:8090/v1",batchPath:"/batch",singlePath:"/{type}",useBatch:!0,contentType:"text/plain",debug:!1,allowAdTracking:!0,cookieMaxAgeDays:730,sessionTimeoutMinutes:30,flushAt:20,flushInterval:5e3,autoPageview:!0,autotrack:!1,integrations:{}},F={analytics:!0,marketing:!0};function G(t,n){if(!Array.isArray(n)||0===n.length)return;const e=n;try{switch(e[0]){case"init":t.init(e[1],e[2]);break;case"pageview":t.pageview(e[1],e[2]);break;case"page":t.page(e[1],e[2]);break;case"screen":t.screen(e[1],e[2]);break;case"track":t.track(e[1],e[2]);break;case"identify":t.identify(e[1],e[2]);break;case"alias":t.alias(e[1],e[2]);break;case"group":t.group(e[1],e[2]);break;case"reset":t.reset();break;case"flush":t.flush();break;case"consent":t.consent(e[1]);break;case"set":t.set(e[1])}}catch(t){}}const K="0.2.0-alpha.4",Q="@cnv-vn/track",W=(()=>{let t=null,p=Object.assign({},H),m=Object.assign({},F),w=null,g=!1,O=null;function P(t){const n=Object.assign({},p);return t?(void 0!==t.endpoint&&(n.endpoint=(e=t.endpoint).endsWith("/")?e.slice(0,-1):e),void 0!==t.batchPath&&(n.batchPath=t.batchPath),void 0!==t.singlePath&&(n.singlePath=t.singlePath),void 0!==t.useBatch&&(n.useBatch=t.useBatch),void 0!==t.contentType&&(n.contentType=t.contentType),void 0!==t.debug&&(n.debug=t.debug),void 0!==t.allowAdTracking&&(n.allowAdTracking=t.allowAdTracking),void 0!==t.cookieDomain&&(n.cookieDomain=t.cookieDomain),void 0!==t.cookieMaxAgeDays&&(n.cookieMaxAgeDays=t.cookieMaxAgeDays),void 0!==t.sessionTimeoutMinutes&&(n.sessionTimeoutMinutes=t.sessionTimeoutMinutes),void 0!==t.flushAt&&(n.flushAt=t.flushAt),void 0!==t.flushInterval&&(n.flushInterval=t.flushInterval),void 0!==t.autoPageview&&(n.autoPageview=t.autoPageview),void 0!==t.autotrack&&(n.autotrack=t.autotrack),void 0!==t.integrations&&(n.integrations=t.integrations),n):n;var e}function D(){return w||(w=new z({endpoint:p.endpoint,batchPath:p.batchPath,singlePath:p.singlePath,useBatch:p.useBatch,contentType:p.contentType,flushAt:p.flushAt,flushInterval:p.flushInterval,projectId:null!=t?t:"",debug:p.debug}),w)}function U(){var n;if(!t)return null;const e=((t={})=>{var n;const e={page:y(),screen:{width:h(()=>window.screen.width,0),height:h(()=>window.screen.height,0),density:h(()=>window.devicePixelRatio||1,1)},locale:h(()=>navigator.language||"",""),timezone:h(()=>Intl.DateTimeFormat().resolvedOptions().timeZone||"",""),userAgent:h(()=>navigator.userAgent||"",""),library:v(t.library)},r=((t,n=!0)=>{const e=h(()=>window.location.search,"");if(!e)return;let r;try{r=new URLSearchParams(e)}catch(t){return}const o={};let i=!1;for(const[t,n]of f){const e=r.get(t);e&&e.length>0&&(o[n]=e,i=!0)}if(n){const t={};for(const n of d){const e=r.get(n);e&&e.length>0&&(t[n]=e)}Object.keys(t).length>0&&(o.clickIds=t,i=!0)}return i?o:void 0})(0,null===(n=t.allowAdTracking)||void 0===n||n);return r&&(e.campaign=r),e})({allowAdTracking:p.allowAdTracking});return m.analytics&&m.marketing||(e.consent=Object.assign({},m)),{anonymousId:I({cookieDomain:p.cookieDomain,cookieMaxAgeDays:p.cookieMaxAgeDays}),sessionId:R({cookieDomain:p.cookieDomain,timeoutMinutes:p.sessionTimeoutMinutes}),userId:null!==(n=k(V)||_(V))&&void 0!==n?n:void 0,context:e,projectId:t,integrations:Object.keys(p.integrations).length>0?p.integrations:void 0}}function C(t){p.debug&&console.warn(`[cnv-track] ${t}() called before init()`)}function $(t,n){try{const e=U();if(!e)return C("pageview");const r=((t,n,e)=>{const r=T("page",e);return t&&(r.name=t),r.properties=null!=n?n:{},r})(null!=t?t:(()=>{try{return"undefined"!=typeof document&&document.title||void 0}catch(t){return}})(),n,e);D().enqueue(r)}catch(t){}}function L(t,n){$(t,n)}function N(t,n){try{if("string"!=typeof t||0===t.length)return;const e=U();if(!e)return C("track");const r=((t,n,e)=>{const r=T("track",e);return r.event=t,r.properties=null!=n?n:{},r})(t,n,e);D().enqueue(r)}catch(t){}}return{get initialized(){return g},get projectId(){return t},init(d,f){try{if(!d||"string"!=typeof d)return;if(p=P(f),(null==f?void 0:f.consent)&&(m=Object.assign(Object.assign({},m),f.consent)),t=d,w&&w.destroy(),w=null,D(),g=!0,I({cookieDomain:p.cookieDomain,cookieMaxAgeDays:p.cookieMaxAgeDays}),R({cookieDomain:p.cookieDomain,timeoutMinutes:p.sessionTimeoutMinutes}),p.autoPageview&&$(),O){try{O()}catch(t){}O=null}p.autotrack&&(O=function(t,d){const f=void 0===(h=d)||!1===h?Object.assign(Object.assign({},a),{searchParams:u}):!0===h?Object.assign(Object.assign({},s),{searchParams:u}):{spa:null===(y=h.spa)||void 0===y||y,outboundClicks:null===(v=h.outboundClicks)||void 0===v||v,scroll:null===(p=h.scroll)||void 0===p||p,downloads:null===(m=h.downloads)||void 0===m||m,siteSearch:null===(b=h.siteSearch)||void 0===b||b,downloadExtensions:h.downloadExtensions,searchParams:null!==(w=h.searchParams)&&void 0!==w?w:u};var h,y,v,p,m,b,w;const g=[];let x=null;function k(n){if(f.siteSearch)try{const e=null!=n?n:(()=>{try{return"undefined"!=typeof location?location.href:""}catch(t){return""}})();if(e===x)return;x=e;const r=((t,n=u)=>{try{if(!t){if("undefined"==typeof location)return null;t=location.href}const e=t instanceof URL?t:new URL(t,(()=>{try{return"undefined"!=typeof location?location.href:"http://localhost/"}catch(t){return"http://localhost/"}})());if(!e.search)return null;for(const t of n){const n=e.searchParams.get(t);if(null===n)continue;const r=n.trim();if(0!==r.length)return{query:r,param:t}}return null}catch(t){return null}})(e,f.searchParams);r&&l(()=>t.track("Site Searched",{query:r.query,param:r.param}))}catch(t){}}if(f.outboundClicks||f.downloads){const i=(t=>{var i;if("undefined"==typeof document)return()=>{};const c=new Set((null!==(i=t.downloadExtensions)&&void 0!==i?i:n).map(t=>t.toLowerCase())),u=!!t.onOutbound,s=!!t.onDownload;if(!u&&!s)return()=>{};function a(n){var i,a;try{if(0!==n.button)return;if(n.defaultPrevented)return;const l=(t=>{const n="function"==typeof t.composedPath?t.composedPath():[];if(n.length>0)for(const t of n)if(e(t))return t;let r=t.target;for(;r;){if(e(r))return r;r=r.parentNode}return null})(n);if(!l)return;const d=l.getAttribute("href");if(!d)return;if(/^(javascript:|mailto:|tel:|sms:)/i.test(d))return;if(d.startsWith("#"))return;const f=(t=>{try{return new URL(t,location.href)}catch(t){return null}})(d);if(!f)return;let h=!1;if(s){const n=l.hasAttribute("download"),e=(t=>{const n=r(t),e=n.lastIndexOf(".");return e<=0||e===n.length-1?null:n.slice(e+1).toLowerCase()})(f.pathname);(n||e&&c.has(e))&&(h=!0,null===(i=t.onDownload)||void 0===i||i.call(t,{url:f.href,fileName:r(f.pathname),fileExtension:null!=e?e:"",text:o(l)}))}u&&!h&&f.host!==(()=>{try{return"undefined"!=typeof location?location.hostname:""}catch(t){return""}})()&&f.host&&(null===(a=t.onOutbound)||void 0===a||a.call(t,{url:f.href,host:f.host,text:o(l),target:l.target||"_self"}))}catch(t){}}try{document.addEventListener("click",a,!0)}catch(t){return()=>{}}return()=>{try{document.removeEventListener("click",a,!0)}catch(t){}}})({downloadExtensions:f.downloadExtensions,onOutbound:f.outboundClicks?n=>l(()=>t.track("Outbound Link Clicked",n)):void 0,onDownload:f.downloads?n=>l(()=>t.track("File Downloaded",n)):void 0});g.push(i)}let j=null;if(f.scroll&&(j=(t=>{if("undefined"==typeof window||"undefined"==typeof document)return{destroy(){},reset(){}};let n=!1,e=null,r=!1;function o(){if(e=null,!r&&!n)try{const e=document.documentElement,r=document.body,o=Math.max(e?e.scrollHeight:0,r?r.scrollHeight:0),i=Math.max(e?e.clientHeight:0,window.innerHeight||0);if(o<=i)return n=!0,c(),void t(90);((window.scrollY||(e?e.scrollTop:0)||0)+i)/o>=.9&&(n=!0,c(),t(90))}catch(t){}}function i(){if(null===e)try{e=window.requestAnimationFrame(o)}catch(t){o()}}function c(){try{window.removeEventListener("scroll",i),null!==e&&window.cancelAnimationFrame(e),e=null}catch(t){}}try{window.addEventListener("scroll",i,{passive:!0})}catch(t){try{window.addEventListener("scroll",i)}catch(t){}}try{window.requestAnimationFrame(o)}catch(t){o()}return{destroy(){r=!0,c()},reset(){if(!r){n=!1;try{window.addEventListener("scroll",i,{passive:!0})}catch(t){try{window.addEventListener("scroll",i)}catch(t){}}try{window.requestAnimationFrame(o)}catch(t){o()}}}}})(n=>{l(()=>t.track("Scrolled",{percent:n}))}),g.push(()=>null==j?void 0:j.destroy())),f.spa){const n=function(){if("undefined"==typeof window||"undefined"==typeof history)return()=>{};let n=c();function e(){try{const e=c();if(e===n)return;n=e,(n=>{l(()=>t.page()),null==j||j.reset(),k(n)})(e)}catch(t){}}const r=history.pushState,o=history.replaceState,u=!0===r[i],s=!0===o[i];if(!u){function f(...t){r.apply(this,t),e()}f[i]=!0,history.pushState=f}if(!s){function h(...t){o.apply(this,t),e()}h[i]=!0,history.replaceState=h}const a=()=>e(),d=()=>e();try{window.addEventListener("popstate",a),window.addEventListener("hashchange",d)}catch(y){}return()=>{try{window.removeEventListener("popstate",a),window.removeEventListener("hashchange",d)}catch(t){}try{!u&&history.pushState[i]&&(history.pushState=r),!s&&history.replaceState[i]&&(history.replaceState=o)}catch(t){}}}();g.push(n)}return k(),()=>{for(;g.length>0;){const t=g.pop();try{null==t||t()}catch(t){}}x=null}}({page(t,n){return L(t,n)},track(t,n){return N(t,n)}},p.autotrack))}catch(t){}},pageview:$,page:L,screen(t,n){try{const e=U();if(!e)return C("screen");const r=((t,n,e)=>{const r=T("screen",e);return t&&(r.name=t),r.properties=null!=n?n:{},r})(t,n,e);D().enqueue(r)}catch(t){}},track:N,identify(t,n){try{if("string"!=typeof t||0===t.length)return;((t,n,e={})=>{var r,o;if(t&&(j(V,t,{domain:e.cookieDomain,maxAgeDays:null!==(r=e.cookieMaxAgeDays)&&void 0!==r?r:730,sameSite:"Lax"}),S(V,t),null!=n)){const t=null!==(o=(()=>{const t=_(E);if(!t)return null;try{const n=JSON.parse(t);return n&&"object"==typeof n&&!Array.isArray(n)?n:null}catch(t){return null}})())&&void 0!==o?o:{},e=Object.assign(Object.assign({},t),n);try{S(E,JSON.stringify(e))}catch(t){}}})(t,n,{cookieDomain:p.cookieDomain,cookieMaxAgeDays:p.cookieMaxAgeDays});const e=U();if(!e)return C("identify");const r=((t,n,e)=>{var r;const o=T("identify",e);return t&&(o.userId=t),o.traits=null!==(r=n)&&void 0!==r?r:{},o})(t,n,e);D().enqueue(r)}catch(t){}},alias(t,n){try{if("string"!=typeof t||0===t.length)return;const e=U();if(!e)return C("alias");const r=((t,n,e)=>{const r=T("alias",e);return t&&(r.userId=t),r.previousId=null!=n?n:e.anonymousId,r})(t,n,e);D().enqueue(r)}catch(t){}},group(t,n){try{if("string"!=typeof t||0===t.length)return;const e=U();if(!e)return C("group");const r=((t,n,e)=>{const r=T("group",e);return r.groupId=t,r.traits=null!=n?n:{},r})(t,n,e);D().enqueue(r)}catch(t){}},reset(){try{((t={})=>{((t,n={})=>{var e;if(!x)return!1;try{let r=`${encodeURIComponent(t)}=`;return r+=`; path=${null!==(e=n.path)&&void 0!==e?e:"/"}`,n.domain&&(r+=`; domain=${n.domain}`),r+="; max-age=0",r+="; expires=Thu, 01 Jan 1970 00:00:00 GMT",document.cookie=r,null===k(t)}catch(t){return!1}})(V,{domain:t.cookieDomain}),A(V),A(E)})({cookieDomain:p.cookieDomain}),((t={})=>{M(b(),t)})({cookieDomain:p.cookieDomain,cookieMaxAgeDays:p.cookieMaxAgeDays}),((t={})=>{q({id:b(),lastActivity:Date.now()},t)})({cookieDomain:p.cookieDomain,timeoutMinutes:p.sessionTimeoutMinutes})}catch(t){}},flush(){try{w&&w.flush()}catch(t){}},consent(t){try{m=Object.assign(Object.assign({},m),t)}catch(t){}},set(t){try{p=P(t),t.consent&&(m=Object.assign(Object.assign({},m),t.consent)),w&&w.setConfig({endpoint:p.endpoint,batchPath:p.batchPath,singlePath:p.singlePath,useBatch:p.useBatch,contentType:p.contentType,flushAt:p.flushAt,flushInterval:p.flushInterval,debug:p.debug})}catch(t){}},destroy(){if(O){try{O()}catch(t){}O=null}w&&w.destroy(),w=null,g=!1,t=null,p=Object.assign({},H),m=Object.assign({},F)}}})();"undefined"!=typeof window&&(t=>{if("undefined"==typeof window)return()=>{};const n=window.cnvQ;if(n&&n.__loaded)return()=>{};const e=window.cnvQ=null!=n?n:[],r=e.splice(0,e.length);e.push.bind(e),e.push=(...n)=>{for(const e of n)G(t,e);return e.length},e.__loaded=!0;for(const n of r)G(t,n)})(W);const X=Object.assign(W,{version:K,name:Q,schemaVersion:U});t.NAME=Q,t.SCHEMA_VERSION=U,t.VERSION=K,t.default=X,Object.defineProperty(t,"t",{value:!0})}(this.cnvTrack=this.cnvTrack||{});
6
+ !function(t){const n=["pdf","doc","docx","xls","xlsx","ppt","pptx","txt","csv","rtf","zip","rar","7z","tar","gz","mp3","mp4","mov","wav","avi","mkv","dmg","exe","pkg","apk","msi","svg"];function e(t){return!!t&&"object"==typeof t&&1===t.nodeType&&"A"===t.tagName}function r(t){const n=t.lastIndexOf("/");return-1===n?t:t.slice(n+1)}function o(t){var n,e,r;let o=(null!==(n=t.textContent)&&void 0!==n?n:"").trim();return o||(o=(null!==(e=t.getAttribute("aria-label"))&&void 0!==e?e:"").trim()),o||(o=(null!==(r=t.getAttribute("title"))&&void 0!==r?r:"").trim()),o.length>200?o.slice(0,200):o}const i=200;function c(t){let n="";try{n=(t.textContent||"").replace(/\s+/g," ").trim(),n||(n=(t.getAttribute("aria-label")||"").trim()),n||(n=(t.getAttribute("title")||"").trim())}catch(t){return""}return n.length>i?n.slice(0,i):n}function u(t){const n=!1!==t.caseInsensitive;return"regex"===t.mode?{mode:"regex",needle:t.value,ci:n,re:b(t.value,n)}:{mode:t.mode,needle:n?t.value.toLowerCase():t.value,ci:n,re:null}}function s(t,n){try{return t.matches(n)}catch(t){return!1}}function a(t){try{if("A"===t.tagName){const n=t.getAttribute("href");return n?p(n):null}const n=t.getAttribute("formaction");if(n)return p(n);const e=t.getAttribute("data-href");if(e)return p(e);const r=t.closest("form");if(r){const t=r.getAttribute("action");if(t)return p(t)}return null}catch(t){return null}}function l(t){return"regex"===t.mode?{mode:"regex",needle:t.value,re:b(t.value,!0)}:{mode:t.mode,needle:t.value.toLowerCase(),re:null}}function f(t){if("startsWith"===t.mode)return{mode:"startsWith",needle:t.value,re:null};const n="glob"===t.mode?"^"+t.value.replace(/[.+^${}()|[\]\\?]/g,"\\$&").replace(/\*/g,".*")+"$":t.value;return{mode:t.mode,needle:t.value,re:b(n,!1)}}function d(t,n){return"startsWith"===t.mode?0===n.indexOf(t.needle):!t.re||g(t.re,n)}const h=/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g,y=/\+?\d[\d\s().-]{7,}\d/g;function v(t){if(!t)return t;try{return t.replace(h,"[email]").replace(y,"[phone]")}catch(n){return t}}function m(t){return!!t&&"object"==typeof t&&1===t.nodeType}function p(t){try{return new URL(t,location.href).href}catch(n){return t}}function b(t,n){try{return!t||t.length>1e3?null:new RegExp(t,n?"i":"")}catch(t){return null}}function g(t,n){try{return t.test(n)}catch(t){return!1}}function w(t){const n=t.match;return n.element?n.element:n.selector||n.id||n.dataAttr||n.classes&&n.classes.length>0||n.destinationUrl?"any":void 0}function x(t,n){if(!((t,n)=>{if(!n)return(t=>{const n=t.tagName;if("BUTTON"===n||"A"===n)return!0;if("INPUT"===n){const n=(t.getAttribute("type")||"").toLowerCase();return"submit"===n||"button"===n||"reset"===n}return"button"===t.getAttribute("role")})(t);if("any"===n)return!0;if("button"===n){const n=t.tagName;if("BUTTON"===n)return!0;if("INPUT"===n){const n=(t.getAttribute("type")||"").toLowerCase();return"submit"===n||"button"===n||"reset"===n}return"button"===t.getAttribute("role")}return"link"===n?"A"===t.tagName:s(t,n)})(n,t.elementSpec))return!1;const e=t.rule.match;return!(t.selector&&!s(n,t.selector)||void 0!==e.id&&!((t,n)=>t.id===n)(n,e.id)||e.classes&&e.classes.length>0&&!((t,n)=>{try{for(let e=0;e<n.length;e++)if(!t.classList.contains(n[e]))return!1;return!0}catch(t){return!1}})(n,e.classes)||e.dataAttr&&!((t,n,e)=>{try{return!!t.hasAttribute(n)&&(void 0===e||t.getAttribute(n)===e)}catch(t){return!1}})(n,e.dataAttr.name,e.dataAttr.value)||t.text&&!((t,n)=>{const e=c(t);if("regex"===n.mode)return!!n.re&&g(n.re,e);const r=n.ci?e.toLowerCase():e;return"exact"===n.mode?r===n.needle:"startsWith"===n.mode?0===r.indexOf(n.needle):-1!==r.indexOf(n.needle)})(n,t.text)||t.dest&&!((t,n)=>{const e=a(t);if(!e)return!1;if("regex"===n.mode)return!!n.re&&g(n.re,e);if("domain"===n.mode)try{return new URL(e).host.toLowerCase()===n.needle}catch(t){return!1}const r=e.toLowerCase();return"exact"===n.mode?r===n.needle:"startsWith"===n.mode?0===r.indexOf(n.needle):-1!==r.indexOf(n.needle)})(n,t.dest))}function k(t,n,e){const r={},o=t.event.staticProps;if(o)for(const t of Object.keys(o))r[t]=o[t];const u=t.capture;if(u)try{if(u.text){const t=v(c(n));t&&(r.text=t)}if(u.href){const t=a(n);t&&(r.href=t)}if(u.elementId&&n.id&&(r.element_id=n.id),u.classes&&(r.element_classes=Array.from(n.classList)),u.dataAttrs&&u.dataAttrs.length>0)for(let t=0;t<u.dataAttrs.length;t++){const e=u.dataAttrs[t],o=n.getAttribute(e);null!==o&&(r[e]=v(o))}if(u.valueFrom){const t=((t,n)=>{try{const e=t.querySelector(n.selector)||(t.parentElement?t.parentElement.querySelector(n.selector):null);if(!e)return null;const r=n.attr?e.getAttribute(n.attr):e.textContent||"";if(null===r)return null;const o=v(r.replace(/\s+/g," ").trim());return o.length>i?o.slice(0,i):o}catch(t){return null}})(n,u.valueFrom);null!==t&&(r[u.valueFrom.as]=t)}u.selectorPath&&(r.selector_path=((t,n=5)=>{try{const e=[];let r=t,o=0;for(;r&&1===r.nodeType&&o<n;){let t=r.tagName.toLowerCase();if(r.id){e.unshift(t+"#"+r.id);break}const n=Array.from(r.classList).slice(0,2).join(".");n&&(t+="."+n),e.unshift(t),r=r.parentElement,o++}return e.join(" > ")}catch(t){return""}})(n)),u.position&&(r.x=e.clientX,r.y=e.clientY)}catch(t){}return r.rule_id=t.id,t.name&&(r.rule_name=t.name),r.tag=n.tagName.toLowerCase(),r}function j(t){try{t()}catch(t){}}function O(){try{return"undefined"!=typeof location?location.href:""}catch(t){return""}}function A(t,n){return"number"!=typeof t||isNaN(t)?n:t}function S(t){return t<0?0:t>1?1:t}const _="__cnvPatched";function P(){try{return"undefined"!=typeof location?location.href:""}catch(t){return""}}const I=["q","s","query","search","keyword"],D={spa:!0,outboundClicks:!0,scroll:!0,downloads:!0,siteSearch:!0},M={spa:!1,outboundClicks:!1,scroll:!1,downloads:!1,siteSearch:!1};function T(t){try{t()}catch(t){}}const U=["gclid","fbclid","ttclid","msclkid","dclid"],$=[["utm_source","source"],["utm_medium","medium"],["utm_campaign","name"],["utm_term","term"],["utm_content","content"],["utm_id","id"]];function R(t,n){try{return t()}catch(t){return n}}function C(){const t=R(()=>window.location.href,"");let n="",e="",r="";if(t)try{const o=new URL(t);n=o.pathname,e=o.search,r=o.hash}catch(t){}return{url:t,path:n,search:e,hash:r,title:R(()=>document.title,""),referrer:R(()=>document.referrer,"")}}function L(t){var n,e;let r="@cnv-vn/track",o="0.0.0-dev";try{r="@cnv-vn/track"}catch(t){}try{o="0.2.0-alpha.5"}catch(t){}return{name:null!==(n=null==t?void 0:t.name)&&void 0!==n?n:r,version:null!==(e=null==t?void 0:t.version)&&void 0!==e?e:o}}const N="0123456789abcdef";function q(t){return N[t>>>4&15]+N[15&t]}function B(){if("undefined"!=typeof crypto){if("function"==typeof crypto.randomUUID)return crypto.randomUUID();if("function"==typeof crypto.getRandomValues){const t=new Uint8Array(16);return crypto.getRandomValues(t),t[6]=15&t[6]|64,t[8]=63&t[8]|128,q(t[0])+q(t[1])+q(t[2])+q(t[3])+"-"+q(t[4])+q(t[5])+"-"+q(t[6])+q(t[7])+"-"+q(t[8])+q(t[9])+"-"+q(t[10])+q(t[11])+q(t[12])+q(t[13])+q(t[14])+q(t[15])}}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const n=16*Math.random()|0;return("x"===t?n:3&n|8).toString(16)})}const z=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function W(t){return"string"==typeof t&&z.test(t)}const J="undefined"!=typeof window&&"undefined"!=typeof document;function E(t){if(!J)return null;try{const n=document.cookie;if(!n)return null;const e=encodeURIComponent(t),r=n.split(";");for(let n=0;n<r.length;n++){const o=r[n].indexOf("=");if(o<0)continue;const i=r[n].slice(0,o).trim();if(i===e||i===t)try{return decodeURIComponent(r[n].slice(o+1))}catch(t){return r[n].slice(o+1)}}return null}catch(t){return null}}function V(t,n,e={}){var r,o,i;if(!J)return!1;try{let c=`${encodeURIComponent(t)}=${encodeURIComponent(n)}`;if(c+=`; path=${null!==(r=e.path)&&void 0!==r?r:"/"}`,e.domain&&(c+=`; domain=${e.domain}`),"number"==typeof e.maxAgeDays){const t=Math.floor(86400*e.maxAgeDays);c+=`; max-age=${t}`,c+=`; expires=${new Date(Date.now()+1e3*t).toUTCString()}`}return c+=`; SameSite=${null!==(o=e.sameSite)&&void 0!==o?o:"Lax"}`,(null!==(i=e.secure)&&void 0!==i?i:"undefined"!=typeof location&&"https:"===location.protocol)&&(c+="; Secure"),document.cookie=c,E(t)===n}catch(t){return!1}}function H(){if(!J)return!1;try{const t="__cnv_probe__";return localStorage.setItem(t,"1"),localStorage.removeItem(t),!0}catch(t){return!1}}function Z(t){if(!H())return null;try{return localStorage.getItem(t)}catch(t){return null}}function F(t,n){if(!H())return!1;try{return localStorage.setItem(t,n),!0}catch(t){return!1}}function G(t){if(!H())return!1;try{return localStorage.removeItem(t),!0}catch(t){return!1}}function K(){if(!J)return!1;try{const t="__cnv_probe__";return sessionStorage.setItem(t,"1"),sessionStorage.removeItem(t),!0}catch(t){return!1}}const Q="_cnv_cid";function X(t={}){const n=E(Q),e=Z(Q);let r=null;return W(n)?r=n:W(e)&&(r=e),r||(r=B()),Y(r,t),r}function Y(t,n={}){var e;V(Q,t,{domain:n.cookieDomain,maxAgeDays:null!==(e=n.cookieMaxAgeDays)&&void 0!==e?e:730,sameSite:"Lax"}),F(Q,t)}const tt="1.0";function nt(){return(new Date).toISOString()}function et(t,n){var e;const r=null!==(e=n.timestamp)&&void 0!==e?e:nt(),o=Object.assign(Object.assign({},n.context),{projectId:n.projectId,schemaVersion:tt}),i={type:t,messageId:B(),anonymousId:n.anonymousId,timestamp:r,originalTimestamp:r,context:o};return n.userId&&(i.userId=n.userId),n.sessionId&&(i.sessionId=n.sessionId),n.integrations&&(i.integrations=n.integrations),i}const rt="_cnv_sid";function ot(t){if(!t)return null;const n=t.lastIndexOf(".");if(n<0)return null;const e=t.slice(0,n),r=Number(t.slice(n+1));return!W(e)||!Number.isFinite(r)||r<=0?null:{id:e,lastActivity:r}}function it(t={}){const n=Date.now(),e=(t=>{var n;return 6e4*(null!==(n=t.timeoutMinutes)&&void 0!==n?n:30)})(t),r=ot(E(rt)),o=ot((t=>{if(!K())return null;try{return sessionStorage.getItem(t)}catch(t){return null}})(rt));let i=null;for(const t of[r,o])t&&(n-t.lastActivity>e||(!i||t.lastActivity>i.lastActivity)&&(i=t));const c=i?{id:i.id,lastActivity:n}:{id:B(),lastActivity:n};return ct(c,t),c.id}function ct(t,n={}){var e;const r=(t=>`${t.id}.${t.lastActivity}`)(t),o=null!==(e=n.timeoutMinutes)&&void 0!==e?e:30;V(rt,r,{domain:n.cookieDomain,maxAgeDays:o/1440,sameSite:"Lax"}),((t,n)=>{if(!K())return!1;try{return sessionStorage.setItem(t,n),!0}catch(t){return!1}})(rt,r)}class ut{constructor(t){var n,e;Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"storageKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"maxMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"flushing",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"onlineHandler",{enumerable:!0,configurable:!0,writable:!0,value:null}),this.storageKey=null!==(n=t.storageKey)&&void 0!==n?n:"_cnv_rq",this.maxMessages=null!==(e=t.maxMessages)&&void 0!==e?e:100,this.installOnlineListener()}stash(t){if(t&&0!==t.length)try{const n=this.read();for(n.push(t);n.length>1&&st(n)>this.maxMessages;)n.shift();this.write(n),this.config.debug&&console.log("[cnv-track] retry queued",t.length,"buffered",st(n))}catch(t){}}flush(){if(this.flushing||"undefined"!=typeof navigator&&!1===navigator.onLine)return Promise.resolve();const t=this.read();if(0===t.length)return Promise.resolve();this.flushing=!0,this.write([]);const n=()=>{this.flushing=!1};return t.reduce((t,n)=>t.then(()=>this.config.resend(n)),Promise.resolve()).then(n,n)}size(){return st(this.read())}clear(){try{G(this.storageKey)}catch(t){}}destroy(){if(this.onlineHandler){try{window.removeEventListener("online",this.onlineHandler)}catch(t){}this.onlineHandler=null}}installOnlineListener(){if("undefined"==typeof window)return;const t=()=>{this.flush()};try{window.addEventListener("online",t),this.onlineHandler=t}catch(t){}}read(){const t=Z(this.storageKey);if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.filter(t=>Array.isArray(t)&&t.length>0):[]}catch(t){return[]}}write(t){0!==t.length?F(this.storageKey,JSON.stringify(t)):G(this.storageKey)}}function st(t){let n=0;for(const e of t)n+=e.length;return n}class at{constructor(t){Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"buffer",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"timer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"handlers",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"retryQueue",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.retryQueue=new ut({debug:t.debug,resend:t=>this.send(t)}),this.installPageLifecycleHandlers(),this.retryQueue.flush()}setConfig(t){this.config=Object.assign(Object.assign({},this.config),t)}enqueue(t){this.destroyed||(this.buffer.push(t),this.buffer.length>=this.config.flushAt?this.flush():this.timer||(this.timer=setTimeout(()=>{this.timer=null,this.flush()},this.config.flushInterval)))}flush(){if(this.timer&&(clearTimeout(this.timer),this.timer=null),0===this.buffer.length)return Promise.resolve();const t=this.buffer;return this.buffer=[],this.send(t)}bufferedCount(){return this.buffer.length}destroy(){this.destroyed||(this.destroyed=!0,this.timer&&(clearTimeout(this.timer),this.timer=null),this.uninstallPageLifecycleHandlers(),this.retryQueue.destroy())}send(t){try{return this.config.useBatch?this.sendBatch(t):Promise.all(t.map(t=>this.sendSingle(t))).then(()=>{})}catch(t){return this.config.debug&&console.warn("[cnv-track] send failed synchronously; dropped batch",t),Promise.resolve()}}sendBatch(t){var n;const e=nt(),r={batch:t.map(t=>lt(t,e)),context:Object.assign(Object.assign({},null!==(n=this.config.batchContext)&&void 0!==n?n:{}),{projectId:this.config.projectId,sentAt:e}),sentAt:e};return this.post(this.batchUrl(),r,t)}sendSingle(t){const n=lt(t,nt());return this.post(this.singleUrl(t.type),n,[t])}batchUrl(){return this.config.endpoint+this.config.batchPath+"?projectId="+encodeURIComponent(this.config.projectId)}singleUrl(t){const n=this.config.singlePath.replace("{type}",t);return this.config.endpoint+n+"?projectId="+encodeURIComponent(this.config.projectId)}post(t,n,e){const r=JSON.stringify(n),o=((t,n)=>{try{return new Blob([t],{type:n})}catch(t){return null}})(r,this.config.contentType),i=o?o.size:(t=>{try{return new Blob([t]).size}catch(n){return t.length}})(r),c=i>65536?null:e;return c&&"undefined"!=typeof navigator&&!1===navigator.onLine?(this.retryQueue.stash(c),this.config.debug&&console.log("[cnv-track] offline; queued for retry",t),Promise.resolve()):o&&this.sendViaBeacon(t,o)?(this.config.debug&&console.log("[cnv-track] beacon",t),Promise.resolve()):this.sendViaFetch(t,r,c)}sendViaBeacon(t,n){if("undefined"==typeof navigator||"function"!=typeof navigator.sendBeacon)return!1;if(n.size>65536)return!1;try{return navigator.sendBeacon(t,n)}catch(t){return!1}}sendViaFetch(t,n,e){return"function"!=typeof fetch?(this.config.debug&&console.warn("[cnv-track] no transport available; queued for retry"),e&&this.retryQueue.stash(e),Promise.resolve()):fetch(t,{method:"POST",headers:{"Content-Type":this.config.contentType},body:n,keepalive:!0,credentials:"omit",mode:"cors"}).then(n=>{this.config.debug&&console.log("[cnv-track] fetch flushed",t,n.status)}).catch(n=>{this.config.debug&&console.warn("[cnv-track] flush failed; queued for retry",t,n),e&&this.retryQueue.stash(e)})}installPageLifecycleHandlers(){if("undefined"==typeof window||"undefined"==typeof document)return;const t=()=>{this.flush()},n=()=>{"hidden"===document.visibilityState&&this.flush()};try{window.addEventListener("pagehide",t),document.addEventListener("visibilitychange",n),this.handlers={pagehide:t,visibility:n}}catch(t){}}uninstallPageLifecycleHandlers(){if(this.handlers){try{window.removeEventListener("pagehide",this.handlers.pagehide),document.removeEventListener("visibilitychange",this.handlers.visibility)}catch(t){}this.handlers=null}}}function lt(t,n){return Object.assign(Object.assign({},t),{sentAt:n})}const ft="_cnv_uid",dt="_cnv_traits",ht={endpoint:"http://localhost:8090/v1",batchPath:"/batch",singlePath:"/{type}",useBatch:!0,contentType:"text/plain",debug:!1,allowAdTracking:!0,cookieMaxAgeDays:730,sessionTimeoutMinutes:30,flushAt:20,flushInterval:5e3,autoPageview:!0,autotrack:!1,integrations:{}},yt={analytics:!0,marketing:!0};function vt(t,n){if(!Array.isArray(n)||0===n.length)return;const e=n;try{switch(e[0]){case"init":t.init(e[1],e[2]);break;case"pageview":t.pageview(e[1],e[2]);break;case"page":t.page(e[1],e[2]);break;case"screen":t.screen(e[1],e[2]);break;case"track":t.track(e[1],e[2]);break;case"identify":t.identify(e[1],e[2]);break;case"alias":t.alias(e[1],e[2]);break;case"group":t.group(e[1],e[2]);break;case"reset":t.reset();break;case"flush":t.flush();break;case"consent":t.consent(e[1]);break;case"set":t.set(e[1])}}catch(t){}}const mt="0.2.0-alpha.5",pt="@cnv-vn/track",bt=(()=>{let t=null,i=Object.assign({},ht),c=Object.assign({},yt),s=null,a=!1,h=null;function y(t){const n=Object.assign({},i);return t?(void 0!==t.endpoint&&(n.endpoint=(e=t.endpoint).endsWith("/")?e.slice(0,-1):e),void 0!==t.batchPath&&(n.batchPath=t.batchPath),void 0!==t.singlePath&&(n.singlePath=t.singlePath),void 0!==t.useBatch&&(n.useBatch=t.useBatch),void 0!==t.contentType&&(n.contentType=t.contentType),void 0!==t.debug&&(n.debug=t.debug),void 0!==t.allowAdTracking&&(n.allowAdTracking=t.allowAdTracking),void 0!==t.cookieDomain&&(n.cookieDomain=t.cookieDomain),void 0!==t.cookieMaxAgeDays&&(n.cookieMaxAgeDays=t.cookieMaxAgeDays),void 0!==t.sessionTimeoutMinutes&&(n.sessionTimeoutMinutes=t.sessionTimeoutMinutes),void 0!==t.flushAt&&(n.flushAt=t.flushAt),void 0!==t.flushInterval&&(n.flushInterval=t.flushInterval),void 0!==t.autoPageview&&(n.autoPageview=t.autoPageview),void 0!==t.autotrack&&(n.autotrack=t.autotrack),void 0!==t.integrations&&(n.integrations=t.integrations),n):n;var e}function v(){return s||(s=new at({endpoint:i.endpoint,batchPath:i.batchPath,singlePath:i.singlePath,useBatch:i.useBatch,contentType:i.contentType,flushAt:i.flushAt,flushInterval:i.flushInterval,projectId:null!=t?t:"",debug:i.debug}),s)}function p(){var n;if(!t)return null;const e=((t={})=>{var n;const e={page:C(),screen:{width:R(()=>window.screen.width,0),height:R(()=>window.screen.height,0),density:R(()=>window.devicePixelRatio||1,1)},locale:R(()=>navigator.language||"",""),timezone:R(()=>Intl.DateTimeFormat().resolvedOptions().timeZone||"",""),userAgent:R(()=>navigator.userAgent||"",""),library:L(t.library)},r=((t,n=!0)=>{const e=R(()=>window.location.search,"");if(!e)return;let r;try{r=new URLSearchParams(e)}catch(t){return}const o={};let i=!1;for(const[t,n]of $){const e=r.get(t);e&&e.length>0&&(o[n]=e,i=!0)}if(n){const t={};for(const n of U){const e=r.get(n);e&&e.length>0&&(t[n]=e)}Object.keys(t).length>0&&(o.clickIds=t,i=!0)}return i?o:void 0})(0,null===(n=t.allowAdTracking)||void 0===n||n);return r&&(e.campaign=r),e})({allowAdTracking:i.allowAdTracking});return c.analytics&&c.marketing||(e.consent=Object.assign({},c)),{anonymousId:X({cookieDomain:i.cookieDomain,cookieMaxAgeDays:i.cookieMaxAgeDays}),sessionId:it({cookieDomain:i.cookieDomain,timeoutMinutes:i.sessionTimeoutMinutes}),userId:null!==(n=E(ft)||Z(ft))&&void 0!==n?n:void 0,context:e,projectId:t,integrations:Object.keys(i.integrations).length>0?i.integrations:void 0}}function b(t){i.debug&&console.warn(`[cnv-track] ${t}() called before init()`)}function g(t,n){try{const e=p();if(!e)return b("pageview");const r=((t,n,e)=>{const r=et("page",e);return t&&(r.name=t),r.properties=null!=n?n:{},r})(null!=t?t:(()=>{try{return"undefined"!=typeof document&&document.title||void 0}catch(t){return}})(),n,e);v().enqueue(r)}catch(t){}}function N(t,n){g(t,n)}function q(t,n){try{if("string"!=typeof t||0===t.length)return;const e=p();if(!e)return b("track");const r=((t,n,e)=>{const r=et("track",e);return r.event=t,r.properties=null!=n?n:{},r})(t,n,e);v().enqueue(r)}catch(t){}}return{get initialized(){return a},get projectId(){return t},init(p,b){try{if(!p||"string"!=typeof p)return;if(i=y(b),(null==b?void 0:b.consent)&&(c=Object.assign(Object.assign({},c),b.consent)),t=p,s&&s.destroy(),s=null,v(),a=!0,X({cookieDomain:i.cookieDomain,cookieMaxAgeDays:i.cookieMaxAgeDays}),it({cookieDomain:i.cookieDomain,timeoutMinutes:i.sessionTimeoutMinutes}),i.autoPageview&&g(),h){try{h()}catch(t){}h=null}i.autotrack&&(h=function(t,i){const c=void 0===(s=i)||!1===s?Object.assign(Object.assign({},M),{searchParams:I}):!0===s?Object.assign(Object.assign({},D),{searchParams:I}):{spa:null===(a=s.spa)||void 0===a||a,outboundClicks:null===(h=s.outboundClicks)||void 0===h||h,scroll:null===(y=s.scroll)||void 0===y||y,downloads:null===(v=s.downloads)||void 0===v||v,siteSearch:null===(p=s.siteSearch)||void 0===p||p,downloadExtensions:s.downloadExtensions,searchParams:null!==(b=s.searchParams)&&void 0!==b?b:I,buttonTracking:s.buttonTracking};var s,a,h,y,v,p,b;const g=[];let U=null;function $(n){if(c.siteSearch)try{const e=null!=n?n:(()=>{try{return"undefined"!=typeof location?location.href:""}catch(t){return""}})();if(e===U)return;U=e;const r=((t,n=I)=>{try{if(!t){if("undefined"==typeof location)return null;t=location.href}const e=t instanceof URL?t:new URL(t,(()=>{try{return"undefined"!=typeof location?location.href:"http://localhost/"}catch(t){return"http://localhost/"}})());if(!e.search)return null;for(const t of n){const n=e.searchParams.get(t);if(null===n)continue;const r=n.trim();if(0!==r.length)return{query:r,param:t}}return null}catch(t){return null}})(e,c.searchParams);r&&T(()=>t.track("Site Searched",{query:r.query,param:r.param}))}catch(t){}}if(c.outboundClicks||c.downloads){const i=(t=>{var i;if("undefined"==typeof document)return()=>{};const c=new Set((null!==(i=t.downloadExtensions)&&void 0!==i?i:n).map(t=>t.toLowerCase())),u=!!t.onOutbound,s=!!t.onDownload;if(!u&&!s)return()=>{};function a(n){var i,a;try{if(0!==n.button)return;if(n.defaultPrevented)return;const l=(t=>{const n="function"==typeof t.composedPath?t.composedPath():[];if(n.length>0)for(const t of n)if(e(t))return t;let r=t.target;for(;r;){if(e(r))return r;r=r.parentNode}return null})(n);if(!l)return;const f=l.getAttribute("href");if(!f)return;if(/^(javascript:|mailto:|tel:|sms:)/i.test(f))return;if(f.startsWith("#"))return;const d=(t=>{try{return new URL(t,location.href)}catch(t){return null}})(f);if(!d)return;let h=!1;if(s){const n=l.hasAttribute("download"),e=(t=>{const n=r(t),e=n.lastIndexOf(".");return e<=0||e===n.length-1?null:n.slice(e+1).toLowerCase()})(d.pathname);(n||e&&c.has(e))&&(h=!0,null===(i=t.onDownload)||void 0===i||i.call(t,{url:d.href,fileName:r(d.pathname),fileExtension:null!=e?e:"",text:o(l)}))}u&&!h&&d.host!==(()=>{try{return"undefined"!=typeof location?location.hostname:""}catch(t){return""}})()&&d.host&&(null===(a=t.onOutbound)||void 0===a||a.call(t,{url:d.href,host:d.host,text:o(l),target:l.target||"_self"}))}catch(t){}}try{document.addEventListener("click",a,!0)}catch(t){return()=>{}}return()=>{try{document.removeEventListener("click",a,!0)}catch(t){}}})({downloadExtensions:c.downloadExtensions,onOutbound:c.outboundClicks?n=>T(()=>t.track("Outbound Link Clicked",n)):void 0,onDownload:c.downloads?n=>T(()=>t.track("File Downloaded",n)):void 0});g.push(i)}c.buttonTracking&&c.buttonTracking.rules&&c.buttonTracking.rules.length>0&&g.push(((t,n)=>{if("undefined"==typeof document)return()=>{};const e=(t=>{const n=t.globalThrottle||{},e=[],r=t.rules||[];for(let t=0;t<r.length;t++){const o=r[t];if(!o||!1===o.enabled)continue;if(!o.match||!o.event||!o.event.name)continue;const i=o.match,c=o.throttle||{};e.push({rule:o,elementSpec:w(o),selector:i.selector||null,text:i.text?u(i.text):null,dest:i.destinationUrl?l(i.destinationUrl):null,urlScope:o.urlScope?f(o.urlScope):null,dedupeWindowMs:A(c.dedupeWindowMs,A(n.dedupeWindowMs,500)),maxPerPageview:A(c.maxPerPageview,A(n.maxPerPageview,1/0)),samplingRate:S(A(c.samplingRate,A(n.samplingRate,1)))})}return e.sort((t,n)=>(t.rule.priority||0)-(n.rule.priority||0)),e})(n);if(0===e.length)return()=>{};const r=new WeakMap;let o=0;const i=t=>{let n=r.get(t);return void 0===n&&(n=++o,r.set(t,n)),String(n)},c=new Map,s=new Map;let a=O();function h(n){try{if(0!==n.button)return;const r=O();r!==a&&(a=r,s.clear(),c.clear());const o=(t=>{const n=[];try{const e="function"==typeof t.composedPath?t.composedPath():[];if(e&&e.length>0){for(const t of e)m(t)&&n.push(t);return n}let r=t.target;for(;r;)m(r)&&n.push(r),r=r.parentNode}catch(t){}return n})(n);if(0===o.length)return;const u=(()=>{try{return"undefined"!=typeof location?location.pathname+location.search:""}catch(t){return""}})();for(let r=0;r<e.length;r++){const a=e[r];if(a.urlScope&&!d(a.urlScope,u))continue;let l=null;for(let t=0;t<o.length;t++)if(x(a,o[t])){l=o[t];break}if(!l)continue;const f=a.rule.id;if((s.get(f)||0)>=a.maxPerPageview)return;const h=f+"#"+i(l),y=Date.now(),v=c.get(h);if(void 0!==v&&y-v<a.dedupeWindowMs)return;if(a.samplingRate<1&&Math.random()>=a.samplingRate)return;c.set(h,y),s.set(f,(s.get(f)||0)+1);const m=a.rule.event.name||"Button Clicked",p=k(a.rule,l,n);return void j(()=>t.track(m,p))}}catch(t){}}try{document.addEventListener("click",h,!0)}catch(t){return()=>{}}return()=>{try{document.removeEventListener("click",h,!0)}catch(t){}c.clear(),s.clear()}})(t,c.buttonTracking));let R=null;if(c.scroll&&(R=(t=>{if("undefined"==typeof window||"undefined"==typeof document)return{destroy(){},reset(){}};let n=!1,e=null,r=!1;function o(){if(e=null,!r&&!n)try{const e=document.documentElement,r=document.body,o=Math.max(e?e.scrollHeight:0,r?r.scrollHeight:0),i=Math.max(e?e.clientHeight:0,window.innerHeight||0);if(o<=i)return n=!0,c(),void t(90);((window.scrollY||(e?e.scrollTop:0)||0)+i)/o>=.9&&(n=!0,c(),t(90))}catch(t){}}function i(){if(null===e)try{e=window.requestAnimationFrame(o)}catch(t){o()}}function c(){try{window.removeEventListener("scroll",i),null!==e&&window.cancelAnimationFrame(e),e=null}catch(t){}}try{window.addEventListener("scroll",i,{passive:!0})}catch(t){try{window.addEventListener("scroll",i)}catch(t){}}try{window.requestAnimationFrame(o)}catch(t){o()}return{destroy(){r=!0,c()},reset(){if(!r){n=!1;try{window.addEventListener("scroll",i,{passive:!0})}catch(t){try{window.addEventListener("scroll",i)}catch(t){}}try{window.requestAnimationFrame(o)}catch(t){o()}}}}})(n=>{T(()=>t.track("Scrolled",{percent:n}))}),g.push(()=>null==R?void 0:R.destroy())),c.spa){const n=function(){if("undefined"==typeof window||"undefined"==typeof history)return()=>{};let n=P();function e(){try{const e=P();if(e===n)return;n=e,(n=>{T(()=>t.page()),null==R||R.reset(),$(n)})(e)}catch(t){}}const r=history.pushState,o=history.replaceState,i=!0===r[_],c=!0===o[_];if(!i){function a(...t){r.apply(this,t),e()}a[_]=!0,history.pushState=a}if(!c){function l(...t){o.apply(this,t),e()}l[_]=!0,history.replaceState=l}const u=()=>e(),s=()=>e();try{window.addEventListener("popstate",u),window.addEventListener("hashchange",s)}catch(f){}return()=>{try{window.removeEventListener("popstate",u),window.removeEventListener("hashchange",s)}catch(t){}try{!i&&history.pushState[_]&&(history.pushState=r),!c&&history.replaceState[_]&&(history.replaceState=o)}catch(t){}}}();g.push(n)}return $(),()=>{for(;g.length>0;){const t=g.pop();try{null==t||t()}catch(t){}}U=null}}({page(t,n){return N(t,n)},track(t,n){return q(t,n)}},i.autotrack))}catch(t){}},pageview:g,page:N,screen(t,n){try{const e=p();if(!e)return b("screen");const r=((t,n,e)=>{const r=et("screen",e);return t&&(r.name=t),r.properties=null!=n?n:{},r})(t,n,e);v().enqueue(r)}catch(t){}},track:q,identify(t,n){try{if("string"!=typeof t||0===t.length)return;((t,n,e={})=>{var r,o;if(t&&(V(ft,t,{domain:e.cookieDomain,maxAgeDays:null!==(r=e.cookieMaxAgeDays)&&void 0!==r?r:730,sameSite:"Lax"}),F(ft,t),null!=n)){const t=null!==(o=(()=>{const t=Z(dt);if(!t)return null;try{const n=JSON.parse(t);return n&&"object"==typeof n&&!Array.isArray(n)?n:null}catch(t){return null}})())&&void 0!==o?o:{},e=Object.assign(Object.assign({},t),n);try{F(dt,JSON.stringify(e))}catch(t){}}})(t,n,{cookieDomain:i.cookieDomain,cookieMaxAgeDays:i.cookieMaxAgeDays});const e=p();if(!e)return b("identify");const r=((t,n,e)=>{var r;const o=et("identify",e);return t&&(o.userId=t),o.traits=null!==(r=n)&&void 0!==r?r:{},o})(t,n,e);v().enqueue(r)}catch(t){}},alias(t,n){try{if("string"!=typeof t||0===t.length)return;const e=p();if(!e)return b("alias");const r=((t,n,e)=>{const r=et("alias",e);return t&&(r.userId=t),r.previousId=null!=n?n:e.anonymousId,r})(t,n,e);v().enqueue(r)}catch(t){}},group(t,n){try{if("string"!=typeof t||0===t.length)return;const e=p();if(!e)return b("group");const r=((t,n,e)=>{const r=et("group",e);return r.groupId=t,r.traits=null!=n?n:{},r})(t,n,e);v().enqueue(r)}catch(t){}},reset(){try{((t={})=>{((t,n={})=>{var e;if(!J)return!1;try{let r=`${encodeURIComponent(t)}=`;return r+=`; path=${null!==(e=n.path)&&void 0!==e?e:"/"}`,n.domain&&(r+=`; domain=${n.domain}`),r+="; max-age=0",r+="; expires=Thu, 01 Jan 1970 00:00:00 GMT",document.cookie=r,null===E(t)}catch(t){return!1}})(ft,{domain:t.cookieDomain}),G(ft),G(dt)})({cookieDomain:i.cookieDomain}),((t={})=>{Y(B(),t)})({cookieDomain:i.cookieDomain,cookieMaxAgeDays:i.cookieMaxAgeDays}),((t={})=>{ct({id:B(),lastActivity:Date.now()},t)})({cookieDomain:i.cookieDomain,timeoutMinutes:i.sessionTimeoutMinutes})}catch(t){}},flush(){try{s&&s.flush()}catch(t){}},consent(t){try{c=Object.assign(Object.assign({},c),t)}catch(t){}},set(t){try{i=y(t),t.consent&&(c=Object.assign(Object.assign({},c),t.consent)),s&&s.setConfig({endpoint:i.endpoint,batchPath:i.batchPath,singlePath:i.singlePath,useBatch:i.useBatch,contentType:i.contentType,flushAt:i.flushAt,flushInterval:i.flushInterval,debug:i.debug})}catch(t){}},destroy(){if(h){try{h()}catch(t){}h=null}s&&s.destroy(),s=null,a=!1,t=null,i=Object.assign({},ht),c=Object.assign({},yt)}}})();"undefined"!=typeof window&&(t=>{if("undefined"==typeof window)return()=>{};const n=window.cnvQ;if(n&&n.__loaded)return()=>{};const e=window.cnvQ=null!=n?n:[],r=e.splice(0,e.length);e.push.bind(e),e.push=(...n)=>{for(const e of n)vt(t,e);return e.length},e.__loaded=!0;for(const n of r)vt(t,n)})(bt);const gt=Object.assign(bt,{version:mt,name:pt,schemaVersion:tt});t.NAME=pt,t.SCHEMA_VERSION=tt,t.VERSION=mt,t.default=gt,Object.defineProperty(t,"t",{value:!0})}(this.cnvTrack=this.cnvTrack||{});
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * @cnv-vn/track v0.2.0-alpha.4
2
+ * @cnv-vn/track v0.2.0-alpha.5
3
3
  * (c) 2026 CNV
4
4
  * Released under the UNLICENSED license.
5
5
  */
6
- var t,n;t=this,n=function(t){const n=["pdf","doc","docx","xls","xlsx","ppt","pptx","txt","csv","rtf","zip","rar","7z","tar","gz","mp3","mp4","mov","wav","avi","mkv","dmg","exe","pkg","apk","msi","svg"];function e(t){return!!t&&"object"==typeof t&&1===t.nodeType&&"A"===t.tagName}function r(t){const n=t.lastIndexOf("/");return-1===n?t:t.slice(n+1)}function o(t){var n,e,r;let o=(null!==(n=t.textContent)&&void 0!==n?n:"").trim();return o||(o=(null!==(e=t.getAttribute("aria-label"))&&void 0!==e?e:"").trim()),o||(o=(null!==(r=t.getAttribute("title"))&&void 0!==r?r:"").trim()),o.length>200?o.slice(0,200):o}const i="__cnvPatched";function c(){try{return"undefined"!=typeof location?location.href:""}catch(t){return""}}const u=["q","s","query","search","keyword"],s={spa:!0,outboundClicks:!0,scroll:!0,downloads:!0,siteSearch:!0},a={spa:!1,outboundClicks:!1,scroll:!1,downloads:!1,siteSearch:!1};function l(t){try{t()}catch(t){}}const d=["gclid","fbclid","ttclid","msclkid","dclid"],f=[["utm_source","source"],["utm_medium","medium"],["utm_campaign","name"],["utm_term","term"],["utm_content","content"],["utm_id","id"]];function h(t,n){try{return t()}catch(t){return n}}function y(){const t=h(()=>window.location.href,"");let n="",e="",r="";if(t)try{const o=new URL(t);n=o.pathname,e=o.search,r=o.hash}catch(t){}return{url:t,path:n,search:e,hash:r,title:h(()=>document.title,""),referrer:h(()=>document.referrer,"")}}function v(t){var n,e;let r="@cnv-vn/track",o="0.0.0-dev";try{r="@cnv-vn/track"}catch(t){}try{o="0.2.0-alpha.4"}catch(t){}return{name:null!==(n=null==t?void 0:t.name)&&void 0!==n?n:r,version:null!==(e=null==t?void 0:t.version)&&void 0!==e?e:o}}const p="0123456789abcdef";function b(t){return p[t>>>4&15]+p[15&t]}function m(){if("undefined"!=typeof crypto){if("function"==typeof crypto.randomUUID)return crypto.randomUUID();if("function"==typeof crypto.getRandomValues){const t=new Uint8Array(16);return crypto.getRandomValues(t),t[6]=15&t[6]|64,t[8]=63&t[8]|128,b(t[0])+b(t[1])+b(t[2])+b(t[3])+"-"+b(t[4])+b(t[5])+"-"+b(t[6])+b(t[7])+"-"+b(t[8])+b(t[9])+"-"+b(t[10])+b(t[11])+b(t[12])+b(t[13])+b(t[14])+b(t[15])}}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const n=16*Math.random()|0;return("x"===t?n:3&n|8).toString(16)})}const w=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function g(t){return"string"==typeof t&&w.test(t)}const x="undefined"!=typeof window&&"undefined"!=typeof document;function k(t){if(!x)return null;try{const n=document.cookie;if(!n)return null;const e=encodeURIComponent(t),r=n.split(";");for(let n=0;n<r.length;n++){const o=r[n].indexOf("=");if(o<0)continue;const i=r[n].slice(0,o).trim();if(i===e||i===t)try{return decodeURIComponent(r[n].slice(o+1))}catch(t){return r[n].slice(o+1)}}return null}catch(t){return null}}function j(t,n,e={}){var r,o,i;if(!x)return!1;try{let c=`${encodeURIComponent(t)}=${encodeURIComponent(n)}`;if(c+=`; path=${null!==(r=e.path)&&void 0!==r?r:"/"}`,e.domain&&(c+=`; domain=${e.domain}`),"number"==typeof e.maxAgeDays){const t=Math.floor(86400*e.maxAgeDays);c+=`; max-age=${t}`,c+=`; expires=${new Date(Date.now()+1e3*t).toUTCString()}`}return c+=`; SameSite=${null!==(o=e.sameSite)&&void 0!==o?o:"Lax"}`,(null!==(i=e.secure)&&void 0!==i?i:"undefined"!=typeof location&&"https:"===location.protocol)&&(c+="; Secure"),document.cookie=c,k(t)===n}catch(t){return!1}}function O(){if(!x)return!1;try{const t="__cnv_probe__";return localStorage.setItem(t,"1"),localStorage.removeItem(t),!0}catch(t){return!1}}function _(t){if(!O())return null;try{return localStorage.getItem(t)}catch(t){return null}}function S(t,n){if(!O())return!1;try{return localStorage.setItem(t,n),!0}catch(t){return!1}}function A(t){if(!O())return!1;try{return localStorage.removeItem(t),!0}catch(t){return!1}}function P(){if(!x)return!1;try{const t="__cnv_probe__";return sessionStorage.setItem(t,"1"),sessionStorage.removeItem(t),!0}catch(t){return!1}}const D="_cnv_cid";function I(t={}){const n=k(D),e=_(D);let r=null;return g(n)?r=n:g(e)&&(r=e),r||(r=m()),M(r,t),r}function M(t,n={}){var e;j(D,t,{domain:n.cookieDomain,maxAgeDays:null!==(e=n.cookieMaxAgeDays)&&void 0!==e?e:730,sameSite:"Lax"}),S(D,t)}const T="1.0";function U(){return(new Date).toISOString()}function C(t,n){var e;const r=null!==(e=n.timestamp)&&void 0!==e?e:U(),o=Object.assign(Object.assign({},n.context),{projectId:n.projectId,schemaVersion:T}),i={type:t,messageId:m(),anonymousId:n.anonymousId,timestamp:r,originalTimestamp:r,context:o};return n.userId&&(i.userId=n.userId),n.sessionId&&(i.sessionId=n.sessionId),n.integrations&&(i.integrations=n.integrations),i}const $="_cnv_sid";function L(t){if(!t)return null;const n=t.lastIndexOf(".");if(n<0)return null;const e=t.slice(0,n),r=Number(t.slice(n+1));return!g(e)||!Number.isFinite(r)||r<=0?null:{id:e,lastActivity:r}}function R(t={}){const n=Date.now(),e=(t=>{var n;return 6e4*(null!==(n=t.timeoutMinutes)&&void 0!==n?n:30)})(t),r=L(k($)),o=L((t=>{if(!P())return null;try{return sessionStorage.getItem(t)}catch(t){return null}})($));let i=null;for(const t of[r,o])t&&(n-t.lastActivity>e||(!i||t.lastActivity>i.lastActivity)&&(i=t));const c=i?{id:i.id,lastActivity:n}:{id:m(),lastActivity:n};return q(c,t),c.id}function q(t,n={}){var e;const r=(t=>`${t.id}.${t.lastActivity}`)(t),o=null!==(e=n.timeoutMinutes)&&void 0!==e?e:30;j($,r,{domain:n.cookieDomain,maxAgeDays:o/1440,sameSite:"Lax"}),((t,n)=>{if(!P())return!1;try{return sessionStorage.setItem(t,n),!0}catch(t){return!1}})($,r)}class N{constructor(t){var n,e;Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"storageKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"maxMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"flushing",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"onlineHandler",{enumerable:!0,configurable:!0,writable:!0,value:null}),this.storageKey=null!==(n=t.storageKey)&&void 0!==n?n:"_cnv_rq",this.maxMessages=null!==(e=t.maxMessages)&&void 0!==e?e:100,this.installOnlineListener()}stash(t){if(t&&0!==t.length)try{const n=this.read();for(n.push(t);n.length>1&&B(n)>this.maxMessages;)n.shift();this.write(n),this.config.debug&&console.log("[cnv-track] retry queued",t.length,"buffered",B(n))}catch(t){}}flush(){if(this.flushing||"undefined"!=typeof navigator&&!1===navigator.onLine)return Promise.resolve();const t=this.read();if(0===t.length)return Promise.resolve();this.flushing=!0,this.write([]);const n=()=>{this.flushing=!1};return t.reduce((t,n)=>t.then(()=>this.config.resend(n)),Promise.resolve()).then(n,n)}size(){return B(this.read())}clear(){try{A(this.storageKey)}catch(t){}}destroy(){if(this.onlineHandler){try{window.removeEventListener("online",this.onlineHandler)}catch(t){}this.onlineHandler=null}}installOnlineListener(){if("undefined"==typeof window)return;const t=()=>{this.flush()};try{window.addEventListener("online",t),this.onlineHandler=t}catch(t){}}read(){const t=_(this.storageKey);if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.filter(t=>Array.isArray(t)&&t.length>0):[]}catch(t){return[]}}write(t){0!==t.length?S(this.storageKey,JSON.stringify(t)):A(this.storageKey)}}function B(t){let n=0;for(const e of t)n+=e.length;return n}class z{constructor(t){Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"buffer",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"timer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"handlers",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"retryQueue",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.retryQueue=new N({debug:t.debug,resend:t=>this.send(t)}),this.installPageLifecycleHandlers(),this.retryQueue.flush()}setConfig(t){this.config=Object.assign(Object.assign({},this.config),t)}enqueue(t){this.destroyed||(this.buffer.push(t),this.buffer.length>=this.config.flushAt?this.flush():this.timer||(this.timer=setTimeout(()=>{this.timer=null,this.flush()},this.config.flushInterval)))}flush(){if(this.timer&&(clearTimeout(this.timer),this.timer=null),0===this.buffer.length)return Promise.resolve();const t=this.buffer;return this.buffer=[],this.send(t)}bufferedCount(){return this.buffer.length}destroy(){this.destroyed||(this.destroyed=!0,this.timer&&(clearTimeout(this.timer),this.timer=null),this.uninstallPageLifecycleHandlers(),this.retryQueue.destroy())}send(t){try{return this.config.useBatch?this.sendBatch(t):Promise.all(t.map(t=>this.sendSingle(t))).then(()=>{})}catch(t){return this.config.debug&&console.warn("[cnv-track] send failed synchronously; dropped batch",t),Promise.resolve()}}sendBatch(t){var n;const e=U(),r={batch:t.map(t=>J(t,e)),context:Object.assign(Object.assign({},null!==(n=this.config.batchContext)&&void 0!==n?n:{}),{projectId:this.config.projectId,sentAt:e}),sentAt:e};return this.post(this.batchUrl(),r,t)}sendSingle(t){const n=J(t,U());return this.post(this.singleUrl(t.type),n,[t])}batchUrl(){return this.config.endpoint+this.config.batchPath+"?projectId="+encodeURIComponent(this.config.projectId)}singleUrl(t){const n=this.config.singlePath.replace("{type}",t);return this.config.endpoint+n+"?projectId="+encodeURIComponent(this.config.projectId)}post(t,n,e){const r=JSON.stringify(n),o=((t,n)=>{try{return new Blob([t],{type:n})}catch(t){return null}})(r,this.config.contentType),i=o?o.size:(t=>{try{return new Blob([t]).size}catch(n){return t.length}})(r),c=i>65536?null:e;return c&&"undefined"!=typeof navigator&&!1===navigator.onLine?(this.retryQueue.stash(c),this.config.debug&&console.log("[cnv-track] offline; queued for retry",t),Promise.resolve()):o&&this.sendViaBeacon(t,o)?(this.config.debug&&console.log("[cnv-track] beacon",t),Promise.resolve()):this.sendViaFetch(t,r,c)}sendViaBeacon(t,n){if("undefined"==typeof navigator||"function"!=typeof navigator.sendBeacon)return!1;if(n.size>65536)return!1;try{return navigator.sendBeacon(t,n)}catch(t){return!1}}sendViaFetch(t,n,e){return"function"!=typeof fetch?(this.config.debug&&console.warn("[cnv-track] no transport available; queued for retry"),e&&this.retryQueue.stash(e),Promise.resolve()):fetch(t,{method:"POST",headers:{"Content-Type":this.config.contentType},body:n,keepalive:!0,credentials:"omit",mode:"cors"}).then(n=>{this.config.debug&&console.log("[cnv-track] fetch flushed",t,n.status)}).catch(n=>{this.config.debug&&console.warn("[cnv-track] flush failed; queued for retry",t,n),e&&this.retryQueue.stash(e)})}installPageLifecycleHandlers(){if("undefined"==typeof window||"undefined"==typeof document)return;const t=()=>{this.flush()},n=()=>{"hidden"===document.visibilityState&&this.flush()};try{window.addEventListener("pagehide",t),document.addEventListener("visibilitychange",n),this.handlers={pagehide:t,visibility:n}}catch(t){}}uninstallPageLifecycleHandlers(){if(this.handlers){try{window.removeEventListener("pagehide",this.handlers.pagehide),document.removeEventListener("visibilitychange",this.handlers.visibility)}catch(t){}this.handlers=null}}}function J(t,n){return Object.assign(Object.assign({},t),{sentAt:n})}const V="_cnv_uid",E="_cnv_traits",H={endpoint:"http://localhost:8090/v1",batchPath:"/batch",singlePath:"/{type}",useBatch:!0,contentType:"text/plain",debug:!1,allowAdTracking:!0,cookieMaxAgeDays:730,sessionTimeoutMinutes:30,flushAt:20,flushInterval:5e3,autoPageview:!0,autotrack:!1,integrations:{}},F={analytics:!0,marketing:!0};function G(t,n){if(!Array.isArray(n)||0===n.length)return;const e=n;try{switch(e[0]){case"init":t.init(e[1],e[2]);break;case"pageview":t.pageview(e[1],e[2]);break;case"page":t.page(e[1],e[2]);break;case"screen":t.screen(e[1],e[2]);break;case"track":t.track(e[1],e[2]);break;case"identify":t.identify(e[1],e[2]);break;case"alias":t.alias(e[1],e[2]);break;case"group":t.group(e[1],e[2]);break;case"reset":t.reset();break;case"flush":t.flush();break;case"consent":t.consent(e[1]);break;case"set":t.set(e[1])}}catch(t){}}const K="0.2.0-alpha.4",Q="@cnv-vn/track",W=(()=>{let t=null,p=Object.assign({},H),b=Object.assign({},F),w=null,g=!1,O=null;function P(t){const n=Object.assign({},p);return t?(void 0!==t.endpoint&&(n.endpoint=(e=t.endpoint).endsWith("/")?e.slice(0,-1):e),void 0!==t.batchPath&&(n.batchPath=t.batchPath),void 0!==t.singlePath&&(n.singlePath=t.singlePath),void 0!==t.useBatch&&(n.useBatch=t.useBatch),void 0!==t.contentType&&(n.contentType=t.contentType),void 0!==t.debug&&(n.debug=t.debug),void 0!==t.allowAdTracking&&(n.allowAdTracking=t.allowAdTracking),void 0!==t.cookieDomain&&(n.cookieDomain=t.cookieDomain),void 0!==t.cookieMaxAgeDays&&(n.cookieMaxAgeDays=t.cookieMaxAgeDays),void 0!==t.sessionTimeoutMinutes&&(n.sessionTimeoutMinutes=t.sessionTimeoutMinutes),void 0!==t.flushAt&&(n.flushAt=t.flushAt),void 0!==t.flushInterval&&(n.flushInterval=t.flushInterval),void 0!==t.autoPageview&&(n.autoPageview=t.autoPageview),void 0!==t.autotrack&&(n.autotrack=t.autotrack),void 0!==t.integrations&&(n.integrations=t.integrations),n):n;var e}function D(){return w||(w=new z({endpoint:p.endpoint,batchPath:p.batchPath,singlePath:p.singlePath,useBatch:p.useBatch,contentType:p.contentType,flushAt:p.flushAt,flushInterval:p.flushInterval,projectId:null!=t?t:"",debug:p.debug}),w)}function T(){var n;if(!t)return null;const e=((t={})=>{var n;const e={page:y(),screen:{width:h(()=>window.screen.width,0),height:h(()=>window.screen.height,0),density:h(()=>window.devicePixelRatio||1,1)},locale:h(()=>navigator.language||"",""),timezone:h(()=>Intl.DateTimeFormat().resolvedOptions().timeZone||"",""),userAgent:h(()=>navigator.userAgent||"",""),library:v(t.library)},r=((t,n=!0)=>{const e=h(()=>window.location.search,"");if(!e)return;let r;try{r=new URLSearchParams(e)}catch(t){return}const o={};let i=!1;for(const[t,n]of f){const e=r.get(t);e&&e.length>0&&(o[n]=e,i=!0)}if(n){const t={};for(const n of d){const e=r.get(n);e&&e.length>0&&(t[n]=e)}Object.keys(t).length>0&&(o.clickIds=t,i=!0)}return i?o:void 0})(0,null===(n=t.allowAdTracking)||void 0===n||n);return r&&(e.campaign=r),e})({allowAdTracking:p.allowAdTracking});return b.analytics&&b.marketing||(e.consent=Object.assign({},b)),{anonymousId:I({cookieDomain:p.cookieDomain,cookieMaxAgeDays:p.cookieMaxAgeDays}),sessionId:R({cookieDomain:p.cookieDomain,timeoutMinutes:p.sessionTimeoutMinutes}),userId:null!==(n=k(V)||_(V))&&void 0!==n?n:void 0,context:e,projectId:t,integrations:Object.keys(p.integrations).length>0?p.integrations:void 0}}function U(t){p.debug&&console.warn(`[cnv-track] ${t}() called before init()`)}function $(t,n){try{const e=T();if(!e)return U("pageview");const r=((t,n,e)=>{const r=C("page",e);return t&&(r.name=t),r.properties=null!=n?n:{},r})(null!=t?t:(()=>{try{return"undefined"!=typeof document&&document.title||void 0}catch(t){return}})(),n,e);D().enqueue(r)}catch(t){}}function L(t,n){$(t,n)}function N(t,n){try{if("string"!=typeof t||0===t.length)return;const e=T();if(!e)return U("track");const r=((t,n,e)=>{const r=C("track",e);return r.event=t,r.properties=null!=n?n:{},r})(t,n,e);D().enqueue(r)}catch(t){}}return{get initialized(){return g},get projectId(){return t},init(d,f){try{if(!d||"string"!=typeof d)return;if(p=P(f),(null==f?void 0:f.consent)&&(b=Object.assign(Object.assign({},b),f.consent)),t=d,w&&w.destroy(),w=null,D(),g=!0,I({cookieDomain:p.cookieDomain,cookieMaxAgeDays:p.cookieMaxAgeDays}),R({cookieDomain:p.cookieDomain,timeoutMinutes:p.sessionTimeoutMinutes}),p.autoPageview&&$(),O){try{O()}catch(t){}O=null}p.autotrack&&(O=function(t,d){const f=void 0===(h=d)||!1===h?Object.assign(Object.assign({},a),{searchParams:u}):!0===h?Object.assign(Object.assign({},s),{searchParams:u}):{spa:null===(y=h.spa)||void 0===y||y,outboundClicks:null===(v=h.outboundClicks)||void 0===v||v,scroll:null===(p=h.scroll)||void 0===p||p,downloads:null===(b=h.downloads)||void 0===b||b,siteSearch:null===(m=h.siteSearch)||void 0===m||m,downloadExtensions:h.downloadExtensions,searchParams:null!==(w=h.searchParams)&&void 0!==w?w:u};var h,y,v,p,b,m,w;const g=[];let x=null;function k(n){if(f.siteSearch)try{const e=null!=n?n:(()=>{try{return"undefined"!=typeof location?location.href:""}catch(t){return""}})();if(e===x)return;x=e;const r=((t,n=u)=>{try{if(!t){if("undefined"==typeof location)return null;t=location.href}const e=t instanceof URL?t:new URL(t,(()=>{try{return"undefined"!=typeof location?location.href:"http://localhost/"}catch(t){return"http://localhost/"}})());if(!e.search)return null;for(const t of n){const n=e.searchParams.get(t);if(null===n)continue;const r=n.trim();if(0!==r.length)return{query:r,param:t}}return null}catch(t){return null}})(e,f.searchParams);r&&l(()=>t.track("Site Searched",{query:r.query,param:r.param}))}catch(t){}}if(f.outboundClicks||f.downloads){const i=(t=>{var i;if("undefined"==typeof document)return()=>{};const c=new Set((null!==(i=t.downloadExtensions)&&void 0!==i?i:n).map(t=>t.toLowerCase())),u=!!t.onOutbound,s=!!t.onDownload;if(!u&&!s)return()=>{};function a(n){var i,a;try{if(0!==n.button)return;if(n.defaultPrevented)return;const l=(t=>{const n="function"==typeof t.composedPath?t.composedPath():[];if(n.length>0)for(const t of n)if(e(t))return t;let r=t.target;for(;r;){if(e(r))return r;r=r.parentNode}return null})(n);if(!l)return;const d=l.getAttribute("href");if(!d)return;if(/^(javascript:|mailto:|tel:|sms:)/i.test(d))return;if(d.startsWith("#"))return;const f=(t=>{try{return new URL(t,location.href)}catch(t){return null}})(d);if(!f)return;let h=!1;if(s){const n=l.hasAttribute("download"),e=(t=>{const n=r(t),e=n.lastIndexOf(".");return e<=0||e===n.length-1?null:n.slice(e+1).toLowerCase()})(f.pathname);(n||e&&c.has(e))&&(h=!0,null===(i=t.onDownload)||void 0===i||i.call(t,{url:f.href,fileName:r(f.pathname),fileExtension:null!=e?e:"",text:o(l)}))}u&&!h&&f.host!==(()=>{try{return"undefined"!=typeof location?location.hostname:""}catch(t){return""}})()&&f.host&&(null===(a=t.onOutbound)||void 0===a||a.call(t,{url:f.href,host:f.host,text:o(l),target:l.target||"_self"}))}catch(t){}}try{document.addEventListener("click",a,!0)}catch(t){return()=>{}}return()=>{try{document.removeEventListener("click",a,!0)}catch(t){}}})({downloadExtensions:f.downloadExtensions,onOutbound:f.outboundClicks?n=>l(()=>t.track("Outbound Link Clicked",n)):void 0,onDownload:f.downloads?n=>l(()=>t.track("File Downloaded",n)):void 0});g.push(i)}let j=null;if(f.scroll&&(j=(t=>{if("undefined"==typeof window||"undefined"==typeof document)return{destroy(){},reset(){}};let n=!1,e=null,r=!1;function o(){if(e=null,!r&&!n)try{const e=document.documentElement,r=document.body,o=Math.max(e?e.scrollHeight:0,r?r.scrollHeight:0),i=Math.max(e?e.clientHeight:0,window.innerHeight||0);if(o<=i)return n=!0,c(),void t(90);((window.scrollY||(e?e.scrollTop:0)||0)+i)/o>=.9&&(n=!0,c(),t(90))}catch(t){}}function i(){if(null===e)try{e=window.requestAnimationFrame(o)}catch(t){o()}}function c(){try{window.removeEventListener("scroll",i),null!==e&&window.cancelAnimationFrame(e),e=null}catch(t){}}try{window.addEventListener("scroll",i,{passive:!0})}catch(t){try{window.addEventListener("scroll",i)}catch(t){}}try{window.requestAnimationFrame(o)}catch(t){o()}return{destroy(){r=!0,c()},reset(){if(!r){n=!1;try{window.addEventListener("scroll",i,{passive:!0})}catch(t){try{window.addEventListener("scroll",i)}catch(t){}}try{window.requestAnimationFrame(o)}catch(t){o()}}}}})(n=>{l(()=>t.track("Scrolled",{percent:n}))}),g.push(()=>null==j?void 0:j.destroy())),f.spa){const n=function(){if("undefined"==typeof window||"undefined"==typeof history)return()=>{};let n=c();function e(){try{const e=c();if(e===n)return;n=e,(n=>{l(()=>t.page()),null==j||j.reset(),k(n)})(e)}catch(t){}}const r=history.pushState,o=history.replaceState,u=!0===r[i],s=!0===o[i];if(!u){function f(...t){r.apply(this,t),e()}f[i]=!0,history.pushState=f}if(!s){function h(...t){o.apply(this,t),e()}h[i]=!0,history.replaceState=h}const a=()=>e(),d=()=>e();try{window.addEventListener("popstate",a),window.addEventListener("hashchange",d)}catch(y){}return()=>{try{window.removeEventListener("popstate",a),window.removeEventListener("hashchange",d)}catch(t){}try{!u&&history.pushState[i]&&(history.pushState=r),!s&&history.replaceState[i]&&(history.replaceState=o)}catch(t){}}}();g.push(n)}return k(),()=>{for(;g.length>0;){const t=g.pop();try{null==t||t()}catch(t){}}x=null}}({page:(t,n)=>L(t,n),track:(t,n)=>N(t,n)},p.autotrack))}catch(t){}},pageview:$,page:L,screen(t,n){try{const e=T();if(!e)return U("screen");const r=((t,n,e)=>{const r=C("screen",e);return t&&(r.name=t),r.properties=null!=n?n:{},r})(t,n,e);D().enqueue(r)}catch(t){}},track:N,identify(t,n){try{if("string"!=typeof t||0===t.length)return;((t,n,e={})=>{var r,o;if(t&&(j(V,t,{domain:e.cookieDomain,maxAgeDays:null!==(r=e.cookieMaxAgeDays)&&void 0!==r?r:730,sameSite:"Lax"}),S(V,t),null!=n)){const t=null!==(o=(()=>{const t=_(E);if(!t)return null;try{const n=JSON.parse(t);return n&&"object"==typeof n&&!Array.isArray(n)?n:null}catch(t){return null}})())&&void 0!==o?o:{},e=Object.assign(Object.assign({},t),n);try{S(E,JSON.stringify(e))}catch(t){}}})(t,n,{cookieDomain:p.cookieDomain,cookieMaxAgeDays:p.cookieMaxAgeDays});const e=T();if(!e)return U("identify");const r=((t,n,e)=>{var r;const o=C("identify",e);return t&&(o.userId=t),o.traits=null!==(r=n)&&void 0!==r?r:{},o})(t,n,e);D().enqueue(r)}catch(t){}},alias(t,n){try{if("string"!=typeof t||0===t.length)return;const e=T();if(!e)return U("alias");const r=((t,n,e)=>{const r=C("alias",e);return t&&(r.userId=t),r.previousId=null!=n?n:e.anonymousId,r})(t,n,e);D().enqueue(r)}catch(t){}},group(t,n){try{if("string"!=typeof t||0===t.length)return;const e=T();if(!e)return U("group");const r=((t,n,e)=>{const r=C("group",e);return r.groupId=t,r.traits=null!=n?n:{},r})(t,n,e);D().enqueue(r)}catch(t){}},reset(){try{((t={})=>{((t,n={})=>{var e;if(!x)return!1;try{let r=`${encodeURIComponent(t)}=`;return r+=`; path=${null!==(e=n.path)&&void 0!==e?e:"/"}`,n.domain&&(r+=`; domain=${n.domain}`),r+="; max-age=0",r+="; expires=Thu, 01 Jan 1970 00:00:00 GMT",document.cookie=r,null===k(t)}catch(t){return!1}})(V,{domain:t.cookieDomain}),A(V),A(E)})({cookieDomain:p.cookieDomain}),((t={})=>{M(m(),t)})({cookieDomain:p.cookieDomain,cookieMaxAgeDays:p.cookieMaxAgeDays}),((t={})=>{q({id:m(),lastActivity:Date.now()},t)})({cookieDomain:p.cookieDomain,timeoutMinutes:p.sessionTimeoutMinutes})}catch(t){}},flush(){try{w&&w.flush()}catch(t){}},consent(t){try{b=Object.assign(Object.assign({},b),t)}catch(t){}},set(t){try{p=P(t),t.consent&&(b=Object.assign(Object.assign({},b),t.consent)),w&&w.setConfig({endpoint:p.endpoint,batchPath:p.batchPath,singlePath:p.singlePath,useBatch:p.useBatch,contentType:p.contentType,flushAt:p.flushAt,flushInterval:p.flushInterval,debug:p.debug})}catch(t){}},destroy(){if(O){try{O()}catch(t){}O=null}w&&w.destroy(),w=null,g=!1,t=null,p=Object.assign({},H),b=Object.assign({},F)}}})();"undefined"!=typeof window&&(t=>{if("undefined"==typeof window)return()=>{};const n=window.cnvQ;if(n&&n.__loaded)return()=>{};const e=window.cnvQ=null!=n?n:[],r=e.splice(0,e.length);e.push.bind(e),e.push=(...n)=>{for(const e of n)G(t,e);return e.length},e.__loaded=!0;for(const n of r)G(t,n)})(W);const X=Object.assign(W,{version:K,name:Q,schemaVersion:T});t.NAME=Q,t.SCHEMA_VERSION=T,t.VERSION=K,t.default=X,Object.defineProperty(t,"t",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).cnvTrack={});
6
+ var t,n;t=this,n=function(t){const n=["pdf","doc","docx","xls","xlsx","ppt","pptx","txt","csv","rtf","zip","rar","7z","tar","gz","mp3","mp4","mov","wav","avi","mkv","dmg","exe","pkg","apk","msi","svg"];function e(t){return!!t&&"object"==typeof t&&1===t.nodeType&&"A"===t.tagName}function r(t){const n=t.lastIndexOf("/");return-1===n?t:t.slice(n+1)}function o(t){var n,e,r;let o=(null!==(n=t.textContent)&&void 0!==n?n:"").trim();return o||(o=(null!==(e=t.getAttribute("aria-label"))&&void 0!==e?e:"").trim()),o||(o=(null!==(r=t.getAttribute("title"))&&void 0!==r?r:"").trim()),o.length>200?o.slice(0,200):o}const i=200;function c(t){let n="";try{n=(t.textContent||"").replace(/\s+/g," ").trim(),n||(n=(t.getAttribute("aria-label")||"").trim()),n||(n=(t.getAttribute("title")||"").trim())}catch(t){return""}return n.length>i?n.slice(0,i):n}function u(t){const n=!1!==t.caseInsensitive;return"regex"===t.mode?{mode:"regex",needle:t.value,ci:n,re:b(t.value,n)}:{mode:t.mode,needle:n?t.value.toLowerCase():t.value,ci:n,re:null}}function s(t,n){try{return t.matches(n)}catch(t){return!1}}function a(t){try{if("A"===t.tagName){const n=t.getAttribute("href");return n?m(n):null}const n=t.getAttribute("formaction");if(n)return m(n);const e=t.getAttribute("data-href");if(e)return m(e);const r=t.closest("form");if(r){const t=r.getAttribute("action");if(t)return m(t)}return null}catch(t){return null}}function l(t){return"regex"===t.mode?{mode:"regex",needle:t.value,re:b(t.value,!0)}:{mode:t.mode,needle:t.value.toLowerCase(),re:null}}function f(t){if("startsWith"===t.mode)return{mode:"startsWith",needle:t.value,re:null};const n="glob"===t.mode?"^"+t.value.replace(/[.+^${}()|[\]\\?]/g,"\\$&").replace(/\*/g,".*")+"$":t.value;return{mode:t.mode,needle:t.value,re:b(n,!1)}}function d(t,n){return"startsWith"===t.mode?0===n.indexOf(t.needle):!t.re||g(t.re,n)}const h=/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g,y=/\+?\d[\d\s().-]{7,}\d/g;function v(t){if(!t)return t;try{return t.replace(h,"[email]").replace(y,"[phone]")}catch(n){return t}}function p(t){return!!t&&"object"==typeof t&&1===t.nodeType}function m(t){try{return new URL(t,location.href).href}catch(n){return t}}function b(t,n){try{return!t||t.length>1e3?null:new RegExp(t,n?"i":"")}catch(t){return null}}function g(t,n){try{return t.test(n)}catch(t){return!1}}function w(t){const n=t.match;return n.element?n.element:n.selector||n.id||n.dataAttr||n.classes&&n.classes.length>0||n.destinationUrl?"any":void 0}function x(t,n){if(!((t,n)=>{if(!n)return(t=>{const n=t.tagName;if("BUTTON"===n||"A"===n)return!0;if("INPUT"===n){const n=(t.getAttribute("type")||"").toLowerCase();return"submit"===n||"button"===n||"reset"===n}return"button"===t.getAttribute("role")})(t);if("any"===n)return!0;if("button"===n){const n=t.tagName;if("BUTTON"===n)return!0;if("INPUT"===n){const n=(t.getAttribute("type")||"").toLowerCase();return"submit"===n||"button"===n||"reset"===n}return"button"===t.getAttribute("role")}return"link"===n?"A"===t.tagName:s(t,n)})(n,t.elementSpec))return!1;const e=t.rule.match;return!(t.selector&&!s(n,t.selector)||void 0!==e.id&&!((t,n)=>t.id===n)(n,e.id)||e.classes&&e.classes.length>0&&!((t,n)=>{try{for(let e=0;e<n.length;e++)if(!t.classList.contains(n[e]))return!1;return!0}catch(t){return!1}})(n,e.classes)||e.dataAttr&&!((t,n,e)=>{try{return!!t.hasAttribute(n)&&(void 0===e||t.getAttribute(n)===e)}catch(t){return!1}})(n,e.dataAttr.name,e.dataAttr.value)||t.text&&!((t,n)=>{const e=c(t);if("regex"===n.mode)return!!n.re&&g(n.re,e);const r=n.ci?e.toLowerCase():e;return"exact"===n.mode?r===n.needle:"startsWith"===n.mode?0===r.indexOf(n.needle):-1!==r.indexOf(n.needle)})(n,t.text)||t.dest&&!((t,n)=>{const e=a(t);if(!e)return!1;if("regex"===n.mode)return!!n.re&&g(n.re,e);if("domain"===n.mode)try{return new URL(e).host.toLowerCase()===n.needle}catch(t){return!1}const r=e.toLowerCase();return"exact"===n.mode?r===n.needle:"startsWith"===n.mode?0===r.indexOf(n.needle):-1!==r.indexOf(n.needle)})(n,t.dest))}function k(t,n,e){const r={},o=t.event.staticProps;if(o)for(const t of Object.keys(o))r[t]=o[t];const u=t.capture;if(u)try{if(u.text){const t=v(c(n));t&&(r.text=t)}if(u.href){const t=a(n);t&&(r.href=t)}if(u.elementId&&n.id&&(r.element_id=n.id),u.classes&&(r.element_classes=Array.from(n.classList)),u.dataAttrs&&u.dataAttrs.length>0)for(let t=0;t<u.dataAttrs.length;t++){const e=u.dataAttrs[t],o=n.getAttribute(e);null!==o&&(r[e]=v(o))}if(u.valueFrom){const t=((t,n)=>{try{const e=t.querySelector(n.selector)||(t.parentElement?t.parentElement.querySelector(n.selector):null);if(!e)return null;const r=n.attr?e.getAttribute(n.attr):e.textContent||"";if(null===r)return null;const o=v(r.replace(/\s+/g," ").trim());return o.length>i?o.slice(0,i):o}catch(t){return null}})(n,u.valueFrom);null!==t&&(r[u.valueFrom.as]=t)}u.selectorPath&&(r.selector_path=((t,n=5)=>{try{const e=[];let r=t,o=0;for(;r&&1===r.nodeType&&o<n;){let t=r.tagName.toLowerCase();if(r.id){e.unshift(t+"#"+r.id);break}const n=Array.from(r.classList).slice(0,2).join(".");n&&(t+="."+n),e.unshift(t),r=r.parentElement,o++}return e.join(" > ")}catch(t){return""}})(n)),u.position&&(r.x=e.clientX,r.y=e.clientY)}catch(t){}return r.rule_id=t.id,t.name&&(r.rule_name=t.name),r.tag=n.tagName.toLowerCase(),r}function j(t){try{t()}catch(t){}}function O(){try{return"undefined"!=typeof location?location.href:""}catch(t){return""}}function A(t,n){return"number"!=typeof t||isNaN(t)?n:t}function S(t){return t<0?0:t>1?1:t}const _="__cnvPatched";function P(){try{return"undefined"!=typeof location?location.href:""}catch(t){return""}}const I=["q","s","query","search","keyword"],D={spa:!0,outboundClicks:!0,scroll:!0,downloads:!0,siteSearch:!0},T={spa:!1,outboundClicks:!1,scroll:!1,downloads:!1,siteSearch:!1};function M(t){try{t()}catch(t){}}const U=["gclid","fbclid","ttclid","msclkid","dclid"],$=[["utm_source","source"],["utm_medium","medium"],["utm_campaign","name"],["utm_term","term"],["utm_content","content"],["utm_id","id"]];function R(t,n){try{return t()}catch(t){return n}}function C(){const t=R(()=>window.location.href,"");let n="",e="",r="";if(t)try{const o=new URL(t);n=o.pathname,e=o.search,r=o.hash}catch(t){}return{url:t,path:n,search:e,hash:r,title:R(()=>document.title,""),referrer:R(()=>document.referrer,"")}}function L(t){var n,e;let r="@cnv-vn/track",o="0.0.0-dev";try{r="@cnv-vn/track"}catch(t){}try{o="0.2.0-alpha.5"}catch(t){}return{name:null!==(n=null==t?void 0:t.name)&&void 0!==n?n:r,version:null!==(e=null==t?void 0:t.version)&&void 0!==e?e:o}}const N="0123456789abcdef";function q(t){return N[t>>>4&15]+N[15&t]}function B(){if("undefined"!=typeof crypto){if("function"==typeof crypto.randomUUID)return crypto.randomUUID();if("function"==typeof crypto.getRandomValues){const t=new Uint8Array(16);return crypto.getRandomValues(t),t[6]=15&t[6]|64,t[8]=63&t[8]|128,q(t[0])+q(t[1])+q(t[2])+q(t[3])+"-"+q(t[4])+q(t[5])+"-"+q(t[6])+q(t[7])+"-"+q(t[8])+q(t[9])+"-"+q(t[10])+q(t[11])+q(t[12])+q(t[13])+q(t[14])+q(t[15])}}return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{const n=16*Math.random()|0;return("x"===t?n:3&n|8).toString(16)})}const z=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function W(t){return"string"==typeof t&&z.test(t)}const J="undefined"!=typeof window&&"undefined"!=typeof document;function E(t){if(!J)return null;try{const n=document.cookie;if(!n)return null;const e=encodeURIComponent(t),r=n.split(";");for(let n=0;n<r.length;n++){const o=r[n].indexOf("=");if(o<0)continue;const i=r[n].slice(0,o).trim();if(i===e||i===t)try{return decodeURIComponent(r[n].slice(o+1))}catch(t){return r[n].slice(o+1)}}return null}catch(t){return null}}function V(t,n,e={}){var r,o,i;if(!J)return!1;try{let c=`${encodeURIComponent(t)}=${encodeURIComponent(n)}`;if(c+=`; path=${null!==(r=e.path)&&void 0!==r?r:"/"}`,e.domain&&(c+=`; domain=${e.domain}`),"number"==typeof e.maxAgeDays){const t=Math.floor(86400*e.maxAgeDays);c+=`; max-age=${t}`,c+=`; expires=${new Date(Date.now()+1e3*t).toUTCString()}`}return c+=`; SameSite=${null!==(o=e.sameSite)&&void 0!==o?o:"Lax"}`,(null!==(i=e.secure)&&void 0!==i?i:"undefined"!=typeof location&&"https:"===location.protocol)&&(c+="; Secure"),document.cookie=c,E(t)===n}catch(t){return!1}}function H(){if(!J)return!1;try{const t="__cnv_probe__";return localStorage.setItem(t,"1"),localStorage.removeItem(t),!0}catch(t){return!1}}function Z(t){if(!H())return null;try{return localStorage.getItem(t)}catch(t){return null}}function F(t,n){if(!H())return!1;try{return localStorage.setItem(t,n),!0}catch(t){return!1}}function G(t){if(!H())return!1;try{return localStorage.removeItem(t),!0}catch(t){return!1}}function K(){if(!J)return!1;try{const t="__cnv_probe__";return sessionStorage.setItem(t,"1"),sessionStorage.removeItem(t),!0}catch(t){return!1}}const Q="_cnv_cid";function X(t={}){const n=E(Q),e=Z(Q);let r=null;return W(n)?r=n:W(e)&&(r=e),r||(r=B()),Y(r,t),r}function Y(t,n={}){var e;V(Q,t,{domain:n.cookieDomain,maxAgeDays:null!==(e=n.cookieMaxAgeDays)&&void 0!==e?e:730,sameSite:"Lax"}),F(Q,t)}const tt="1.0";function nt(){return(new Date).toISOString()}function et(t,n){var e;const r=null!==(e=n.timestamp)&&void 0!==e?e:nt(),o=Object.assign(Object.assign({},n.context),{projectId:n.projectId,schemaVersion:tt}),i={type:t,messageId:B(),anonymousId:n.anonymousId,timestamp:r,originalTimestamp:r,context:o};return n.userId&&(i.userId=n.userId),n.sessionId&&(i.sessionId=n.sessionId),n.integrations&&(i.integrations=n.integrations),i}const rt="_cnv_sid";function ot(t){if(!t)return null;const n=t.lastIndexOf(".");if(n<0)return null;const e=t.slice(0,n),r=Number(t.slice(n+1));return!W(e)||!Number.isFinite(r)||r<=0?null:{id:e,lastActivity:r}}function it(t={}){const n=Date.now(),e=(t=>{var n;return 6e4*(null!==(n=t.timeoutMinutes)&&void 0!==n?n:30)})(t),r=ot(E(rt)),o=ot((t=>{if(!K())return null;try{return sessionStorage.getItem(t)}catch(t){return null}})(rt));let i=null;for(const t of[r,o])t&&(n-t.lastActivity>e||(!i||t.lastActivity>i.lastActivity)&&(i=t));const c=i?{id:i.id,lastActivity:n}:{id:B(),lastActivity:n};return ct(c,t),c.id}function ct(t,n={}){var e;const r=(t=>`${t.id}.${t.lastActivity}`)(t),o=null!==(e=n.timeoutMinutes)&&void 0!==e?e:30;V(rt,r,{domain:n.cookieDomain,maxAgeDays:o/1440,sameSite:"Lax"}),((t,n)=>{if(!K())return!1;try{return sessionStorage.setItem(t,n),!0}catch(t){return!1}})(rt,r)}class ut{constructor(t){var n,e;Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"storageKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"maxMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"flushing",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"onlineHandler",{enumerable:!0,configurable:!0,writable:!0,value:null}),this.storageKey=null!==(n=t.storageKey)&&void 0!==n?n:"_cnv_rq",this.maxMessages=null!==(e=t.maxMessages)&&void 0!==e?e:100,this.installOnlineListener()}stash(t){if(t&&0!==t.length)try{const n=this.read();for(n.push(t);n.length>1&&st(n)>this.maxMessages;)n.shift();this.write(n),this.config.debug&&console.log("[cnv-track] retry queued",t.length,"buffered",st(n))}catch(t){}}flush(){if(this.flushing||"undefined"!=typeof navigator&&!1===navigator.onLine)return Promise.resolve();const t=this.read();if(0===t.length)return Promise.resolve();this.flushing=!0,this.write([]);const n=()=>{this.flushing=!1};return t.reduce((t,n)=>t.then(()=>this.config.resend(n)),Promise.resolve()).then(n,n)}size(){return st(this.read())}clear(){try{G(this.storageKey)}catch(t){}}destroy(){if(this.onlineHandler){try{window.removeEventListener("online",this.onlineHandler)}catch(t){}this.onlineHandler=null}}installOnlineListener(){if("undefined"==typeof window)return;const t=()=>{this.flush()};try{window.addEventListener("online",t),this.onlineHandler=t}catch(t){}}read(){const t=Z(this.storageKey);if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.filter(t=>Array.isArray(t)&&t.length>0):[]}catch(t){return[]}}write(t){0!==t.length?F(this.storageKey,JSON.stringify(t)):G(this.storageKey)}}function st(t){let n=0;for(const e of t)n+=e.length;return n}class at{constructor(t){Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"buffer",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"timer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"handlers",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"retryQueue",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.retryQueue=new ut({debug:t.debug,resend:t=>this.send(t)}),this.installPageLifecycleHandlers(),this.retryQueue.flush()}setConfig(t){this.config=Object.assign(Object.assign({},this.config),t)}enqueue(t){this.destroyed||(this.buffer.push(t),this.buffer.length>=this.config.flushAt?this.flush():this.timer||(this.timer=setTimeout(()=>{this.timer=null,this.flush()},this.config.flushInterval)))}flush(){if(this.timer&&(clearTimeout(this.timer),this.timer=null),0===this.buffer.length)return Promise.resolve();const t=this.buffer;return this.buffer=[],this.send(t)}bufferedCount(){return this.buffer.length}destroy(){this.destroyed||(this.destroyed=!0,this.timer&&(clearTimeout(this.timer),this.timer=null),this.uninstallPageLifecycleHandlers(),this.retryQueue.destroy())}send(t){try{return this.config.useBatch?this.sendBatch(t):Promise.all(t.map(t=>this.sendSingle(t))).then(()=>{})}catch(t){return this.config.debug&&console.warn("[cnv-track] send failed synchronously; dropped batch",t),Promise.resolve()}}sendBatch(t){var n;const e=nt(),r={batch:t.map(t=>lt(t,e)),context:Object.assign(Object.assign({},null!==(n=this.config.batchContext)&&void 0!==n?n:{}),{projectId:this.config.projectId,sentAt:e}),sentAt:e};return this.post(this.batchUrl(),r,t)}sendSingle(t){const n=lt(t,nt());return this.post(this.singleUrl(t.type),n,[t])}batchUrl(){return this.config.endpoint+this.config.batchPath+"?projectId="+encodeURIComponent(this.config.projectId)}singleUrl(t){const n=this.config.singlePath.replace("{type}",t);return this.config.endpoint+n+"?projectId="+encodeURIComponent(this.config.projectId)}post(t,n,e){const r=JSON.stringify(n),o=((t,n)=>{try{return new Blob([t],{type:n})}catch(t){return null}})(r,this.config.contentType),i=o?o.size:(t=>{try{return new Blob([t]).size}catch(n){return t.length}})(r),c=i>65536?null:e;return c&&"undefined"!=typeof navigator&&!1===navigator.onLine?(this.retryQueue.stash(c),this.config.debug&&console.log("[cnv-track] offline; queued for retry",t),Promise.resolve()):o&&this.sendViaBeacon(t,o)?(this.config.debug&&console.log("[cnv-track] beacon",t),Promise.resolve()):this.sendViaFetch(t,r,c)}sendViaBeacon(t,n){if("undefined"==typeof navigator||"function"!=typeof navigator.sendBeacon)return!1;if(n.size>65536)return!1;try{return navigator.sendBeacon(t,n)}catch(t){return!1}}sendViaFetch(t,n,e){return"function"!=typeof fetch?(this.config.debug&&console.warn("[cnv-track] no transport available; queued for retry"),e&&this.retryQueue.stash(e),Promise.resolve()):fetch(t,{method:"POST",headers:{"Content-Type":this.config.contentType},body:n,keepalive:!0,credentials:"omit",mode:"cors"}).then(n=>{this.config.debug&&console.log("[cnv-track] fetch flushed",t,n.status)}).catch(n=>{this.config.debug&&console.warn("[cnv-track] flush failed; queued for retry",t,n),e&&this.retryQueue.stash(e)})}installPageLifecycleHandlers(){if("undefined"==typeof window||"undefined"==typeof document)return;const t=()=>{this.flush()},n=()=>{"hidden"===document.visibilityState&&this.flush()};try{window.addEventListener("pagehide",t),document.addEventListener("visibilitychange",n),this.handlers={pagehide:t,visibility:n}}catch(t){}}uninstallPageLifecycleHandlers(){if(this.handlers){try{window.removeEventListener("pagehide",this.handlers.pagehide),document.removeEventListener("visibilitychange",this.handlers.visibility)}catch(t){}this.handlers=null}}}function lt(t,n){return Object.assign(Object.assign({},t),{sentAt:n})}const ft="_cnv_uid",dt="_cnv_traits",ht={endpoint:"http://localhost:8090/v1",batchPath:"/batch",singlePath:"/{type}",useBatch:!0,contentType:"text/plain",debug:!1,allowAdTracking:!0,cookieMaxAgeDays:730,sessionTimeoutMinutes:30,flushAt:20,flushInterval:5e3,autoPageview:!0,autotrack:!1,integrations:{}},yt={analytics:!0,marketing:!0};function vt(t,n){if(!Array.isArray(n)||0===n.length)return;const e=n;try{switch(e[0]){case"init":t.init(e[1],e[2]);break;case"pageview":t.pageview(e[1],e[2]);break;case"page":t.page(e[1],e[2]);break;case"screen":t.screen(e[1],e[2]);break;case"track":t.track(e[1],e[2]);break;case"identify":t.identify(e[1],e[2]);break;case"alias":t.alias(e[1],e[2]);break;case"group":t.group(e[1],e[2]);break;case"reset":t.reset();break;case"flush":t.flush();break;case"consent":t.consent(e[1]);break;case"set":t.set(e[1])}}catch(t){}}const pt="0.2.0-alpha.5",mt="@cnv-vn/track",bt=(()=>{let t=null,i=Object.assign({},ht),c=Object.assign({},yt),s=null,a=!1,h=null;function y(t){const n=Object.assign({},i);return t?(void 0!==t.endpoint&&(n.endpoint=(e=t.endpoint).endsWith("/")?e.slice(0,-1):e),void 0!==t.batchPath&&(n.batchPath=t.batchPath),void 0!==t.singlePath&&(n.singlePath=t.singlePath),void 0!==t.useBatch&&(n.useBatch=t.useBatch),void 0!==t.contentType&&(n.contentType=t.contentType),void 0!==t.debug&&(n.debug=t.debug),void 0!==t.allowAdTracking&&(n.allowAdTracking=t.allowAdTracking),void 0!==t.cookieDomain&&(n.cookieDomain=t.cookieDomain),void 0!==t.cookieMaxAgeDays&&(n.cookieMaxAgeDays=t.cookieMaxAgeDays),void 0!==t.sessionTimeoutMinutes&&(n.sessionTimeoutMinutes=t.sessionTimeoutMinutes),void 0!==t.flushAt&&(n.flushAt=t.flushAt),void 0!==t.flushInterval&&(n.flushInterval=t.flushInterval),void 0!==t.autoPageview&&(n.autoPageview=t.autoPageview),void 0!==t.autotrack&&(n.autotrack=t.autotrack),void 0!==t.integrations&&(n.integrations=t.integrations),n):n;var e}function v(){return s||(s=new at({endpoint:i.endpoint,batchPath:i.batchPath,singlePath:i.singlePath,useBatch:i.useBatch,contentType:i.contentType,flushAt:i.flushAt,flushInterval:i.flushInterval,projectId:null!=t?t:"",debug:i.debug}),s)}function m(){var n;if(!t)return null;const e=((t={})=>{var n;const e={page:C(),screen:{width:R(()=>window.screen.width,0),height:R(()=>window.screen.height,0),density:R(()=>window.devicePixelRatio||1,1)},locale:R(()=>navigator.language||"",""),timezone:R(()=>Intl.DateTimeFormat().resolvedOptions().timeZone||"",""),userAgent:R(()=>navigator.userAgent||"",""),library:L(t.library)},r=((t,n=!0)=>{const e=R(()=>window.location.search,"");if(!e)return;let r;try{r=new URLSearchParams(e)}catch(t){return}const o={};let i=!1;for(const[t,n]of $){const e=r.get(t);e&&e.length>0&&(o[n]=e,i=!0)}if(n){const t={};for(const n of U){const e=r.get(n);e&&e.length>0&&(t[n]=e)}Object.keys(t).length>0&&(o.clickIds=t,i=!0)}return i?o:void 0})(0,null===(n=t.allowAdTracking)||void 0===n||n);return r&&(e.campaign=r),e})({allowAdTracking:i.allowAdTracking});return c.analytics&&c.marketing||(e.consent=Object.assign({},c)),{anonymousId:X({cookieDomain:i.cookieDomain,cookieMaxAgeDays:i.cookieMaxAgeDays}),sessionId:it({cookieDomain:i.cookieDomain,timeoutMinutes:i.sessionTimeoutMinutes}),userId:null!==(n=E(ft)||Z(ft))&&void 0!==n?n:void 0,context:e,projectId:t,integrations:Object.keys(i.integrations).length>0?i.integrations:void 0}}function b(t){i.debug&&console.warn(`[cnv-track] ${t}() called before init()`)}function g(t,n){try{const e=m();if(!e)return b("pageview");const r=((t,n,e)=>{const r=et("page",e);return t&&(r.name=t),r.properties=null!=n?n:{},r})(null!=t?t:(()=>{try{return"undefined"!=typeof document&&document.title||void 0}catch(t){return}})(),n,e);v().enqueue(r)}catch(t){}}function N(t,n){g(t,n)}function q(t,n){try{if("string"!=typeof t||0===t.length)return;const e=m();if(!e)return b("track");const r=((t,n,e)=>{const r=et("track",e);return r.event=t,r.properties=null!=n?n:{},r})(t,n,e);v().enqueue(r)}catch(t){}}return{get initialized(){return a},get projectId(){return t},init(m,b){try{if(!m||"string"!=typeof m)return;if(i=y(b),(null==b?void 0:b.consent)&&(c=Object.assign(Object.assign({},c),b.consent)),t=m,s&&s.destroy(),s=null,v(),a=!0,X({cookieDomain:i.cookieDomain,cookieMaxAgeDays:i.cookieMaxAgeDays}),it({cookieDomain:i.cookieDomain,timeoutMinutes:i.sessionTimeoutMinutes}),i.autoPageview&&g(),h){try{h()}catch(t){}h=null}i.autotrack&&(h=function(t,i){const c=void 0===(s=i)||!1===s?Object.assign(Object.assign({},T),{searchParams:I}):!0===s?Object.assign(Object.assign({},D),{searchParams:I}):{spa:null===(a=s.spa)||void 0===a||a,outboundClicks:null===(h=s.outboundClicks)||void 0===h||h,scroll:null===(y=s.scroll)||void 0===y||y,downloads:null===(v=s.downloads)||void 0===v||v,siteSearch:null===(m=s.siteSearch)||void 0===m||m,downloadExtensions:s.downloadExtensions,searchParams:null!==(b=s.searchParams)&&void 0!==b?b:I,buttonTracking:s.buttonTracking};var s,a,h,y,v,m,b;const g=[];let U=null;function $(n){if(c.siteSearch)try{const e=null!=n?n:(()=>{try{return"undefined"!=typeof location?location.href:""}catch(t){return""}})();if(e===U)return;U=e;const r=((t,n=I)=>{try{if(!t){if("undefined"==typeof location)return null;t=location.href}const e=t instanceof URL?t:new URL(t,(()=>{try{return"undefined"!=typeof location?location.href:"http://localhost/"}catch(t){return"http://localhost/"}})());if(!e.search)return null;for(const t of n){const n=e.searchParams.get(t);if(null===n)continue;const r=n.trim();if(0!==r.length)return{query:r,param:t}}return null}catch(t){return null}})(e,c.searchParams);r&&M(()=>t.track("Site Searched",{query:r.query,param:r.param}))}catch(t){}}if(c.outboundClicks||c.downloads){const i=(t=>{var i;if("undefined"==typeof document)return()=>{};const c=new Set((null!==(i=t.downloadExtensions)&&void 0!==i?i:n).map(t=>t.toLowerCase())),u=!!t.onOutbound,s=!!t.onDownload;if(!u&&!s)return()=>{};function a(n){var i,a;try{if(0!==n.button)return;if(n.defaultPrevented)return;const l=(t=>{const n="function"==typeof t.composedPath?t.composedPath():[];if(n.length>0)for(const t of n)if(e(t))return t;let r=t.target;for(;r;){if(e(r))return r;r=r.parentNode}return null})(n);if(!l)return;const f=l.getAttribute("href");if(!f)return;if(/^(javascript:|mailto:|tel:|sms:)/i.test(f))return;if(f.startsWith("#"))return;const d=(t=>{try{return new URL(t,location.href)}catch(t){return null}})(f);if(!d)return;let h=!1;if(s){const n=l.hasAttribute("download"),e=(t=>{const n=r(t),e=n.lastIndexOf(".");return e<=0||e===n.length-1?null:n.slice(e+1).toLowerCase()})(d.pathname);(n||e&&c.has(e))&&(h=!0,null===(i=t.onDownload)||void 0===i||i.call(t,{url:d.href,fileName:r(d.pathname),fileExtension:null!=e?e:"",text:o(l)}))}u&&!h&&d.host!==(()=>{try{return"undefined"!=typeof location?location.hostname:""}catch(t){return""}})()&&d.host&&(null===(a=t.onOutbound)||void 0===a||a.call(t,{url:d.href,host:d.host,text:o(l),target:l.target||"_self"}))}catch(t){}}try{document.addEventListener("click",a,!0)}catch(t){return()=>{}}return()=>{try{document.removeEventListener("click",a,!0)}catch(t){}}})({downloadExtensions:c.downloadExtensions,onOutbound:c.outboundClicks?n=>M(()=>t.track("Outbound Link Clicked",n)):void 0,onDownload:c.downloads?n=>M(()=>t.track("File Downloaded",n)):void 0});g.push(i)}c.buttonTracking&&c.buttonTracking.rules&&c.buttonTracking.rules.length>0&&g.push(((t,n)=>{if("undefined"==typeof document)return()=>{};const e=(t=>{const n=t.globalThrottle||{},e=[],r=t.rules||[];for(let t=0;t<r.length;t++){const o=r[t];if(!o||!1===o.enabled)continue;if(!o.match||!o.event||!o.event.name)continue;const i=o.match,c=o.throttle||{};e.push({rule:o,elementSpec:w(o),selector:i.selector||null,text:i.text?u(i.text):null,dest:i.destinationUrl?l(i.destinationUrl):null,urlScope:o.urlScope?f(o.urlScope):null,dedupeWindowMs:A(c.dedupeWindowMs,A(n.dedupeWindowMs,500)),maxPerPageview:A(c.maxPerPageview,A(n.maxPerPageview,1/0)),samplingRate:S(A(c.samplingRate,A(n.samplingRate,1)))})}return e.sort((t,n)=>(t.rule.priority||0)-(n.rule.priority||0)),e})(n);if(0===e.length)return()=>{};const r=new WeakMap;let o=0;const i=t=>{let n=r.get(t);return void 0===n&&(n=++o,r.set(t,n)),String(n)},c=new Map,s=new Map;let a=O();function h(n){try{if(0!==n.button)return;const r=O();r!==a&&(a=r,s.clear(),c.clear());const o=(t=>{const n=[];try{const e="function"==typeof t.composedPath?t.composedPath():[];if(e&&e.length>0){for(const t of e)p(t)&&n.push(t);return n}let r=t.target;for(;r;)p(r)&&n.push(r),r=r.parentNode}catch(t){}return n})(n);if(0===o.length)return;const u=(()=>{try{return"undefined"!=typeof location?location.pathname+location.search:""}catch(t){return""}})();for(let r=0;r<e.length;r++){const a=e[r];if(a.urlScope&&!d(a.urlScope,u))continue;let l=null;for(let t=0;t<o.length;t++)if(x(a,o[t])){l=o[t];break}if(!l)continue;const f=a.rule.id;if((s.get(f)||0)>=a.maxPerPageview)return;const h=f+"#"+i(l),y=Date.now(),v=c.get(h);if(void 0!==v&&y-v<a.dedupeWindowMs)return;if(a.samplingRate<1&&Math.random()>=a.samplingRate)return;c.set(h,y),s.set(f,(s.get(f)||0)+1);const p=a.rule.event.name||"Button Clicked",m=k(a.rule,l,n);return void j(()=>t.track(p,m))}}catch(t){}}try{document.addEventListener("click",h,!0)}catch(t){return()=>{}}return()=>{try{document.removeEventListener("click",h,!0)}catch(t){}c.clear(),s.clear()}})(t,c.buttonTracking));let R=null;if(c.scroll&&(R=(t=>{if("undefined"==typeof window||"undefined"==typeof document)return{destroy(){},reset(){}};let n=!1,e=null,r=!1;function o(){if(e=null,!r&&!n)try{const e=document.documentElement,r=document.body,o=Math.max(e?e.scrollHeight:0,r?r.scrollHeight:0),i=Math.max(e?e.clientHeight:0,window.innerHeight||0);if(o<=i)return n=!0,c(),void t(90);((window.scrollY||(e?e.scrollTop:0)||0)+i)/o>=.9&&(n=!0,c(),t(90))}catch(t){}}function i(){if(null===e)try{e=window.requestAnimationFrame(o)}catch(t){o()}}function c(){try{window.removeEventListener("scroll",i),null!==e&&window.cancelAnimationFrame(e),e=null}catch(t){}}try{window.addEventListener("scroll",i,{passive:!0})}catch(t){try{window.addEventListener("scroll",i)}catch(t){}}try{window.requestAnimationFrame(o)}catch(t){o()}return{destroy(){r=!0,c()},reset(){if(!r){n=!1;try{window.addEventListener("scroll",i,{passive:!0})}catch(t){try{window.addEventListener("scroll",i)}catch(t){}}try{window.requestAnimationFrame(o)}catch(t){o()}}}}})(n=>{M(()=>t.track("Scrolled",{percent:n}))}),g.push(()=>null==R?void 0:R.destroy())),c.spa){const n=function(){if("undefined"==typeof window||"undefined"==typeof history)return()=>{};let n=P();function e(){try{const e=P();if(e===n)return;n=e,(n=>{M(()=>t.page()),null==R||R.reset(),$(n)})(e)}catch(t){}}const r=history.pushState,o=history.replaceState,i=!0===r[_],c=!0===o[_];if(!i){function a(...t){r.apply(this,t),e()}a[_]=!0,history.pushState=a}if(!c){function l(...t){o.apply(this,t),e()}l[_]=!0,history.replaceState=l}const u=()=>e(),s=()=>e();try{window.addEventListener("popstate",u),window.addEventListener("hashchange",s)}catch(f){}return()=>{try{window.removeEventListener("popstate",u),window.removeEventListener("hashchange",s)}catch(t){}try{!i&&history.pushState[_]&&(history.pushState=r),!c&&history.replaceState[_]&&(history.replaceState=o)}catch(t){}}}();g.push(n)}return $(),()=>{for(;g.length>0;){const t=g.pop();try{null==t||t()}catch(t){}}U=null}}({page:(t,n)=>N(t,n),track:(t,n)=>q(t,n)},i.autotrack))}catch(t){}},pageview:g,page:N,screen(t,n){try{const e=m();if(!e)return b("screen");const r=((t,n,e)=>{const r=et("screen",e);return t&&(r.name=t),r.properties=null!=n?n:{},r})(t,n,e);v().enqueue(r)}catch(t){}},track:q,identify(t,n){try{if("string"!=typeof t||0===t.length)return;((t,n,e={})=>{var r,o;if(t&&(V(ft,t,{domain:e.cookieDomain,maxAgeDays:null!==(r=e.cookieMaxAgeDays)&&void 0!==r?r:730,sameSite:"Lax"}),F(ft,t),null!=n)){const t=null!==(o=(()=>{const t=Z(dt);if(!t)return null;try{const n=JSON.parse(t);return n&&"object"==typeof n&&!Array.isArray(n)?n:null}catch(t){return null}})())&&void 0!==o?o:{},e=Object.assign(Object.assign({},t),n);try{F(dt,JSON.stringify(e))}catch(t){}}})(t,n,{cookieDomain:i.cookieDomain,cookieMaxAgeDays:i.cookieMaxAgeDays});const e=m();if(!e)return b("identify");const r=((t,n,e)=>{var r;const o=et("identify",e);return t&&(o.userId=t),o.traits=null!==(r=n)&&void 0!==r?r:{},o})(t,n,e);v().enqueue(r)}catch(t){}},alias(t,n){try{if("string"!=typeof t||0===t.length)return;const e=m();if(!e)return b("alias");const r=((t,n,e)=>{const r=et("alias",e);return t&&(r.userId=t),r.previousId=null!=n?n:e.anonymousId,r})(t,n,e);v().enqueue(r)}catch(t){}},group(t,n){try{if("string"!=typeof t||0===t.length)return;const e=m();if(!e)return b("group");const r=((t,n,e)=>{const r=et("group",e);return r.groupId=t,r.traits=null!=n?n:{},r})(t,n,e);v().enqueue(r)}catch(t){}},reset(){try{((t={})=>{((t,n={})=>{var e;if(!J)return!1;try{let r=`${encodeURIComponent(t)}=`;return r+=`; path=${null!==(e=n.path)&&void 0!==e?e:"/"}`,n.domain&&(r+=`; domain=${n.domain}`),r+="; max-age=0",r+="; expires=Thu, 01 Jan 1970 00:00:00 GMT",document.cookie=r,null===E(t)}catch(t){return!1}})(ft,{domain:t.cookieDomain}),G(ft),G(dt)})({cookieDomain:i.cookieDomain}),((t={})=>{Y(B(),t)})({cookieDomain:i.cookieDomain,cookieMaxAgeDays:i.cookieMaxAgeDays}),((t={})=>{ct({id:B(),lastActivity:Date.now()},t)})({cookieDomain:i.cookieDomain,timeoutMinutes:i.sessionTimeoutMinutes})}catch(t){}},flush(){try{s&&s.flush()}catch(t){}},consent(t){try{c=Object.assign(Object.assign({},c),t)}catch(t){}},set(t){try{i=y(t),t.consent&&(c=Object.assign(Object.assign({},c),t.consent)),s&&s.setConfig({endpoint:i.endpoint,batchPath:i.batchPath,singlePath:i.singlePath,useBatch:i.useBatch,contentType:i.contentType,flushAt:i.flushAt,flushInterval:i.flushInterval,debug:i.debug})}catch(t){}},destroy(){if(h){try{h()}catch(t){}h=null}s&&s.destroy(),s=null,a=!1,t=null,i=Object.assign({},ht),c=Object.assign({},yt)}}})();"undefined"!=typeof window&&(t=>{if("undefined"==typeof window)return()=>{};const n=window.cnvQ;if(n&&n.__loaded)return()=>{};const e=window.cnvQ=null!=n?n:[],r=e.splice(0,e.length);e.push.bind(e),e.push=(...n)=>{for(const e of n)vt(t,e);return e.length},e.__loaded=!0;for(const n of r)vt(t,n)})(bt);const gt=Object.assign(bt,{version:pt,name:mt,schemaVersion:tt});t.NAME=mt,t.SCHEMA_VERSION=tt,t.VERSION=pt,t.default=gt,Object.defineProperty(t,"t",{value:!0})},"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t="undefined"!=typeof globalThis?globalThis:t||self).cnvTrack={});
@@ -308,6 +308,139 @@ interface AutotrackOptions {
308
308
  * Order matters — first non-empty match wins.
309
309
  */
310
310
  searchParams?: ReadonlyArray<string>;
311
+ /**
312
+ * Configurable button / element click tracking. Unlike `outboundClicks`
313
+ * (which auto-fires on every outbound anchor), this fires ONLY for elements
314
+ * matching a user-defined rule — the mechanism for tracking specific buttons
315
+ * (e.g. "Mua", "Đặt hàng") without flooding analytics with noise.
316
+ *
317
+ * In Phase 1 the rules are supplied inline here. In a later phase the same
318
+ * {@link ClickRule} shape is fetched from remote config so non-technical
319
+ * users can manage rules from the dashboard without redeploying the site.
320
+ *
321
+ * Default: undefined (no button tracking).
322
+ */
323
+ buttonTracking?: ButtonTrackingOptions;
324
+ }
325
+ /**
326
+ * Top-level button-tracking config. A flat list of rules plus optional global
327
+ * throttle defaults that individual rules can override.
328
+ */
329
+ interface ButtonTrackingOptions {
330
+ /** Rules evaluated (ascending `priority`) against every click. */
331
+ rules: ClickRule[];
332
+ /** Throttle defaults applied to rules that don't set their own. */
333
+ globalThrottle?: ThrottleSpec;
334
+ }
335
+ /**
336
+ * One button-tracking rule. A click matches the rule when EVERY field present
337
+ * in `match` is satisfied by the same element (logical AND). The first
338
+ * matching rule (lowest `priority`) wins and fires `event.name`.
339
+ */
340
+ interface ClickRule {
341
+ /** Stable id (ULID from backend). Stamped onto the event as `rule_id`. */
342
+ id: string;
343
+ /** Human label, e.g. "Nút Mua hàng". Optional; stamped as `rule_name`. */
344
+ name?: string;
345
+ /** Default `true`. Set `false` to keep the rule but stop it firing. */
346
+ enabled?: boolean;
347
+ /** Lower runs first. Default `0`. */
348
+ priority?: number;
349
+ /** Conditions that select which element(s) this rule applies to. */
350
+ match: ClickMatch;
351
+ /** What event to emit when the rule matches. */
352
+ event: ClickEventSpec;
353
+ /** Properties to auto-collect from the matched element. */
354
+ capture?: CaptureSpec;
355
+ /** Per-rule noise controls (override `globalThrottle`). */
356
+ throttle?: ThrottleSpec;
357
+ /** Restrict the rule to certain pages. */
358
+ urlScope?: UrlMatch;
359
+ }
360
+ /**
361
+ * Element selection criteria. All present fields are AND-ed and evaluated
362
+ * against the SAME element (the nearest matching ancestor of the click target).
363
+ */
364
+ interface ClickMatch {
365
+ /**
366
+ * Element type filter. Special values: `'button'` (button / input[submit|
367
+ * button|reset] / [role=button]), `'link'` (anchor), `'any'`. Any other
368
+ * string is treated as a CSS selector. When omitted, defaults to the
369
+ * actionable set (button-like + link) unless another attribute/selector
370
+ * criterion is present, in which case it defaults to `'any'`.
371
+ */
372
+ element?: 'button' | 'link' | 'any' | (string & {});
373
+ /** Match the element's visible text. */
374
+ text?: TextMatch;
375
+ /** Match `element.id` exactly. */
376
+ id?: string;
377
+ /** Element must carry ALL of these CSS classes. */
378
+ classes?: string[];
379
+ /** Match a `data-*` attribute (presence, or exact value if `value` given). */
380
+ dataAttr?: DataAttrMatch;
381
+ /** Free-form CSS selector; matched via `element.matches(selector)`. */
382
+ selector?: string;
383
+ /** Match the URL the button/link navigates to (anchor href, formaction, form action, or data-href). */
384
+ destinationUrl?: DestinationMatch;
385
+ }
386
+ interface TextMatch {
387
+ mode: 'contains' | 'exact' | 'startsWith' | 'regex';
388
+ value: string;
389
+ /** Default `true`. Ignored for `regex` except to add the `i` flag. */
390
+ caseInsensitive?: boolean;
391
+ }
392
+ interface DataAttrMatch {
393
+ /** Full attribute name, e.g. `data-track`. */
394
+ name: string;
395
+ /** If omitted, presence is enough; otherwise exact value match. */
396
+ value?: string;
397
+ }
398
+ interface DestinationMatch {
399
+ mode: 'contains' | 'exact' | 'startsWith' | 'regex' | 'domain';
400
+ value: string;
401
+ }
402
+ interface UrlMatch {
403
+ mode: 'glob' | 'regex' | 'startsWith';
404
+ /** Compared against `location.pathname + location.search`. */
405
+ value: string;
406
+ }
407
+ /** The event emitted when a rule matches — keeps captured data clean & named. */
408
+ interface ClickEventSpec {
409
+ /** Standard event name, e.g. "Add to Cart". Falls back to "Button Clicked". */
410
+ name: string;
411
+ /** Constant properties merged into every event this rule fires. */
412
+ staticProps?: Record<string, string | number | boolean>;
413
+ }
414
+ /** Allowlist of properties to auto-collect from the matched element. */
415
+ interface CaptureSpec {
416
+ /** Visible text (trimmed, capped at 200 chars, PII-scrubbed). */
417
+ text?: boolean;
418
+ /** Resolved absolute destination URL. */
419
+ href?: boolean;
420
+ /** `element.id`. */
421
+ elementId?: boolean;
422
+ /** `element.classList` as an array. */
423
+ classes?: boolean;
424
+ /** Names of `data-*` attributes to copy (PII-scrubbed). */
425
+ dataAttrs?: string[];
426
+ /** Read a value from a descendant selector (e.g. a price near the button). */
427
+ valueFrom?: {
428
+ selector: string;
429
+ attr?: string;
430
+ as: string;
431
+ };
432
+ /** A short CSS path of the element (debug / attribution). */
433
+ selectorPath?: boolean;
434
+ /** Click coordinates `{ x, y }`. */
435
+ position?: boolean;
436
+ }
437
+ interface ThrottleSpec {
438
+ /** Ignore repeat clicks on the same element within this window. Default 500. */
439
+ dedupeWindowMs?: number;
440
+ /** Cap events fired per rule per pageview. Default unlimited. */
441
+ maxPerPageview?: number;
442
+ /** Probability 0..1 an eligible click is recorded. Default 1. */
443
+ samplingRate?: number;
311
444
  }
312
445
  /**
313
446
  * Each entry in `window.cnvQ` is a tuple `[methodName, ...args]`.
@@ -446,4 +579,4 @@ declare const cnvTrack: Runtime & {
446
579
  };
447
580
 
448
581
  export { NAME, SCHEMA_VERSION, VERSION, cnvTrack as default };
449
- export type { AutotrackOptions, ContextCampaign, ContextConsent, ContextLibrary, ContextPage, ContextScreen, JSONValue, MessageType, PayloadContext, QueuedCommand, SDKOptions, SegmentBatchRequest, SegmentMessage, UserTraits };
582
+ export type { AutotrackOptions, ButtonTrackingOptions, CaptureSpec, ClickEventSpec, ClickMatch, ClickRule, ContextCampaign, ContextConsent, ContextLibrary, ContextPage, ContextScreen, DataAttrMatch, DestinationMatch, JSONValue, MessageType, PayloadContext, QueuedCommand, SDKOptions, SegmentBatchRequest, SegmentMessage, TextMatch, ThrottleSpec, UrlMatch, UserTraits };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cnv-vn/track",
3
- "version": "0.2.0-alpha.4",
3
+ "version": "0.2.0-alpha.5",
4
4
  "description": "CNV Tracking SDK — lightweight, async-first web analytics tracker (<20KB gzipped).",
5
5
  "keywords": [
6
6
  "analytics",