userlens-analytics-sdk 0.1.52 → 0.1.53

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/main.cjs.js CHANGED
@@ -5,5 +5,5 @@
5
5
  * MIT License | (c) Dustin Diaz 2012-2015
6
6
  * MIT License | (c) Denis Demchenko 2015-2019
7
7
  */class Sw{static getParser(e,t=!1){if("string"!=typeof e)throw new Error("UserAgent should be a string");return new vw(e,t)}static parse(e){return new vw(e).getResult()}static get BROWSER_MAP(){return hw}static get ENGINE_MAP(){return dw}static get OS_MAP(){return pw}static get PLATFORMS_MAP(){return uw}}var Cw="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function Iw(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var xw,kw={exports:{}},Ow=kw.exports;
8
- /*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */function Mw(){return xw||(xw=1,e=kw,function(t){e.exports=function(e){if(e.CSS&&e.CSS.escape)return e.CSS.escape;var t=function(e){if(0==arguments.length)throw new TypeError("`CSS.escape` requires an argument.");for(var t,r=String(e),s=r.length,n=-1,o="",i=r.charCodeAt(0);++n<s;)0!=(t=r.charCodeAt(n))?o+=t>=1&&t<=31||127==t||0==n&&t>=48&&t<=57||1==n&&t>=48&&t<=57&&45==i?"\\"+t.toString(16)+" ":0==n&&1==s&&45==t||!(t>=128||45==t||95==t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122)?"\\"+r.charAt(n):r.charAt(n):o+="�";return o};return e.CSS||(e.CSS={}),e.CSS.escape=t,t}(t)}(void 0!==Cw?Cw:Ow)),kw.exports;var e}var Aw,Ew,Rw,Nw={};var Tw,Pw,Fw,Dw,Lw,Bw,_w,Uw,jw,zw,Ww,Vw,Gw,Zw,Yw,Jw,Xw,$w,Hw=function(){if(Rw)return Ew;Rw=1,Mw();const{ShadowRootTypes:e,nodeNameInCorrectCase:t,NodeType:r}=(Aw||(Aw=1,Nw.nodeNameInCorrectCase=function(e){const t=e.shadowRoot&&e.shadowRoot.mode;return t?"#shadow-root ("+t+")":e.localName?e.localName.length!==e.nodeName.length?e.nodeName:e.localName:e.nodeName},Nw.shadowRootType=function(e){const t=e.ancestorShadowRoot();return t?t.mode:null},Nw.NodeType={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9},Nw.ShadowRootTypes={UserAgent:"user-agent",Open:"open",Closed:"closed"}),Nw);let s={DOMPath:{}};return s.DOMPath.fullQualifiedSelector=function(e,t){try{return e.nodeType!==r.ELEMENT_NODE?e.localName||e.nodeName.toLowerCase():s.DOMPath.cssPath(e,t)}catch(e){return null}},s.DOMPath.cssPath=function(e,t){if(e.nodeType!==r.ELEMENT_NODE)return"";const n=[];let o=e;for(;o;){const r=s.DOMPath._cssPathStep(o,!!t,o===e);if(!r)break;if(n.push(r),r.optimized)break;o=o.parentNode}return n.reverse(),n.join(" > ")},s.DOMPath.canGetJSPath=function(t){let r=t;for(;r;){if(r.shadowRoot&&r.shadowRoot.mode!==e.Open)return!1;r=r.shadowRoot&&r.shadowRoot.host}return!0},s.DOMPath.jsPath=function(e,t){if(e.nodeType!==r.ELEMENT_NODE)return"";const n=[];let o=e;for(;o;)n.push(s.DOMPath.cssPath(o,t)),o=o.shadowRoot&&o.shadowRoot.host;n.reverse();let i="";for(let e=0;e<n.length;++e){const t=JSON.stringify(n[e]);i+=e?`.shadowRoot.querySelector(${t})`:`document.querySelector(${t})`}return i},s.DOMPath._cssPathStep=function(e,n,o){if(e.nodeType!==r.ELEMENT_NODE)return null;const i=e.getAttribute("id");if(n){if(i)return new s.DOMPath.Step(h(i),!0);const r=e.nodeName.toLowerCase();if("body"===r||"head"===r||"html"===r)return new s.DOMPath.Step(t(e),!0)}const a=t(e);if(i)return new s.DOMPath.Step(a+h(i),!0);const l=e.parentNode;if(!l||l.nodeType===r.DOCUMENT_NODE)return new s.DOMPath.Step(a,!0);function c(e){const t=e.getAttribute("class");return t?t.split(/\s+/g).filter(Boolean).map(function(e){return"$"+e}):[]}function h(e){return"#"+CSS.escape(e)}const u=c(e);let p=!1,d=!1,f=-1,m=-1;const g=l.children;for(let s=0;(-1===f||!d)&&s<g.length;++s){const n=g[s];if(n.nodeType!==r.ELEMENT_NODE)continue;if(m+=1,n===e){f=m;continue}if(d)continue;if(t(n)!==a)continue;p=!0;const o=new Set(u);if(!o.size){d=!0;continue}const i=c(n);for(let e=0;e<i.length;++e){const t=i[e];if(o.has(t)&&(o.delete(t),!o.size)){d=!0;break}}}let y=a;if(o&&"input"===a.toLowerCase()&&e.getAttribute("type")&&!e.getAttribute("id")&&!e.getAttribute("class")&&(y+="[type="+CSS.escape(e.getAttribute("type"))+"]"),d)y+=":nth-child("+(f+1)+")";else if(p)for(const e of u)y+="."+CSS.escape(e.slice(1));return new s.DOMPath.Step(y,!1)},s.DOMPath.xPath=function(e,t){if(e.nodeType===r.DOCUMENT_NODE)return"/";const n=[];let o=e;for(;o;){const e=s.DOMPath._xPathValue(o,t);if(!e)break;if(n.push(e),e.optimized)break;o=o.parentNode}return n.reverse(),(n.length&&n[0].optimized?"":"/")+n.join("/")},s.DOMPath._xPathValue=function(e,t){let n;const o=s.DOMPath._xPathIndex(e);if(-1===o)return null;switch(e.nodeType){case r.ELEMENT_NODE:if(t&&e.getAttribute("id"))return new s.DOMPath.Step('//*[@id="'+e.getAttribute("id")+'"]',!0);n=e.localName;break;case r.ATTRIBUTE_NODE:n="@"+e.nodeName;break;case r.TEXT_NODE:case r.CDATA_SECTION_NODE:n="text()";break;case r.PROCESSING_INSTRUCTION_NODE:n="processing-instruction()";break;case r.COMMENT_NODE:n="comment()";break;case r.DOCUMENT_NODE:default:n=""}return o>0&&(n+="["+o+"]"),new s.DOMPath.Step(n,e.nodeType===r.DOCUMENT_NODE)},s.DOMPath._xPathIndex=function(e){function t(e,t){if(e===t)return!0;if(e.nodeType===r.ELEMENT_NODE&&t.nodeType===r.ELEMENT_NODE)return e.localName===t.localName;if(e.nodeType===t.nodeType)return!0;return(e.nodeType===r.CDATA_SECTION_NODE?r.TEXT_NODE:e.nodeType)===(t.nodeType===r.CDATA_SECTION_NODE?r.TEXT_NODE:t.nodeType)}const s=e.parentNode?e.parentNode.children:null;if(!s)return 0;let n;for(let r=0;r<s.length;++r)if(t(e,s[r])&&s[r]!==e){n=!0;break}if(!n)return 0;let o=1;for(let r=0;r<s.length;++r)if(t(e,s[r])){if(s[r]===e)return o;++o}return-1},s.DOMPath.Step=class{constructor(e,t){this.value=e,this.optimized=t||!1}toString(){return this.value}},Ew=s.DOMPath}(),Kw=Iw(Hw);Pw=new WeakMap,Fw=new WeakMap,Dw=new WeakMap,Lw=new WeakMap,Bw=new WeakMap,Zw=new WeakMap,Tw=new WeakSet,_w=function(){document.body.addEventListener("click",e(this,Lw,"f"))},Uw=function(t){const r=t.target;if(!(r instanceof HTMLElement))return;const s=Kw.xPath(r,!0),n=e(this,Tw,"m",jw).call(this,r),o={event:s,is_raw:!0,snapshot:n?[n]:[],properties:{...this.getUserContext()}};this.userId&&(o.userId=this.userId),this.events.push(o),this.events.length>100&&(this.events=this.events.slice(-100)),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))},jw=function(t){if(!(t instanceof HTMLElement))return null;const r=[];let s=t;for(;s&&1===s.nodeType;)r.unshift(s),s=s.parentElement;let n=null,o=null;for(let t=0;t<r.length;t++){const s=r[t],i=t>=r.length-3,a=t===r.length-1,l=e(this,Tw,"m",zw).call(this,s,{isTarget:a,leadsToTarget:!0});let c=[l];if(i&&s.parentElement){c=[l,...Array.from(s.parentElement.children).filter(e=>e!==s&&e instanceof HTMLElement).map(t=>e(this,Tw,"m",zw).call(this,t,{includeChildren:!0})).filter(Boolean)]}n||(n=l),o&&(o.children||(o.children=[]),o.children.push(...c)),o=l}return n},zw=function t(r,{isTarget:s=!1,includeChildren:n=!1,leadsToTarget:o=!1}={}){var i,a;const l=r.tagName.toLowerCase(),c=r.classList.length?Array.from(r.classList):null,h=r.id||null,u=r.getAttribute("href")||null,p=Array.from((null===(i=r.parentNode)||void 0===i?void 0:i.children)||[]).indexOf(r)+1,d=Array.from((null===(a=r.parentNode)||void 0===a?void 0:a.children)||[]).filter(e=>e instanceof HTMLElement&&e.tagName===r.tagName).indexOf(r)+1,f={};for(let e of Array.from(r.attributes))f[`attr__${e.name}`]=e.value;const m=Array.from(r.childNodes).filter(e=>e.nodeType===Node.TEXT_NODE),g=m.map(e=>{var t;return null===(t=e.textContent)||void 0===t?void 0:t.trim()}).filter(Boolean).join(" ")||null,y={tag_name:l,attr_class:c,attr_id:h,href:u,nth_child:p,nth_of_type:d,attributes:f,text:g,...s&&{is_target:!0},...o&&!s&&{leads_to_target:!0}};return(n&&r.children.length>0||s)&&(y.children=Array.from(r.children).filter(e=>e instanceof HTMLElement).map(r=>e(this,Tw,"m",t).call(this,r,{includeChildren:!0})).filter(Boolean)),y},Ww=function(){t(this,Pw,setInterval(()=>{e(this,Zw,"f").call(this)},this.intervalTime),"f")},Vw=function(){t(this,Fw,history.pushState,"f"),t(this,Dw,history.replaceState,"f"),history.pushState=(...t)=>{e(this,Fw,"f").apply(history,t),e(this,Tw,"m",Gw).call(this)},history.replaceState=(...t)=>{e(this,Dw,"f").apply(history,t),e(this,Tw,"m",Gw).call(this)},window.addEventListener("popstate",e(this,Bw,"f"))},Gw=function(){try{const e=new URL(window.location.href);if("localhost"===(null==e?void 0:e.hostname)||"127.0.0.1"===(null==e?void 0:e.hostname)||"::1"===(null==e?void 0:e.hostname))return;let t="";try{document.referrer&&/^https?:\/\//.test(document.referrer)&&(t=new URL(document.referrer).origin+new URL(document.referrer).pathname)}catch(e){t=""}const r=Object.fromEntries(e.searchParams.entries()),s={event:"$ul_pageview",properties:{$ul_page:(null==e?void 0:e.origin)+(null==e?void 0:e.pathname)||null,$ul_referrer:t||null,$ul_query:r}};this.userId&&(s.userId=this.userId),this.events.push(s),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))}catch(e){console.warn("Userlens EventCollector error: tracking page view failed")}},Yw=function(){this.events=[],window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))},Jw=function(){document.body.removeEventListener("click",e(this,Lw,"f"))},Xw=function(){e(this,Zw,"f").call(this),clearInterval(e(this,Pw,"f")),e(this,Tw,"m",Yw).call(this)},$w=function(){history.pushState=e(this,Fw,"f"),history.replaceState=e(this,Dw,"f"),window.removeEventListener("popstate",e(this,Bw,"f"))},exports.EventCollector=class{constructor(t){if(Tw.add(this),this.userContext=null,Pw.set(this,void 0),Fw.set(this,void 0),Dw.set(this,void 0),Lw.set(this,e(this,Tw,"m",Uw).bind(this)),Bw.set(this,e(this,Tw,"m",Gw).bind(this)),Zw.set(this,()=>{if(0===this.events.length)return;const t=[...this.events];if(this.callback){try{this.callback(t)}catch(e){console.error("Userlens callback error:",e)}e(this,Tw,"m",Yw).call(this)}else Promise.allSettled([this.userId&&this.userTraits?Xy({userId:this.userId,traits:this.userTraits}):null,$y(t)]),e(this,Tw,"m",Yw).call(this)}),"undefined"==typeof window)return void console.error("Userlens EventCollector error: unavailable outside of browser environment.");const{userId:r,WRITE_CODE:s,callback:n,intervalTime:o=5e3}=t,i=t.userTraits;if(this.autoUploadModeEnabled=!n,this.autoUploadModeEnabled&&!(null==r?void 0:r.length))return void console.error("Userlens EventCollector error: userId is missing.");if(this.autoUploadModeEnabled&&!(null==s?void 0:s.length))return void console.error("Userlens EventCollector error: WRITE_CODE is missing.");if(this.autoUploadModeEnabled&&Hy(s),!this.autoUploadModeEnabled&&"function"!=typeof n)return void console.error("Userlens EventCollector error: callback is not a function.");this.userId=r,this.userTraits=i,this.callback=n,this.intervalTime=o;const a=window.localStorage.getItem("userlensEvents");this.events=a?JSON.parse(a):[],e(this,Tw,"m",_w).call(this),e(this,Tw,"m",Ww).call(this),e(this,Tw,"m",Vw).call(this),this.userContext=this.getUserContext()}pushEvent(e){const t={is_raw:!1,...e,properties:{...null==e?void 0:e.properties,...this.getUserContext()}};this.userId&&(t.userId=this.userId),this.events.push(t),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))}updateUserTraits(e){this.userTraits=e}stop(){e(this,Tw,"m",Jw).call(this),e(this,Tw,"m",Xw).call(this),e(this,Tw,"m",$w).call(this)}getUserContext(){var e,t,r,s,n,o,i;if(this.userContext)return this.userContext;const a=Sw.getParser(window.navigator.userAgent),l=a.getBrowser(),c=a.getOS(),h={$ul_browser:null!==(e=l.name)&&void 0!==e?e:"Unknown",$ul_browser_version:null!==(t=l.version)&&void 0!==t?t:"Unknown",$ul_os:null!==(r=c.name)&&void 0!==r?r:"Unknown",$ul_os_version:null!==(s=c.versionName)&&void 0!==s?s:"Unknown",$ul_browser_language:null!==(n=navigator.language)&&void 0!==n?n:"en-US",$ul_browser_language_prefix:null!==(i=null===(o=navigator.language)||void 0===o?void 0:o.split("-")[0])&&void 0!==i?i:"en",$ul_screen_width:window.screen.width,$ul_screen_height:window.screen.height,$ul_viewport_width:window.innerWidth,$ul_viewport_height:window.innerHeight,$ul_page:window.location.href,$ul_pathname:window.location.pathname,$ul_host:window.location.host,$ul_referrer:document.referrer||"$direct",$ul_referring_domain:document.referrer?new URL(document.referrer).hostname:"$direct",$ul_lib:"userlens.js",$ul_lib_version:"0.1.52",$ul_device_type:/Mobi|Android/i.test(navigator.userAgent)?"Mobile":"Desktop",$ul_timezone:Intl.DateTimeFormat().resolvedOptions().timeZone};return this.userContext=h,h}},exports.SessionRecorder=class{constructor({WRITE_CODE:r,userId:s,recordingOptions:n={}}){if(Ky.add(this),this.sessionEvents=[],this.rrwebStop=null,Qy.set(this,void 0),sw.set(this,()=>{document.visibilityState&&gc()}),"undefined"==typeof window&&console.error("Userlens SDK error: unavailable outside of browser environment."),!(null==r?void 0:r.trim()))throw new Error("Userlens SDK Error: WRITE_CODE is required and must be a string");(null==s?void 0:s.trim())||console.error("Userlens SDK Error: userId is required to identify session user.");const{TIMEOUT:o=18e5,BUFFER_SIZE:i=10,maskingOptions:a=["passwords"]}=n;if("string"!=typeof r)throw new Error("WRITE_CODE must be a string to base64 encode it");Hy(r),this.userId=s,this.TIMEOUT=o,this.BUFFER_SIZE=i,this.maskingOptions=a,this.sessionEvents=[],t(this,Qy,e(this,Ky,"m",ow).call(this,()=>{e(this,Ky,"m",iw).call(this)},5e3),"f"),e(this,Ky,"m",qy).call(this)}stop(){this.rrwebStop&&(this.rrwebStop(),this.rrwebStop=null,e(this,Ky,"m",aw).call(this),e(this,Ky,"m",lw).call(this),window.removeEventListener("visibilitychange",e(this,sw,"f")))}};
8
+ /*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */function Mw(){return xw||(xw=1,e=kw,function(t){e.exports=function(e){if(e.CSS&&e.CSS.escape)return e.CSS.escape;var t=function(e){if(0==arguments.length)throw new TypeError("`CSS.escape` requires an argument.");for(var t,r=String(e),s=r.length,n=-1,o="",i=r.charCodeAt(0);++n<s;)0!=(t=r.charCodeAt(n))?o+=t>=1&&t<=31||127==t||0==n&&t>=48&&t<=57||1==n&&t>=48&&t<=57&&45==i?"\\"+t.toString(16)+" ":0==n&&1==s&&45==t||!(t>=128||45==t||95==t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122)?"\\"+r.charAt(n):r.charAt(n):o+="�";return o};return e.CSS||(e.CSS={}),e.CSS.escape=t,t}(t)}(void 0!==Cw?Cw:Ow)),kw.exports;var e}var Aw,Ew,Rw,Nw={};var Tw,Pw,Fw,Dw,Lw,Bw,_w,Uw,jw,zw,Ww,Vw,Gw,Zw,Yw,Jw,Xw,$w,Hw=function(){if(Rw)return Ew;Rw=1,Mw();const{ShadowRootTypes:e,nodeNameInCorrectCase:t,NodeType:r}=(Aw||(Aw=1,Nw.nodeNameInCorrectCase=function(e){const t=e.shadowRoot&&e.shadowRoot.mode;return t?"#shadow-root ("+t+")":e.localName?e.localName.length!==e.nodeName.length?e.nodeName:e.localName:e.nodeName},Nw.shadowRootType=function(e){const t=e.ancestorShadowRoot();return t?t.mode:null},Nw.NodeType={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9},Nw.ShadowRootTypes={UserAgent:"user-agent",Open:"open",Closed:"closed"}),Nw);let s={DOMPath:{}};return s.DOMPath.fullQualifiedSelector=function(e,t){try{return e.nodeType!==r.ELEMENT_NODE?e.localName||e.nodeName.toLowerCase():s.DOMPath.cssPath(e,t)}catch(e){return null}},s.DOMPath.cssPath=function(e,t){if(e.nodeType!==r.ELEMENT_NODE)return"";const n=[];let o=e;for(;o;){const r=s.DOMPath._cssPathStep(o,!!t,o===e);if(!r)break;if(n.push(r),r.optimized)break;o=o.parentNode}return n.reverse(),n.join(" > ")},s.DOMPath.canGetJSPath=function(t){let r=t;for(;r;){if(r.shadowRoot&&r.shadowRoot.mode!==e.Open)return!1;r=r.shadowRoot&&r.shadowRoot.host}return!0},s.DOMPath.jsPath=function(e,t){if(e.nodeType!==r.ELEMENT_NODE)return"";const n=[];let o=e;for(;o;)n.push(s.DOMPath.cssPath(o,t)),o=o.shadowRoot&&o.shadowRoot.host;n.reverse();let i="";for(let e=0;e<n.length;++e){const t=JSON.stringify(n[e]);i+=e?`.shadowRoot.querySelector(${t})`:`document.querySelector(${t})`}return i},s.DOMPath._cssPathStep=function(e,n,o){if(e.nodeType!==r.ELEMENT_NODE)return null;const i=e.getAttribute("id");if(n){if(i)return new s.DOMPath.Step(h(i),!0);const r=e.nodeName.toLowerCase();if("body"===r||"head"===r||"html"===r)return new s.DOMPath.Step(t(e),!0)}const a=t(e);if(i)return new s.DOMPath.Step(a+h(i),!0);const l=e.parentNode;if(!l||l.nodeType===r.DOCUMENT_NODE)return new s.DOMPath.Step(a,!0);function c(e){const t=e.getAttribute("class");return t?t.split(/\s+/g).filter(Boolean).map(function(e){return"$"+e}):[]}function h(e){return"#"+CSS.escape(e)}const u=c(e);let p=!1,d=!1,f=-1,m=-1;const g=l.children;for(let s=0;(-1===f||!d)&&s<g.length;++s){const n=g[s];if(n.nodeType!==r.ELEMENT_NODE)continue;if(m+=1,n===e){f=m;continue}if(d)continue;if(t(n)!==a)continue;p=!0;const o=new Set(u);if(!o.size){d=!0;continue}const i=c(n);for(let e=0;e<i.length;++e){const t=i[e];if(o.has(t)&&(o.delete(t),!o.size)){d=!0;break}}}let y=a;if(o&&"input"===a.toLowerCase()&&e.getAttribute("type")&&!e.getAttribute("id")&&!e.getAttribute("class")&&(y+="[type="+CSS.escape(e.getAttribute("type"))+"]"),d)y+=":nth-child("+(f+1)+")";else if(p)for(const e of u)y+="."+CSS.escape(e.slice(1));return new s.DOMPath.Step(y,!1)},s.DOMPath.xPath=function(e,t){if(e.nodeType===r.DOCUMENT_NODE)return"/";const n=[];let o=e;for(;o;){const e=s.DOMPath._xPathValue(o,t);if(!e)break;if(n.push(e),e.optimized)break;o=o.parentNode}return n.reverse(),(n.length&&n[0].optimized?"":"/")+n.join("/")},s.DOMPath._xPathValue=function(e,t){let n;const o=s.DOMPath._xPathIndex(e);if(-1===o)return null;switch(e.nodeType){case r.ELEMENT_NODE:if(t&&e.getAttribute("id"))return new s.DOMPath.Step('//*[@id="'+e.getAttribute("id")+'"]',!0);n=e.localName;break;case r.ATTRIBUTE_NODE:n="@"+e.nodeName;break;case r.TEXT_NODE:case r.CDATA_SECTION_NODE:n="text()";break;case r.PROCESSING_INSTRUCTION_NODE:n="processing-instruction()";break;case r.COMMENT_NODE:n="comment()";break;case r.DOCUMENT_NODE:default:n=""}return o>0&&(n+="["+o+"]"),new s.DOMPath.Step(n,e.nodeType===r.DOCUMENT_NODE)},s.DOMPath._xPathIndex=function(e){function t(e,t){if(e===t)return!0;if(e.nodeType===r.ELEMENT_NODE&&t.nodeType===r.ELEMENT_NODE)return e.localName===t.localName;if(e.nodeType===t.nodeType)return!0;return(e.nodeType===r.CDATA_SECTION_NODE?r.TEXT_NODE:e.nodeType)===(t.nodeType===r.CDATA_SECTION_NODE?r.TEXT_NODE:t.nodeType)}const s=e.parentNode?e.parentNode.children:null;if(!s)return 0;let n;for(let r=0;r<s.length;++r)if(t(e,s[r])&&s[r]!==e){n=!0;break}if(!n)return 0;let o=1;for(let r=0;r<s.length;++r)if(t(e,s[r])){if(s[r]===e)return o;++o}return-1},s.DOMPath.Step=class{constructor(e,t){this.value=e,this.optimized=t||!1}toString(){return this.value}},Ew=s.DOMPath}(),Kw=Iw(Hw);Pw=new WeakMap,Fw=new WeakMap,Dw=new WeakMap,Lw=new WeakMap,Bw=new WeakMap,Zw=new WeakMap,Tw=new WeakSet,_w=function(){document.body.addEventListener("click",e(this,Lw,"f"))},Uw=function(t){const r=t.target;if(!(r instanceof HTMLElement))return;const s=Kw.xPath(r,!0),n=e(this,Tw,"m",jw).call(this,r),o={event:s,is_raw:!0,snapshot:n?[n]:[],properties:{...this.getUserContext()}};this.userId&&(o.userId=this.userId),this.events.push(o),this.events.length>100&&(this.events=this.events.slice(-100)),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))},jw=function(t){if(!(t instanceof HTMLElement))return null;const r=[];let s=t;for(;s&&1===s.nodeType;)r.unshift(s),s=s.parentElement;let n=null,o=null;for(let t=0;t<r.length;t++){const s=r[t],i=t>=r.length-3,a=t===r.length-1,l=e(this,Tw,"m",zw).call(this,s,{isTarget:a,leadsToTarget:!0});let c=[l];if(i&&s.parentElement){c=[l,...Array.from(s.parentElement.children).filter(e=>e!==s&&e instanceof HTMLElement).map(t=>e(this,Tw,"m",zw).call(this,t,{includeChildren:!0})).filter(Boolean)]}n||(n=l),o&&(o.children||(o.children=[]),o.children.push(...c)),o=l}return n},zw=function t(r,{isTarget:s=!1,includeChildren:n=!1,leadsToTarget:o=!1}={}){var i,a;const l=r.tagName.toLowerCase(),c=r.classList.length?Array.from(r.classList):null,h=r.id||null,u=r.getAttribute("href")||null,p=Array.from((null===(i=r.parentNode)||void 0===i?void 0:i.children)||[]).indexOf(r)+1,d=Array.from((null===(a=r.parentNode)||void 0===a?void 0:a.children)||[]).filter(e=>e instanceof HTMLElement&&e.tagName===r.tagName).indexOf(r)+1,f={};for(let e of Array.from(r.attributes))f[`attr__${e.name}`]=e.value;const m=Array.from(r.childNodes).filter(e=>e.nodeType===Node.TEXT_NODE),g=m.map(e=>{var t;return null===(t=e.textContent)||void 0===t?void 0:t.trim()}).filter(Boolean).join(" ")||null,y={tag_name:l,attr_class:c,attr_id:h,href:u,nth_child:p,nth_of_type:d,attributes:f,text:g,...s&&{is_target:!0},...o&&!s&&{leads_to_target:!0}};return(n&&r.children.length>0||s)&&(y.children=Array.from(r.children).filter(e=>e instanceof HTMLElement).map(r=>e(this,Tw,"m",t).call(this,r,{includeChildren:!0})).filter(Boolean)),y},Ww=function(){t(this,Pw,setInterval(()=>{e(this,Zw,"f").call(this)},this.intervalTime),"f")},Vw=function(){t(this,Fw,history.pushState,"f"),t(this,Dw,history.replaceState,"f"),history.pushState=(...t)=>{e(this,Fw,"f").apply(history,t),e(this,Tw,"m",Gw).call(this)},history.replaceState=(...t)=>{e(this,Dw,"f").apply(history,t),e(this,Tw,"m",Gw).call(this)},window.addEventListener("popstate",e(this,Bw,"f"))},Gw=function(){try{const e=new URL(window.location.href);if("localhost"===(null==e?void 0:e.hostname)||"127.0.0.1"===(null==e?void 0:e.hostname)||"::1"===(null==e?void 0:e.hostname))return;let t="";try{document.referrer&&/^https?:\/\//.test(document.referrer)&&(t=new URL(document.referrer).origin+new URL(document.referrer).pathname)}catch(e){t=""}const r=Object.fromEntries(e.searchParams.entries()),s={event:"$ul_pageview",properties:{$ul_page:(null==e?void 0:e.origin)+(null==e?void 0:e.pathname)||null,$ul_referrer:t||null,$ul_query:r}};this.userId&&(s.userId=this.userId),this.events.push(s),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))}catch(e){console.warn("Userlens EventCollector error: tracking page view failed")}},Yw=function(){this.events=[],window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))},Jw=function(){document.body.removeEventListener("click",e(this,Lw,"f"))},Xw=function(){e(this,Zw,"f").call(this),clearInterval(e(this,Pw,"f")),e(this,Tw,"m",Yw).call(this)},$w=function(){history.pushState=e(this,Fw,"f"),history.replaceState=e(this,Dw,"f"),window.removeEventListener("popstate",e(this,Bw,"f"))},exports.EventCollector=class{constructor(t){if(Tw.add(this),this.userContext=null,Pw.set(this,void 0),Fw.set(this,void 0),Dw.set(this,void 0),Lw.set(this,e(this,Tw,"m",Uw).bind(this)),Bw.set(this,e(this,Tw,"m",Gw).bind(this)),Zw.set(this,()=>{if(0===this.events.length)return;const t=[...this.events];if(this.callback){try{this.callback(t)}catch(e){console.error("Userlens callback error:",e)}e(this,Tw,"m",Yw).call(this)}else Promise.allSettled([this.userId&&this.userTraits?Xy({userId:this.userId,traits:this.userTraits}):null,$y(t)]),e(this,Tw,"m",Yw).call(this)}),"undefined"==typeof window)return void console.error("Userlens EventCollector error: unavailable outside of browser environment.");const{userId:r,WRITE_CODE:s,callback:n,intervalTime:o=5e3}=t,i=t.userTraits;if(this.autoUploadModeEnabled=!n,this.autoUploadModeEnabled&&!(null==r?void 0:r.length))return void console.error("Userlens EventCollector error: userId is missing.");if(this.autoUploadModeEnabled&&!(null==s?void 0:s.length))return void console.error("Userlens EventCollector error: WRITE_CODE is missing.");if(this.autoUploadModeEnabled&&Hy(s),!this.autoUploadModeEnabled&&"function"!=typeof n)return void console.error("Userlens EventCollector error: callback is not a function.");this.userId=r,this.userTraits=i,this.callback=n,this.intervalTime=o;const a=window.localStorage.getItem("userlensEvents");this.events=a?JSON.parse(a):[],e(this,Tw,"m",_w).call(this),e(this,Tw,"m",Ww).call(this),e(this,Tw,"m",Vw).call(this),this.userContext=this.getUserContext()}pushEvent(e){const t={is_raw:!1,...e,properties:{...null==e?void 0:e.properties,...this.getUserContext()}};this.userId&&(t.userId=this.userId),this.events.push(t),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))}updateUserTraits(e){this.userTraits=e}stop(){e(this,Tw,"m",Jw).call(this),e(this,Tw,"m",Xw).call(this),e(this,Tw,"m",$w).call(this)}getUserContext(){var e,t,r,s,n,o,i;if(this.userContext)return this.userContext;const a=Sw.getParser(window.navigator.userAgent),l=a.getBrowser(),c=a.getOS(),h={$ul_browser:null!==(e=l.name)&&void 0!==e?e:"Unknown",$ul_browser_version:null!==(t=l.version)&&void 0!==t?t:"Unknown",$ul_os:null!==(r=c.name)&&void 0!==r?r:"Unknown",$ul_os_version:null!==(s=c.versionName)&&void 0!==s?s:"Unknown",$ul_browser_language:null!==(n=navigator.language)&&void 0!==n?n:"en-US",$ul_browser_language_prefix:null!==(i=null===(o=navigator.language)||void 0===o?void 0:o.split("-")[0])&&void 0!==i?i:"en",$ul_screen_width:window.screen.width,$ul_screen_height:window.screen.height,$ul_viewport_width:window.innerWidth,$ul_viewport_height:window.innerHeight,$ul_page:window.location.href,$ul_pathname:window.location.pathname,$ul_host:window.location.host,$ul_referrer:document.referrer||"$direct",$ul_referring_domain:document.referrer?new URL(document.referrer).hostname:"$direct",$ul_lib:"userlens.js",$ul_lib_version:"0.1.53",$ul_device_type:/Mobi|Android/i.test(navigator.userAgent)?"Mobile":"Desktop",$ul_timezone:Intl.DateTimeFormat().resolvedOptions().timeZone};return this.userContext=h,h}},exports.SessionRecorder=class{constructor({WRITE_CODE:r,userId:s,recordingOptions:n={}}){if(Ky.add(this),this.sessionEvents=[],this.rrwebStop=null,Qy.set(this,void 0),sw.set(this,()=>{document.visibilityState&&gc()}),"undefined"==typeof window&&console.error("Userlens SDK error: unavailable outside of browser environment."),!(null==r?void 0:r.trim()))throw new Error("Userlens SDK Error: WRITE_CODE is required and must be a string");(null==s?void 0:s.trim())||console.error("Userlens SDK Error: userId is required to identify session user.");const{TIMEOUT:o=18e5,BUFFER_SIZE:i=10,maskingOptions:a=["passwords"]}=n;if("string"!=typeof r)throw new Error("WRITE_CODE must be a string to base64 encode it");Hy(r),this.userId=s,this.TIMEOUT=o,this.BUFFER_SIZE=i,this.maskingOptions=a,this.sessionEvents=[],t(this,Qy,e(this,Ky,"m",ow).call(this,()=>{e(this,Ky,"m",iw).call(this)},5e3),"f"),e(this,Ky,"m",qy).call(this)}stop(){this.rrwebStop&&(this.rrwebStop(),this.rrwebStop=null,e(this,Ky,"m",aw).call(this),e(this,Ky,"m",lw).call(this),window.removeEventListener("visibilitychange",e(this,sw,"f")))}};
9
9
  //# sourceMappingURL=main.cjs.js.map