@gem-sdk/clarity-js 0.8.94

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.
Files changed (127) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +1 -0
  3. package/build/clarity.extended.js +1 -0
  4. package/build/clarity.insight.js +1 -0
  5. package/build/clarity.js +7148 -0
  6. package/build/clarity.livechat.js +1 -0
  7. package/build/clarity.min.js +1 -0
  8. package/build/clarity.module.js +7144 -0
  9. package/build/clarity.performance.js +1 -0
  10. package/build/dynamic/clarity.crisp.js +1 -0
  11. package/build/dynamic/clarity.tidio.js +1 -0
  12. package/package.json +49 -0
  13. package/rollup.config.ts +161 -0
  14. package/src/clarity.ts +72 -0
  15. package/src/core/api.ts +8 -0
  16. package/src/core/config.ts +35 -0
  17. package/src/core/copy.ts +3 -0
  18. package/src/core/dynamic.ts +68 -0
  19. package/src/core/event.ts +53 -0
  20. package/src/core/hash.ts +19 -0
  21. package/src/core/history.ts +82 -0
  22. package/src/core/index.ts +81 -0
  23. package/src/core/measure.ts +19 -0
  24. package/src/core/report.ts +28 -0
  25. package/src/core/scrub.ts +201 -0
  26. package/src/core/task.ts +181 -0
  27. package/src/core/throttle.ts +46 -0
  28. package/src/core/time.ts +26 -0
  29. package/src/core/timeout.ts +10 -0
  30. package/src/core/version.ts +2 -0
  31. package/src/custom/README.md +44 -0
  32. package/src/custom/dialog.ts +69 -0
  33. package/src/custom/index.ts +6 -0
  34. package/src/data/baseline.ts +162 -0
  35. package/src/data/compress.ts +31 -0
  36. package/src/data/consent.ts +84 -0
  37. package/src/data/cookie.ts +90 -0
  38. package/src/data/custom.ts +23 -0
  39. package/src/data/dimension.ts +53 -0
  40. package/src/data/encode.ts +155 -0
  41. package/src/data/envelope.ts +53 -0
  42. package/src/data/extract.ts +217 -0
  43. package/src/data/gemx-upload.ts +51 -0
  44. package/src/data/gemx.ts +35 -0
  45. package/src/data/index.ts +57 -0
  46. package/src/data/limit.ts +44 -0
  47. package/src/data/metadata.ts +340 -0
  48. package/src/data/metric.ts +51 -0
  49. package/src/data/ping.ts +36 -0
  50. package/src/data/signal.ts +30 -0
  51. package/src/data/summary.ts +34 -0
  52. package/src/data/token.ts +39 -0
  53. package/src/data/upgrade.ts +44 -0
  54. package/src/data/upload.ts +375 -0
  55. package/src/data/util.ts +18 -0
  56. package/src/data/variable.ts +84 -0
  57. package/src/diagnostic/encode.ts +40 -0
  58. package/src/diagnostic/fraud.ts +37 -0
  59. package/src/diagnostic/index.ts +13 -0
  60. package/src/diagnostic/internal.ts +28 -0
  61. package/src/diagnostic/script.ts +35 -0
  62. package/src/dynamic/agent/blank.ts +2 -0
  63. package/src/dynamic/agent/crisp.ts +40 -0
  64. package/src/dynamic/agent/encode.ts +25 -0
  65. package/src/dynamic/agent/index.ts +8 -0
  66. package/src/dynamic/agent/livechat.ts +58 -0
  67. package/src/dynamic/agent/tidio.ts +44 -0
  68. package/src/global.ts +6 -0
  69. package/src/index.ts +10 -0
  70. package/src/insight/blank.ts +14 -0
  71. package/src/insight/encode.ts +64 -0
  72. package/src/insight/snapshot.ts +115 -0
  73. package/src/interaction/change.ts +38 -0
  74. package/src/interaction/click.ts +256 -0
  75. package/src/interaction/clipboard.ts +32 -0
  76. package/src/interaction/encode.ts +217 -0
  77. package/src/interaction/focus.ts +25 -0
  78. package/src/interaction/index.ts +66 -0
  79. package/src/interaction/input.ts +66 -0
  80. package/src/interaction/pageshow.ts +35 -0
  81. package/src/interaction/pointer.ts +137 -0
  82. package/src/interaction/resize.ts +50 -0
  83. package/src/interaction/scroll.ts +134 -0
  84. package/src/interaction/selection.ts +66 -0
  85. package/src/interaction/submit.ts +30 -0
  86. package/src/interaction/timeline.ts +69 -0
  87. package/src/interaction/unload.ts +32 -0
  88. package/src/interaction/visibility.ts +28 -0
  89. package/src/layout/animation.ts +133 -0
  90. package/src/layout/constants.ts +13 -0
  91. package/src/layout/custom.ts +48 -0
  92. package/src/layout/discover.ts +31 -0
  93. package/src/layout/document.ts +46 -0
  94. package/src/layout/dom.ts +444 -0
  95. package/src/layout/encode.ts +157 -0
  96. package/src/layout/gemx-snapshot.ts +84 -0
  97. package/src/layout/index.ts +47 -0
  98. package/src/layout/mutation.ts +424 -0
  99. package/src/layout/node.ts +302 -0
  100. package/src/layout/offset.ts +19 -0
  101. package/src/layout/region.ts +151 -0
  102. package/src/layout/schema.ts +63 -0
  103. package/src/layout/selector.ts +113 -0
  104. package/src/layout/style.ts +160 -0
  105. package/src/layout/target.ts +34 -0
  106. package/src/layout/traverse.ts +28 -0
  107. package/src/performance/blank.ts +10 -0
  108. package/src/performance/encode.ts +31 -0
  109. package/src/performance/index.ts +12 -0
  110. package/src/performance/interaction.ts +125 -0
  111. package/src/performance/navigation.ts +31 -0
  112. package/src/performance/observer.ts +112 -0
  113. package/src/queue.ts +33 -0
  114. package/test/consentv2.test.ts +1309 -0
  115. package/test/hash.test.ts +68 -0
  116. package/test/time.test.ts +42 -0
  117. package/tsconfig.json +12 -0
  118. package/tslint.json +33 -0
  119. package/types/agent.d.ts +39 -0
  120. package/types/core.d.ts +156 -0
  121. package/types/data.d.ts +611 -0
  122. package/types/diagnostic.d.ts +24 -0
  123. package/types/global.d.ts +43 -0
  124. package/types/index.d.ts +46 -0
  125. package/types/interaction.d.ts +187 -0
  126. package/types/layout.d.ts +271 -0
  127. package/types/performance.d.ts +34 -0
