userlens-analytics-sdk 0.1.69 → 0.1.71
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/README.md +117 -10
- package/dist/main.cjs.js +1 -1
- package/dist/main.esm.js +1 -1
- package/dist/react.cjs.js +1 -1
- package/dist/react.cjs.js.map +1 -1
- package/dist/react.esm.js +1 -1
- package/dist/react.esm.js.map +1 -1
- package/dist/userlens.umd.js +1 -1
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -20,7 +20,14 @@ Powerful and lightweight event tracking + session replay SDK for web apps. Works
|
|
|
20
20
|
- [📌 Tracking Custom Events](#️-tracking-custom-events)
|
|
21
21
|
- [✍️ Example](#️-example)
|
|
22
22
|
- [🧠 How it works](#-how-it-works)
|
|
23
|
-
- [
|
|
23
|
+
- [🛰 API Documentation](#-api-documentation)
|
|
24
|
+
- [🔐 Authentication](#-authentication)
|
|
25
|
+
- [🧭 Endpoint](#-endpoint)
|
|
26
|
+
- [1. Identify](#1-identify)
|
|
27
|
+
- [2. Group](#2-group)
|
|
28
|
+
- [3. Track](#3-track)
|
|
29
|
+
- [🔄 Sending Raw Events (from EventCollector)](#-sending-raw-events-from-eventcollector)
|
|
30
|
+
|
|
24
31
|
|
|
25
32
|
## 📘 Introduction
|
|
26
33
|
|
|
@@ -87,15 +94,6 @@ const router = express.Router();
|
|
|
87
94
|
/**
|
|
88
95
|
* Your WRITE_CODE — retrieve it from:
|
|
89
96
|
* 👉 https://app.userlens.io/settings/userlens-sdk
|
|
90
|
-
*
|
|
91
|
-
* Before using it as an Authorization header:
|
|
92
|
-
* 1. Append a colon (`:`) at the end of the string
|
|
93
|
-
* 2. Base64 encode the result
|
|
94
|
-
*
|
|
95
|
-
* Example:
|
|
96
|
-
* const raw = "your_write_code:";
|
|
97
|
-
* const encoded = Buffer.from(raw).toString("base64");
|
|
98
|
-
* → use that as the value for Authorization: `Basic ${encoded}`
|
|
99
97
|
*/
|
|
100
98
|
const WRITE_CODE = process.env.USERLENS_WRITE_CODE!;
|
|
101
99
|
|
|
@@ -364,3 +362,112 @@ if (collector) {
|
|
|
364
362
|
collector.pushEvent({ event: "Something" });
|
|
365
363
|
}
|
|
366
364
|
```
|
|
365
|
+
|
|
366
|
+
### 🛰 API Documentation
|
|
367
|
+
|
|
368
|
+
As an alternative to using `userlens-analytics-sdk`, you can implement event tracking manually via our HTTP API.
|
|
369
|
+
|
|
370
|
+
---
|
|
371
|
+
|
|
372
|
+
#### 🔐 Authentication
|
|
373
|
+
|
|
374
|
+
All requests must include a **write code** in the `Authorization` header.
|
|
375
|
+
|
|
376
|
+
You can retrieve your write code at:
|
|
377
|
+
👉 [https://app.userlens.io/settings/userlens-sdk](https://app.userlens.io/settings/userlens-sdk)
|
|
378
|
+
|
|
379
|
+
---
|
|
380
|
+
|
|
381
|
+
#### 🧭 Endpoint
|
|
382
|
+
|
|
383
|
+
All standard requests go to:
|
|
384
|
+
|
|
385
|
+
```
|
|
386
|
+
POST https://events.userlens.io/event
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
You can send three types of calls:
|
|
390
|
+
|
|
391
|
+
---
|
|
392
|
+
|
|
393
|
+
##### 1. Identify
|
|
394
|
+
|
|
395
|
+
Keeps user traits up to date.
|
|
396
|
+
|
|
397
|
+
```ts
|
|
398
|
+
const body = {
|
|
399
|
+
type: "identify",
|
|
400
|
+
userId, // string
|
|
401
|
+
source: "userlens-restapi",
|
|
402
|
+
traits, // object with user info (e.g. email, name, etc.)
|
|
403
|
+
};
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
> `traits` is a free-form object — add any relevant user properties.
|
|
407
|
+
|
|
408
|
+
---
|
|
409
|
+
|
|
410
|
+
##### 2. Group
|
|
411
|
+
|
|
412
|
+
Updates company or organization traits.
|
|
413
|
+
|
|
414
|
+
```ts
|
|
415
|
+
const body = {
|
|
416
|
+
type: "group",
|
|
417
|
+
groupId, // string
|
|
418
|
+
userId, // string (required for association)
|
|
419
|
+
source: "userlens-restapi",
|
|
420
|
+
traits, // object with company info
|
|
421
|
+
};
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
---
|
|
425
|
+
|
|
426
|
+
##### 3. Track
|
|
427
|
+
|
|
428
|
+
Sends a single custom event.
|
|
429
|
+
|
|
430
|
+
```ts
|
|
431
|
+
const body = {
|
|
432
|
+
type: "track",
|
|
433
|
+
userId, // string
|
|
434
|
+
source: "userlens-restapi",
|
|
435
|
+
event: "button-clicked", // event name
|
|
436
|
+
properties: {
|
|
437
|
+
color: "red", // optional metadata
|
|
438
|
+
},
|
|
439
|
+
};
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
---
|
|
443
|
+
|
|
444
|
+
#### 🔄 Sending Raw Events (from EventCollector)
|
|
445
|
+
|
|
446
|
+
If you're forwarding events collected by `EventCollector`, send them to:
|
|
447
|
+
|
|
448
|
+
```
|
|
449
|
+
POST https://raw.userlens.io/raw/event
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
Payload format:
|
|
453
|
+
|
|
454
|
+
```ts
|
|
455
|
+
const body = {
|
|
456
|
+
events: [
|
|
457
|
+
{
|
|
458
|
+
event: "input-change",
|
|
459
|
+
is_raw: true,
|
|
460
|
+
snapshot: [], // DOM snapshot (optional)
|
|
461
|
+
properties: {}, // metadata
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
event: "form-submitted",
|
|
465
|
+
is_raw: false, // explicitly pushed via pushEvent()
|
|
466
|
+
properties: {},
|
|
467
|
+
},
|
|
468
|
+
],
|
|
469
|
+
};
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
✅ Use this for sending batched autocollected + custom events.
|
|
473
|
+
|
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 Cw{static getParser(e,t=!1){if("string"!=typeof e)throw new Error("UserAgent should be a string");return new Sw(e,t)}static parse(e){return new Sw(e).getResult()}static get BROWSER_MAP(){return uw}static get ENGINE_MAP(){return fw}static get OS_MAP(){return dw}static get PLATFORMS_MAP(){return pw}}var Iw="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function xw(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var kw,Ow={exports:{}},Mw=Ow.exports;
|
|
8
|
-
/*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */function Aw(){return kw||(kw=1,e=Ow,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,i="",o=r.charCodeAt(0);++n<s;)0!=(t=r.charCodeAt(n))?i+=t>=1&&t<=31||127==t||0==n&&t>=48&&t<=57||1==n&&t>=48&&t<=57&&45==o?"\\"+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):i+="�";return i};return e.CSS||(e.CSS={}),e.CSS.escape=t,t}(t)}(void 0!==Iw?Iw:Mw)),Ow.exports;var e}var Ew,Rw,Nw,Tw={};var Pw,Fw,Dw,Lw,Bw,_w,Uw,jw,zw,Ww,Vw,Gw,Zw,Yw,Jw,$w,Xw,Hw,Kw=function(){if(Nw)return Rw;Nw=1,Aw();const{ShadowRootTypes:e,nodeNameInCorrectCase:t,NodeType:r}=(Ew||(Ew=1,Tw.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},Tw.shadowRootType=function(e){const t=e.ancestorShadowRoot();return t?t.mode:null},Tw.NodeType={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9},Tw.ShadowRootTypes={UserAgent:"user-agent",Open:"open",Closed:"closed"}),Tw);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 i=e;for(;i;){const r=s.DOMPath._cssPathStep(i,!!t,i===e);if(!r)break;if(n.push(r),r.optimized)break;i=i.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 i=e;for(;i;)n.push(s.DOMPath.cssPath(i,t)),i=i.shadowRoot&&i.shadowRoot.host;n.reverse();let o="";for(let e=0;e<n.length;++e){const t=JSON.stringify(n[e]);o+=e?`.shadowRoot.querySelector(${t})`:`document.querySelector(${t})`}return o},s.DOMPath._cssPathStep=function(e,n,i){if(e.nodeType!==r.ELEMENT_NODE)return null;const o=e.getAttribute("id");if(n){if(o)return new s.DOMPath.Step(h(o),!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(o)return new s.DOMPath.Step(a+h(o),!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 i=new Set(u);if(!i.size){d=!0;continue}const o=c(n);for(let e=0;e<o.length;++e){const t=o[e];if(i.has(t)&&(i.delete(t),!i.size)){d=!0;break}}}let y=a;if(i&&"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 i=e;for(;i;){const e=s.DOMPath._xPathValue(i,t);if(!e)break;if(n.push(e),e.optimized)break;i=i.parentNode}return n.reverse(),(n.length&&n[0].optimized?"":"/")+n.join("/")},s.DOMPath._xPathValue=function(e,t){let n;const i=s.DOMPath._xPathIndex(e);if(-1===i)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 i>0&&(n+="["+i+"]"),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 i=1;for(let r=0;r<s.length;++r)if(t(e,s[r])){if(s[r]===e)return i;++i}return-1},s.DOMPath.Step=class{constructor(e,t){this.value=e,this.optimized=t||!1}toString(){return this.value}},Rw=s.DOMPath}(),Qw=xw(Kw);Fw=new WeakMap,Dw=new WeakMap,Lw=new WeakMap,Bw=new WeakMap,_w=new WeakMap,Yw=new WeakMap,Pw=new WeakSet,Uw=function(){document.body.addEventListener("click",e(this,Bw,"f"))},jw=function(t){try{const r=t.target;if(!(r instanceof HTMLElement))return;const s=Qw.xPath(r,!0),n=e(this,Pw,"m",zw).call(this,r),i={event:s,is_raw:!0,snapshot:n?[n]:[],properties:{...this.getUserContext(),...this.getPageMetadata()}};this.userId&&(i.userId=this.userId),this.events.push(i),this.events.length>100&&(this.events=this.events.slice(-100))}catch(e){}},zw=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,i=null;for(let t=0;t<r.length;t++){const s=r[t],o=t>=r.length-3,a=t===r.length-1,l=e(this,Pw,"m",Ww).call(this,s,{isTarget:a,leadsToTarget:!0});let c=[l];if(o&&s.parentElement){c=[l,...Array.from(s.parentElement.children).filter(e=>e!==s&&e instanceof HTMLElement).map(t=>e(this,Pw,"m",Ww).call(this,t,{includeChildren:!0})).filter(Boolean)]}n||(n=l),i&&(i.children||(i.children=[]),i.children.push(...c)),i=l}return n},Ww=function t(r,{isTarget:s=!1,includeChildren:n=!1,leadsToTarget:i=!1}={}){var o,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===(o=r.parentNode)||void 0===o?void 0:o.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,nth_child:p,nth_of_type:d,attributes:f,...c?{attr_class:c}:{},...h?{attr_id:h}:{},...u?{href:u}:{},...g?{text:g}:{},...s?{is_target:!0}:{},...i&&!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,Pw,"m",t).call(this,r,{includeChildren:!0})).filter(Boolean)),y},Vw=function(){t(this,Fw,setInterval(()=>{e(this,Yw,"f").call(this)},this.intervalTime),"f")},Gw=function(){t(this,Dw,history.pushState,"f"),t(this,Lw,history.replaceState,"f"),history.pushState=(...t)=>{e(this,Dw,"f").apply(history,t),e(this,Pw,"m",Zw).call(this)},history.replaceState=(...t)=>{e(this,Lw,"f").apply(history,t),e(this,Pw,"m",Zw).call(this)},window.addEventListener("popstate",e(this,_w,"f"))},Zw=function(){if(function(){if("undefined"==typeof window)return!1;const e=window.location.hostname;return"localhost"===e||"127.0.0.1"===e||"::1"===e||e.endsWith(".localhost")}())return;const e={event:"$ul_pageview",properties:this.getPageMetadata()};this.userId&&(e.userId=this.userId),this.events.push(e)},Jw=function(){this.events=[]},$w=function(){document.body.removeEventListener("click",e(this,Bw,"f"))},Xw=function(){e(this,Yw,"f").call(this),clearInterval(e(this,Fw,"f")),e(this,Pw,"m",Jw).call(this)},Hw=function(){history.pushState=e(this,Dw,"f"),history.replaceState=e(this,Lw,"f"),window.removeEventListener("popstate",e(this,_w,"f"))},exports.EventCollector=class{constructor(t){if(Pw.add(this),this.userContext=null,Fw.set(this,void 0),Dw.set(this,void 0),Lw.set(this,void 0),Bw.set(this,e(this,Pw,"m",jw).bind(this)),_w.set(this,e(this,Pw,"m",Zw).bind(this)),Yw.set(this,()=>{if(0===this.events.length)return;const t=[...this.events];if(this.callback){try{this.callback(t)}catch(e){}e(this,Pw,"m",Jw).call(this)}else Promise.allSettled([this.userId&&this.userTraits?Xy({userId:this.userId,traits:this.userTraits}):null,Hy(t)]),e(this,Pw,"m",Jw).call(this)}),"undefined"==typeof window)return;const{userId:r,WRITE_CODE:s,callback:n,intervalTime:i=5e3,skipRawEvents:o=!1}=t,a=t.userTraits;this.autoUploadModeEnabled=!n,this.autoUploadModeEnabled&&!(null==r?void 0:r.length)||this.autoUploadModeEnabled&&!(null==s?void 0:s.length)||(this.autoUploadModeEnabled&&Ky(s),(this.autoUploadModeEnabled||"function"==typeof n)&&(this.userId=r,this.userTraits="object"==typeof a&&null!==a?a:{},this.callback=n,this.intervalTime=i,this.events=[],o||(e(this,Pw,"m",Uw).call(this),e(this,Pw,"m",Gw).call(this)),e(this,Pw,"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.getPageMetadata()}};this.userId&&(t.userId=this.userId),this.events.push(t)}identify(e,t){return Xy({userId:e,traits:t})}group(e,t){return(async e=>{if(!(null==e?void 0:e.groupId))return;const{groupId:t,traits:r,userId:s}=e,n={type:"group",groupId:t,...s&&{userId:s},source:"userlens-js-analytics-sdk",traits:r};if(!(await fetch(`${Jy}/event`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Basic ${$y()}`},body:JSON.stringify(n)})).ok)throw new Error("Userlens HTTP error: failed to identify");return"ok"})({groupId:e,traits:t,userId:this.userId})}updateUserTraits(e){this.userTraits=e}stop(){e(this,Pw,"m",$w).call(this),e(this,Pw,"m",Xw).call(this),e(this,Pw,"m",Hw).call(this)}getUserContext(){var e,t,r,s,n,i,o;if(this.userContext)return this.userContext;const a=Cw.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!==(o=null===(i=navigator.language)||void 0===i?void 0:i.split("-")[0])&&void 0!==o?o:"en",$ul_screen_width:window.screen.width,$ul_screen_height:window.screen.height,$ul_viewport_width:window.innerWidth,$ul_viewport_height:window.innerHeight,$ul_lib:"userlens.js",$ul_lib_version:"0.1.69",$ul_device_type:/Mobi|Android/i.test(navigator.userAgent)?"Mobile":"Desktop",$ul_timezone:Intl.DateTimeFormat().resolvedOptions().timeZone};return this.userContext=h,h}getPageMetadata(){try{const e=new URL(window.location.href);let t=document.referrer||"$direct",r="$direct";try{t&&/^https?:\/\//.test(t)&&(r=new URL(t).hostname)}catch(e){}const s=e.search.slice(1);return{$ul_page:e.origin+e.pathname,$ul_pathname:e.pathname,$ul_host:e.host,$ul_referrer:t,$ul_referring_domain:r,$ul_query:s}}catch(e){return{$ul_page:"",$ul_pathname:"",$ul_host:"",$ul_referrer:"",$ul_referring_domain:"",$ul_query:""}}}},exports.SessionRecorder=class{constructor({WRITE_CODE:r,userId:s,recordingOptions:n={}}){if(Qy.add(this),this.sessionEvents=[],this.rrwebStop=null,qy.set(this,void 0),nw.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:i=18e5,BUFFER_SIZE:o=10,maskingOptions:a=["passwords"]}=n;if("string"!=typeof r)throw new Error("WRITE_CODE must be a string to base64 encode it");Ky(r),this.userId=s,this.TIMEOUT=i,this.BUFFER_SIZE=o,this.maskingOptions=a,this.sessionEvents=[],t(this,qy,e(this,Qy,"m",ow).call(this,()=>{e(this,Qy,"m",aw).call(this)},5e3),"f"),e(this,Qy,"m",ew).call(this)}stop(){this.rrwebStop&&(this.rrwebStop(),this.rrwebStop=null,e(this,Qy,"m",lw).call(this),e(this,Qy,"m",cw).call(this),window.removeEventListener("visibilitychange",e(this,nw,"f")))}};
|
|
8
|
+
/*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */function Aw(){return kw||(kw=1,e=Ow,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,i="",o=r.charCodeAt(0);++n<s;)0!=(t=r.charCodeAt(n))?i+=t>=1&&t<=31||127==t||0==n&&t>=48&&t<=57||1==n&&t>=48&&t<=57&&45==o?"\\"+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):i+="�";return i};return e.CSS||(e.CSS={}),e.CSS.escape=t,t}(t)}(void 0!==Iw?Iw:Mw)),Ow.exports;var e}var Ew,Rw,Nw,Tw={};var Pw,Fw,Dw,Lw,Bw,_w,Uw,jw,zw,Ww,Vw,Gw,Zw,Yw,Jw,$w,Xw,Hw,Kw=function(){if(Nw)return Rw;Nw=1,Aw();const{ShadowRootTypes:e,nodeNameInCorrectCase:t,NodeType:r}=(Ew||(Ew=1,Tw.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},Tw.shadowRootType=function(e){const t=e.ancestorShadowRoot();return t?t.mode:null},Tw.NodeType={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9},Tw.ShadowRootTypes={UserAgent:"user-agent",Open:"open",Closed:"closed"}),Tw);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 i=e;for(;i;){const r=s.DOMPath._cssPathStep(i,!!t,i===e);if(!r)break;if(n.push(r),r.optimized)break;i=i.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 i=e;for(;i;)n.push(s.DOMPath.cssPath(i,t)),i=i.shadowRoot&&i.shadowRoot.host;n.reverse();let o="";for(let e=0;e<n.length;++e){const t=JSON.stringify(n[e]);o+=e?`.shadowRoot.querySelector(${t})`:`document.querySelector(${t})`}return o},s.DOMPath._cssPathStep=function(e,n,i){if(e.nodeType!==r.ELEMENT_NODE)return null;const o=e.getAttribute("id");if(n){if(o)return new s.DOMPath.Step(h(o),!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(o)return new s.DOMPath.Step(a+h(o),!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 i=new Set(u);if(!i.size){d=!0;continue}const o=c(n);for(let e=0;e<o.length;++e){const t=o[e];if(i.has(t)&&(i.delete(t),!i.size)){d=!0;break}}}let y=a;if(i&&"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 i=e;for(;i;){const e=s.DOMPath._xPathValue(i,t);if(!e)break;if(n.push(e),e.optimized)break;i=i.parentNode}return n.reverse(),(n.length&&n[0].optimized?"":"/")+n.join("/")},s.DOMPath._xPathValue=function(e,t){let n;const i=s.DOMPath._xPathIndex(e);if(-1===i)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 i>0&&(n+="["+i+"]"),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 i=1;for(let r=0;r<s.length;++r)if(t(e,s[r])){if(s[r]===e)return i;++i}return-1},s.DOMPath.Step=class{constructor(e,t){this.value=e,this.optimized=t||!1}toString(){return this.value}},Rw=s.DOMPath}(),Qw=xw(Kw);Fw=new WeakMap,Dw=new WeakMap,Lw=new WeakMap,Bw=new WeakMap,_w=new WeakMap,Yw=new WeakMap,Pw=new WeakSet,Uw=function(){document.body.addEventListener("click",e(this,Bw,"f"))},jw=function(t){try{const r=t.target;if(!(r instanceof HTMLElement))return;const s=Qw.xPath(r,!0),n=e(this,Pw,"m",zw).call(this,r),i={event:s,is_raw:!0,snapshot:n?[n]:[],properties:{...this.getUserContext(),...this.getPageMetadata()}};this.userId&&(i.userId=this.userId),this.events.push(i),this.events.length>100&&(this.events=this.events.slice(-100))}catch(e){}},zw=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,i=null;for(let t=0;t<r.length;t++){const s=r[t],o=t>=r.length-3,a=t===r.length-1,l=e(this,Pw,"m",Ww).call(this,s,{isTarget:a,leadsToTarget:!0});let c=[l];if(o&&s.parentElement){c=[l,...Array.from(s.parentElement.children).filter(e=>e!==s&&e instanceof HTMLElement).map(t=>e(this,Pw,"m",Ww).call(this,t,{includeChildren:!0})).filter(Boolean)]}n||(n=l),i&&(i.children||(i.children=[]),i.children.push(...c)),i=l}return n},Ww=function t(r,{isTarget:s=!1,includeChildren:n=!1,leadsToTarget:i=!1}={}){var o,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===(o=r.parentNode)||void 0===o?void 0:o.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,nth_child:p,nth_of_type:d,attributes:f,...c?{attr_class:c}:{},...h?{attr_id:h}:{},...u?{href:u}:{},...g?{text:g}:{},...s?{is_target:!0}:{},...i&&!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,Pw,"m",t).call(this,r,{includeChildren:!0})).filter(Boolean)),y},Vw=function(){t(this,Fw,setInterval(()=>{e(this,Yw,"f").call(this)},this.intervalTime),"f")},Gw=function(){t(this,Dw,history.pushState,"f"),t(this,Lw,history.replaceState,"f"),history.pushState=(...t)=>{e(this,Dw,"f").apply(history,t),e(this,Pw,"m",Zw).call(this)},history.replaceState=(...t)=>{e(this,Lw,"f").apply(history,t),e(this,Pw,"m",Zw).call(this)},window.addEventListener("popstate",e(this,_w,"f"))},Zw=function(){if(function(){if("undefined"==typeof window)return!1;const e=window.location.hostname;return"localhost"===e||"127.0.0.1"===e||"::1"===e||e.endsWith(".localhost")}())return;const e={event:"$ul_pageview",properties:this.getPageMetadata()};this.userId&&(e.userId=this.userId),this.events.push(e)},Jw=function(){this.events=[]},$w=function(){document.body.removeEventListener("click",e(this,Bw,"f"))},Xw=function(){e(this,Yw,"f").call(this),clearInterval(e(this,Fw,"f")),e(this,Pw,"m",Jw).call(this)},Hw=function(){history.pushState=e(this,Dw,"f"),history.replaceState=e(this,Lw,"f"),window.removeEventListener("popstate",e(this,_w,"f"))},exports.EventCollector=class{constructor(t){if(Pw.add(this),this.userContext=null,Fw.set(this,void 0),Dw.set(this,void 0),Lw.set(this,void 0),Bw.set(this,e(this,Pw,"m",jw).bind(this)),_w.set(this,e(this,Pw,"m",Zw).bind(this)),Yw.set(this,()=>{if(0===this.events.length)return;const t=[...this.events];if(this.callback){try{this.callback(t)}catch(e){}e(this,Pw,"m",Jw).call(this)}else Promise.allSettled([this.userId&&this.userTraits?Xy({userId:this.userId,traits:this.userTraits}):null,Hy(t)]),e(this,Pw,"m",Jw).call(this)}),"undefined"==typeof window)return;const{userId:r,WRITE_CODE:s,callback:n,intervalTime:i=5e3,skipRawEvents:o=!1}=t,a=t.userTraits;this.autoUploadModeEnabled=!n,this.autoUploadModeEnabled&&!(null==r?void 0:r.length)||this.autoUploadModeEnabled&&!(null==s?void 0:s.length)||(this.autoUploadModeEnabled&&Ky(s),(this.autoUploadModeEnabled||"function"==typeof n)&&(this.userId=r,this.userTraits="object"==typeof a&&null!==a?a:{},this.callback=n,this.intervalTime=i,this.events=[],o||(e(this,Pw,"m",Uw).call(this),e(this,Pw,"m",Gw).call(this)),e(this,Pw,"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.getPageMetadata()}};this.userId&&(t.userId=this.userId),this.events.push(t)}identify(e,t){return Xy({userId:e,traits:t})}group(e,t){return(async e=>{if(!(null==e?void 0:e.groupId))return;const{groupId:t,traits:r,userId:s}=e,n={type:"group",groupId:t,...s&&{userId:s},source:"userlens-js-analytics-sdk",traits:r};if(!(await fetch(`${Jy}/event`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Basic ${$y()}`},body:JSON.stringify(n)})).ok)throw new Error("Userlens HTTP error: failed to identify");return"ok"})({groupId:e,traits:t,userId:this.userId})}updateUserTraits(e){this.userTraits=e}stop(){e(this,Pw,"m",$w).call(this),e(this,Pw,"m",Xw).call(this),e(this,Pw,"m",Hw).call(this)}getUserContext(){var e,t,r,s,n,i,o;if(this.userContext)return this.userContext;const a=Cw.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!==(o=null===(i=navigator.language)||void 0===i?void 0:i.split("-")[0])&&void 0!==o?o:"en",$ul_screen_width:window.screen.width,$ul_screen_height:window.screen.height,$ul_viewport_width:window.innerWidth,$ul_viewport_height:window.innerHeight,$ul_lib:"userlens.js",$ul_lib_version:"0.1.71",$ul_device_type:/Mobi|Android/i.test(navigator.userAgent)?"Mobile":"Desktop",$ul_timezone:Intl.DateTimeFormat().resolvedOptions().timeZone};return this.userContext=h,h}getPageMetadata(){try{const e=new URL(window.location.href);let t=document.referrer||"$direct",r="$direct";try{t&&/^https?:\/\//.test(t)&&(r=new URL(t).hostname)}catch(e){}const s=e.search.slice(1);return{$ul_page:e.origin+e.pathname,$ul_pathname:e.pathname,$ul_host:e.host,$ul_referrer:t,$ul_referring_domain:r,$ul_query:s}}catch(e){return{$ul_page:"",$ul_pathname:"",$ul_host:"",$ul_referrer:"",$ul_referring_domain:"",$ul_query:""}}}},exports.SessionRecorder=class{constructor({WRITE_CODE:r,userId:s,recordingOptions:n={}}){if(Qy.add(this),this.sessionEvents=[],this.rrwebStop=null,qy.set(this,void 0),nw.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:i=18e5,BUFFER_SIZE:o=10,maskingOptions:a=["passwords"]}=n;if("string"!=typeof r)throw new Error("WRITE_CODE must be a string to base64 encode it");Ky(r),this.userId=s,this.TIMEOUT=i,this.BUFFER_SIZE=o,this.maskingOptions=a,this.sessionEvents=[],t(this,qy,e(this,Qy,"m",ow).call(this,()=>{e(this,Qy,"m",aw).call(this)},5e3),"f"),e(this,Qy,"m",ew).call(this)}stop(){this.rrwebStop&&(this.rrwebStop(),this.rrwebStop=null,e(this,Qy,"m",lw).call(this),e(this,Qy,"m",cw).call(this),window.removeEventListener("visibilitychange",e(this,nw,"f")))}};
|
|
9
9
|
//# sourceMappingURL=main.cjs.js.map
|
package/dist/main.esm.js
CHANGED
|
@@ -5,5 +5,5 @@ 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 Iw{static getParser(e,t=!1){if("string"!=typeof e)throw new Error("UserAgent should be a string");return new Cw(e,t)}static parse(e){return new Cw(e).getResult()}static get BROWSER_MAP(){return pw}static get ENGINE_MAP(){return mw}static get OS_MAP(){return fw}static get PLATFORMS_MAP(){return dw}}var xw="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function kw(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Ow,Mw={exports:{}},Aw=Mw.exports;
|
|
8
|
-
/*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */function Ew(){return Ow||(Ow=1,e=Mw,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,i="",o=r.charCodeAt(0);++n<s;)0!=(t=r.charCodeAt(n))?i+=t>=1&&t<=31||127==t||0==n&&t>=48&&t<=57||1==n&&t>=48&&t<=57&&45==o?"\\"+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):i+="�";return i};return e.CSS||(e.CSS={}),e.CSS.escape=t,t}(t)}(void 0!==xw?xw:Aw)),Mw.exports;var e}var Rw,Nw,Tw,Pw={};var Fw,Dw,Lw,Bw,_w,Uw,jw,zw,Ww,Vw,Gw,Zw,Yw,Jw,$w,Xw,Hw,Kw,Qw=function(){if(Tw)return Nw;Tw=1,Ew();const{ShadowRootTypes:e,nodeNameInCorrectCase:t,NodeType:r}=(Rw||(Rw=1,Pw.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},Pw.shadowRootType=function(e){const t=e.ancestorShadowRoot();return t?t.mode:null},Pw.NodeType={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9},Pw.ShadowRootTypes={UserAgent:"user-agent",Open:"open",Closed:"closed"}),Pw);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 i=e;for(;i;){const r=s.DOMPath._cssPathStep(i,!!t,i===e);if(!r)break;if(n.push(r),r.optimized)break;i=i.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 i=e;for(;i;)n.push(s.DOMPath.cssPath(i,t)),i=i.shadowRoot&&i.shadowRoot.host;n.reverse();let o="";for(let e=0;e<n.length;++e){const t=JSON.stringify(n[e]);o+=e?`.shadowRoot.querySelector(${t})`:`document.querySelector(${t})`}return o},s.DOMPath._cssPathStep=function(e,n,i){if(e.nodeType!==r.ELEMENT_NODE)return null;const o=e.getAttribute("id");if(n){if(o)return new s.DOMPath.Step(h(o),!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(o)return new s.DOMPath.Step(a+h(o),!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 i=new Set(u);if(!i.size){d=!0;continue}const o=c(n);for(let e=0;e<o.length;++e){const t=o[e];if(i.has(t)&&(i.delete(t),!i.size)){d=!0;break}}}let y=a;if(i&&"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 i=e;for(;i;){const e=s.DOMPath._xPathValue(i,t);if(!e)break;if(n.push(e),e.optimized)break;i=i.parentNode}return n.reverse(),(n.length&&n[0].optimized?"":"/")+n.join("/")},s.DOMPath._xPathValue=function(e,t){let n;const i=s.DOMPath._xPathIndex(e);if(-1===i)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 i>0&&(n+="["+i+"]"),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 i=1;for(let r=0;r<s.length;++r)if(t(e,s[r])){if(s[r]===e)return i;++i}return-1},s.DOMPath.Step=class{constructor(e,t){this.value=e,this.optimized=t||!1}toString(){return this.value}},Nw=s.DOMPath}(),qw=kw(Qw);class eb{constructor(t){if(Fw.add(this),this.userContext=null,Dw.set(this,void 0),Lw.set(this,void 0),Bw.set(this,void 0),_w.set(this,e(this,Fw,"m",zw).bind(this)),Uw.set(this,e(this,Fw,"m",Yw).bind(this)),Jw.set(this,()=>{if(0===this.events.length)return;const t=[...this.events];if(this.callback){try{this.callback(t)}catch(e){}e(this,Fw,"m",$w).call(this)}else Promise.allSettled([this.userId&&this.userTraits?Xy({userId:this.userId,traits:this.userTraits}):null,Hy(t)]),e(this,Fw,"m",$w).call(this)}),"undefined"==typeof window)return;const{userId:r,WRITE_CODE:s,callback:n,intervalTime:i=5e3,skipRawEvents:o=!1}=t,a=t.userTraits;this.autoUploadModeEnabled=!n,this.autoUploadModeEnabled&&!(null==r?void 0:r.length)||this.autoUploadModeEnabled&&!(null==s?void 0:s.length)||(this.autoUploadModeEnabled&&Ky(s),(this.autoUploadModeEnabled||"function"==typeof n)&&(this.userId=r,this.userTraits="object"==typeof a&&null!==a?a:{},this.callback=n,this.intervalTime=i,this.events=[],o||(e(this,Fw,"m",jw).call(this),e(this,Fw,"m",Zw).call(this)),e(this,Fw,"m",Gw).call(this),this.userContext=this.getUserContext()))}pushEvent(e){const t={is_raw:!1,...e,properties:{...null==e?void 0:e.properties,...this.getUserContext(),...this.getPageMetadata()}};this.userId&&(t.userId=this.userId),this.events.push(t)}identify(e,t){return Xy({userId:e,traits:t})}group(e,t){return(async e=>{if(!(null==e?void 0:e.groupId))return;const{groupId:t,traits:r,userId:s}=e,n={type:"group",groupId:t,...s&&{userId:s},source:"userlens-js-analytics-sdk",traits:r};if(!(await fetch(`${Jy}/event`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Basic ${$y()}`},body:JSON.stringify(n)})).ok)throw new Error("Userlens HTTP error: failed to identify");return"ok"})({groupId:e,traits:t,userId:this.userId})}updateUserTraits(e){this.userTraits=e}stop(){e(this,Fw,"m",Xw).call(this),e(this,Fw,"m",Hw).call(this),e(this,Fw,"m",Kw).call(this)}getUserContext(){var e,t,r,s,n,i,o;if(this.userContext)return this.userContext;const a=Iw.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!==(o=null===(i=navigator.language)||void 0===i?void 0:i.split("-")[0])&&void 0!==o?o:"en",$ul_screen_width:window.screen.width,$ul_screen_height:window.screen.height,$ul_viewport_width:window.innerWidth,$ul_viewport_height:window.innerHeight,$ul_lib:"userlens.js",$ul_lib_version:"0.1.69",$ul_device_type:/Mobi|Android/i.test(navigator.userAgent)?"Mobile":"Desktop",$ul_timezone:Intl.DateTimeFormat().resolvedOptions().timeZone};return this.userContext=h,h}getPageMetadata(){try{const e=new URL(window.location.href);let t=document.referrer||"$direct",r="$direct";try{t&&/^https?:\/\//.test(t)&&(r=new URL(t).hostname)}catch(e){}const s=e.search.slice(1);return{$ul_page:e.origin+e.pathname,$ul_pathname:e.pathname,$ul_host:e.host,$ul_referrer:t,$ul_referring_domain:r,$ul_query:s}}catch(e){return{$ul_page:"",$ul_pathname:"",$ul_host:"",$ul_referrer:"",$ul_referring_domain:"",$ul_query:""}}}}Dw=new WeakMap,Lw=new WeakMap,Bw=new WeakMap,_w=new WeakMap,Uw=new WeakMap,Jw=new WeakMap,Fw=new WeakSet,jw=function(){document.body.addEventListener("click",e(this,_w,"f"))},zw=function(t){try{const r=t.target;if(!(r instanceof HTMLElement))return;const s=qw.xPath(r,!0),n=e(this,Fw,"m",Ww).call(this,r),i={event:s,is_raw:!0,snapshot:n?[n]:[],properties:{...this.getUserContext(),...this.getPageMetadata()}};this.userId&&(i.userId=this.userId),this.events.push(i),this.events.length>100&&(this.events=this.events.slice(-100))}catch(e){}},Ww=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,i=null;for(let t=0;t<r.length;t++){const s=r[t],o=t>=r.length-3,a=t===r.length-1,l=e(this,Fw,"m",Vw).call(this,s,{isTarget:a,leadsToTarget:!0});let c=[l];if(o&&s.parentElement){c=[l,...Array.from(s.parentElement.children).filter(e=>e!==s&&e instanceof HTMLElement).map(t=>e(this,Fw,"m",Vw).call(this,t,{includeChildren:!0})).filter(Boolean)]}n||(n=l),i&&(i.children||(i.children=[]),i.children.push(...c)),i=l}return n},Vw=function t(r,{isTarget:s=!1,includeChildren:n=!1,leadsToTarget:i=!1}={}){var o,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===(o=r.parentNode)||void 0===o?void 0:o.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,nth_child:p,nth_of_type:d,attributes:f,...c?{attr_class:c}:{},...h?{attr_id:h}:{},...u?{href:u}:{},...g?{text:g}:{},...s?{is_target:!0}:{},...i&&!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,Fw,"m",t).call(this,r,{includeChildren:!0})).filter(Boolean)),y},Gw=function(){t(this,Dw,setInterval(()=>{e(this,Jw,"f").call(this)},this.intervalTime),"f")},Zw=function(){t(this,Lw,history.pushState,"f"),t(this,Bw,history.replaceState,"f"),history.pushState=(...t)=>{e(this,Lw,"f").apply(history,t),e(this,Fw,"m",Yw).call(this)},history.replaceState=(...t)=>{e(this,Bw,"f").apply(history,t),e(this,Fw,"m",Yw).call(this)},window.addEventListener("popstate",e(this,Uw,"f"))},Yw=function(){if(function(){if("undefined"==typeof window)return!1;const e=window.location.hostname;return"localhost"===e||"127.0.0.1"===e||"::1"===e||e.endsWith(".localhost")}())return;const e={event:"$ul_pageview",properties:this.getPageMetadata()};this.userId&&(e.userId=this.userId),this.events.push(e)},$w=function(){this.events=[]},Xw=function(){document.body.removeEventListener("click",e(this,_w,"f"))},Hw=function(){e(this,Jw,"f").call(this),clearInterval(e(this,Dw,"f")),e(this,Fw,"m",$w).call(this)},Kw=function(){history.pushState=e(this,Lw,"f"),history.replaceState=e(this,Bw,"f"),window.removeEventListener("popstate",e(this,Uw,"f"))};export{eb as EventCollector,hw as SessionRecorder};
|
|
8
|
+
/*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */function Ew(){return Ow||(Ow=1,e=Mw,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,i="",o=r.charCodeAt(0);++n<s;)0!=(t=r.charCodeAt(n))?i+=t>=1&&t<=31||127==t||0==n&&t>=48&&t<=57||1==n&&t>=48&&t<=57&&45==o?"\\"+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):i+="�";return i};return e.CSS||(e.CSS={}),e.CSS.escape=t,t}(t)}(void 0!==xw?xw:Aw)),Mw.exports;var e}var Rw,Nw,Tw,Pw={};var Fw,Dw,Lw,Bw,_w,Uw,jw,zw,Ww,Vw,Gw,Zw,Yw,Jw,$w,Xw,Hw,Kw,Qw=function(){if(Tw)return Nw;Tw=1,Ew();const{ShadowRootTypes:e,nodeNameInCorrectCase:t,NodeType:r}=(Rw||(Rw=1,Pw.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},Pw.shadowRootType=function(e){const t=e.ancestorShadowRoot();return t?t.mode:null},Pw.NodeType={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9},Pw.ShadowRootTypes={UserAgent:"user-agent",Open:"open",Closed:"closed"}),Pw);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 i=e;for(;i;){const r=s.DOMPath._cssPathStep(i,!!t,i===e);if(!r)break;if(n.push(r),r.optimized)break;i=i.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 i=e;for(;i;)n.push(s.DOMPath.cssPath(i,t)),i=i.shadowRoot&&i.shadowRoot.host;n.reverse();let o="";for(let e=0;e<n.length;++e){const t=JSON.stringify(n[e]);o+=e?`.shadowRoot.querySelector(${t})`:`document.querySelector(${t})`}return o},s.DOMPath._cssPathStep=function(e,n,i){if(e.nodeType!==r.ELEMENT_NODE)return null;const o=e.getAttribute("id");if(n){if(o)return new s.DOMPath.Step(h(o),!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(o)return new s.DOMPath.Step(a+h(o),!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 i=new Set(u);if(!i.size){d=!0;continue}const o=c(n);for(let e=0;e<o.length;++e){const t=o[e];if(i.has(t)&&(i.delete(t),!i.size)){d=!0;break}}}let y=a;if(i&&"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 i=e;for(;i;){const e=s.DOMPath._xPathValue(i,t);if(!e)break;if(n.push(e),e.optimized)break;i=i.parentNode}return n.reverse(),(n.length&&n[0].optimized?"":"/")+n.join("/")},s.DOMPath._xPathValue=function(e,t){let n;const i=s.DOMPath._xPathIndex(e);if(-1===i)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 i>0&&(n+="["+i+"]"),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 i=1;for(let r=0;r<s.length;++r)if(t(e,s[r])){if(s[r]===e)return i;++i}return-1},s.DOMPath.Step=class{constructor(e,t){this.value=e,this.optimized=t||!1}toString(){return this.value}},Nw=s.DOMPath}(),qw=kw(Qw);class eb{constructor(t){if(Fw.add(this),this.userContext=null,Dw.set(this,void 0),Lw.set(this,void 0),Bw.set(this,void 0),_w.set(this,e(this,Fw,"m",zw).bind(this)),Uw.set(this,e(this,Fw,"m",Yw).bind(this)),Jw.set(this,()=>{if(0===this.events.length)return;const t=[...this.events];if(this.callback){try{this.callback(t)}catch(e){}e(this,Fw,"m",$w).call(this)}else Promise.allSettled([this.userId&&this.userTraits?Xy({userId:this.userId,traits:this.userTraits}):null,Hy(t)]),e(this,Fw,"m",$w).call(this)}),"undefined"==typeof window)return;const{userId:r,WRITE_CODE:s,callback:n,intervalTime:i=5e3,skipRawEvents:o=!1}=t,a=t.userTraits;this.autoUploadModeEnabled=!n,this.autoUploadModeEnabled&&!(null==r?void 0:r.length)||this.autoUploadModeEnabled&&!(null==s?void 0:s.length)||(this.autoUploadModeEnabled&&Ky(s),(this.autoUploadModeEnabled||"function"==typeof n)&&(this.userId=r,this.userTraits="object"==typeof a&&null!==a?a:{},this.callback=n,this.intervalTime=i,this.events=[],o||(e(this,Fw,"m",jw).call(this),e(this,Fw,"m",Zw).call(this)),e(this,Fw,"m",Gw).call(this),this.userContext=this.getUserContext()))}pushEvent(e){const t={is_raw:!1,...e,properties:{...null==e?void 0:e.properties,...this.getUserContext(),...this.getPageMetadata()}};this.userId&&(t.userId=this.userId),this.events.push(t)}identify(e,t){return Xy({userId:e,traits:t})}group(e,t){return(async e=>{if(!(null==e?void 0:e.groupId))return;const{groupId:t,traits:r,userId:s}=e,n={type:"group",groupId:t,...s&&{userId:s},source:"userlens-js-analytics-sdk",traits:r};if(!(await fetch(`${Jy}/event`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Basic ${$y()}`},body:JSON.stringify(n)})).ok)throw new Error("Userlens HTTP error: failed to identify");return"ok"})({groupId:e,traits:t,userId:this.userId})}updateUserTraits(e){this.userTraits=e}stop(){e(this,Fw,"m",Xw).call(this),e(this,Fw,"m",Hw).call(this),e(this,Fw,"m",Kw).call(this)}getUserContext(){var e,t,r,s,n,i,o;if(this.userContext)return this.userContext;const a=Iw.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!==(o=null===(i=navigator.language)||void 0===i?void 0:i.split("-")[0])&&void 0!==o?o:"en",$ul_screen_width:window.screen.width,$ul_screen_height:window.screen.height,$ul_viewport_width:window.innerWidth,$ul_viewport_height:window.innerHeight,$ul_lib:"userlens.js",$ul_lib_version:"0.1.71",$ul_device_type:/Mobi|Android/i.test(navigator.userAgent)?"Mobile":"Desktop",$ul_timezone:Intl.DateTimeFormat().resolvedOptions().timeZone};return this.userContext=h,h}getPageMetadata(){try{const e=new URL(window.location.href);let t=document.referrer||"$direct",r="$direct";try{t&&/^https?:\/\//.test(t)&&(r=new URL(t).hostname)}catch(e){}const s=e.search.slice(1);return{$ul_page:e.origin+e.pathname,$ul_pathname:e.pathname,$ul_host:e.host,$ul_referrer:t,$ul_referring_domain:r,$ul_query:s}}catch(e){return{$ul_page:"",$ul_pathname:"",$ul_host:"",$ul_referrer:"",$ul_referring_domain:"",$ul_query:""}}}}Dw=new WeakMap,Lw=new WeakMap,Bw=new WeakMap,_w=new WeakMap,Uw=new WeakMap,Jw=new WeakMap,Fw=new WeakSet,jw=function(){document.body.addEventListener("click",e(this,_w,"f"))},zw=function(t){try{const r=t.target;if(!(r instanceof HTMLElement))return;const s=qw.xPath(r,!0),n=e(this,Fw,"m",Ww).call(this,r),i={event:s,is_raw:!0,snapshot:n?[n]:[],properties:{...this.getUserContext(),...this.getPageMetadata()}};this.userId&&(i.userId=this.userId),this.events.push(i),this.events.length>100&&(this.events=this.events.slice(-100))}catch(e){}},Ww=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,i=null;for(let t=0;t<r.length;t++){const s=r[t],o=t>=r.length-3,a=t===r.length-1,l=e(this,Fw,"m",Vw).call(this,s,{isTarget:a,leadsToTarget:!0});let c=[l];if(o&&s.parentElement){c=[l,...Array.from(s.parentElement.children).filter(e=>e!==s&&e instanceof HTMLElement).map(t=>e(this,Fw,"m",Vw).call(this,t,{includeChildren:!0})).filter(Boolean)]}n||(n=l),i&&(i.children||(i.children=[]),i.children.push(...c)),i=l}return n},Vw=function t(r,{isTarget:s=!1,includeChildren:n=!1,leadsToTarget:i=!1}={}){var o,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===(o=r.parentNode)||void 0===o?void 0:o.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,nth_child:p,nth_of_type:d,attributes:f,...c?{attr_class:c}:{},...h?{attr_id:h}:{},...u?{href:u}:{},...g?{text:g}:{},...s?{is_target:!0}:{},...i&&!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,Fw,"m",t).call(this,r,{includeChildren:!0})).filter(Boolean)),y},Gw=function(){t(this,Dw,setInterval(()=>{e(this,Jw,"f").call(this)},this.intervalTime),"f")},Zw=function(){t(this,Lw,history.pushState,"f"),t(this,Bw,history.replaceState,"f"),history.pushState=(...t)=>{e(this,Lw,"f").apply(history,t),e(this,Fw,"m",Yw).call(this)},history.replaceState=(...t)=>{e(this,Bw,"f").apply(history,t),e(this,Fw,"m",Yw).call(this)},window.addEventListener("popstate",e(this,Uw,"f"))},Yw=function(){if(function(){if("undefined"==typeof window)return!1;const e=window.location.hostname;return"localhost"===e||"127.0.0.1"===e||"::1"===e||e.endsWith(".localhost")}())return;const e={event:"$ul_pageview",properties:this.getPageMetadata()};this.userId&&(e.userId=this.userId),this.events.push(e)},$w=function(){this.events=[]},Xw=function(){document.body.removeEventListener("click",e(this,_w,"f"))},Hw=function(){e(this,Jw,"f").call(this),clearInterval(e(this,Dw,"f")),e(this,Fw,"m",$w).call(this)},Kw=function(){history.pushState=e(this,Lw,"f"),history.replaceState=e(this,Bw,"f"),window.removeEventListener("popstate",e(this,Uw,"f"))};export{eb as EventCollector,hw as SessionRecorder};
|
|
9
9
|
//# sourceMappingURL=main.esm.js.map
|
package/dist/react.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("./main.cjs.js");const l=e.createContext({collector:null,sessionRecorder:null});exports.default=({children:n,config:o})=>{const[i,s]=e.useState(null),[u,t]=e.useState(null),d=e.useRef(null),v=e.useRef(null),c=e.useRef(void 0);e.useEffect(()=>{var e,l,n,i,u,t;if("undefined"==typeof window)return void console.error("UserlensProvider: unavailable outside of browser environment.");if(!o)return void console.error("UserlensProvider: config is required.");if((null==c?void 0:c.current)===(null==o?void 0:o.userId))return;if(c.current=null==o?void 0:o.userId,d.current)return void console.warn("UserlensProvider: EventCollector already initialized.");let v;v="function"==typeof(null===(e=null==o?void 0:o.eventCollector)||void 0===e?void 0:e.callback)?{callback:null===(l=null==o?void 0:o.eventCollector)||void 0===l?void 0:l.callback,intervalTime:null===(n=null==o?void 0:o.eventCollector)||void 0===n?void 0:n.intervalTime,skipRawEvents:null===(i=null==o?void 0:o.eventCollector)||void 0===i?void 0:i.skipRawEvents}:{userId:null==o?void 0:o.userId,WRITE_CODE:null==o?void 0:o.WRITE_CODE,userTraits:null==o?void 0:o.userTraits,intervalTime:null===(u=null==o?void 0:o.eventCollector)||void 0===u?void 0:u.intervalTime,skipRawEvents:null===(t=null==o?void 0:o.eventCollector)||void 0===t?void 0:t.skipRawEvents};const a=new r.EventCollector(v);d.current=a,s(a)},[null==o?void 0:o.userId]),e.useEffect(()=>{(null==o?void 0:o.userTraits)&&i&&(null==i||i.updateUserTraits(null==o?void 0:o.userTraits))},[null==o?void 0:o.userTraits]);const a=e.useRef(void 0);return e.useEffect(()=>{if(!o)return void console.error("UserlensProvider: config is required.");if(!1===(null==o?void 0:o.enableSessionReplay))return;if(!(null==o?void 0:o.WRITE_CODE)||!(null==o?void 0:o.userId))return void console.error("UserlensProvider: WRITE_CODE and userId are required for session recording.");if((null==a?void 0:a.current)===(null==o?void 0:o.userId))return;if(null==v?void 0:v.current)return void console.warn("UserlensProvider: SessionRecorder already initialized.");a.current=null==o?void 0:o.userId;const e=new r.SessionRecorder({WRITE_CODE:null==o?void 0:o.WRITE_CODE,userId:null==o?void 0:o.userId,recordingOptions:null==o?void 0:o.sessionRecorder});return v.current=e,t(e),()=>{null==e||e.stop()}},[null==o?void 0:o.userId,null==o?void 0:o.enableSessionReplay]),React.createElement(l.Provider,{value:{collector:i,sessionRecorder:u}},n)},exports.useUserlens=()=>{const r=e.useContext(l);if(!r)throw new Error("useUserlens must be used within a <UserlensProvider>");return r};
|
|
2
2
|
//# sourceMappingURL=react.cjs.js.map
|
package/dist/react.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.cjs.js","sources":["../src/react/index.tsx"],"sourcesContent":null,"names":["UserlensContext","createContext","collector","sessionRecorder","children","config","eventCollector","setEventCollector","useState","setSessionRecorder","collectorRef","useRef","sessionRecorderRef","lastUserIdRefEc","undefined","useEffect","window","console","error","current","userId","warn","ecConfig","_a","callback","_b","intervalTime","_c","skipRawEvents","_d","WRITE_CODE","userTraits","_e","_f","EventCollector","updateUserTraits","lastUserIdRefSr","enableSessionReplay","sr","SessionRecorder","recordingOptions","stop","
|
|
1
|
+
{"version":3,"file":"react.cjs.js","sources":["../src/react/index.tsx"],"sourcesContent":null,"names":["UserlensContext","createContext","collector","sessionRecorder","children","config","eventCollector","setEventCollector","useState","setSessionRecorder","collectorRef","useRef","sessionRecorderRef","lastUserIdRefEc","undefined","useEffect","window","console","error","current","userId","warn","ecConfig","_a","callback","_b","intervalTime","_c","skipRawEvents","_d","WRITE_CODE","userTraits","_e","_f","EventCollector","updateUserTraits","lastUserIdRefSr","enableSessionReplay","sr","SessionRecorder","recordingOptions","stop","React","createElement","Provider","value","ctx","useContext","Error"],"mappings":"sHAWA,MAAMA,EAAkBC,EAAAA,cAAmC,CACzDC,UAAW,KACXC,gBAAiB,uBAMd,EAAGC,WAAUC,aAChB,MAAOC,EAAgBC,GAAqBC,EAAAA,SAC1C,OAEKL,EAAiBM,GACtBD,EAAAA,SAAiC,MAE7BE,EAAeC,EAAAA,OAA8B,MAC7CC,EAAqBD,EAAAA,OAA+B,MAEpDE,EAAkBF,EAAAA,YAA2BG,GACnDC,EAAAA,UAAU,qBACR,GAAsB,oBAAXC,OAIT,YAHAC,QAAQC,MACN,iEAKJ,IAAKb,EAEH,YADAY,QAAQC,MAAM,yCAIhB,IAAIL,aAAe,EAAfA,EAAiBM,YAAYd,aAAM,EAANA,EAAQe,QACvC,OAKF,GAHAP,EAAgBM,QAAUd,aAAM,EAANA,EAAQe,OAG9BV,EAAaS,QAEf,YADAF,QAAQI,KAAK,yDAIf,IAAIC,EAEFA,EAD8C,2BAArCC,EAAAlB,aAAM,EAANA,EAAQC,qCAAgBkB,UACtB,CACTA,SAAgC,QAAtBC,EAAApB,eAAAA,EAAQC,sBAAc,IAAAmB,OAAA,EAAAA,EAAED,SAClCE,aAAoC,QAAtBC,EAAAtB,eAAAA,EAAQC,sBAAc,IAAAqB,OAAA,EAAAA,EAAED,aACtCE,cAAqC,QAAtBC,EAAAxB,eAAAA,EAAQC,sBAAc,IAAAuB,OAAA,EAAAA,EAAED,eAG9B,CACTR,OAAQf,aAAM,EAANA,EAAQe,OAChBU,WAAYzB,aAAM,EAANA,EAAQyB,WACpBC,WAAY1B,aAAM,EAANA,EAAQ0B,WACpBL,aAAoC,QAAtBM,EAAA3B,eAAAA,EAAQC,sBAAc,IAAA0B,OAAA,EAAAA,EAAEN,aACtCE,cAAqC,QAAtBK,EAAA5B,eAAAA,EAAQC,sBAAc,IAAA2B,OAAA,EAAAA,EAAEL,eAI3C,MAAM1B,EAAY,IAAIgC,EAAAA,eAAeZ,GACrCZ,EAAaS,QAAUjB,EACvBK,EAAkBL,IACjB,CAACG,aAAM,EAANA,EAAQe,SAEZL,EAAAA,UAAU,MACHV,aAAM,EAANA,EAAQ0B,aACRzB,IAELA,SAAAA,EAAgB6B,iBAAiB9B,aAAM,EAANA,EAAQ0B,cACxC,CAAC1B,aAAM,EAANA,EAAQ0B,aAEZ,MAAMK,EAAkBzB,EAAAA,YAA2BG,GAsCnD,OArCAC,EAAAA,UAAU,KACR,IAAKV,EAEH,YADAY,QAAQC,MAAM,yCAIhB,IAAoC,KAAhCb,aAAM,EAANA,EAAQgC,qBACV,OAEF,KAAKhC,aAAM,EAANA,EAAQyB,eAAezB,aAAM,EAANA,EAAQe,QAIlC,YAHAH,QAAQC,MACN,+EAIJ,IAAIkB,aAAe,EAAfA,EAAiBjB,YAAYd,aAAM,EAANA,EAAQe,QACvC,OAEF,GAAIR,aAAkB,EAAlBA,EAAoBO,QAEtB,YADAF,QAAQI,KAAK,0DAIfe,EAAgBjB,QAAUd,aAAM,EAANA,EAAQe,OAClC,MAAMkB,EAAK,IAAIC,kBAAgB,CAC7BT,WAAYzB,aAAM,EAANA,EAAQyB,WACpBV,OAAQf,aAAM,EAANA,EAAQe,OAChBoB,iBAAkBnC,aAAM,EAANA,EAAQF,kBAK5B,OAHAS,EAAmBO,QAAUmB,EAC7B7B,EAAmB6B,GAEZ,KACLA,SAAAA,EAAIG,SAEL,CAACpC,aAAM,EAANA,EAAQe,OAAQf,aAAM,EAANA,EAAQgC,sBAG1BK,MAAAC,cAAC3C,EAAgB4C,SAAQ,CACvBC,MAAO,CACL3C,UAAWI,EACXH,gBAAiBA,IAGlBC,wBAKoB,KACzB,MAAM0C,EAAMC,EAAAA,WAAW/C,GACvB,IAAK8C,EACH,MAAM,IAAIE,MAAM,wDAElB,OAAOF"}
|
package/dist/react.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{createContext as e,useContext as r,useState as l,useRef as n,useEffect as o}from"react";import{EventCollector as i,SessionRecorder as u}from"./main.esm.js";const d=e({collector:null,sessionRecorder:null}),s=({children:e,config:r})=>{const[s,t]=l(null),[v,c]=l(null),a=n(null),f=n(null),E=n(void 0);o(()=>{var e,l,n,o,u,d;if("undefined"==typeof window)return void console.error("UserlensProvider: unavailable outside of browser environment.");if(!r)return void console.error("UserlensProvider: config is required.");if((null==E?void 0:E.current)===(null==r?void 0:r.userId))return;if(E.current=null==r?void 0:r.userId,a.current)return void console.warn("UserlensProvider: EventCollector already initialized.");let s;s="function"==typeof(null===(e=null==r?void 0:r.eventCollector)||void 0===e?void 0:e.callback)?{callback:null===(l=null==r?void 0:r.eventCollector)||void 0===l?void 0:l.callback,intervalTime:null===(n=null==r?void 0:r.eventCollector)||void 0===n?void 0:n.intervalTime,skipRawEvents:null===(o=null==r?void 0:r.eventCollector)||void 0===o?void 0:o.skipRawEvents}:{userId:null==r?void 0:r.userId,WRITE_CODE:null==r?void 0:r.WRITE_CODE,userTraits:null==r?void 0:r.userTraits,intervalTime:null===(u=null==r?void 0:r.eventCollector)||void 0===u?void 0:u.intervalTime,skipRawEvents:null===(d=null==r?void 0:r.eventCollector)||void 0===d?void 0:d.skipRawEvents};const v=new i(s);a.current=v,t(v)},[null==r?void 0:r.userId]),o(()=>{(null==r?void 0:r.userTraits)&&s&&(null==s||s.updateUserTraits(null==r?void 0:r.userTraits))},[null==r?void 0:r.userTraits]);const I=n(void 0);return o(()=>{if(!r)return void console.error("UserlensProvider: config is required.");if(!1===(null==r?void 0:r.enableSessionReplay))return;if(!(null==r?void 0:r.WRITE_CODE)||!(null==r?void 0:r.userId))return void console.error("UserlensProvider: WRITE_CODE and userId are required for session recording.");if((null==I?void 0:I.current)===(null==r?void 0:r.userId))return;if(null==f?void 0:f.current)return void console.warn("UserlensProvider: SessionRecorder already initialized.");I.current=null==r?void 0:r.userId;const e=new u({WRITE_CODE:null==r?void 0:r.WRITE_CODE,userId:null==r?void 0:r.userId,recordingOptions:null==r?void 0:r.sessionRecorder});return f.current=e,c(e),()=>{null==e||e.stop()}},[null==r?void 0:r.userId,null==r?void 0:r.enableSessionReplay]),React.createElement(d.Provider,{value:{collector:s,sessionRecorder:v}},e)},t=()=>{const e=r(d);if(!e)throw new Error("useUserlens must be used within a <UserlensProvider>");return e};export{s as default,t as useUserlens};
|
|
2
2
|
//# sourceMappingURL=react.esm.js.map
|
package/dist/react.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.esm.js","sources":["../src/react/index.tsx"],"sourcesContent":null,"names":["UserlensContext","createContext","collector","sessionRecorder","UserlensProvider","children","config","eventCollector","setEventCollector","useState","setSessionRecorder","collectorRef","useRef","sessionRecorderRef","lastUserIdRefEc","undefined","useEffect","window","console","error","current","userId","warn","ecConfig","_a","callback","_b","intervalTime","_c","skipRawEvents","_d","WRITE_CODE","userTraits","_e","_f","EventCollector","updateUserTraits","lastUserIdRefSr","enableSessionReplay","sr","SessionRecorder","recordingOptions","stop","
|
|
1
|
+
{"version":3,"file":"react.esm.js","sources":["../src/react/index.tsx"],"sourcesContent":null,"names":["UserlensContext","createContext","collector","sessionRecorder","UserlensProvider","children","config","eventCollector","setEventCollector","useState","setSessionRecorder","collectorRef","useRef","sessionRecorderRef","lastUserIdRefEc","undefined","useEffect","window","console","error","current","userId","warn","ecConfig","_a","callback","_b","intervalTime","_c","skipRawEvents","_d","WRITE_CODE","userTraits","_e","_f","EventCollector","updateUserTraits","lastUserIdRefSr","enableSessionReplay","sr","SessionRecorder","recordingOptions","stop","React","createElement","Provider","value","useUserlens","ctx","useContext","Error"],"mappings":"mKAWA,MAAMA,EAAkBC,EAAmC,CACzDC,UAAW,KACXC,gBAAiB,OAGbC,EAGD,EAAGC,WAAUC,aAChB,MAAOC,EAAgBC,GAAqBC,EAC1C,OAEKN,EAAiBO,GACtBD,EAAiC,MAE7BE,EAAeC,EAA8B,MAC7CC,EAAqBD,EAA+B,MAEpDE,EAAkBF,OAA2BG,GACnDC,EAAU,qBACR,GAAsB,oBAAXC,OAIT,YAHAC,QAAQC,MACN,iEAKJ,IAAKb,EAEH,YADAY,QAAQC,MAAM,yCAIhB,IAAIL,aAAe,EAAfA,EAAiBM,YAAYd,aAAM,EAANA,EAAQe,QACvC,OAKF,GAHAP,EAAgBM,QAAUd,aAAM,EAANA,EAAQe,OAG9BV,EAAaS,QAEf,YADAF,QAAQI,KAAK,yDAIf,IAAIC,EAEFA,EAD8C,2BAArCC,EAAAlB,aAAM,EAANA,EAAQC,qCAAgBkB,UACtB,CACTA,SAAgC,QAAtBC,EAAApB,eAAAA,EAAQC,sBAAc,IAAAmB,OAAA,EAAAA,EAAED,SAClCE,aAAoC,QAAtBC,EAAAtB,eAAAA,EAAQC,sBAAc,IAAAqB,OAAA,EAAAA,EAAED,aACtCE,cAAqC,QAAtBC,EAAAxB,eAAAA,EAAQC,sBAAc,IAAAuB,OAAA,EAAAA,EAAED,eAG9B,CACTR,OAAQf,aAAM,EAANA,EAAQe,OAChBU,WAAYzB,aAAM,EAANA,EAAQyB,WACpBC,WAAY1B,aAAM,EAANA,EAAQ0B,WACpBL,aAAoC,QAAtBM,EAAA3B,eAAAA,EAAQC,sBAAc,IAAA0B,OAAA,EAAAA,EAAEN,aACtCE,cAAqC,QAAtBK,EAAA5B,eAAAA,EAAQC,sBAAc,IAAA2B,OAAA,EAAAA,EAAEL,eAI3C,MAAM3B,EAAY,IAAIiC,EAAeZ,GACrCZ,EAAaS,QAAUlB,EACvBM,EAAkBN,IACjB,CAACI,aAAM,EAANA,EAAQe,SAEZL,EAAU,MACHV,aAAM,EAANA,EAAQ0B,aACRzB,IAELA,SAAAA,EAAgB6B,iBAAiB9B,aAAM,EAANA,EAAQ0B,cACxC,CAAC1B,aAAM,EAANA,EAAQ0B,aAEZ,MAAMK,EAAkBzB,OAA2BG,GAsCnD,OArCAC,EAAU,KACR,IAAKV,EAEH,YADAY,QAAQC,MAAM,yCAIhB,IAAoC,KAAhCb,aAAM,EAANA,EAAQgC,qBACV,OAEF,KAAKhC,aAAM,EAANA,EAAQyB,eAAezB,aAAM,EAANA,EAAQe,QAIlC,YAHAH,QAAQC,MACN,+EAIJ,IAAIkB,aAAe,EAAfA,EAAiBjB,YAAYd,aAAM,EAANA,EAAQe,QACvC,OAEF,GAAIR,aAAkB,EAAlBA,EAAoBO,QAEtB,YADAF,QAAQI,KAAK,0DAIfe,EAAgBjB,QAAUd,aAAM,EAANA,EAAQe,OAClC,MAAMkB,EAAK,IAAIC,EAAgB,CAC7BT,WAAYzB,aAAM,EAANA,EAAQyB,WACpBV,OAAQf,aAAM,EAANA,EAAQe,OAChBoB,iBAAkBnC,aAAM,EAANA,EAAQH,kBAK5B,OAHAU,EAAmBO,QAAUmB,EAC7B7B,EAAmB6B,GAEZ,KACLA,SAAAA,EAAIG,SAEL,CAACpC,aAAM,EAANA,EAAQe,OAAQf,aAAM,EAANA,EAAQgC,sBAG1BK,MAAAC,cAAC5C,EAAgB6C,SAAQ,CACvBC,MAAO,CACL5C,UAAWK,EACXJ,gBAAiBA,IAGlBE,IAKM0C,EAAc,KACzB,MAAMC,EAAMC,EAAWjD,GACvB,IAAKgD,EACH,MAAM,IAAIE,MAAM,wDAElB,OAAOF"}
|
package/dist/userlens.umd.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 Iw{static getParser(e,t=!1){if("string"!=typeof e)throw new Error("UserAgent should be a string");return new Cw(e,t)}static parse(e){return new Cw(e).getResult()}static get BROWSER_MAP(){return pw}static get ENGINE_MAP(){return mw}static get OS_MAP(){return fw}static get PLATFORMS_MAP(){return dw}}var xw="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function kw(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Ow,Mw={exports:{}},Aw=Mw.exports;
|
|
8
|
-
/*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */function Ew(){return Ow||(Ow=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,i="",o=r.charCodeAt(0);++n<s;)0!=(t=r.charCodeAt(n))?i+=t>=1&&t<=31||127==t||0==n&&t>=48&&t<=57||1==n&&t>=48&&t<=57&&45==o?"\\"+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):i+="�";return i};e.CSS||(e.CSS={});return e.CSS.escape=t,t}(t)}(void 0!==xw?xw:Aw)}(Mw)),Mw.exports}var Rw,Nw,Tw,Pw={};var Fw,Dw,Lw,Bw,_w,Uw,jw,zw,Ww,Vw,Gw,Zw,Yw,Jw,$w,Xw,Hw,Kw,Qw=function(){if(Tw)return Nw;Tw=1,Ew();const{ShadowRootTypes:e,nodeNameInCorrectCase:t,NodeType:r}=(Rw||(Rw=1,Pw.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},Pw.shadowRootType=function(e){const t=e.ancestorShadowRoot();return t?t.mode:null},Pw.NodeType={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9},Pw.ShadowRootTypes={UserAgent:"user-agent",Open:"open",Closed:"closed"}),Pw);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 i=e;for(;i;){const r=s.DOMPath._cssPathStep(i,!!t,i===e);if(!r)break;if(n.push(r),r.optimized)break;i=i.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 i=e;for(;i;)n.push(s.DOMPath.cssPath(i,t)),i=i.shadowRoot&&i.shadowRoot.host;n.reverse();let o="";for(let e=0;e<n.length;++e){const t=JSON.stringify(n[e]);o+=e?`.shadowRoot.querySelector(${t})`:`document.querySelector(${t})`}return o},s.DOMPath._cssPathStep=function(e,n,i){if(e.nodeType!==r.ELEMENT_NODE)return null;const o=e.getAttribute("id");if(n){if(o)return new s.DOMPath.Step(h(o),!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(o)return new s.DOMPath.Step(a+h(o),!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 i=new Set(u);if(!i.size){d=!0;continue}const o=c(n);for(let e=0;e<o.length;++e){const t=o[e];if(i.has(t)&&(i.delete(t),!i.size)){d=!0;break}}}let y=a;if(i&&"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 i=e;for(;i;){const e=s.DOMPath._xPathValue(i,t);if(!e)break;if(n.push(e),e.optimized)break;i=i.parentNode}return n.reverse(),(n.length&&n[0].optimized?"":"/")+n.join("/")},s.DOMPath._xPathValue=function(e,t){let n;const i=s.DOMPath._xPathIndex(e);if(-1===i)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 i>0&&(n+="["+i+"]"),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 i=1;for(let r=0;r<s.length;++r)if(t(e,s[r])){if(s[r]===e)return i;++i}return-1},s.DOMPath.Step=class{constructor(e,t){this.value=e,this.optimized=t||!1}toString(){return this.value}},Nw=s.DOMPath}(),qw=kw(Qw);Dw=new WeakMap,Lw=new WeakMap,Bw=new WeakMap,_w=new WeakMap,Uw=new WeakMap,Jw=new WeakMap,Fw=new WeakSet,jw=function(){document.body.addEventListener("click",t(this,_w,"f"))},zw=function(e){try{const r=e.target;if(!(r instanceof HTMLElement))return;const s=qw.xPath(r,!0),n=t(this,Fw,"m",Ww).call(this,r),i={event:s,is_raw:!0,snapshot:n?[n]:[],properties:{...this.getUserContext(),...this.getPageMetadata()}};this.userId&&(i.userId=this.userId),this.events.push(i),this.events.length>100&&(this.events=this.events.slice(-100))}catch(e){}},Ww=function(e){if(!(e instanceof HTMLElement))return null;const r=[];let s=e;for(;s&&1===s.nodeType;)r.unshift(s),s=s.parentElement;let n=null,i=null;for(let e=0;e<r.length;e++){const s=r[e],o=e>=r.length-3,a=e===r.length-1,l=t(this,Fw,"m",Vw).call(this,s,{isTarget:a,leadsToTarget:!0});let c=[l];if(o&&s.parentElement){c=[l,...Array.from(s.parentElement.children).filter(e=>e!==s&&e instanceof HTMLElement).map(e=>t(this,Fw,"m",Vw).call(this,e,{includeChildren:!0})).filter(Boolean)]}n||(n=l),i&&(i.children||(i.children=[]),i.children.push(...c)),i=l}return n},Vw=function e(r,{isTarget:s=!1,includeChildren:n=!1,leadsToTarget:i=!1}={}){var o,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===(o=r.parentNode)||void 0===o?void 0:o.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,nth_child:p,nth_of_type:d,attributes:f,...c?{attr_class:c}:{},...h?{attr_id:h}:{},...u?{href:u}:{},...g?{text:g}:{},...s?{is_target:!0}:{},...i&&!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=>t(this,Fw,"m",e).call(this,r,{includeChildren:!0})).filter(Boolean)),y},Gw=function(){r(this,Dw,setInterval(()=>{t(this,Jw,"f").call(this)},this.intervalTime),"f")},Zw=function(){r(this,Lw,history.pushState,"f"),r(this,Bw,history.replaceState,"f"),history.pushState=(...e)=>{t(this,Lw,"f").apply(history,e),t(this,Fw,"m",Yw).call(this)},history.replaceState=(...e)=>{t(this,Bw,"f").apply(history,e),t(this,Fw,"m",Yw).call(this)},window.addEventListener("popstate",t(this,Uw,"f"))},Yw=function(){if(function(){if("undefined"==typeof window)return!1;const e=window.location.hostname;return"localhost"===e||"127.0.0.1"===e||"::1"===e||e.endsWith(".localhost")}())return;const e={event:"$ul_pageview",properties:this.getPageMetadata()};this.userId&&(e.userId=this.userId),this.events.push(e)},$w=function(){this.events=[]},Xw=function(){document.body.removeEventListener("click",t(this,_w,"f"))},Hw=function(){t(this,Jw,"f").call(this),clearInterval(t(this,Dw,"f")),t(this,Fw,"m",$w).call(this)},Kw=function(){history.pushState=t(this,Lw,"f"),history.replaceState=t(this,Bw,"f"),window.removeEventListener("popstate",t(this,Uw,"f"))},e.EventCollector=class{constructor(e){if(Fw.add(this),this.userContext=null,Dw.set(this,void 0),Lw.set(this,void 0),Bw.set(this,void 0),_w.set(this,t(this,Fw,"m",zw).bind(this)),Uw.set(this,t(this,Fw,"m",Yw).bind(this)),Jw.set(this,()=>{if(0===this.events.length)return;const e=[...this.events];if(this.callback){try{this.callback(e)}catch(e){}t(this,Fw,"m",$w).call(this)}else Promise.allSettled([this.userId&&this.userTraits?Hy({userId:this.userId,traits:this.userTraits}):null,Ky(e)]),t(this,Fw,"m",$w).call(this)}),"undefined"==typeof window)return;const{userId:r,WRITE_CODE:s,callback:n,intervalTime:i=5e3,skipRawEvents:o=!1}=e,a=e.userTraits;this.autoUploadModeEnabled=!n,this.autoUploadModeEnabled&&!(null==r?void 0:r.length)||this.autoUploadModeEnabled&&!(null==s?void 0:s.length)||(this.autoUploadModeEnabled&&Qy(s),(this.autoUploadModeEnabled||"function"==typeof n)&&(this.userId=r,this.userTraits="object"==typeof a&&null!==a?a:{},this.callback=n,this.intervalTime=i,this.events=[],o||(t(this,Fw,"m",jw).call(this),t(this,Fw,"m",Zw).call(this)),t(this,Fw,"m",Gw).call(this),this.userContext=this.getUserContext()))}pushEvent(e){const t={is_raw:!1,...e,properties:{...null==e?void 0:e.properties,...this.getUserContext(),...this.getPageMetadata()}};this.userId&&(t.userId=this.userId),this.events.push(t)}identify(e,t){return Hy({userId:e,traits:t})}group(e,t){return(async e=>{if(!(null==e?void 0:e.groupId))return;const{groupId:t,traits:r,userId:s}=e,n={type:"group",groupId:t,...s&&{userId:s},source:"userlens-js-analytics-sdk",traits:r};if(!(await fetch(`${$y}/event`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Basic ${Xy()}`},body:JSON.stringify(n)})).ok)throw new Error("Userlens HTTP error: failed to identify");return"ok"})({groupId:e,traits:t,userId:this.userId})}updateUserTraits(e){this.userTraits=e}stop(){t(this,Fw,"m",Xw).call(this),t(this,Fw,"m",Hw).call(this),t(this,Fw,"m",Kw).call(this)}getUserContext(){var e,t,r,s,n,i,o;if(this.userContext)return this.userContext;const a=Iw.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!==(o=null===(i=navigator.language)||void 0===i?void 0:i.split("-")[0])&&void 0!==o?o:"en",$ul_screen_width:window.screen.width,$ul_screen_height:window.screen.height,$ul_viewport_width:window.innerWidth,$ul_viewport_height:window.innerHeight,$ul_lib:"userlens.js",$ul_lib_version:"0.1.69",$ul_device_type:/Mobi|Android/i.test(navigator.userAgent)?"Mobile":"Desktop",$ul_timezone:Intl.DateTimeFormat().resolvedOptions().timeZone};return this.userContext=h,h}getPageMetadata(){try{const e=new URL(window.location.href);let t=document.referrer||"$direct",r="$direct";try{t&&/^https?:\/\//.test(t)&&(r=new URL(t).hostname)}catch(e){}const s=e.search.slice(1);return{$ul_page:e.origin+e.pathname,$ul_pathname:e.pathname,$ul_host:e.host,$ul_referrer:t,$ul_referring_domain:r,$ul_query:s}}catch(e){return{$ul_page:"",$ul_pathname:"",$ul_host:"",$ul_referrer:"",$ul_referring_domain:"",$ul_query:""}}}},e.SessionRecorder=class{constructor({WRITE_CODE:e,userId:s,recordingOptions:n={}}){if(qy.add(this),this.sessionEvents=[],this.rrwebStop=null,ew.set(this,void 0),iw.set(this,()=>{document.visibilityState&&yc()}),"undefined"==typeof window&&console.error("Userlens SDK error: unavailable outside of browser environment."),!(null==e?void 0:e.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:i=18e5,BUFFER_SIZE:o=10,maskingOptions:a=["passwords"]}=n;if("string"!=typeof e)throw new Error("WRITE_CODE must be a string to base64 encode it");Qy(e),this.userId=s,this.TIMEOUT=i,this.BUFFER_SIZE=o,this.maskingOptions=a,this.sessionEvents=[],r(this,ew,t(this,qy,"m",aw).call(this,()=>{t(this,qy,"m",lw).call(this)},5e3),"f"),t(this,qy,"m",tw).call(this)}stop(){this.rrwebStop&&(this.rrwebStop(),this.rrwebStop=null,t(this,qy,"m",cw).call(this),t(this,qy,"m",hw).call(this),window.removeEventListener("visibilitychange",t(this,iw,"f")))}}});
|
|
8
|
+
/*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */function Ew(){return Ow||(Ow=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,i="",o=r.charCodeAt(0);++n<s;)0!=(t=r.charCodeAt(n))?i+=t>=1&&t<=31||127==t||0==n&&t>=48&&t<=57||1==n&&t>=48&&t<=57&&45==o?"\\"+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):i+="�";return i};e.CSS||(e.CSS={});return e.CSS.escape=t,t}(t)}(void 0!==xw?xw:Aw)}(Mw)),Mw.exports}var Rw,Nw,Tw,Pw={};var Fw,Dw,Lw,Bw,_w,Uw,jw,zw,Ww,Vw,Gw,Zw,Yw,Jw,$w,Xw,Hw,Kw,Qw=function(){if(Tw)return Nw;Tw=1,Ew();const{ShadowRootTypes:e,nodeNameInCorrectCase:t,NodeType:r}=(Rw||(Rw=1,Pw.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},Pw.shadowRootType=function(e){const t=e.ancestorShadowRoot();return t?t.mode:null},Pw.NodeType={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9},Pw.ShadowRootTypes={UserAgent:"user-agent",Open:"open",Closed:"closed"}),Pw);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 i=e;for(;i;){const r=s.DOMPath._cssPathStep(i,!!t,i===e);if(!r)break;if(n.push(r),r.optimized)break;i=i.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 i=e;for(;i;)n.push(s.DOMPath.cssPath(i,t)),i=i.shadowRoot&&i.shadowRoot.host;n.reverse();let o="";for(let e=0;e<n.length;++e){const t=JSON.stringify(n[e]);o+=e?`.shadowRoot.querySelector(${t})`:`document.querySelector(${t})`}return o},s.DOMPath._cssPathStep=function(e,n,i){if(e.nodeType!==r.ELEMENT_NODE)return null;const o=e.getAttribute("id");if(n){if(o)return new s.DOMPath.Step(h(o),!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(o)return new s.DOMPath.Step(a+h(o),!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 i=new Set(u);if(!i.size){d=!0;continue}const o=c(n);for(let e=0;e<o.length;++e){const t=o[e];if(i.has(t)&&(i.delete(t),!i.size)){d=!0;break}}}let y=a;if(i&&"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 i=e;for(;i;){const e=s.DOMPath._xPathValue(i,t);if(!e)break;if(n.push(e),e.optimized)break;i=i.parentNode}return n.reverse(),(n.length&&n[0].optimized?"":"/")+n.join("/")},s.DOMPath._xPathValue=function(e,t){let n;const i=s.DOMPath._xPathIndex(e);if(-1===i)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 i>0&&(n+="["+i+"]"),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 i=1;for(let r=0;r<s.length;++r)if(t(e,s[r])){if(s[r]===e)return i;++i}return-1},s.DOMPath.Step=class{constructor(e,t){this.value=e,this.optimized=t||!1}toString(){return this.value}},Nw=s.DOMPath}(),qw=kw(Qw);Dw=new WeakMap,Lw=new WeakMap,Bw=new WeakMap,_w=new WeakMap,Uw=new WeakMap,Jw=new WeakMap,Fw=new WeakSet,jw=function(){document.body.addEventListener("click",t(this,_w,"f"))},zw=function(e){try{const r=e.target;if(!(r instanceof HTMLElement))return;const s=qw.xPath(r,!0),n=t(this,Fw,"m",Ww).call(this,r),i={event:s,is_raw:!0,snapshot:n?[n]:[],properties:{...this.getUserContext(),...this.getPageMetadata()}};this.userId&&(i.userId=this.userId),this.events.push(i),this.events.length>100&&(this.events=this.events.slice(-100))}catch(e){}},Ww=function(e){if(!(e instanceof HTMLElement))return null;const r=[];let s=e;for(;s&&1===s.nodeType;)r.unshift(s),s=s.parentElement;let n=null,i=null;for(let e=0;e<r.length;e++){const s=r[e],o=e>=r.length-3,a=e===r.length-1,l=t(this,Fw,"m",Vw).call(this,s,{isTarget:a,leadsToTarget:!0});let c=[l];if(o&&s.parentElement){c=[l,...Array.from(s.parentElement.children).filter(e=>e!==s&&e instanceof HTMLElement).map(e=>t(this,Fw,"m",Vw).call(this,e,{includeChildren:!0})).filter(Boolean)]}n||(n=l),i&&(i.children||(i.children=[]),i.children.push(...c)),i=l}return n},Vw=function e(r,{isTarget:s=!1,includeChildren:n=!1,leadsToTarget:i=!1}={}){var o,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===(o=r.parentNode)||void 0===o?void 0:o.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,nth_child:p,nth_of_type:d,attributes:f,...c?{attr_class:c}:{},...h?{attr_id:h}:{},...u?{href:u}:{},...g?{text:g}:{},...s?{is_target:!0}:{},...i&&!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=>t(this,Fw,"m",e).call(this,r,{includeChildren:!0})).filter(Boolean)),y},Gw=function(){r(this,Dw,setInterval(()=>{t(this,Jw,"f").call(this)},this.intervalTime),"f")},Zw=function(){r(this,Lw,history.pushState,"f"),r(this,Bw,history.replaceState,"f"),history.pushState=(...e)=>{t(this,Lw,"f").apply(history,e),t(this,Fw,"m",Yw).call(this)},history.replaceState=(...e)=>{t(this,Bw,"f").apply(history,e),t(this,Fw,"m",Yw).call(this)},window.addEventListener("popstate",t(this,Uw,"f"))},Yw=function(){if(function(){if("undefined"==typeof window)return!1;const e=window.location.hostname;return"localhost"===e||"127.0.0.1"===e||"::1"===e||e.endsWith(".localhost")}())return;const e={event:"$ul_pageview",properties:this.getPageMetadata()};this.userId&&(e.userId=this.userId),this.events.push(e)},$w=function(){this.events=[]},Xw=function(){document.body.removeEventListener("click",t(this,_w,"f"))},Hw=function(){t(this,Jw,"f").call(this),clearInterval(t(this,Dw,"f")),t(this,Fw,"m",$w).call(this)},Kw=function(){history.pushState=t(this,Lw,"f"),history.replaceState=t(this,Bw,"f"),window.removeEventListener("popstate",t(this,Uw,"f"))},e.EventCollector=class{constructor(e){if(Fw.add(this),this.userContext=null,Dw.set(this,void 0),Lw.set(this,void 0),Bw.set(this,void 0),_w.set(this,t(this,Fw,"m",zw).bind(this)),Uw.set(this,t(this,Fw,"m",Yw).bind(this)),Jw.set(this,()=>{if(0===this.events.length)return;const e=[...this.events];if(this.callback){try{this.callback(e)}catch(e){}t(this,Fw,"m",$w).call(this)}else Promise.allSettled([this.userId&&this.userTraits?Hy({userId:this.userId,traits:this.userTraits}):null,Ky(e)]),t(this,Fw,"m",$w).call(this)}),"undefined"==typeof window)return;const{userId:r,WRITE_CODE:s,callback:n,intervalTime:i=5e3,skipRawEvents:o=!1}=e,a=e.userTraits;this.autoUploadModeEnabled=!n,this.autoUploadModeEnabled&&!(null==r?void 0:r.length)||this.autoUploadModeEnabled&&!(null==s?void 0:s.length)||(this.autoUploadModeEnabled&&Qy(s),(this.autoUploadModeEnabled||"function"==typeof n)&&(this.userId=r,this.userTraits="object"==typeof a&&null!==a?a:{},this.callback=n,this.intervalTime=i,this.events=[],o||(t(this,Fw,"m",jw).call(this),t(this,Fw,"m",Zw).call(this)),t(this,Fw,"m",Gw).call(this),this.userContext=this.getUserContext()))}pushEvent(e){const t={is_raw:!1,...e,properties:{...null==e?void 0:e.properties,...this.getUserContext(),...this.getPageMetadata()}};this.userId&&(t.userId=this.userId),this.events.push(t)}identify(e,t){return Hy({userId:e,traits:t})}group(e,t){return(async e=>{if(!(null==e?void 0:e.groupId))return;const{groupId:t,traits:r,userId:s}=e,n={type:"group",groupId:t,...s&&{userId:s},source:"userlens-js-analytics-sdk",traits:r};if(!(await fetch(`${$y}/event`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Basic ${Xy()}`},body:JSON.stringify(n)})).ok)throw new Error("Userlens HTTP error: failed to identify");return"ok"})({groupId:e,traits:t,userId:this.userId})}updateUserTraits(e){this.userTraits=e}stop(){t(this,Fw,"m",Xw).call(this),t(this,Fw,"m",Hw).call(this),t(this,Fw,"m",Kw).call(this)}getUserContext(){var e,t,r,s,n,i,o;if(this.userContext)return this.userContext;const a=Iw.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!==(o=null===(i=navigator.language)||void 0===i?void 0:i.split("-")[0])&&void 0!==o?o:"en",$ul_screen_width:window.screen.width,$ul_screen_height:window.screen.height,$ul_viewport_width:window.innerWidth,$ul_viewport_height:window.innerHeight,$ul_lib:"userlens.js",$ul_lib_version:"0.1.71",$ul_device_type:/Mobi|Android/i.test(navigator.userAgent)?"Mobile":"Desktop",$ul_timezone:Intl.DateTimeFormat().resolvedOptions().timeZone};return this.userContext=h,h}getPageMetadata(){try{const e=new URL(window.location.href);let t=document.referrer||"$direct",r="$direct";try{t&&/^https?:\/\//.test(t)&&(r=new URL(t).hostname)}catch(e){}const s=e.search.slice(1);return{$ul_page:e.origin+e.pathname,$ul_pathname:e.pathname,$ul_host:e.host,$ul_referrer:t,$ul_referring_domain:r,$ul_query:s}}catch(e){return{$ul_page:"",$ul_pathname:"",$ul_host:"",$ul_referrer:"",$ul_referring_domain:"",$ul_query:""}}}},e.SessionRecorder=class{constructor({WRITE_CODE:e,userId:s,recordingOptions:n={}}){if(qy.add(this),this.sessionEvents=[],this.rrwebStop=null,ew.set(this,void 0),iw.set(this,()=>{document.visibilityState&&yc()}),"undefined"==typeof window&&console.error("Userlens SDK error: unavailable outside of browser environment."),!(null==e?void 0:e.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:i=18e5,BUFFER_SIZE:o=10,maskingOptions:a=["passwords"]}=n;if("string"!=typeof e)throw new Error("WRITE_CODE must be a string to base64 encode it");Qy(e),this.userId=s,this.TIMEOUT=i,this.BUFFER_SIZE=o,this.maskingOptions=a,this.sessionEvents=[],r(this,ew,t(this,qy,"m",aw).call(this,()=>{t(this,qy,"m",lw).call(this)},5e3),"f"),t(this,qy,"m",tw).call(this)}stop(){this.rrwebStop&&(this.rrwebStop(),this.rrwebStop=null,t(this,qy,"m",cw).call(this),t(this,qy,"m",hw).call(this),window.removeEventListener("visibilitychange",t(this,iw,"f")))}}});
|
|
9
9
|
//# sourceMappingURL=userlens.umd.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "userlens-analytics-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.71",
|
|
4
4
|
"main": "./dist/main.cjs.js",
|
|
5
5
|
"module": "./dist/main.esm.js",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
36
36
|
"@rollup/plugin-terser": "^0.4.4",
|
|
37
37
|
"@rollup/plugin-typescript": "^12.1.4",
|
|
38
|
-
"@types/react": "^
|
|
39
|
-
"react": "^
|
|
38
|
+
"@types/react": "^16.9.0",
|
|
39
|
+
"react": "^16.14.0",
|
|
40
40
|
"rollup": "^4.34.6",
|
|
41
41
|
"rollup-plugin-dts": "^6.2.3",
|
|
42
42
|
"typescript": "^5.8.3"
|
|
@@ -44,6 +44,11 @@
|
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"react": ">=17.0.0"
|
|
46
46
|
},
|
|
47
|
+
"peerDependenciesMeta": {
|
|
48
|
+
"react": {
|
|
49
|
+
"optional": true
|
|
50
|
+
}
|
|
51
|
+
},
|
|
47
52
|
"dependencies": {
|
|
48
53
|
"@rrweb/rrweb-plugin-console-record": "^2.0.0-alpha.18",
|
|
49
54
|
"bowser": "^2.11.0",
|