userlens-analytics-sdk 0.1.20 → 0.1.21
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/userlens.cjs.js
CHANGED
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* MIT License | (c) Dustin Diaz 2012-2015
|
|
6
6
|
* MIT License | (c) Denis Demchenko 2015-2019
|
|
7
7
|
*/class fw{static getParser(e,t=!1){if("string"!=typeof e)throw new Error("UserAgent should be a string");return new dw(e,t)}static parse(e){return new dw(e).getResult()}static get BROWSER_MAP(){return sw}static get ENGINE_MAP(){return iw}static get OS_MAP(){return ow}static get PLATFORMS_MAP(){return nw}}var mw="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function gw(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var yw,ww={exports:{}},bw=ww.exports;
|
|
8
|
-
/*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */function vw(){return yw||(yw=1,e=ww,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!==mw?mw:bw)),ww.exports;var e}var Sw,Cw,Iw,xw={};var kw,Ow,Aw,Mw,Ew,Rw,Nw,Pw,Tw,Fw=function(){if(Iw)return Cw;Iw=1,vw();const{ShadowRootTypes:e,nodeNameInCorrectCase:t,NodeType:r}=(Sw||(Sw=1,xw.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},xw.shadowRootType=function(e){const t=e.ancestorShadowRoot();return t?t.mode:null},xw.NodeType={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9},xw.ShadowRootTypes={UserAgent:"user-agent",Open:"open",Closed:"closed"}),xw);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}},Cw=s.DOMPath}(),Dw=gw(Fw);kw=new WeakSet,Ow=function(){const e=fw.getParser(window.navigator.userAgent),t=e.getBrowser(),r=e.getOS(),s={$ul_browser:t.name??"Unknown",$ul_browser_version:t.version??"Unknown",$ul_os:r.name??"Unknown",$ul_os_version:r.versionName??"Unknown",$ul_browser_language:navigator.language??"en-US",$ul_browser_language_prefix:navigator.language?.split("-")[0]??"en",$ul_screen_width:window.screen.width,$ul_screen_height:window.screen.height,$ul_viewport_width:window.innerWidth,$ul_viewport_height:window.innerHeight,$ul_current_url: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.0",$ul_device_type:/Mobi|Android/i.test(navigator.userAgent)?"Mobile":"Desktop",$ul_timezone:Intl.DateTimeFormat().resolvedOptions().timeZone};return this.userContext=s,s},Aw=function(){document.body.addEventListener("click",(t=>{e(this,kw,"m",Mw).call(this,t)}))},Mw=function(t){const r=t.target;if(!(r instanceof Element))return;const s={event:Dw.xPath(r,!0),is_raw:!0,snapshot:e(this,kw,"m",Ew).call(this,r),current_url:window.location.href,properties:{...e(this,kw,"m",Ow).call(this)}};this.events.push(s),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))},Ew=function(e){const t=[];let r=e;for(;r&&r!==document.documentElement;){if(!(r instanceof HTMLElement)){r=r.parentElement;continue}const e=r.tagName.toLowerCase(),s=r.classList.length?[...r.classList]:null,n=r.id||null,o=Array.from(r.parentNode?.children||[]).indexOf(r)+1,i=Array.from(r.parentNode?.children||[]).filter((e=>e.tagName===r?.tagName)).indexOf(r)+1,a={};for(let e of r.attributes)a[`attr__${e.name}`]=e.value;const l=t.length<3,c=["a","button","span","label"].includes(e)||"button"===r.getAttribute("role")||null!==r.getAttribute("tabindex")||"function"==typeof r.onclick||r.className&&/btn|button|clickable|cta/.test(r.className),h=l&&c&&r.innerText?.trim()||null;t.unshift({text:h,tag_name:e,attr_class:s,href:r.getAttribute("href"),attr_id:n,nth_child:o,nth_of_type:i,attributes:a}),r=r.parentElement}return t},Rw=function(){setInterval((()=>{if(this.events.length>0){const t=[...this.events];this.callback(t),e(this,kw,"m",Tw).call(this)}}),this.intervalTime)},Nw=function(){const t=history.pushState,r=history.replaceState;history.pushState=(...r)=>{t.apply(history,r),e(this,kw,"m",Pw).call(this)},history.replaceState=(...t)=>{r.apply(history,t),e(this,kw,"m",Pw).call(this)},window.addEventListener("popstate",(()=>e(this,kw,"m",Pw).call(this)))},Pw=function(){try{const e=new URL(window.location.href);if("localhost"===e?.hostname||"127.0.0.1"===e?.hostname||"::1"===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:e?.origin+e?.pathname||null,$ul_referrer:t||null,$ul_query:r}};this.events.push(s),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))}catch(e){console.warn("Userlens EventCollector error: tracking page view failed")}},Tw=function(){this.events=[],window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))},exports.EventCollector=class{constructor(t,r=5e3){if(kw.add(this),this.userContext=null,"undefined"==typeof window&&console.error("Userlens EventCollector error: unavailable outside of browser environment."),"function"!=typeof t)return void console.error("Userlens EventCollector error: callback is not a function.");this.callback=t,this.intervalTime=r;const s=window.localStorage.getItem("userlensEvents");this.events=s?JSON.parse(s):[],e(this,kw,"m",Aw).call(this),e(this,kw,"m",Rw).call(this),e(this,kw,"m",Nw).call(this),this.userContext=e(this,kw,"m",Ow).call(this)}pushEvent(t){const r={...t,is_raw:!1,properties:{...t.properties,...e(this,kw,"m",Ow).call(this)}};this.events.push(r),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))}},exports.SessionRecorder=class{constructor({WRITE_CODE:t,userId:r,recordingOptions:s={}}){if(Yy.add(this),this.sessionEvents=[],this.rrwebControl=null,Jy.set(this,void 0),"undefined"==typeof window&&console.error("Userlens SDK error: unavailable outside of browser environment."),!t?.trim())throw new Error("Userlens SDK Error: WRITE_CODE is required and must be a string");r?.trim()||console.error("Userlens SDK Error: userId is required to identify session user.");const{TIMEOUT:n=18e5,BUFFER_SIZE:o=10,maskingOptions:i=["passwords"]}=s;this.WRITE_CODE=t,this.userId=r,this.TIMEOUT=n,this.BUFFER_SIZE=o,this.maskingOptions=i,this.sessionEvents=[],function(e,t,r,s,n){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===s?n.call(e,r):n?n.value=r:t.set(e,r)}(this,Jy,e(this,Yy,"m",qy).call(this,(()=>{e(this,Yy,"m",ew).call(this)}),5e3),"f"),e(this,Yy,"m",Xy).call(this)}};
|
|
8
|
+
/*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */function vw(){return yw||(yw=1,e=ww,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!==mw?mw:bw)),ww.exports;var e}var Sw,Cw,Iw,xw={};var kw,Ow,Aw,Mw,Ew,Rw,Nw,Pw,Tw,Fw=function(){if(Iw)return Cw;Iw=1,vw();const{ShadowRootTypes:e,nodeNameInCorrectCase:t,NodeType:r}=(Sw||(Sw=1,xw.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},xw.shadowRootType=function(e){const t=e.ancestorShadowRoot();return t?t.mode:null},xw.NodeType={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9},xw.ShadowRootTypes={UserAgent:"user-agent",Open:"open",Closed:"closed"}),xw);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}},Cw=s.DOMPath}(),Dw=gw(Fw);kw=new WeakSet,Ow=function(){if(this.userContext)return this.userContext;const e=fw.getParser(window.navigator.userAgent),t=e.getBrowser(),r=e.getOS(),s={$ul_browser:t.name??"Unknown",$ul_browser_version:t.version??"Unknown",$ul_os:r.name??"Unknown",$ul_os_version:r.versionName??"Unknown",$ul_browser_language:navigator.language??"en-US",$ul_browser_language_prefix:navigator.language?.split("-")[0]??"en",$ul_screen_width:window.screen.width,$ul_screen_height:window.screen.height,$ul_viewport_width:window.innerWidth,$ul_viewport_height:window.innerHeight,$ul_current_url: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.21",$ul_device_type:/Mobi|Android/i.test(navigator.userAgent)?"Mobile":"Desktop",$ul_timezone:Intl.DateTimeFormat().resolvedOptions().timeZone};return this.userContext=s,s},Aw=function(){document.body.addEventListener("click",(t=>{e(this,kw,"m",Mw).call(this,t)}))},Mw=function(t){const r=t.target;if(!(r instanceof Element))return;const s={event:Dw.xPath(r,!0),is_raw:!0,snapshot:e(this,kw,"m",Ew).call(this,r),current_url:window.location.href,properties:{...e(this,kw,"m",Ow).call(this)}};this.events.push(s),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))},Ew=function(e){const t=[];let r=e;for(;r&&r!==document.documentElement;){if(!(r instanceof HTMLElement)){r=r.parentElement;continue}const e=r.tagName.toLowerCase(),s=r.classList.length?[...r.classList]:null,n=r.id||null,o=Array.from(r.parentNode?.children||[]).indexOf(r)+1,i=Array.from(r.parentNode?.children||[]).filter((e=>e.tagName===r?.tagName)).indexOf(r)+1,a={};for(let e of r.attributes)a[`attr__${e.name}`]=e.value;const l=t.length<3,c=["a","button","span","label"].includes(e)||"button"===r.getAttribute("role")||null!==r.getAttribute("tabindex")||"function"==typeof r.onclick||r.className&&/btn|button|clickable|cta/.test(r.className),h=l&&c&&r.innerText?.trim()||null;t.unshift({text:h,tag_name:e,attr_class:s,href:r.getAttribute("href"),attr_id:n,nth_child:o,nth_of_type:i,attributes:a}),r=r.parentElement}return t},Rw=function(){setInterval((()=>{if(this.events.length>0){const t=[...this.events];this.callback(t),e(this,kw,"m",Tw).call(this)}}),this.intervalTime)},Nw=function(){const t=history.pushState,r=history.replaceState;history.pushState=(...r)=>{t.apply(history,r),e(this,kw,"m",Pw).call(this)},history.replaceState=(...t)=>{r.apply(history,t),e(this,kw,"m",Pw).call(this)},window.addEventListener("popstate",(()=>e(this,kw,"m",Pw).call(this)))},Pw=function(){try{const e=new URL(window.location.href);if("localhost"===e?.hostname||"127.0.0.1"===e?.hostname||"::1"===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:e?.origin+e?.pathname||null,$ul_referrer:t||null,$ul_query:r}};this.events.push(s),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))}catch(e){console.warn("Userlens EventCollector error: tracking page view failed")}},Tw=function(){this.events=[],window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))},exports.EventCollector=class{constructor(t,r=5e3){if(kw.add(this),this.userContext=null,"undefined"==typeof window&&console.error("Userlens EventCollector error: unavailable outside of browser environment."),"function"!=typeof t)return void console.error("Userlens EventCollector error: callback is not a function.");this.callback=t,this.intervalTime=r;const s=window.localStorage.getItem("userlensEvents");this.events=s?JSON.parse(s):[],e(this,kw,"m",Aw).call(this),e(this,kw,"m",Rw).call(this),e(this,kw,"m",Nw).call(this),this.userContext=e(this,kw,"m",Ow).call(this)}pushEvent(t){const r={...t,is_raw:!1,properties:{...t.properties,...e(this,kw,"m",Ow).call(this)}};this.events.push(r),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))}},exports.SessionRecorder=class{constructor({WRITE_CODE:t,userId:r,recordingOptions:s={}}){if(Yy.add(this),this.sessionEvents=[],this.rrwebControl=null,Jy.set(this,void 0),"undefined"==typeof window&&console.error("Userlens SDK error: unavailable outside of browser environment."),!t?.trim())throw new Error("Userlens SDK Error: WRITE_CODE is required and must be a string");r?.trim()||console.error("Userlens SDK Error: userId is required to identify session user.");const{TIMEOUT:n=18e5,BUFFER_SIZE:o=10,maskingOptions:i=["passwords"]}=s;this.WRITE_CODE=t,this.userId=r,this.TIMEOUT=n,this.BUFFER_SIZE=o,this.maskingOptions=i,this.sessionEvents=[],function(e,t,r,s,n){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===s?n.call(e,r):n?n.value=r:t.set(e,r)}(this,Jy,e(this,Yy,"m",qy).call(this,(()=>{e(this,Yy,"m",ew).call(this)}),5e3),"f"),e(this,Yy,"m",Xy).call(this)}};
|
package/dist/userlens.esm.js
CHANGED
|
@@ -5,4 +5,4 @@ function e(e,t,r,s){if("a"===r&&!s)throw new TypeError("Private accessor was def
|
|
|
5
5
|
* MIT License | (c) Dustin Diaz 2012-2015
|
|
6
6
|
* MIT License | (c) Denis Demchenko 2015-2019
|
|
7
7
|
*/class mw{static getParser(e,t=!1){if("string"!=typeof e)throw new Error("UserAgent should be a string");return new fw(e,t)}static parse(e){return new fw(e).getResult()}static get BROWSER_MAP(){return nw}static get ENGINE_MAP(){return aw}static get OS_MAP(){return iw}static get PLATFORMS_MAP(){return ow}}var gw="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function yw(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ww,bw={exports:{}},vw=bw.exports;
|
|
8
|
-
/*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */function Sw(){return ww||(ww=1,e=bw,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!==gw?gw:vw)),bw.exports;var e}var Cw,Iw,xw,kw={};var Ow,Aw,Mw,Ew,Rw,Nw,Pw,Tw,Fw,Dw=function(){if(xw)return Iw;xw=1,Sw();const{ShadowRootTypes:e,nodeNameInCorrectCase:t,NodeType:r}=(Cw||(Cw=1,kw.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},kw.shadowRootType=function(e){const t=e.ancestorShadowRoot();return t?t.mode:null},kw.NodeType={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9},kw.ShadowRootTypes={UserAgent:"user-agent",Open:"open",Closed:"closed"}),kw);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}},Iw=s.DOMPath}(),Lw=yw(Dw);class Bw{constructor(t,r=5e3){if(Ow.add(this),this.userContext=null,"undefined"==typeof window&&console.error("Userlens EventCollector error: unavailable outside of browser environment."),"function"!=typeof t)return void console.error("Userlens EventCollector error: callback is not a function.");this.callback=t,this.intervalTime=r;const s=window.localStorage.getItem("userlensEvents");this.events=s?JSON.parse(s):[],e(this,Ow,"m",Mw).call(this),e(this,Ow,"m",Nw).call(this),e(this,Ow,"m",Pw).call(this),this.userContext=e(this,Ow,"m",Aw).call(this)}pushEvent(t){const r={...t,is_raw:!1,properties:{...t.properties,...e(this,Ow,"m",Aw).call(this)}};this.events.push(r),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))}}Ow=new WeakSet,Aw=function(){const e=mw.getParser(window.navigator.userAgent),t=e.getBrowser(),r=e.getOS(),s={$ul_browser:t.name??"Unknown",$ul_browser_version:t.version??"Unknown",$ul_os:r.name??"Unknown",$ul_os_version:r.versionName??"Unknown",$ul_browser_language:navigator.language??"en-US",$ul_browser_language_prefix:navigator.language?.split("-")[0]??"en",$ul_screen_width:window.screen.width,$ul_screen_height:window.screen.height,$ul_viewport_width:window.innerWidth,$ul_viewport_height:window.innerHeight,$ul_current_url: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.
|
|
8
|
+
/*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */function Sw(){return ww||(ww=1,e=bw,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!==gw?gw:vw)),bw.exports;var e}var Cw,Iw,xw,kw={};var Ow,Aw,Mw,Ew,Rw,Nw,Pw,Tw,Fw,Dw=function(){if(xw)return Iw;xw=1,Sw();const{ShadowRootTypes:e,nodeNameInCorrectCase:t,NodeType:r}=(Cw||(Cw=1,kw.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},kw.shadowRootType=function(e){const t=e.ancestorShadowRoot();return t?t.mode:null},kw.NodeType={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9},kw.ShadowRootTypes={UserAgent:"user-agent",Open:"open",Closed:"closed"}),kw);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}},Iw=s.DOMPath}(),Lw=yw(Dw);class Bw{constructor(t,r=5e3){if(Ow.add(this),this.userContext=null,"undefined"==typeof window&&console.error("Userlens EventCollector error: unavailable outside of browser environment."),"function"!=typeof t)return void console.error("Userlens EventCollector error: callback is not a function.");this.callback=t,this.intervalTime=r;const s=window.localStorage.getItem("userlensEvents");this.events=s?JSON.parse(s):[],e(this,Ow,"m",Mw).call(this),e(this,Ow,"m",Nw).call(this),e(this,Ow,"m",Pw).call(this),this.userContext=e(this,Ow,"m",Aw).call(this)}pushEvent(t){const r={...t,is_raw:!1,properties:{...t.properties,...e(this,Ow,"m",Aw).call(this)}};this.events.push(r),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))}}Ow=new WeakSet,Aw=function(){if(this.userContext)return this.userContext;const e=mw.getParser(window.navigator.userAgent),t=e.getBrowser(),r=e.getOS(),s={$ul_browser:t.name??"Unknown",$ul_browser_version:t.version??"Unknown",$ul_os:r.name??"Unknown",$ul_os_version:r.versionName??"Unknown",$ul_browser_language:navigator.language??"en-US",$ul_browser_language_prefix:navigator.language?.split("-")[0]??"en",$ul_screen_width:window.screen.width,$ul_screen_height:window.screen.height,$ul_viewport_width:window.innerWidth,$ul_viewport_height:window.innerHeight,$ul_current_url: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.21",$ul_device_type:/Mobi|Android/i.test(navigator.userAgent)?"Mobile":"Desktop",$ul_timezone:Intl.DateTimeFormat().resolvedOptions().timeZone};return this.userContext=s,s},Mw=function(){document.body.addEventListener("click",(t=>{e(this,Ow,"m",Ew).call(this,t)}))},Ew=function(t){const r=t.target;if(!(r instanceof Element))return;const s={event:Lw.xPath(r,!0),is_raw:!0,snapshot:e(this,Ow,"m",Rw).call(this,r),current_url:window.location.href,properties:{...e(this,Ow,"m",Aw).call(this)}};this.events.push(s),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))},Rw=function(e){const t=[];let r=e;for(;r&&r!==document.documentElement;){if(!(r instanceof HTMLElement)){r=r.parentElement;continue}const e=r.tagName.toLowerCase(),s=r.classList.length?[...r.classList]:null,n=r.id||null,o=Array.from(r.parentNode?.children||[]).indexOf(r)+1,i=Array.from(r.parentNode?.children||[]).filter((e=>e.tagName===r?.tagName)).indexOf(r)+1,a={};for(let e of r.attributes)a[`attr__${e.name}`]=e.value;const l=t.length<3,c=["a","button","span","label"].includes(e)||"button"===r.getAttribute("role")||null!==r.getAttribute("tabindex")||"function"==typeof r.onclick||r.className&&/btn|button|clickable|cta/.test(r.className),h=l&&c&&r.innerText?.trim()||null;t.unshift({text:h,tag_name:e,attr_class:s,href:r.getAttribute("href"),attr_id:n,nth_child:o,nth_of_type:i,attributes:a}),r=r.parentElement}return t},Nw=function(){setInterval((()=>{if(this.events.length>0){const t=[...this.events];this.callback(t),e(this,Ow,"m",Fw).call(this)}}),this.intervalTime)},Pw=function(){const t=history.pushState,r=history.replaceState;history.pushState=(...r)=>{t.apply(history,r),e(this,Ow,"m",Tw).call(this)},history.replaceState=(...t)=>{r.apply(history,t),e(this,Ow,"m",Tw).call(this)},window.addEventListener("popstate",(()=>e(this,Ow,"m",Tw).call(this)))},Tw=function(){try{const e=new URL(window.location.href);if("localhost"===e?.hostname||"127.0.0.1"===e?.hostname||"::1"===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:e?.origin+e?.pathname||null,$ul_referrer:t||null,$ul_query:r}};this.events.push(s),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))}catch(e){console.warn("Userlens EventCollector error: tracking page view failed")}},Fw=function(){this.events=[],window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))};export{Bw as EventCollector,rw as SessionRecorder};
|
package/dist/userlens.umd.js
CHANGED
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* MIT License | (c) Dustin Diaz 2012-2015
|
|
6
6
|
* MIT License | (c) Denis Demchenko 2015-2019
|
|
7
7
|
*/class mw{static getParser(e,t=!1){if("string"!=typeof e)throw new Error("UserAgent should be a string");return new fw(e,t)}static parse(e){return new fw(e).getResult()}static get BROWSER_MAP(){return nw}static get ENGINE_MAP(){return aw}static get OS_MAP(){return iw}static get PLATFORMS_MAP(){return ow}}var gw="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function yw(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ww,bw={exports:{}},vw=bw.exports;
|
|
8
|
-
/*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */function Sw(){return ww||(ww=1,function(e){!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};e.CSS||(e.CSS={});return e.CSS.escape=t,t}(t)}(void 0!==gw?gw:vw)}(bw)),bw.exports}var Cw,Iw,xw,kw={};var Ow,Aw,Mw,Ew,Rw,Nw,Pw,Tw,Fw,Dw=function(){if(xw)return Iw;xw=1,Sw();const{ShadowRootTypes:e,nodeNameInCorrectCase:t,NodeType:r}=(Cw||(Cw=1,kw.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},kw.shadowRootType=function(e){const t=e.ancestorShadowRoot();return t?t.mode:null},kw.NodeType={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9},kw.ShadowRootTypes={UserAgent:"user-agent",Open:"open",Closed:"closed"}),kw);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}},Iw=s.DOMPath}(),Lw=yw(Dw);Ow=new WeakSet,Aw=function(){const e=mw.getParser(window.navigator.userAgent),t=e.getBrowser(),r=e.getOS(),s={$ul_browser:t.name??"Unknown",$ul_browser_version:t.version??"Unknown",$ul_os:r.name??"Unknown",$ul_os_version:r.versionName??"Unknown",$ul_browser_language:navigator.language??"en-US",$ul_browser_language_prefix:navigator.language?.split("-")[0]??"en",$ul_screen_width:window.screen.width,$ul_screen_height:window.screen.height,$ul_viewport_width:window.innerWidth,$ul_viewport_height:window.innerHeight,$ul_current_url: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.0",$ul_device_type:/Mobi|Android/i.test(navigator.userAgent)?"Mobile":"Desktop",$ul_timezone:Intl.DateTimeFormat().resolvedOptions().timeZone};return this.userContext=s,s},Mw=function(){document.body.addEventListener("click",(e=>{t(this,Ow,"m",Ew).call(this,e)}))},Ew=function(e){const r=e.target;if(!(r instanceof Element))return;const s={event:Lw.xPath(r,!0),is_raw:!0,snapshot:t(this,Ow,"m",Rw).call(this,r),current_url:window.location.href,properties:{...t(this,Ow,"m",Aw).call(this)}};this.events.push(s),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))},Rw=function(e){const t=[];let r=e;for(;r&&r!==document.documentElement;){if(!(r instanceof HTMLElement)){r=r.parentElement;continue}const e=r.tagName.toLowerCase(),s=r.classList.length?[...r.classList]:null,n=r.id||null,o=Array.from(r.parentNode?.children||[]).indexOf(r)+1,i=Array.from(r.parentNode?.children||[]).filter((e=>e.tagName===r?.tagName)).indexOf(r)+1,a={};for(let e of r.attributes)a[`attr__${e.name}`]=e.value;const l=t.length<3,c=["a","button","span","label"].includes(e)||"button"===r.getAttribute("role")||null!==r.getAttribute("tabindex")||"function"==typeof r.onclick||r.className&&/btn|button|clickable|cta/.test(r.className),h=l&&c&&r.innerText?.trim()||null;t.unshift({text:h,tag_name:e,attr_class:s,href:r.getAttribute("href"),attr_id:n,nth_child:o,nth_of_type:i,attributes:a}),r=r.parentElement}return t},Nw=function(){setInterval((()=>{if(this.events.length>0){const e=[...this.events];this.callback(e),t(this,Ow,"m",Fw).call(this)}}),this.intervalTime)},Pw=function(){const e=history.pushState,r=history.replaceState;history.pushState=(...r)=>{e.apply(history,r),t(this,Ow,"m",Tw).call(this)},history.replaceState=(...e)=>{r.apply(history,e),t(this,Ow,"m",Tw).call(this)},window.addEventListener("popstate",(()=>t(this,Ow,"m",Tw).call(this)))},Tw=function(){try{const e=new URL(window.location.href);if("localhost"===e?.hostname||"127.0.0.1"===e?.hostname||"::1"===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:e?.origin+e?.pathname||null,$ul_referrer:t||null,$ul_query:r}};this.events.push(s),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))}catch(e){console.warn("Userlens EventCollector error: tracking page view failed")}},Fw=function(){this.events=[],window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))},e.EventCollector=class{constructor(e,r=5e3){if(Ow.add(this),this.userContext=null,"undefined"==typeof window&&console.error("Userlens EventCollector error: unavailable outside of browser environment."),"function"!=typeof e)return void console.error("Userlens EventCollector error: callback is not a function.");this.callback=e,this.intervalTime=r;const s=window.localStorage.getItem("userlensEvents");this.events=s?JSON.parse(s):[],t(this,Ow,"m",Mw).call(this),t(this,Ow,"m",Nw).call(this),t(this,Ow,"m",Pw).call(this),this.userContext=t(this,Ow,"m",Aw).call(this)}pushEvent(e){const r={...e,is_raw:!1,properties:{...e.properties,...t(this,Ow,"m",Aw).call(this)}};this.events.push(r),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))}},e.SessionRecorder=class{constructor({WRITE_CODE:e,userId:r,recordingOptions:s={}}){if(Jy.add(this),this.sessionEvents=[],this.rrwebControl=null,Xy.set(this,void 0),"undefined"==typeof window&&console.error("Userlens SDK error: unavailable outside of browser environment."),!e?.trim())throw new Error("Userlens SDK Error: WRITE_CODE is required and must be a string");r?.trim()||console.error("Userlens SDK Error: userId is required to identify session user.");const{TIMEOUT:n=18e5,BUFFER_SIZE:o=10,maskingOptions:i=["passwords"]}=s;this.WRITE_CODE=e,this.userId=r,this.TIMEOUT=n,this.BUFFER_SIZE=o,this.maskingOptions=i,this.sessionEvents=[],function(e,t,r,s,n){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===s?n.call(e,r):n?n.value=r:t.set(e,r)}(this,Xy,t(this,Jy,"m",ew).call(this,(()=>{t(this,Jy,"m",tw).call(this)}),5e3),"f"),t(this,Jy,"m",$y).call(this)}},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
8
|
+
/*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */function Sw(){return ww||(ww=1,function(e){!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};e.CSS||(e.CSS={});return e.CSS.escape=t,t}(t)}(void 0!==gw?gw:vw)}(bw)),bw.exports}var Cw,Iw,xw,kw={};var Ow,Aw,Mw,Ew,Rw,Nw,Pw,Tw,Fw,Dw=function(){if(xw)return Iw;xw=1,Sw();const{ShadowRootTypes:e,nodeNameInCorrectCase:t,NodeType:r}=(Cw||(Cw=1,kw.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},kw.shadowRootType=function(e){const t=e.ancestorShadowRoot();return t?t.mode:null},kw.NodeType={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9},kw.ShadowRootTypes={UserAgent:"user-agent",Open:"open",Closed:"closed"}),kw);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}},Iw=s.DOMPath}(),Lw=yw(Dw);Ow=new WeakSet,Aw=function(){if(this.userContext)return this.userContext;const e=mw.getParser(window.navigator.userAgent),t=e.getBrowser(),r=e.getOS(),s={$ul_browser:t.name??"Unknown",$ul_browser_version:t.version??"Unknown",$ul_os:r.name??"Unknown",$ul_os_version:r.versionName??"Unknown",$ul_browser_language:navigator.language??"en-US",$ul_browser_language_prefix:navigator.language?.split("-")[0]??"en",$ul_screen_width:window.screen.width,$ul_screen_height:window.screen.height,$ul_viewport_width:window.innerWidth,$ul_viewport_height:window.innerHeight,$ul_current_url: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.21",$ul_device_type:/Mobi|Android/i.test(navigator.userAgent)?"Mobile":"Desktop",$ul_timezone:Intl.DateTimeFormat().resolvedOptions().timeZone};return this.userContext=s,s},Mw=function(){document.body.addEventListener("click",(e=>{t(this,Ow,"m",Ew).call(this,e)}))},Ew=function(e){const r=e.target;if(!(r instanceof Element))return;const s={event:Lw.xPath(r,!0),is_raw:!0,snapshot:t(this,Ow,"m",Rw).call(this,r),current_url:window.location.href,properties:{...t(this,Ow,"m",Aw).call(this)}};this.events.push(s),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))},Rw=function(e){const t=[];let r=e;for(;r&&r!==document.documentElement;){if(!(r instanceof HTMLElement)){r=r.parentElement;continue}const e=r.tagName.toLowerCase(),s=r.classList.length?[...r.classList]:null,n=r.id||null,o=Array.from(r.parentNode?.children||[]).indexOf(r)+1,i=Array.from(r.parentNode?.children||[]).filter((e=>e.tagName===r?.tagName)).indexOf(r)+1,a={};for(let e of r.attributes)a[`attr__${e.name}`]=e.value;const l=t.length<3,c=["a","button","span","label"].includes(e)||"button"===r.getAttribute("role")||null!==r.getAttribute("tabindex")||"function"==typeof r.onclick||r.className&&/btn|button|clickable|cta/.test(r.className),h=l&&c&&r.innerText?.trim()||null;t.unshift({text:h,tag_name:e,attr_class:s,href:r.getAttribute("href"),attr_id:n,nth_child:o,nth_of_type:i,attributes:a}),r=r.parentElement}return t},Nw=function(){setInterval((()=>{if(this.events.length>0){const e=[...this.events];this.callback(e),t(this,Ow,"m",Fw).call(this)}}),this.intervalTime)},Pw=function(){const e=history.pushState,r=history.replaceState;history.pushState=(...r)=>{e.apply(history,r),t(this,Ow,"m",Tw).call(this)},history.replaceState=(...e)=>{r.apply(history,e),t(this,Ow,"m",Tw).call(this)},window.addEventListener("popstate",(()=>t(this,Ow,"m",Tw).call(this)))},Tw=function(){try{const e=new URL(window.location.href);if("localhost"===e?.hostname||"127.0.0.1"===e?.hostname||"::1"===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:e?.origin+e?.pathname||null,$ul_referrer:t||null,$ul_query:r}};this.events.push(s),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))}catch(e){console.warn("Userlens EventCollector error: tracking page view failed")}},Fw=function(){this.events=[],window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))},e.EventCollector=class{constructor(e,r=5e3){if(Ow.add(this),this.userContext=null,"undefined"==typeof window&&console.error("Userlens EventCollector error: unavailable outside of browser environment."),"function"!=typeof e)return void console.error("Userlens EventCollector error: callback is not a function.");this.callback=e,this.intervalTime=r;const s=window.localStorage.getItem("userlensEvents");this.events=s?JSON.parse(s):[],t(this,Ow,"m",Mw).call(this),t(this,Ow,"m",Nw).call(this),t(this,Ow,"m",Pw).call(this),this.userContext=t(this,Ow,"m",Aw).call(this)}pushEvent(e){const r={...e,is_raw:!1,properties:{...e.properties,...t(this,Ow,"m",Aw).call(this)}};this.events.push(r),window.localStorage.setItem("userlensEvents",JSON.stringify(this.events))}},e.SessionRecorder=class{constructor({WRITE_CODE:e,userId:r,recordingOptions:s={}}){if(Jy.add(this),this.sessionEvents=[],this.rrwebControl=null,Xy.set(this,void 0),"undefined"==typeof window&&console.error("Userlens SDK error: unavailable outside of browser environment."),!e?.trim())throw new Error("Userlens SDK Error: WRITE_CODE is required and must be a string");r?.trim()||console.error("Userlens SDK Error: userId is required to identify session user.");const{TIMEOUT:n=18e5,BUFFER_SIZE:o=10,maskingOptions:i=["passwords"]}=s;this.WRITE_CODE=e,this.userId=r,this.TIMEOUT=n,this.BUFFER_SIZE=o,this.maskingOptions=i,this.sessionEvents=[],function(e,t,r,s,n){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");"a"===s?n.call(e,r):n?n.value=r:t.set(e,r)}(this,Xy,t(this,Jy,"m",ew).call(this,(()=>{t(this,Jy,"m",tw).call(this)}),5e3),"f"),t(this,Jy,"m",$y).call(this)}},Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -59,6 +59,10 @@ export default class EventCollector {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
#getUserContext(): UserContext {
|
|
62
|
+
if (this.userContext) {
|
|
63
|
+
return this.userContext;
|
|
64
|
+
}
|
|
65
|
+
|
|
62
66
|
const browser = Bowser.getParser(window.navigator.userAgent);
|
|
63
67
|
const info = browser.getBrowser();
|
|
64
68
|
const os = browser.getOS();
|
|
@@ -82,7 +86,7 @@ export default class EventCollector {
|
|
|
82
86
|
? new URL(document.referrer).hostname
|
|
83
87
|
: "$direct",
|
|
84
88
|
$ul_lib: "userlens.js",
|
|
85
|
-
$ul_lib_version: "0.1.
|
|
89
|
+
$ul_lib_version: "0.1.21",
|
|
86
90
|
$ul_device_type: /Mobi|Android/i.test(navigator.userAgent)
|
|
87
91
|
? "Mobile"
|
|
88
92
|
: "Desktop",
|