@@ -0,0 +1 @@
1
+ !function(){"use strict";var t=Object.freeze({__proto__:null,get flush(){return oe},get inject(){return ie},get queue(){return ae},get start(){return re},get stop(){return ue},get track(){return Ft}}),e=Object.freeze({__proto__:null,get check(){return he},get compute(){return ve},get data(){return Kt},get start(){return pe},get stop(){return me},get trigger(){return ge}}),n=Object.freeze({__proto__:null,get compute(){return Ie},get data(){return ye},get log(){return ke},get reset(){return Ee},get start(){return _e},get stop(){return Se},get updates(){return we}}),r=Object.freeze({__proto__:null,get compute(){return Ae},get config(){return Ne},get consent(){return je},get data(){return Oe},get start(){return xe},get stop(){return Me},get trackConsentv2(){return Pe}}),a=Object.freeze({__proto__:null,get callback(){return Qe},get callbacks(){return De},get clear(){return Ke},get consent(){return Je},get consentv2(){return We},get data(){return qe},get electron(){return Re},get id(){return Ye},get metadata(){return Ve},get save(){return $e},get shortid(){return en},get start(){return Ue},get stop(){return Be}}),o=Object.freeze({__proto__:null,get data(){return on},get envelope(){return sn},get start(){return un},get stop(){return cn}}),i={projectId:null,delay:1e3,lean:!1,lite:!1,track:!0,content:!0,drop:[],mask:[],unmask:[],regions:[],cookies:[],fraud:!0,checksum:[],report:null,upload:null,fallback:null,upgrade:null,action:null,dob:null,delayDom:!1,throttleDom:!0,conversions:!1,includeSubdomains:!0,modules:[],diagnostics:!1,externalSession:!1,userId:null,sessionId:null,mode:"gemx"};function u(t){return window.Zone&&"__symbol__"in window.Zone?window.Zone.__symbol__(t):t}var c=0;function s(){return performance.now()+performance.timeOrigin}function l(t){void 0===t&&(t=null);var e=0===c?s():c,n=t&&t.timeStamp>0?t.timeStamp:performance.now(),r=t&&t.view?t.view.performance.timeOrigin:performance.timeOrigin;return Math.max(Math.round(n+r-e),0)}var d="0.8.94";var f=/\S/gi,p=255,h=!0,g=null,v=null,m=null;function y(t,e,n,r,a){if(void 0===r&&(r=!1),t){if("input"==e&&("checkbox"===a||"radio"===a))return t;switch(n){case 0:return t;case 1:switch(e){case"*T":case"value":case"placeholder":case"click":return function(t){var e=-1,n=0,r=!1,a=!1,o=!1,i=null;I();for(var u=0;u<t.length;u++){var c=t.charCodeAt(u);if(r=r||c>=48&&c<=57,a=a||64===c,o=9===c||10===c||13===c||32===c,0===u||u===t.length-1||o){if(r||a){null===i&&(i=t.split(""));var s=t.substring(e+1,o?u:u+1);s=h&&null!==m?s.match(m)?s:S(s,"▪","▫"):_(s),i.splice(e+1-n,s.length,s),n+=s.length-1}o&&(r=!1,a=!1,e=u)}}return i?i.join(""):t}(t);case"input":case"change":return k(t)}return t;case 2:case 3:switch(e){case"*T":case"data-":return r?b(t):_(t);case"src":case"srcset":case"title":case"alt":case"href":case"xlink:href":return 3===n?(null==t?void 0:t.startsWith("blob:"))?"blob:":"":t;case"value":case"click":case"input":case"change":return k(t);case"placeholder":return _(t)}break;case 4:switch(e){case"*T":case"data-":return r?b(t):_(t);case"value":case"input":case"click":case"change":return Array(5).join("•");case"checksum":return""}break;case 5:switch(e){case"*T":case"data-":return S(t,"▪","▫");case"value":case"input":case"click":case"change":return Array(5).join("•");case"checksum":case"src":case"srcset":case"alt":case"title":return""}}}return t}function w(t,e,n){void 0===e&&(e=!1),void 0===n&&(n=!1);var r=t;if(e)r="".concat("https://").concat("Electron");else{var a=i.drop;if(a&&a.length>0&&t&&t.indexOf("?")>0){var o=t.split("?"),u=o[0],c=o[1];r=u+"?"+c.split("&").map((function(t){return a.some((function(e){return 0===t.indexOf("".concat(e,"="))}))?"".concat(t.split("=")[0],"=").concat("*na*"):t})).join("&")}}return n&&(r=r.substring(0,p)),r}function b(t){var e=t.trim();if(e.length>0){var n=e[0],r=t.indexOf(n),a=t.substr(0,r),o=t.substr(r+e.length);return"".concat(a).concat(e.length.toString(36)).concat(o)}return t}function _(t){return t.replace(f,"•")}function S(t,e,n){return I(),t?t.replace(v,e).replace(g,n):t}function k(t){for(var e=5*(Math.floor(t.length/5)+1),n="",r=0;r<e;r++)n+=r>0&&r%5==0?" ":"•";return n}function I(){if(h&&null===g)try{g=new RegExp("\\p{N}","gu"),v=new RegExp("\\p{L}","gu"),m=new RegExp("\\p{Sc}","gu")}catch(t){h=!1}}var E=[],O=null;function T(){}var x=[];function M(){}function C(){}function N(){}function j(){}function z(){}var P=Object.freeze({__proto__:null,checkDocumentStyles:function(t){},compute:function(){},data:O,event:j,hashText:M,keys:x,log:T,observe:function(){},register:z,reset:function(){},sheetAdoptionState:[],sheetUpdateState:[],start:function(){},state:E,stop:function(){},track:N,trigger:C}),A=null;function q(t,e){zn()&&t&&"string"==typeof t&&t.length<255&&(A=e&&"string"==typeof e&&e.length<255?{key:t,value:e}:{value:t},fe(24))}var D,R=null,X=null;function H(t){t in R||(R[t]=0),t in X||(X[t]=0),R[t]++,X[t]++}function L(t,e){null!==e&&(t in R||(R[t]=0),t in X||(X[t]=0),R[t]+=e,X[t]+=e)}function U(t,e){null!==e&&!1===isNaN(e)&&(t in R||(R[t]=0),(e>R[t]||0===R[t])&&(X[t]=e,R[t]=e))}function G(t,e,n){return window.setTimeout(fn(t),e,n)}function B(t){return window.clearTimeout(t)}var V=0,Y=0,J=null;function W(){J&&B(J),J=G(Z,Y),V=l()}function Z(){var t=l();D={gap:t-V},fe(25),D.gap<3e5?J=G(Z,Y):Cn&&(q("clarityGemX","suspend"),ar(),["mousemove","touchstart"].forEach((function(t){return hn(document,t,Pn)})),["resize","scroll","pageshow"].forEach((function(t){return hn(window,t,Pn)})))}var F=Object.freeze({__proto__:null,get data(){return D},reset:W,start:function(){Y=6e4,V=0},stop:function(){B(J),V=0,Y=0}}),K=null;function Q(t){zn()&&i.lean&&(i.lean=!1,K={key:t},Qe(),$e(),i.upgrade&&i.upgrade(t),fe(3),i.lite)}var $=Object.freeze({__proto__:null,get data(){return K},start:function(){!i.lean&&i.upgrade&&i.upgrade("Config"),K=null},stop:function(){K=null},upgrade:Q}),tt=function(){return tt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var a in e=arguments[n])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t},tt.apply(this,arguments)};function et(t,e,n,r){return new(n||(n=Promise))((function(a,o){function i(t){try{c(r.next(t))}catch(t){o(t)}}function u(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?a(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(i,u)}c((r=r.apply(t,e||[])).next())}))}function nt(t,e){var n,r,a,o,i={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(c){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(i=0)),i;)try{if(n=1,r&&(a=2&u[0]?r.return:u[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,u[1])).done)return a;switch(r=0,a&&(u=[2&u[0],a.value]),u[0]){case 0:case 1:a=u;break;case 4:return i.label++,{value:u[1],done:!1};case 5:i.label++,r=u[1],u=[0];continue;case 7:u=i.ops.pop(),i.trys.pop();continue;default:if(!(a=i.trys,(a=a.length>0&&a[a.length-1])||6!==u[0]&&2!==u[0])){i=0;continue}if(3===u[0]&&(!a||u[1]>a[0]&&u[1]<a[3])){i.label=u[1];break}if(6===u[0]&&i.label<a[1]){i.label=a[1],a=u;break}if(a&&i.label<a[2]){i.label=a[2],i.ops.push(u);break}a[2]&&i.ops.pop(),i.trys.pop();continue}u=e.call(t,i)}catch(t){u=[6,t],r=0}finally{n=a=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}}var rt=null;function at(t,e){it(t,"string"==typeof e?[e]:e)}function ot(t,e,n,r){return void 0===e&&(e=null),void 0===n&&(n=null),void 0===r&&(r=null),et(this,void 0,void 0,(function(){var a,o;return nt(this,(function(i){switch(i.label){case 0:return o={},[4,st(t)];case 1:return o.userId=i.sent(),o.userHint=r||((u=t)&&u.length>=5?"".concat(u.substring(0,2)).concat(S(u.substring(2),"*","*")):S(u,"*","*")),it("userId",[(a=o).userId]),it("userHint",[a.userHint]),it("userType",[lt(t)]),e&&(it("sessionId",[e]),a.sessionId=e),n&&(it("pageId",[n]),a.pageId=n),[2,a]}var u}))}))}function it(t,e){if(zn()&&t&&e&&"string"==typeof t&&t.length<255){for(var n=(t in rt?rt[t]:[]),r=0;r<e.length;r++)"string"==typeof e[r]&&e[r].length<255&&n.push(e[r]);rt[t]=n}}function ut(){fe(34)}function ct(){rt={}}function st(t){return et(this,void 0,void 0,(function(){var e;return nt(this,(function(n){switch(n.label){case 0:return n.trys.push([0,4,,5]),crypto&&t?[4,crypto.subtle.digest("SHA-256",(new TextEncoder).encode(t))]:[3,2];case 1:return e=n.sent(),[2,Array.prototype.map.call(new Uint8Array(e),(function(t){return("00"+t.toString(16)).slice(-2)})).join("")];case 2:return[2,""];case 3:return[3,5];case 4:return n.sent(),[2,""];case 5:return[2]}}))}))}function lt(t){return t&&t.indexOf("@")>0?"email":"string"}var dt=Object.freeze({__proto__:null,compute:ut,get data(){return rt},identify:ot,reset:ct,set:at,start:function(){ct()},stop:function(){ct()}}),ft="CompressionStream"in window;function pt(t){return et(this,void 0,void 0,(function(){var e,n;return nt(this,(function(r){switch(r.label){case 0:return r.trys.push([0,3,,4]),ft?(e=new ReadableStream({start:function(e){return et(this,void 0,void 0,(function(){return nt(this,(function(n){return e.enqueue(t),e.close(),[2]}))}))}}).pipeThrough(new TextEncoderStream).pipeThrough(new window.CompressionStream("gzip")),n=Uint8Array.bind,[4,ht(e)]):[3,2];case 1:return[2,new(n.apply(Uint8Array,[void 0,r.sent()]))];case 2:return[3,4];case 3:return r.sent(),[3,4];case 4:return[2,null]}}))}))}function ht(t){return et(this,void 0,void 0,(function(){var e,n,r,a,o;return nt(this,(function(i){switch(i.label){case 0:e=t.getReader(),n=[],r=!1,a=[],i.label=1;case 1:return r?[3,3]:[4,e.read()];case 2:return o=i.sent(),r=o.done,a=o.value,r?[2,n]:(n.push.apply(n,a),[3,1]);case 3:return[2,n]}}))}))}function gt(t,e){try{return!!t[e]}catch(t){return!1}}function vt(t){try{var e=decodeURIComponent(t);return[e!=t,e]}catch(t){}return[!1,t]}var mt=null,yt="^";function wt(t,e){var n;if(void 0===e&&(e=!1),gt(document,"cookie")){var r=document.cookie.split(";");if(r)for(var a=0;a<r.length;a++){var o=r[a].split("=");if(o.length>1&&o[0]&&o[0].trim()===t){for(var i=vt(o[1]),u=i[0],c=i[1];u;)u=(n=vt(c))[0],c=n[1];return e?c.endsWith("".concat("~","1"))?c.substring(0,c.length-2):null:c}}}return null}function bt(t,e,n){if((i.track||""==e)&&(navigator&&navigator.cookieEnabled||gt(document,"cookie"))){var r=function(t){return encodeURIComponent(t)}(e),a=new Date;a.setDate(a.getDate()+n);var o=a?"expires="+a.toUTCString():"",u="".concat(t,"=").concat(r).concat(";").concat(o).concat(";path=/");try{if(null===mt){for(var c=location.hostname?location.hostname.split("."):[],s=c.length-1;s>=0;s--)if(mt=".".concat(c[s]).concat(mt||""),s<c.length-1&&(document.cookie="".concat(u).concat(";").concat("domain=").concat(mt),wt(t)===e))return;mt=""}}catch(t){mt=""}document.cookie=mt?"".concat(u).concat(";").concat("domain=").concat(mt):u}}var _t=Object.freeze({__proto__:null,COOKIE_SEP:yt,getCookie:wt,setCookie:bt,start:function(){mt=null},stop:function(){mt=null}}),St={debug:!1,excludeClassNames:[],ignoreMutationClassNames:[],discoverTrigger:null},kt=tt({},St);function It(){return kt.debug}var Et=Object.freeze({__proto__:null,get:function(){return kt},isDebug:It,set:function(t){kt=tt(tt({},kt),t)},start:function(){var t,e,n,r,a,o,i,u;kt={debug:new URLSearchParams(window.location.search).has("gemx_debug")||null!==(e=null===(t=null===window||void 0===window?void 0:window.GemXHeatmap)||void 0===t?void 0:t.debug)&&void 0!==e&&e,excludeClassNames:null!==(r=null===(n=null===window||void 0===window?void 0:window.GemXHeatmap)||void 0===n?void 0:n.excludeClassNames)&&void 0!==r?r:[],ignoreMutationClassNames:null!==(o=null===(a=null===window||void 0===window?void 0:window.GemXHeatmap)||void 0===a?void 0:a.ignoreMutationClassNames)&&void 0!==o?o:[],discoverTrigger:null!==(u=null===(i=null===window||void 0===window?void 0:window.GemXHeatmap)||void 0===i?void 0:i.discoverTrigger)&&void 0!==u?u:null}},stop:function(){kt=tt({},St)}}),Ot=[],Tt=0,xt=!1,Mt=0,Ct=null;function Nt(){return xt}function jt(t,e){Ot.push(t),Tt+=e,Mt>0&&Tt>=Mt&&Ct&&Ct()}var zt=null;function Pt(t){try{if(!zt)return;var e=function(t){try{return JSON.parse(t)}catch(t){return[]}}(t);e.forEach((function(t){zt(t)}))}catch(t){}}var At=[Et,Object.freeze({__proto__:null,config:function(t,e){return Mt=null!=t?t:0,Ct=null!=e?e:null,!0},drain:function(){xt=!1;var t=Ot;return Ot=[],Tt=0,t},getBytes:function(){return Tt},hold:jt,isActive:Nt,start:function(){Ot=[],Tt=0,xt=!0},stop:function(){Ot=[],Tt=0,xt=!1,Mt=0,Ct=null}}),P,n,dt,e,P,_t,r,a,o,t,F,$,P];function qt(){R={},X={},H(5),At.forEach((function(t){return fn(t.start)()}))}function Dt(){At.slice().reverse().forEach((function(t){return fn(t.stop)()})),R={},X={}}function Rt(){ve(),Ae(),"gemx"!==i.mode&&(ut(),Ie(),fe(0))}function Xt(t,e,n,r){return"href"===t&&"LINK"===r?"".concat(t,"=").concat(e):"".concat(t,"=").concat(y(e,0===t.indexOf("data-")?"data-":t,n))}var Ht=[],Lt=1,Ut=null;function Gt(){Ht=[],function(t){var e=[t];for(;e.length>0;){for(var n=null,r=null,a=null,o=e.shift(),i=o.firstChild,u=o.parentElement?o.parentElement:o.parentNode?o.parentNode:null;i;)e.push(i),i=i.nextSibling;switch(o.nodeType){case Node.DOCUMENT_TYPE_NODE:var c=o;r="*D",n={name:c.name,publicId:c.publicId,systemId:c.systemId};break;case Node.TEXT_NODE:a=o.nodeValue,r=Ut.get(u)?"*T":r;break;case Node.ELEMENT_NODE:var s=o;n=Bt(s),r=["NOSCRIPT","SCRIPT","STYLE"].indexOf(s.tagName)<0?s.tagName:r}Vt(o,u,{tag:r,attributes:n,value:a})}}(document),function(t){et(this,void 0,void 0,(function(){var e,n,r,a,o,i,u,c,s,d,f,p,h;return nt(this,(function(g){switch(e=l(),n=[e,t],t){case 8:r=O,n.push(r.width),n.push(r.height),r.width,r.height,ae(n);break;case 43:if((a=Ht).length>0){for(o=0,i=a;o<i.length;o++)for(u=i[o],c=u.metadata.privacy,s=u.data,d=0,f=["tag","attributes","value"];d<f.length;d++)if(s[p=f[d]])switch(p){case"tag":n.push(u.id),u.parent&&n.push(u.parent),u.previous&&n.push(u.previous),n.push(s[p]);break;case"attributes":for(h in s[p])void 0!==s[p][h]&&n.push(Xt(h,s[p][h],c,s.tag));break;case"value":n.push(y(s[p],s.tag,c))}ae(function(t){for(var e=[],n={},r=0,a=null,o=0;o<t.length;o++)if("string"==typeof t[o]){var i=t[o],u=n[i]||-1;u>=0?a?a.push(u):(a=[u],e.push(a),r++):(a=null,e.push(i),n[i]=r++)}else a=null,e.push(t[o]),r++;return e}(n),!0)}}return[2]}))}))}(43)}function Bt(t){var e={},n=t.attributes;if(n&&n.length>0)for(var r=0;r<n.length;r++)e[n[r].name]=n[r].value;return e}function Vt(t,e,n){if(t&&n&&n.tag){var r=function(t){return null===t?null:Ut.has(t)?Ut.get(t):(Ut.set(t,Lt),Lt++)}(t),a=e?Ut.get(e):null,o=t.previousSibling?Ut.get(t.previousSibling):null;Ht.push({id:r,parent:a,previous:o,children:[],data:n,selector:null,hash:null,region:null,metadata:{active:!0,suspend:!1,privacy:5,position:null,fraud:null,size:null}})}}var Yt,Jt,Wt,Zt,Ft,Kt,Qt=0,$t=0,te=null,ee=0,ne=!1;function re(){Zt=!0,Qt=0,$t=0,ne=!1,ee=0,Yt=[],Jt=[],Wt={},Ft=null}function ae(t,e){if(void 0===e&&(e=!0),Zt){var n=l(),r=t.length>1?t[1]:null,a=JSON.stringify(t);switch(i.lean?!ne&&$t+a.length>10485760&&(ne=!0):ne=!1,r){case 5:if(ne)break;if(Nt()){jt(t,a.length);break}Qt+=a.length;case 37:case 6:case 43:case 45:case 46:case 44:case 51:if(ne)break;Nt()&&jt(t,a.length),$t+=a.length,Yt.push(a);break;default:Jt.push(a)}H(25);var o=function(){var t=!1===i.lean&&Qt>0?100:on.sequence*i.delay;return"string"==typeof i.upload?Math.max(Math.min(t,3e4),100):i.delay}();n-ee>2*o&&(B(te),te=null),e&&null===te&&(25!==r&&W(),te=G(ce,o),ee=n,he($t))}}function oe(t){Zt&&(B(te),te=null,ce(!1,t))}function ie(t){for(var e=0,n=t;e<n.length;e++){var r=n[e],a=JSON.stringify(r);Qt+=a.length,$t+=a.length,Yt.push(a)}}function ue(){B(te),ce(!0),Qt=0,$t=0,ne=!1,ee=0,Yt=[],Jt=[],Wt={},Ft=null,Zt=!1}function ce(t,e){return void 0===t&&(t=!1),et(this,void 0,void 0,(function(){var n,r,a,o,u,c,s,l,d,f,p,h,g,v,m,y,w;return nt(this,(function(b){switch(b.label){case 0:if(!Zt)return[2];if(te=null,(n=("gemx-snapshot"===e||!1===i.lean)&&$t>0&&($t<1048576||on.sequence>0))&&U(1,1),Rt(),r=!0===t,!on)return[2];if(a=It(),!e&&a){for(o=[[9,"click"],[10,"scroll"]],u=new Set(Jt.map((function(t){return JSON.parse(t)[1]}))),c=[],s=0,l=o;s<l.length;s++)f=(d=l[s])[0],p=d[1],u.has(f)&&c.push(p);e=c.length>0?c.join("-"):void 0}return h=JSON.stringify(sn(r)),g="[".concat(Jt.join(),"]"),v=n?"[".concat(Yt.join(),"]"):"",r&&v.length>0&&h.length+g.length+v.length>65536&&(v=""),m=function(t){return t.p.length>0?'{"e":'.concat(t.e,',"a":').concat(t.a,',"p":').concat(t.p,"}"):'{"e":'.concat(t.e,',"a":').concat(t.a,"}")}({e:h,a:g,p:v}),r?(w=null,[3,3]):[3,1];case 1:return[4,pt(m)];case 2:w=b.sent(),b.label=3;case 3:return L(2,(y=w)?y.length:m.length),se(m,y,on.sequence,r,e),Jt=[],n&&(Yt=[],$t=0,Qt=0,ne=!1),[2]}}))}))}function se(t,e,n,r,a){if(void 0===r&&(r=!1),"string"==typeof i.upload){var o=i.upload,u=!1;if(r&&navigator&&navigator.sendBeacon)try{(u=navigator.sendBeacon.bind(navigator)(o,t))&&de(n)}catch(t){}if(!1===u){n in Wt?Wt[n].attempts++:Wt[n]={data:t,attempts:1};var c=new XMLHttpRequest;c.open("POST",o,!0),c.timeout=15e3,c.ontimeout=function(){dn(new Error("".concat("Timeout"," : ").concat(o)))},null!==n&&(c.onreadystatechange=function(){fn(le)(c,n)}),c.withCredentials=!0,e?(c.setRequestHeader("Accept","application/x-clarity-gzip"),c.send(e)):c.send(t)}}else if(i.upload){(0,i.upload)(t,a),de(n)}}function le(t,e){var n=Wt[e];t&&4===t.readyState&&n&&((t.status<200||t.status>208)&&n.attempts<=1?t.status>=400&&t.status<500?ge(6):(0===t.status&&(i.upload=i.fallback?i.fallback:i.upload),Ft={sequence:e,attempts:n.attempts,status:t.status},fe(2),se(n.data,null,e)):(Ft={sequence:e,attempts:n.attempts,status:t.status},n.attempts>1&&fe(2),200===t.status&&t.responseText&&function(t){for(var e=t&&t.length>0?t.split("\n"):[],n=0,r=e;n<r.length;n++){var a=r[n],o=a&&a.length>0?a.split(/ (.*)/):[""];switch(o[0]){case"END":ge(6);break;case"UPGRADE":Q("Auto");break;case"ACTION":i.action&&o.length>1&&i.action(o[1]);break;case"EXTRACT":case"MODULE":o.length>1&&o[1];break;case"SIGNAL":o.length>1&&Pt(o[1]);break;case"SNAPSHOT":i.lean=!1,Gt()}}}(t.responseText),0===t.status&&(se(n.data,null,e,!0),ge(3)),t.status>=200&&t.status<=208&&de(e),delete Wt[e]))}function de(t){1===t&&($e(),Qe())}function fe(t){var e=[l(),t];switch(t){case 4:var n=E;n&&n.data&&((e=[n.time,n.event]).push(n.data.visible),e.push(n.data.docWidth),e.push(n.data.docHeight),e.push(n.data.screenWidth),e.push(n.data.screenHeight),e.push(n.data.scrollX),e.push(n.data.scrollY),e.push(n.data.pointerX),e.push(n.data.pointerY),e.push(n.data.activityTime),e.push(n.data.scrollTime),e.push(n.data.pointerTime),e.push(n.data.moveX),e.push(n.data.moveY),e.push(n.data.moveTime),e.push(n.data.downX),e.push(n.data.downY),e.push(n.data.downTime),e.push(n.data.upX),e.push(n.data.upY),e.push(n.data.upTime),e.push(n.data.pointerPrevX),e.push(n.data.pointerPrevY),e.push(n.data.pointerPrevTime),e.push(n.data.modules),ae(e,!1));break;case 25:e.push(D.gap),ae(e);break;case 35:e.push(Kt.check),ae(e,!1);break;case 3:e.push(K.key),ae(e);break;case 2:e.push(Ft.sequence),e.push(Ft.attempts),e.push(Ft.status),ae(e,!1);break;case 24:A.key&&e.push(A.key),e.push(A.value),ae(e);break;case 34:var r=Object.keys(rt);if(r.length>0){for(var a=0,o=r;a<o.length;a++){var i=o[a];e.push(i),e.push(rt[i])}ct(),ae(e,!1)}break;case 0:var u=Object.keys(X);if(u.length>0){for(var c=0,s=u;c<s.length;c++){var d=s[c],f=parseInt(d,10);e.push(f),e.push(Math.round(X[d]))}X={},ae(e,!1)}break;case 1:var p=Object.keys(we);if(p.length>0){for(var h=0,g=p;h<g.length;h++){var v=g[h];f=parseInt(v,10);e.push(f),e.push(we[v])}Ee(),ae(e,!1)}break;case 36:var m=Object.keys(O);if(m.length>0){for(var y=0,w=m;y<w.length;y++){var b=w[y];f=parseInt(b,10);e.push(f),e.push([].concat.apply([],O[b]))}ae(e,!1)}break;case 40:x.forEach((function(t){e.push(t);var n=[];for(var r in O[t]){var a=parseInt(r,10);n.push(a),n.push(O[t][r])}e.push(n)})),ae(e,!1);break;case 47:e.push(Oe.source),e.push(Oe.ad_Storage),e.push(Oe.analytics_Storage),ae(e,!1)}}function pe(){Kt={check:0}}function he(t){if(0===Kt.check){var e=Kt.check;e=on.sequence>=128?1:e,e=on.pageNum>=128?7:e,e=l()>72e5?2:e,(e=t>10485760?2:e)!==Kt.check&&ge(e)}}function ge(t){Kt.check=t,5!==t&&(Ke(),ar())}function ve(){0!==Kt.check&&fe(35)}function me(){Kt=null}var ye=null,we=null,be=!1;function _e(){ye={},we={},be=!1}function Se(){ye={},we={},be=!1}function ke(t,e){if(e&&(e="".concat(e),t in ye||(ye[t]=[]),ye[t].indexOf(e)<0)){if(ye[t].length>128)return void(be||(be=!0,ge(5)));ye[t].push(e),t in we||(we[t]=[]),we[t].push(e)}}function Ie(){fe(1)}function Ee(){we={},be=!1}var Oe=null,Te=!0;function xe(){var t,e=null===(t=window.google_tag_data)||void 0===t?void 0:t.ics;Te=!0,(null==e?void 0:e.addListener)&&e.addListener(["ad_storage","analytics_storage"],Ce)}function Me(){Te=!0}function Ce(){var t,e=null===(t=window.google_tag_data)||void 0===t?void 0:t.ics;if(null==e?void 0:e.getConsentState)try{var n=e.getConsentState("analytics_storage");We(function(t){var e={source:2,ad_Storage:1===t.ad_Storage?"granted":"denied",analytics_Storage:1===t.analytics_Storage?"granted":"denied"};return e}({ad_Storage:e.getConsentState("ad_storage"),analytics_Storage:n}))}catch(t){return}}function Ne(t){ze(t.analytics_Storage?1:0),Oe=t}function je(){ze(2)}function ze(t){ke(36,t.toString())}function Pe(t){Oe=t,fe(47)}function Ae(){var t;if(Te&&(fe(47),Te=!1,!i.track)){var e=null===(t=window.google_tag_data)||void 0===t?void 0:t.ics;(null==e?void 0:e.usedUpdate)&&Ce()}}var qe=null,De=[],Re=0,Xe=null,He=!1,Le={source:7,ad_Storage:"denied",analytics_Storage:"denied"};function Ue(){var t,e,n,r=navigator&&"userAgent"in navigator?navigator.userAgent:"",a=null!==(n="undefined"!=typeof Intl&&(null===(e=null===(t=null===Intl||void 0===Intl?void 0:Intl.DateTimeFormat())||void 0===t?void 0:t.resolvedOptions())||void 0===e?void 0:e.timeZone))&&void 0!==n?n:"",o=(new Date).getTimezoneOffset().toString(),u=window.location.ancestorOrigins?Array.from(window.location.ancestorOrigins).toString():"",c=document&&document.title?document.title:"";Re=r.indexOf("Electron")>0?1:0;var s=function(){var t={session:en(),ts:Math.round(Date.now()),count:1,upgrade:null,upload:""},e=wt("_clsk",!i.includeSubdomains);if(e){var n=e.includes("^")?e.split("^"):e.split("|");n.length>=5&&t.ts-nn(n[1])<18e5&&(t.session=n[0],t.count=nn(n[2])+1,t.upgrade=nn(n[3]),t.upload=n.length>=6?"".concat("https://").concat(n[5],"/").concat(n[4]):"".concat("https://").concat(n[4]))}return t}(),l=rn(),d=i.projectId||function(t,e){void 0===e&&(e=null);for(var n,r=5381,a=r,o=0;o<t.length;o+=2)r=(r<<5)+r^t.charCodeAt(o),o+1<t.length&&(a=(a<<5)+a^t.charCodeAt(o+1));return n=Math.abs(r+11579*a),(e?n%Math.pow(2,e):n).toString(36)}(location.host),f=i.externalSession&&i.userId?i.userId:l.id,p=i.externalSession&&i.sessionId?i.sessionId:s.session;qe={projectId:d,userId:f,sessionId:p,pageNum:s.count},i.lean=i.track&&null!==s.upgrade?0===s.upgrade:i.lean,i.upload=i.track&&"string"==typeof i.upload&&s.upload&&s.upload.length>"https://".length?s.upload:i.upload,ke(0,r),ke(3,c),ke(1,w(location.href,!!Re)),ke(2,document.referrer),ke(15,function(){var t=en();if(i.track&&gt(window,"sessionStorage")){var e=sessionStorage.getItem("_cltk");t=e||t,sessionStorage.setItem("_cltk",t)}return t}()),ke(16,document.documentElement.lang),ke(17,document.dir),ke(26,"".concat(window.devicePixelRatio)),ke(28,l.dob.toString()),ke(29,l.version.toString()),ke(33,u),ke(34,a),ke(35,o),U(0,s.ts),U(1,0),U(35,Re);var h,g=null===window||void 0===window?void 0:window.Zone;g&&"__symbol__"in g&&U(39,1),navigator&&(ke(9,navigator.language),U(33,navigator.hardwareConcurrency),U(32,navigator.maxTouchPoints),U(34,Math.round(navigator.deviceMemory)),(h=navigator.userAgentData)&&h.getHighEntropyValues?h.getHighEntropyValues(["model","platform","platformVersion","uaFullVersion"]).then((function(t){var e;ke(22,t.platform),ke(23,t.platformVersion),null===(e=t.brands)||void 0===e||e.forEach((function(t){ke(24,t.name+"~"+t.version)})),ke(25,t.model),U(27,t.mobile?1:0)})):ke(22,navigator.platform)),screen&&(U(14,Math.round(screen.width)),U(15,Math.round(screen.height)),U(16,Math.round(screen.colorDepth))),null===Xe&&(Xe={source:l.consent?6:0,ad_Storage:i.track?"granted":"denied",analytics_Storage:i.track?"granted":"denied"}),Ge(),Ne(Ze(Xe)),i.externalSession||tn(l)}function Ge(){if(!He&&"granted"===(null==Xe?void 0:Xe.analytics_Storage)&&"granted"===(null==Xe?void 0:Xe.ad_Storage)){for(var t=0,e=i.cookies;t<e.length;t++){var n=e[t],r=wt(n);r&&at(n,r)}He=!0}}function Be(){qe=null,He=!1,De.forEach((function(t){t.called=!1}))}function Ve(t,e,n,r){void 0===e&&(e=!0),void 0===n&&(n=!1),void 0===r&&(r=!1);var a=i.lean?0:1,o=!1;qe&&(a||!1===e)&&(t(qe,!i.lean,r?Xe:void 0),o=!0),!n&&o||De.push({callback:t,wait:e,recall:n,called:o,consentInfo:r})}function Ye(){return qe?[qe.userId,qe.sessionId,qe.pageNum].join("."):""}function Je(t){void 0===t&&(t=!0),We(t?{source:4,ad_Storage:"granted",analytics_Storage:"granted"}:{source:4,ad_Storage:"denied",analytics_Storage:"denied"})}function We(t,e){var n;if(void 0===t&&(t=Le),void 0===e&&(e=5),zn()){var r={source:null!==(n=t.source)&&void 0!==n?n:e,ad_Storage:Fe(t.ad_Storage,null==Xe?void 0:Xe.ad_Storage),analytics_Storage:Fe(t.analytics_Storage,null==Xe?void 0:Xe.analytics_Storage)};if(Xe&&r.ad_Storage===Xe.ad_Storage&&r.analytics_Storage===Xe.analytics_Storage)return Xe.source=r.source,Pe(Ze(Xe)),void je();Xe=r,Qe(!0);var a=Ze(Xe);if(!a.analytics_Storage&&i.track)return i.track=!1,Ke(!0),ar(),void window.setTimeout(rr,250);zn()&&a.analytics_Storage&&(i.track=!0,tn(rn(),1),$e()),Ge(),Pe(a),je()}}function Ze(t){var e;return{source:null!==(e=t.source)&&void 0!==e?e:255,ad_Storage:"granted"===t.ad_Storage?1:0,analytics_Storage:"granted"===t.analytics_Storage?1:0}}function Fe(t,e){return void 0===e&&(e="denied"),"string"==typeof t?t.toLowerCase():e}function Ke(t){void 0===t&&(t=!1),bt("_clsk","",0),t&&bt("_clck","",0)}function Qe(t){void 0===t&&(t=!1),function(t,e){void 0===e&&(e=!1);if(De.length>0)for(var n=0;n<De.length;n++){var r=De[n];r.callback&&(!r.called&&!e||r.consentInfo&&e)&&(!r.wait||t)&&(r.callback(qe,!i.lean,r.consentInfo?Xe:void 0),r.called=!0,r.recall||(De.splice(n,1),n--))}}(i.lean?0:1,t)}function $e(){if(qe&&i.track&&!i.externalSession){var t=Math.round(Date.now()),e=i.upload&&"string"==typeof i.upload?i.upload.replace("https://",""):"",n=i.lean?0:1;bt("_clsk",[qe.sessionId,t,qe.pageNum,n,e].join(yt),1)}}function tn(t,e){void 0===e&&(e=null),e=null===e?t.consent:e;var n=Math.ceil((Date.now()+31536e6)/864e5),r=0===t.dob?null===i.dob?0:i.dob:t.dob;(null===t.expiry||Math.abs(n-t.expiry)>=1||t.consent!==e||t.dob!==r)&&bt("_clck",[qe.userId,2,n.toString(36),e,r].join(yt),365)}function en(){var t=Math.floor(Math.random()*Math.pow(2,32));return window&&window.crypto&&window.crypto.getRandomValues&&Uint32Array&&(t=window.crypto.getRandomValues(new Uint32Array(1))[0]),t.toString(36)}function nn(t,e){return void 0===e&&(e=10),parseInt(t,e)}function rn(){var t={id:en(),version:0,expiry:null,consent:0,dob:0},e=wt("_clck",!i.includeSubdomains);if(e&&e.length>0){var n=e.includes("^")?e.split("^"):e.split("|");n.length>1&&(t.version=nn(n[1])),n.length>2&&(t.expiry=nn(n[2],36)),n.length>3&&1===nn(n[3])&&(t.consent=1),n.length>4&&nn(n[1])>1&&(t.dob=nn(n[4])),i.track=i.track||1===t.consent,t.id=i.track?n[0]:t.id}return t}var an,on=null;function un(){var t=qe;on={version:d,sequence:0,start:0,duration:0,projectId:t.projectId,userId:t.userId,sessionId:t.sessionId,pageNum:t.pageNum,upload:0,end:0,applicationPlatform:0,url:""}}function cn(){on=null}function sn(t){return on.start=on.start+on.duration,on.duration=l()-on.start,on.sequence++,on.upload=t&&"sendBeacon"in navigator?1:0,on.end=t?1:0,on.applicationPlatform=0,on.url=w(location.href,!1,!0),[on.version,on.sequence,on.start,on.duration,on.projectId,on.userId,on.sessionId,on.pageNum,on.upload,on.end,on.applicationPlatform,on.url]}function ln(){an=[]}function dn(t){if(an&&-1===an.indexOf(t.message)){var e=i.report;if(e&&e.length>0&&on){var n={v:on.version,p:on.projectId,u:on.userId,s:on.sessionId,n:on.pageNum};t.message&&(n.m=t.message),t.stack&&(n.e=t.stack);var r=new XMLHttpRequest;r.open("POST",e,!0),r.send(JSON.stringify(n)),an.push(t.message)}}return t}function fn(t){return function(){var e=performance.now();try{t.apply(this,arguments)}catch(t){throw dn(t)}var n=performance.now()-e;L(4,n),n>30&&(H(7),U(6,n),t.dn&&"".concat(t.dn,"-").concat(n))}}var pn=new Map;function hn(t,e,n,r,a){void 0===r&&(r=!1),void 0===a&&(a=!0),n=fn(n);try{t[u("addEventListener")](e,n,{capture:r,passive:a}),function(t){return pn.has(t)}(t)||pn.set(t,[]),pn.get(t).push({event:e,listener:n,options:{capture:r,passive:a}})}catch(t){}}function gn(){pn.forEach((function(t,e){!function(t,e){t.forEach((function(t){try{e[u("removeEventListener")](t.event,t.listener,{capture:t.options.capture,passive:t.options.passive})}catch(t){}})),pn.delete(e)}(t,e)})),pn=new Map}var vn=null,mn=null,yn=null,wn=0;function bn(){return!(wn++>20)}function _n(){wn=0,yn!==kn()&&(ar(),window.setTimeout(Sn,250))}function Sn(){rr(),U(29,1)}function kn(){return location.href?location.href.replace(location.hash,""):location.href}var In=[],En=null,On=null,Tn=null;function xn(){In=[],En=null,On=null}function Mn(){var t=In.shift();t&&(En=t,t.task().then((function(){t.id===Ye()&&(t.resolve(),En=null,Mn())})).catch((function(e){t.id===Ye()&&(e&&(e.name,e.message,e.stack),En=null,Mn())})))}var Cn=!1;function Nn(){Cn=!0,c=s(),xn(),gn(),ln(),function(){if(yn=kn(),wn=0,hn(window,"popstate",_n),null===vn)try{vn=history.pushState,history.pushState=function(){vn.apply(this,arguments),zn()&&bn()&&_n()}}catch(t){vn=null}if(null===mn)try{mn=history.replaceState,history.replaceState=function(){mn.apply(this,arguments),zn()&&bn()&&_n()}}catch(t){mn=null}}()}function jn(){yn=null,wn=0,ln(),gn(),xn(),c=0,Cn=!1}function zn(){return Cn}function Pn(){rr(),q("clarityGemX","restart")}var An=null;function qn(){An=null}function Dn(t){An={fetchStart:Math.round(t.fetchStart),connectStart:Math.round(t.connectStart),connectEnd:Math.round(t.connectEnd),requestStart:Math.round(t.requestStart),responseStart:Math.round(t.responseStart),responseEnd:Math.round(t.responseEnd),domInteractive:Math.round(t.domInteractive),domComplete:Math.round(t.domComplete),loadEventStart:Math.round(t.loadEventStart),loadEventEnd:Math.round(t.loadEventEnd),redirectCount:Math.round(t.redirectCount),size:t.transferSize?t.transferSize:0,type:t.type,protocol:t.nextHopProtocol,encodedSize:t.encodedBodySize?t.encodedBodySize:0,decodedSize:t.decodedBodySize?t.decodedBodySize:0},function(t){et(this,void 0,void 0,(function(){var e,n;return nt(this,(function(r){return e=l(),n=[e,t],29===t&&(n.push(An.fetchStart),n.push(An.connectStart),n.push(An.connectEnd),n.push(An.requestStart),n.push(An.responseStart),n.push(An.responseEnd),n.push(An.domInteractive),n.push(An.domComplete),n.push(An.loadEventStart),n.push(An.loadEventEnd),n.push(An.redirectCount),n.push(An.size),n.push(An.type),n.push(An.protocol),n.push(An.encodedSize),n.push(An.decodedSize),qn(),ae(n)),[2]}))}))}(29)}var Rn,Xn=0,Hn=1/0,Ln=0,Un=0,Gn=[],Bn=new Map,Vn=function(){return Xn||0},Yn=function(){if(!Gn.length)return-1;var t=Math.min(Gn.length-1,Math.floor((Vn()-Un)/50));return Gn[t].latency},Jn=function(){Un=Vn(),Gn.length=0,Bn.clear()},Wn=function(t){if(t.interactionId&&!(t.duration<40)){!function(t){"interactionCount"in performance?Xn=performance.interactionCount:t.interactionId&&(Hn=Math.min(Hn,t.interactionId),Ln=Math.max(Ln,t.interactionId),Xn=Ln?(Ln-Hn)/7+1:0)}(t);var e=Gn[Gn.length-1],n=Bn.get(t.interactionId);if(n||Gn.length<10||t.duration>(null==e?void 0:e.latency)){if(n)t.duration>n.latency&&(n.latency=t.duration);else{var r={id:t.interactionId,latency:t.duration};Bn.set(r.id,r),Gn.push(r)}Gn.sort((function(t,e){return e.latency-t.latency})),Gn.length>10&&Gn.splice(10).forEach((function(t){return Bn.delete(t.id)}))}}},Zn=["navigation","resource","longtask","first-input","layout-shift","largest-contentful-paint","event"];function Fn(){try{Rn&&Rn.disconnect(),Rn=new PerformanceObserver(fn(Kn));for(var t=0,e=Zn;t<e.length;t++){var n=e[t];PerformanceObserver.supportedEntryTypes.indexOf(n)>=0&&("layout-shift"===n&&L(9,0),Rn.observe({type:n,buffered:!0}))}}catch(t){}}function Kn(t){!function(t){for(var e=(!("visibilityState"in document)||"visible"===document.visibilityState),n=0;n<t.length;n++){var r=t[n];switch(r.entryType){case"navigation":Dn(r);break;case"resource":var a=r.name;ke(4,$n(a)),a!==i.upload&&a!==i.fallback||U(28,r.duration);break;case"longtask":H(7);break;case"first-input":e&&U(10,r.processingStart-r.startTime);break;case"event":e&&"PerformanceEventTiming"in window&&"interactionId"in PerformanceEventTiming.prototype&&(Wn(r),ke(37,Yn().toString()));break;case"layout-shift":e&&!r.hadRecentInput&&L(9,1e3*r.value);break;case"largest-contentful-paint":e&&U(8,r.startTime)}}}(t.getEntries())}var Qn=null;function $n(t){return Qn||(Qn=document.createElement("a")),Qn.href=t,Qn.host}var tr=[P,P,P],er=[P,P,P,Object.freeze({__proto__:null,start:function(){qn(),function(){navigator&&navigator.connection&&ke(27,navigator.connection.effectiveType),window.PerformanceObserver&&PerformanceObserver.supportedEntryTypes&&("complete"!==document.readyState?hn(window,"load",G.bind(this,Fn,0)):Fn())}()},stop:function(){Rn&&Rn.disconnect(),Rn=null,Jn(),Qn=null,qn()}}),P],nr=er;function rr(t){void 0===t&&(t=null),nr="gemx"===(null==t?void 0:t.mode)?tr:er,console.log("[clarity] version:",d),function(){try{var t=navigator&&"globalPrivacyControl"in navigator&&1==navigator.globalPrivacyControl;return!1===Cn&&"undefined"!=typeof Promise&&window.MutationObserver&&document.createTreeWalker&&"now"in Date&&"now"in performance&&"undefined"!=typeof WeakMap&&!t}catch(t){return!1}}()&&(!function(t){if(null===t||Cn)return!1;for(var e in t)e in i&&(i[e]=t[e])}(t),Nn(),qt(),nr.forEach((function(t){return fn(t.start)()})),null===t&&cr())}function ar(){zn()&&(nr.slice().reverse().forEach((function(t){return fn(t.stop)()})),Dt(),jn(),void 0!==ir&&(ir[ur]=function(){(ir[ur].q=ir[ur].q||[]).push(arguments),"start"===arguments[0]&&ir[ur].q.unshift(ir[ur].q.pop())&&cr()}))}var or=Object.freeze({__proto__:null,consent:Je,consentv2:We,dlog:ke,event:q,hashText:M,identify:ot,maxMetric:U,measure:fn,metadata:Ve,pause:function(){zn()&&(q("clarityGemX","pause"),null===On&&(On=new Promise((function(t){Tn=t}))))},queue:ae,register:z,resume:function(){zn()&&(On&&(Tn(),On=null,null===En&&Mn()),q("clarityGemX","resume"))},schedule:function(t,e){return void 0===e&&(e=0),et(this,void 0,void 0,(function(){var n,r,a;return nt(this,(function(o){for(n=0,r=In;n<r.length;n++)if(r[n].task===t)return[2];return a=new Promise((function(n){In[1===e?"unshift":"push"]({task:t,resolve:n,id:Ye()})})),null===En&&null===On&&Mn(),[2,a]}))}))},set:at,signal:function(t){zt=t},start:rr,stop:ar,time:l,upgrade:Q,version:d}),ir=window,ur="clarityGemX";function cr(){if(void 0!==ir){if(ir[ur]&&ir[ur].v)return console.warn("Error CL001: Multiple Clarity tags detected.");var t=ir[ur]&&ir[ur].q||[];for(ir[ur]=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];return or[t].apply(or,e)},ir[ur].v=d;t.length>0;)ir[ur].apply(ir,t.shift())}}cr()}();
@@ -0,0 +1 @@
1
+ !function(){"use strict";function i(i){var n=[window.clarity("time"),52];switch(i){case 0:case 1:case 2:case 3:case 4:case 5:case 6:n.push(i)}!function(i){"undefined"!=typeof window&&window.clarity&&window.clarity("queue",i)}(n)}function n(){i(3)}function s(){i(4)}function e(){i(6)}function c(){i(5)}function o(){window.$crisp&&(window.$crisp.push(["off","chat:opened",n]),window.$crisp.push(["off","chat:closed",s]),window.$crisp.push(["off","message:sent",e]),window.$crisp.push(["off","message:received",c]))}window.$crisp&&(window.$crisp.push(["on","chat:opened",n]),window.$crisp.push(["on","chat:closed",s]),window.$crisp.push(["on","message:sent",e]),window.$crisp.push(["on","message:received",c])),"undefined"!=typeof window&&window.clarity&&window.clarity("register",o)}();
@@ -0,0 +1 @@
1
+ !function(){"use strict";function i(i){var o=[window.clarity("time"),52];switch(i){case 0:case 1:case 2:case 3:case 4:case 5:case 6:o.push(i)}!function(i){"undefined"!=typeof window&&window.clarity&&window.clarity("queue",i)}(o)}var o=!1;function n(){o&&i(3)}function t(){o&&i(4)}function w(){o&&i(6)}function e(){o&&i(5)}function a(){window.tidioChatApi&&(o=!1)}window.tidioChatApi&&(window.tidioChatApi.on("open",n),window.tidioChatApi.on("close",t),window.tidioChatApi.on("messageFromVisitor",w),window.tidioChatApi.on("messageFromOperator",e),o=!0),"undefined"!=typeof window&&window.clarity&&window.clarity("register",a)}();
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@gem-sdk/clarity-js",
3
+ "version": "0.8.94",
4
+ "description": "Clarity js",
5
+ "author": "Microsoft Corp.",
6
+ "license": "MIT",
7
+ "main": "build/clarity.js",
8
+ "module": "build/clarity.module.js",
9
+ "unpkg": "build/clarity.min.js",
10
+ "extended": "build/clarity.extended.js",
11
+ "insight": "build/clarity.insight.js",
12
+ "performance": "build/clarity.performance.js",
13
+ "livechat": "build/clarity.livechat.js",
14
+ "tidio": "build/dynamic/clarity.tidio.js",
15
+ "crisp": "build/dynamic/clarity.crisp.js",
16
+ "types": "types/index.d.ts",
17
+ "devDependencies": {
18
+ "@rollup/plugin-alias": "^4.0.0",
19
+ "@rollup/plugin-commonjs": "^24.0.0",
20
+ "@rollup/plugin-node-resolve": "^15.0.0",
21
+ "@rollup/plugin-terser": "^0.4.0",
22
+ "@rollup/plugin-typescript": "^11.0.0",
23
+ "@types/resize-observer-browser": "^0.1.6",
24
+ "del-cli": "^5.0.0",
25
+ "husky": "^8.0.0",
26
+ "lint-staged": "^13.1.0",
27
+ "rollup": "^3.0.0",
28
+ "tslint": "^6.1.3",
29
+ "typescript": "^4.3.5"
30
+ },
31
+ "scripts": {
32
+ "build": "yarn build:clean && yarn build:main",
33
+ "build:main": "rollup -c rollup.config.ts --configPlugin @rollup/plugin-typescript",
34
+ "build:clean": "del-cli build/*",
35
+ "test": "playwright test --config ../../playwright.config.ts --project=clarity-js",
36
+ "tslint": "tslint --project ./",
37
+ "tslint:fix": "tslint --fix --project ./ --force"
38
+ },
39
+ "husky": {
40
+ "hooks": {
41
+ "pre-commit": "lint-staged"
42
+ }
43
+ },
44
+ "lint-staged": {
45
+ "*.ts": [
46
+ "tslint --format codeFrame"
47
+ ]
48
+ }
49
+ }
@@ -0,0 +1,161 @@
1
+ import alias from "@rollup/plugin-alias";
2
+ import commonjs from "@rollup/plugin-commonjs";
3
+ import resolve from "@rollup/plugin-node-resolve";
4
+ import terser from "@rollup/plugin-terser";
5
+ import typescript from "@rollup/plugin-typescript";
6
+ import { readFileSync } from "fs";
7
+
8
+ const pkg = JSON.parse(readFileSync("./package.json", "utf-8"));
9
+ export default [
10
+ {
11
+ input: "src/index.ts",
12
+ output: [
13
+ { file: pkg.main, format: "cjs", exports: "named" },
14
+ { file: pkg.module, format: "es", exports: "named" }
15
+ ],
16
+ plugins: [
17
+ resolve(),
18
+ typescript(),
19
+ commonjs({ include: ["node_modules/**"] })
20
+ ],
21
+ onwarn(message, warn) {
22
+ if (message.code === 'CIRCULAR_DEPENDENCY') { return; }
23
+ warn(message);
24
+ }
25
+ },
26
+ {
27
+ input: "src/global.ts",
28
+ output: [ { file: pkg.unpkg, format: "iife", exports: "named" } ],
29
+ onwarn(message, warn) {
30
+ if (message.code === 'CIRCULAR_DEPENDENCY') { return; }
31
+ warn(message);
32
+ },
33
+ plugins: [
34
+ resolve(),
35
+ typescript(),
36
+ terser({output: {comments: false}}),
37
+ commonjs({ include: ["node_modules/**"] })
38
+ ]
39
+ },
40
+ {
41
+ input: "src/global.ts",
42
+ output: [ { file: pkg.extended, format: "iife", exports: "named" } ],
43
+ onwarn(message, warn) {
44
+ if (message.code === 'CIRCULAR_DEPENDENCY') { return; }
45
+ warn(message);
46
+ },
47
+ plugins: [
48
+ resolve(),
49
+ typescript(),
50
+ terser({output: {comments: false}}),
51
+ commonjs({ include: ["node_modules/**"] })
52
+ ]
53
+ },
54
+ {
55
+ input: "src/global.ts",
56
+ output: [ { file: pkg.insight, format: "iife", exports: "named" } ],
57
+ onwarn(message, warn) {
58
+ if (message.code === 'CIRCULAR_DEPENDENCY') { return; }
59
+ warn(message);
60
+ },
61
+ plugins: [
62
+ alias({
63
+ entries: [
64
+ { find: '@src/layout/style', replacement: '@src/insight/blank' },
65
+ { find: '@src/layout/document', replacement: '@src/layout/document' },
66
+ { find: '@src/layout/encode', replacement: '@src/insight/encode' },
67
+ { find: /@src\/interaction\/(change|clipboard|input|pointer|selection)/, replacement: '@src/insight/blank' },
68
+ { find: /@src\/layout.*/, replacement: '@src/insight/snapshot' },
69
+ { find: /@src\/performance.*/, replacement: '@src/insight/blank' }
70
+ ]
71
+ }),
72
+ resolve(),
73
+ typescript(),
74
+ terser({output: {comments: false}}),
75
+ commonjs({ include: ["node_modules/**"] })
76
+ ]
77
+ },
78
+ {
79
+ input: "src/global.ts",
80
+ output: [ { file: pkg.performance, format: "iife", exports: "named" } ],
81
+ onwarn(message, warn) {
82
+ if (message.code === 'CIRCULAR_DEPENDENCY') { return; }
83
+ warn(message);
84
+ },
85
+ plugins: [
86
+ alias({
87
+ entries: [
88
+ { find: /@src\/interaction.*/, replacement: '@src/performance/blank' },
89
+ { find: /@src\/layout.*/, replacement: '@src/performance/blank' },
90
+ { find: /@src\/diagnostic.*/, replacement: '@src/performance/blank' },
91
+ { find: /@src\/data\/(extract|baseline|summary)/, replacement: '@src/performance/blank' },
92
+ { find: /@src\/core\/dynamic/, replacement: '@src/performance/blank' }
93
+ ]
94
+ }),
95
+ resolve(),
96
+ typescript(),
97
+ terser({output: {comments: false}}),
98
+ commonjs({ include: ["node_modules/**"] })
99
+ ]
100
+ },
101
+ {
102
+ input: "src/dynamic/agent/index.ts",
103
+ output: [ { file: pkg.livechat, format: "iife", exports: "named" } ],
104
+ onwarn(message, warn) {
105
+ if (message.code === 'CIRCULAR_DEPENDENCY') { return; }
106
+ warn(message);
107
+ },
108
+ plugins: [
109
+ alias({
110
+ entries: [
111
+ { find: /@src\/dynamic\/agent\/tidio.*/, replacement: '@src/dynamic/agent/blank' },
112
+ { find: /@src\/dynamic\/agent\/crisp.*/, replacement: '@src/dynamic/agent/blank' }
113
+ ]
114
+ }),
115
+ resolve(),
116
+ typescript(),
117
+ terser({output: {comments: false}}),
118
+ commonjs({ include: ["node_modules/**"] })
119
+ ]
120
+ },
121
+ {
122
+ input: "src/dynamic/agent/index.ts",
123
+ output: [ { file: pkg.tidio, format: "iife", exports: "named" } ],
124
+ onwarn(message, warn) {
125
+ if (message.code === 'CIRCULAR_DEPENDENCY') { return; }
126
+ warn(message);
127
+ },
128
+ plugins: [
129
+ alias({
130
+ entries: [
131
+ { find: /@src\/dynamic\/agent\/livechat.*/, replacement: '@src/dynamic/agent/blank' },
132
+ { find: /@src\/dynamic\/agent\/crisp.*/, replacement: '@src/dynamic/agent/blank' }
133
+ ]
134
+ }),
135
+ resolve(),
136
+ typescript(),
137
+ terser({output: {comments: false}}),
138
+ commonjs({ include: ["node_modules/**"] })
139
+ ]
140
+ },
141
+ {
142
+ input: "src/dynamic/agent/index.ts",
143
+ output: [ { file: pkg.crisp, format: "iife", exports: "named" } ],
144
+ onwarn(message, warn) {
145
+ if (message.code === 'CIRCULAR_DEPENDENCY') { return; }
146
+ warn(message);
147
+ },
148
+ plugins: [
149
+ alias({
150
+ entries: [
151
+ { find: /@src\/dynamic\/agent\/livechat.*/, replacement: '@src/dynamic/agent/blank' },
152
+ { find: /@src\/dynamic\/agent\/tidio.*/, replacement: '@src/dynamic/agent/blank' }
153
+ ]
154
+ }),
155
+ resolve(),
156
+ typescript(),
157
+ terser({output: {comments: false}}),
158
+ commonjs({ include: ["node_modules/**"] })
159
+ ]
160
+ }
161
+ ];
package/src/clarity.ts ADDED
@@ -0,0 +1,72 @@
1
+ import { Config, Module } from "@clarity-types/core";
2
+ import { Constant } from "@clarity-types/data";
3
+ import * as queue from "@src/queue";
4
+ import * as core from "@src/core";
5
+ import measure from "@src/core/measure";
6
+ import * as task from "@src/core/task";
7
+ import version from "@src/core/version";
8
+ import * as data from "@src/data";
9
+ import * as diagnostic from "@src/diagnostic";
10
+ import * as interaction from "@src/interaction";
11
+ import * as layout from "@src/layout";
12
+ import * as performance from "@src/performance";
13
+ import * as dynamic from "@src/core/dynamic";
14
+ export { version };
15
+ export { consent, consentv2, event, identify, set, upgrade, metadata, signal, maxMetric, dlog } from "@src/data";
16
+ export { queue } from "@src/data/upload";
17
+ export { register } from "@src/core/dynamic";
18
+ export { schedule } from "@src/core/task";
19
+ export { time } from "@src/core/time";
20
+ export { hashText } from "@src/layout";
21
+ export { measure };
22
+
23
+ const GEMX: Module[] = [diagnostic, layout, interaction];
24
+ const ALL: Module[] = [diagnostic, layout, interaction, performance, dynamic];
25
+
26
+ let modules: Module[] = ALL;
27
+
28
+ export function start(config: Config = null): void {
29
+ modules = config?.mode === "gemx" ? GEMX : ALL;
30
+ console.log("[clarity] version:", version);
31
+ // Check that browser supports required APIs and we do not attempt to start Clarity multiple times
32
+ if (core.check()) {
33
+ core.config(config);
34
+ core.start();
35
+ data.start();
36
+ modules.forEach(x => measure(x.start)());
37
+
38
+ // If it's an internal call to start, without explicit configuration,
39
+ // re-process any newly accumulated items in the queue
40
+ if (config === null) { queue.process(); }
41
+ }
42
+ }
43
+
44
+ // By default Clarity is asynchronous and will yield by looking for requestIdleCallback.
45
+ // However, there can still be situations with single page apps where a user action can result
46
+ // in the whole DOM being destroyed and reconstructed. While Clarity will perform favorably out of the box,
47
+ // we do allow external clients to manually pause Clarity for that short burst of time and minimize
48
+ // performance impact even further. For reference, we are talking single digit milliseconds optimization here, not seconds.
49
+ export function pause(): void {
50
+ if (core.active()) {
51
+ data.event(Constant.Clarity, Constant.Pause);
52
+ task.pause();
53
+ }
54
+ }
55
+
56
+ // This is how external clients can get out of pause state, and resume Clarity to continue monitoring the page
57
+ export function resume(): void {
58
+ if (core.active()) {
59
+ task.resume();
60
+ data.event(Constant.Clarity, Constant.Resume);
61
+ }
62
+ }
63
+
64
+ export function stop(): void {
65
+ if (core.active()) {
66
+ // Stop modules in the reverse order of their initialization and start queuing up items again
67
+ modules.slice().reverse().forEach(x => measure(x.stop)());
68
+ data.stop();
69
+ core.stop();
70
+ queue.setup();
71
+ }
72
+ }
@@ -0,0 +1,8 @@
1
+ import { Constant } from "@clarity-types/core";
2
+
3
+ export default function api(method: string): string {
4
+ // Zone.js, a popular package for Angular, overrides native browser APIs which can lead to inconsistent state for single page applications.
5
+ // Example issue: https://github.com/angular/angular/issues/31712
6
+ // As a work around, we ensuring Clarity access APIs outside of Zone (and use native implementation instead)
7
+ return window[Constant.Zone] && Constant.Symbol in window[Constant.Zone] ? window[Constant.Zone][Constant.Symbol](method) : method;
8
+ }
@@ -0,0 +1,35 @@
1
+ import { Config, Time } from "@clarity-types/core";
2
+
3
+ let config: Config = {
4
+ projectId: null,
5
+ delay: 1 * Time.Second,
6
+ lean: false,
7
+ lite: false,
8
+ track: true,
9
+ content: true,
10
+ drop: [],
11
+ mask: [],
12
+ unmask: [],
13
+ regions: [],
14
+ cookies: [],
15
+ fraud: true,
16
+ checksum: [],
17
+ report: null,
18
+ upload: null,
19
+ fallback: null,
20
+ upgrade: null,
21
+ action: null,
22
+ dob: null,
23
+ delayDom: false,
24
+ throttleDom: true,
25
+ conversions: false,
26
+ includeSubdomains: true,
27
+ modules: [],
28
+ diagnostics: false,
29
+ externalSession: false,
30
+ userId: null,
31
+ sessionId: null,
32
+ mode: "gemx",
33
+ };
34
+
35
+ export default config;
@@ -0,0 +1,3 @@
1
+ export default function<T>(input: T): T {
2
+ return JSON.parse(JSON.stringify(input));
3
+ }
@@ -0,0 +1,68 @@
1
+ import { Constant as DataConstant } from "@clarity-types/data";
2
+ import { Constant } from "@clarity-types/layout";
3
+ import config from "@src/core/config";
4
+ import { report } from "@src/core/report";
5
+ import * as baseline from "@src/data/baseline";
6
+
7
+ let stopCallbacks: (() => void)[] = [];
8
+ let active = false;
9
+ let modules: Set<number> = null;
10
+
11
+ export function start(): void {
12
+ active = true;
13
+ modules = new Set<number>();
14
+
15
+ if (config.modules && config.modules.length > 0) {
16
+ config.modules.forEach((m) => { event(m); });
17
+ }
18
+ }
19
+
20
+ export function stop(): void {
21
+ stopCallbacks.reverse().forEach((callback) => {
22
+ try {
23
+ callback();
24
+ } catch (error) {
25
+ // Do nothing
26
+ }
27
+ });
28
+ stopCallbacks = [];
29
+ active = false;
30
+ }
31
+
32
+ export function register(stopCallback: () => void): void {
33
+ if (active && typeof stopCallback === "function") {
34
+ stopCallbacks.push(stopCallback);
35
+ }
36
+ }
37
+
38
+ export function event(signal: string): void {
39
+ if (!active) return;
40
+
41
+ const parts = signal ? signal.split(" ") : [Constant.Empty];
42
+ const m = parts.length > 1 ? parseInt(parts[1], 10) : null;
43
+ if (m && modules.has(m)) {
44
+ return;
45
+ }
46
+
47
+ load(parts[0], m);
48
+ }
49
+
50
+ function load(url: string, mid: number | null): void {
51
+ try {
52
+ const script = document.createElement("script");
53
+ script.src = url;
54
+ script.async = true;
55
+ script.onload = () => {
56
+ if (mid) {
57
+ modules.add(mid);
58
+ baseline.dynamic(modules);
59
+ }
60
+ };
61
+ script.onerror = () => {
62
+ report(new Error(`${DataConstant.Module}: ${url}`));
63
+ };
64
+ document.head.appendChild(script);
65
+ } catch (error) {
66
+ // Do nothing
67
+ }
68
+ }
@@ -0,0 +1,53 @@
1
+ import { BrowserEvent, Constant } from "@clarity-types/core";
2
+ import api from "./api";
3
+ import measure from "./measure";
4
+
5
+ let bindings: Map<EventTarget, BrowserEvent[]> = new Map();
6
+
7
+ export function bind(target: EventTarget, event: string, listener: EventListener, capture: boolean = false, passive: boolean = true): void {
8
+ listener = measure(listener) as EventListener;
9
+ // Wrapping following lines inside try / catch to cover edge cases where we might try to access an inaccessible element.
10
+ // E.g. Iframe may start off as same-origin but later turn into cross-origin, and the following lines will throw an exception.
11
+ try {
12
+ target[api(Constant.AddEventListener)](event, listener, { capture, passive });
13
+ if (!has(target)) {
14
+ bindings.set(target, []);
15
+ }
16
+
17
+ bindings.get(target).push({ event, listener, options: { capture, passive } });
18
+ } catch {
19
+ /* do nothing */
20
+ }
21
+ }
22
+
23
+ export function reset(): void {
24
+ // Walk through existing list of bindings and remove them all
25
+ bindings.forEach((bindingsPerTarget: BrowserEvent[], target: EventTarget) => {
26
+ resetByTarget(bindingsPerTarget, target);
27
+ });
28
+
29
+ bindings = new Map();
30
+ }
31
+
32
+ export function unbind(target: EventTarget) {
33
+ if (!has(target)) {
34
+ return;
35
+ }
36
+ resetByTarget(bindings.get(target), target);
37
+ }
38
+
39
+ export function has(target: EventTarget): boolean {
40
+ return bindings.has(target);
41
+ }
42
+
43
+ function resetByTarget(bindingsPerTarget: BrowserEvent[], target: EventTarget): void {
44
+ bindingsPerTarget.forEach((binding) => {
45
+ // Wrapping inside try / catch to avoid situations where the element may be destroyed before we get a chance to unbind
46
+ try {
47
+ target[api(Constant.RemoveEventListener)](binding.event, binding.listener, { capture: binding.options.capture, passive: binding.options.passive });
48
+ } catch {
49
+ /* do nothing */
50
+ }
51
+ });
52
+ bindings.delete(target);
53
+ }
@@ -0,0 +1,19 @@
1
+ // tslint:disable: no-bitwise
2
+ export default function(input: string, precision: number = null): string {
3
+ // Code inspired from C# GetHashCode: https://github.com/Microsoft/referencesource/blob/master/mscorlib/system/string.cs
4
+ let hash = 0;
5
+ let hashOne = 5381;
6
+ let hashTwo = hashOne;
7
+ for (let i = 0; i < input.length; i += 2) {
8
+ let charOne = input.charCodeAt(i);
9
+ hashOne = ((hashOne << 5) + hashOne) ^ charOne;
10
+ if (i + 1 < input.length) {
11
+ let charTwo = input.charCodeAt(i + 1);
12
+ hashTwo = ((hashTwo << 5) + hashTwo) ^ charTwo;
13
+ }
14
+ }
15
+ // Replace the magic number from C# implementation (1566083941) with a smaller prime number (11579)
16
+ // This ensures we don't hit integer overflow and prevent collisions
17
+ hash = Math.abs(hashOne + (hashTwo * 11579));
18
+ return (precision ? hash % Math.pow(2, precision) : hash).toString(36);
19
+ }
@@ -0,0 +1,82 @@
1
+ import { BooleanFlag, Code, Constant, Metric, Setting, Severity } from "@clarity-types/data";
2
+ import * as clarity from "@src/clarity";
3
+ import * as core from "@src/core"
4
+ import { bind } from "@src/core/event";
5
+ import * as internal from "@src/diagnostic/internal";
6
+ import * as metric from "@src/data/metric";
7
+
8
+ let pushState = null;
9
+ let replaceState = null;
10
+ let url = null;
11
+ let count = 0;
12
+
13
+ export function start(): void {
14
+ url = getCurrentUrl();
15
+ count = 0;
16
+ bind(window, "popstate", compute);
17
+
18
+ // Add a proxy to history.pushState function
19
+ // Wrap in try-catch to handle Safari iOS where history methods may be readonly
20
+ if (pushState === null) {
21
+ try {
22
+ pushState = history.pushState;
23
+ history.pushState = function(): void {
24
+ pushState.apply(this, arguments);
25
+ if (core.active() && check()) {
26
+ compute();
27
+ }
28
+ };
29
+ } catch (e) {
30
+ // history.pushState is readonly in this environment (e.g., Safari iOS WKWebView)
31
+ pushState = null;
32
+ }
33
+ }
34
+
35
+ // Add a proxy to history.replaceState function
36
+ // Wrap in try-catch to handle Safari iOS where history methods may be readonly
37
+ if (replaceState === null) {
38
+ try {
39
+ replaceState = history.replaceState;
40
+ history.replaceState = function(): void {
41
+ replaceState.apply(this, arguments);
42
+ if (core.active() && check()) {
43
+ compute();
44
+ }
45
+ };
46
+ } catch (e) {
47
+ // history.replaceState is readonly in this environment (e.g., Safari iOS WKWebView)
48
+ replaceState = null;
49
+ }
50
+ }
51
+ }
52
+
53
+ function check(): boolean {
54
+ if (count++ > Setting.CallStackDepth) {
55
+ internal.log(Code.CallStackDepth, Severity.Info);
56
+ return false;
57
+ }
58
+ return true;
59
+ }
60
+
61
+ function compute(): void {
62
+ count = 0; // Reset the counter
63
+ if (url !== getCurrentUrl()) {
64
+ // If the url changed, start tracking it as a new page
65
+ clarity.stop();
66
+ window.setTimeout(restart, Setting.RestartDelay);
67
+ }
68
+ }
69
+
70
+ function restart(): void {
71
+ clarity.start();
72
+ metric.max(Metric.SinglePage, BooleanFlag.True);
73
+ }
74
+
75
+ function getCurrentUrl(): string {
76
+ return location.href ? location.href.replace(location.hash, Constant.Empty) : location.href;
77
+ }
78
+
79
+ export function stop(): void {
80
+ url = null;
81
+ count = 0;
82
+ }