@cnv-vn/track 0.2.0-alpha.2 → 0.2.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cnv-track.esm.js +2 -2
- package/dist/cnv-track.min.js +2 -2
- package/dist/cnv-track.umd.cjs +2 -2
- package/package.json +1 -1
package/dist/cnv-track.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @cnv-vn/track v0.2.0-alpha.
|
|
2
|
+
* @cnv-vn/track v0.2.0-alpha.4
|
|
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.2"}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 m(t){return v[t>>>4&15]+v[15&t]}function p(){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 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=p()),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:p(),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:p(),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",batchPath:"/segment/batch",singlePath:"/segment/{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.2",K="@cnv-vn/track",Q=(()=>{let v=null,m=Object.assign({},E),b=Object.assign({},H),w=null,j=!1,A=null;function P(t){const n=Object.assign({},m);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:m.endpoint,batchPath:m.batchPath,singlePath:m.singlePath,useBatch:m.useBatch,contentType:m.contentType,flushAt:m.flushAt,flushInterval:m.flushInterval,projectId:null!=v?v:"",debug:m.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:m.allowAdTracking});return b.analytics&&b.marketing||(n.consent=Object.assign({},b)),{anonymousId:D({cookieDomain:m.cookieDomain,cookieMaxAgeDays:m.cookieMaxAgeDays}),sessionId:L({cookieDomain:m.cookieDomain,timeoutMinutes:m.sessionTimeoutMinutes}),userId:null!==(t=x(J)||O(J))&&void 0!==t?t:void 0,context:n,projectId:v,integrations:Object.keys(m.integrations).length>0?m.integrations:void 0}}function T(t){m.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(m=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:m.cookieDomain,cookieMaxAgeDays:m.cookieMaxAgeDays}),L({cookieDomain:m.cookieDomain,timeoutMinutes:m.sessionTimeoutMinutes}),m.autoPageview&&$(),A){try{A()}catch(t){}A=null}m.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===(m=h.scroll)||void 0===m||m,downloads:null===(p=h.downloads)||void 0===p||p,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,m,p,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)}},m.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:m.cookieDomain,cookieMaxAgeDays:m.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:m.cookieDomain}),((t={})=>{I(p(),t)})({cookieDomain:m.cookieDomain,cookieMaxAgeDays:m.cookieMaxAgeDays}),((t={})=>{R({id:p(),lastActivity:Date.now()},t)})({cookieDomain:m.cookieDomain,timeoutMinutes:m.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{m=P(t),t.consent&&(b=Object.assign(Object.assign({},b),t.consent)),w&&w.setConfig({endpoint:m.endpoint,batchPath:m.batchPath,singlePath:m.singlePath,useBatch:m.useBatch,contentType:m.contentType,flushAt:m.flushAt,flushInterval:m.flushInterval,debug:m.debug})}catch(t){}},destroy(){if(A){try{A()}catch(t){}A=null}w&&w.destroy(),w=null,j=!1,v=null,m=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="__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};
|
package/dist/cnv-track.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @cnv-vn/track v0.2.0-alpha.
|
|
2
|
+
* @cnv-vn/track v0.2.0-alpha.4
|
|
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.2"}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 m="0123456789abcdef";function p(t){return m[t>>>4&15]+m[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,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 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",batchPath:"/segment/batch",singlePath:"/segment/{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.2",Q="@cnv-vn/track",W=(()=>{let t=null,m=Object.assign({},H),p=Object.assign({},F),w=null,g=!1,O=null;function P(t){const n=Object.assign({},m);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:m.endpoint,batchPath:m.batchPath,singlePath:m.singlePath,useBatch:m.useBatch,contentType:m.contentType,flushAt:m.flushAt,flushInterval:m.flushInterval,projectId:null!=t?t:"",debug:m.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:m.allowAdTracking});return p.analytics&&p.marketing||(e.consent=Object.assign({},p)),{anonymousId:I({cookieDomain:m.cookieDomain,cookieMaxAgeDays:m.cookieMaxAgeDays}),sessionId:R({cookieDomain:m.cookieDomain,timeoutMinutes:m.sessionTimeoutMinutes}),userId:null!==(n=k(V)||_(V))&&void 0!==n?n:void 0,context:e,projectId:t,integrations:Object.keys(m.integrations).length>0?m.integrations:void 0}}function C(t){m.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(m=P(f),(null==f?void 0:f.consent)&&(p=Object.assign(Object.assign({},p),f.consent)),t=d,w&&w.destroy(),w=null,D(),g=!0,I({cookieDomain:m.cookieDomain,cookieMaxAgeDays:m.cookieMaxAgeDays}),R({cookieDomain:m.cookieDomain,timeoutMinutes:m.sessionTimeoutMinutes}),m.autoPageview&&$(),O){try{O()}catch(t){}O=null}m.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===(m=h.scroll)||void 0===m||m,downloads:null===(p=h.downloads)||void 0===p||p,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,m,p,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)}},m.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:m.cookieDomain,cookieMaxAgeDays:m.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:m.cookieDomain}),((t={})=>{M(b(),t)})({cookieDomain:m.cookieDomain,cookieMaxAgeDays:m.cookieMaxAgeDays}),((t={})=>{q({id:b(),lastActivity:Date.now()},t)})({cookieDomain:m.cookieDomain,timeoutMinutes:m.sessionTimeoutMinutes})}catch(t){}},flush(){try{w&&w.flush()}catch(t){}},consent(t){try{p=Object.assign(Object.assign({},p),t)}catch(t){}},set(t){try{m=P(t),t.consent&&(p=Object.assign(Object.assign({},p),t.consent)),w&&w.setConfig({endpoint:m.endpoint,batchPath:m.batchPath,singlePath:m.singlePath,useBatch:m.useBatch,contentType:m.contentType,flushAt:m.flushAt,flushInterval:m.flushInterval,debug:m.debug})}catch(t){}},destroy(){if(O){try{O()}catch(t){}O=null}w&&w.destroy(),w=null,g=!1,t=null,m=Object.assign({},H),p=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="__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||{});
|
package/dist/cnv-track.umd.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @cnv-vn/track v0.2.0-alpha.
|
|
2
|
+
* @cnv-vn/track v0.2.0-alpha.4
|
|
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.2"}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 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: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=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",batchPath:"/segment/batch",singlePath:"/segment/{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.2",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 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 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 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)&&(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)=>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(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: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="__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={});
|