"use strict";(self.webpackChunkflow_web_extension=self.webpackChunkflow_web_extension||[]).push([["59117"],{693627:function(t,e,r){r.r(e),r.d(e,{TrackMonitor:()=>a});var n=r(41139);class a{static getInstance(){return null===this.monitorInstance&&(this.monitorInstance=new a),this.monitorInstance}init(){document.addEventListener("click",t=>{var e=t.target;this.startMonitoring({target:e,type:"click"})},!0),document.addEventListener("copy",t=>{var e=t.target;this.startMonitoring({target:e,type:"copy"})},!0),document.addEventListener("unload",this.destroy.bind(this))}getTrackElementKey(t){try{var e=t.tagName||"",r=(t.className||"").toString().trim().replace(/\s+/g,"_"),n=t.getAttribute("data-click-telemetry")||"",a=t.getAttribute("data-copy-telemetry")||"";return"".concat(e,"_").concat(r,"_").concat(n||a)}catch(t){return""}}reportError(t){var{type:e,errorType:r,eventName:a,expected:i,target:s}=t,o=JSON.stringify({dataset:null==i?void 0:i.el.dataset,className:null==i?void 0:i.el.className}),c=JSON.stringify({dataset:null==s?void 0:s.dataset,className:null==s?void 0:s.className});n.k.persist.error({eventName:"l1_tea_track_event_error",error:Error("[telemetry]:".concat(r,":[").concat(e,"] ").concat(a)),meta:{eventName:a,expectedInfo:o,targetInfo:c}})}markTracked(t){t&&this.monitorEventNames.has(t)&&(this.trackEvents.size>100&&this.trackEvents.clear(),this.trackEvents.add({[t]:Date.now()}))}markTrackedElement(t){t&&(this.trackElements.size>100&&this.trackElements.clear(),this.trackElements.add({[t]:Date.now()}))}findExpectedEventName(t,e){for(var r=[],n=t;n;){var a,i=null===(a=n.getAttribute)||void 0===a?void 0:a.call(n,"data-".concat(e,"-telemetry"));if(i&&"string"==typeof i&&i.trim()){var s=i.trim();if(r.push({el:n,name:s}),this.monitorEventNames.add(s),"copy"===e)break}n=n.parentElement}return r}getTrackedEventCount(t,e,r){var n,a,i=(null===(n=[...this.trackEvents].filter(r=>r[t]&&r[t]>=e))||void 0===n?void 0:n.length)||0;return"copy"!==r||i||(i=(null===(a=[...this.trackEvents].filter(t=>t.copy&&t.copy>=e))||void 0===a?void 0:a.length)||0),i}expectTelemetry(t){var{type:e,start:r,expected:a,target:i}=t,s=a.name,o=this.getTrackElementKey(a.el);this.markTrackedElement(o),setTimeout(()=>{try{var t,c=this.getTrackedEventCount(s,r,e),l=(null===(t=[...this.trackElements].filter(t=>t[o]&&t[o]>=r))||void 0===t?void 0:t.length)||0;c||this.reportError({type:e,errorType:"missing_telemetry",eventName:s,expected:a,target:i}),c>l&&this.reportError({type:e,errorType:"multiple_telemetry",eventName:s,expected:a,target:i}),n.k.persist.info({eventName:"l1_tea_track_event_count",meta:{type:e,eventName:s,trackElementKey:o}})}catch(t){n.k.persist.error({eventName:"l1_tea_moniter_js_error",error:t});return}},200)}startMonitoring(t){var{target:e,type:r="click"}=t;try{if(!e)return;var a=this.findExpectedEventName(e,r);if(0===a.length)return;var i=Date.now();a.forEach(t=>{this.expectTelemetry({target:e,type:r,start:i,expected:t})})}catch(t){n.k.persist.error({eventName:"l1_tea_moniter_js_error",error:t});return}}destroy(){this.trackElements.clear(),this.trackEvents.clear()}constructor(){this.trackElements=new Set,this.trackEvents=new Set,this.monitorEventNames=new Set,this.init()}}a.monitorInstance=null}}]);
//# sourceMappingURL=59117.js.map