posthog-js
Advanced tools
Comparing version 1.183.0 to 1.184.0
@@ -1,2 +0,2 @@ | ||
!function(){"use strict";const t="undefined"!=typeof window?window:void 0,e="undefined"!=typeof globalThis?globalThis:t,n=Array.prototype.forEach,i=null==e?void 0:e.navigator,o=null==e?void 0:e.document;null==e||e.location,null==e||e.fetch,null!=e&&e.XMLHttpRequest&&"withCredentials"in new e.XMLHttpRequest&&e.XMLHttpRequest,null==e||e.AbortController,null==i||i.userAgent;const s=null!=t?t:{},r=Array.isArray,l=Object.prototype,a=l.hasOwnProperty,c=l.toString,u=r||function(t){return"[object Array]"===c.call(t)},_=function(t){return void 0===t},h=function(t){return"[object String]"==c.call(t)},d=function(t){return null===t},m=function(t){return _(t)||d(t)},f=function(t){return"[object Number]"==c.call(t)},g=t=>t instanceof FormData,p="[PostHog.js]",v={_log:function(e){if(t&&s.POSTHOG_DEBUG&&!_(t.console)&&t.console){const s="__rrweb_original__"in t.console[e]?t.console[e].__rrweb_original__:t.console[e];for(var n=arguments.length,i=new Array(n>1?n-1:0),o=1;o<n;o++)i[o-1]=arguments[o];s(p,...i)}},info:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];v._log("log",...e)},warn:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];v._log("warn",...e)},error:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];v._log("error",...e)},critical:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];console.error(p,...e)},uninitializedWarning:t=>{v.error(`You must initialize PostHog before calling ${t}`)}},b={},k=function(t){return t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")};function y(t,e,i){if(u(t))if(n&&t.forEach===n)t.forEach(e,i);else if("length"in t&&t.length===+t.length)for(let n=0,o=t.length;n<o;n++)if(n in t&&e.call(i,t[n],n)===b)return}function C(t,e,n){if(!m(t)){if(u(t))return y(t,e,n);if(g(t)){for(const i of t.entries())if(e.call(n,i[1],i[0])===b)return}else for(const i in t)if(a.call(t,i)&&e.call(n,t[i],i)===b)return}}const w=function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),i=1;i<e;i++)n[i-1]=arguments[i];return y(n,(function(e){for(const n in e)void 0!==e[n]&&(t[n]=e[n])})),t};function $(t,e){return-1!==t.indexOf(e)}function x(t){const e=Object.keys(t);let n=e.length;const i=new Array(n);for(;n--;)i[n]=[e[n],t[e[n]]];return i}const M="__POSTHOG_TOOLBAR__";function D(t){return!!t&&1===t.nodeType}function N(t,e){return!!t&&!!t.tagName&&t.tagName.toLowerCase()===e.toLowerCase()}function A(t){return t?k(t).split(/\s+/):[]}function E(t){let e="";switch(typeof t.className){case"string":e=t.className;break;case"object":e=(t.className&&"baseVal"in t.className?t.className.baseVal:null)||t.getAttribute("class")||"";break;default:e=""}return A(e)}function O(t){let e="";return L(t)&&!T(t)&&t.childNodes&&t.childNodes.length&&C(t.childNodes,(function(t){var n,i;(function(t){return!!t&&3===t.nodeType})(t)&&t.textContent&&(e+=null!==(i=t.textContent,n=m(i)?null:k(i).split(/(\s+)/).filter((t=>z(t))).join("").replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255))&&void 0!==n?n:"")})),k(e)}const S=["a","button","form","input","select","textarea","label"];function L(t){for(let e=t;e.parentNode&&!N(e,"body");e=e.parentNode){const t=E(e);if($(t,"ph-sensitive")||$(t,"ph-no-capture"))return!1}if($(E(t),"ph-include"))return!0;const e=t.type||"";if(h(e))switch(e.toLowerCase()){case"hidden":case"password":return!1}const n=t.name||t.id||"";if(h(n)){if(/^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i.test(n.replace(/[^a-zA-Z0-9]/g,"")))return!1}return!0}function T(t){return!!(N(t,"input")&&!["button","checkbox","submit","reset"].includes(t.type)||N(t,"select")||N(t,"textarea")||"true"===t.getAttribute("contenteditable"))}const j="(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11})",R=new RegExp(`^(?:${j})$`),P=new RegExp(j),F="\\d{3}-?\\d{2}-?\\d{4}",H=new RegExp(`^(${F})$`),q=new RegExp(`(${F})`);function z(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(m(t))return!1;if(h(t)){t=k(t);if((e?R:P).test((t||"").replace(/[- ]/g,"")))return!1;if((e?H:q).test(t))return!1}return!0}function G(t){let e=O(t);return e=`${e} ${X(t)}`.trim(),z(e)?e:""}function X(t){let e="";return t&&t.childNodes&&t.childNodes.length&&C(t.childNodes,(function(t){var n;if(t&&"span"===(null===(n=t.tagName)||void 0===n?void 0:n.toLowerCase()))try{const n=O(t);e=`${e} ${n}`.trim(),t.childNodes&&t.childNodes.length&&(e=`${e} ${X(t)}`.trim())}catch(t){v.error(t)}})),e}function B(t){return function(t){const e=t.map((t=>{var e,n;let i="";if(t.tag_name&&(i+=t.tag_name),t.attr_class){t.attr_class.sort();for(const e of t.attr_class)i+=`.${e.replace(/"/g,"")}`}const o={...t.text?{text:t.text}:{},"nth-child":null!==(e=t.nth_child)&&void 0!==e?e:0,"nth-of-type":null!==(n=t.nth_of_type)&&void 0!==n?n:0,...t.href?{href:t.href}:{},...t.attr_id?{attr_id:t.attr_id}:{},...t.attributes},s={};return x(o).sort(((t,e)=>{let[n]=t,[i]=e;return n.localeCompare(i)})).forEach((t=>{let[e,n]=t;return s[I(e.toString())]=I(n.toString())})),i+=":",i+=x(o).map((t=>{let[e,n]=t;return`${e}="${n}"`})).join(""),i}));return e.join(";")}(function(t){return t.map((t=>{var e,n;const i={text:null===(e=t.$el_text)||void 0===e?void 0:e.slice(0,400),tag_name:t.tag_name,href:null===(n=t.attr__href)||void 0===n?void 0:n.slice(0,2048),attr_class:V(t),attr_id:t.attr__id,nth_child:t.nth_child,nth_of_type:t.nth_of_type,attributes:{}};return x(t).filter((t=>{let[e]=t;return 0===e.indexOf("attr__")})).forEach((t=>{let[e,n]=t;return i.attributes[e]=n})),i}))}(t))}function I(t){return t.replace(/"|\\"/g,'\\"')}function V(t){const e=t.attr__class;return e?u(e)?e:A(e):void 0}function U(t,e){return e.length>t?e.slice(0,t)+"...":e}function W(t){if(t.previousElementSibling)return t.previousElementSibling;let e=t;do{e=e.previousSibling}while(e&&!D(e));return e}function Y(t,e,n,i){const o=t.tagName.toLowerCase(),s={tag_name:o};S.indexOf(o)>-1&&!n&&("a"===o.toLowerCase()||"button"===o.toLowerCase()?s.$el_text=U(1024,G(t)):s.$el_text=U(1024,O(t)));const r=E(t);r.length>0&&(s.classes=r.filter((function(t){return""!==t}))),C(t.attributes,(function(n){var o;if((!T(t)||-1!==["name","id","class","aria-label"].indexOf(n.name))&&((null==i||!i.includes(n.name))&&!e&&z(n.value)&&(o=n.name,!h(o)||"_ngcontent"!==o.substring(0,10)&&"_nghost"!==o.substring(0,7)))){let t=n.value;"class"===n.name&&(t=A(t).join(" ")),s["attr__"+n.name]=U(1024,t)}}));let l=1,a=1,c=t;for(;c=W(c);)l++,c.tagName===t.tagName&&a++;return s.nth_child=l,s.nth_of_type=a,s}function Z(e,n){var i,s;let{e:r,maskAllElementAttributes:l,maskAllText:a,elementAttributeIgnoreList:c,elementsChainAsString:u}=n;const h=[e];let d=e;for(;d.parentNode&&!N(d,"body");)(m=d.parentNode)&&11===m.nodeType?(h.push(d.parentNode.host),d=d.parentNode.host):(h.push(d.parentNode),d=d.parentNode);var m;const f=[],g={};let p,v=!1,b=!1;if(C(h,(t=>{const e=L(t);"a"===t.tagName.toLowerCase()&&(v=t.getAttribute("href"),v=e&&v&&z(v)&&v);$(E(t),"ph-no-capture")&&(b=!0),f.push(Y(t,l,a,c));const n=function(t){if(!L(t))return{};const e={};return C(t.attributes,(function(t){if(t.name&&0===t.name.indexOf("data-ph-capture-attribute")){const n=t.name.replace("data-ph-capture-attribute-",""),i=t.value;n&&i&&z(i)&&(e[n]=i)}})),e}(t);w(g,n)})),b)return{props:{},explicitNoCapture:b};if(a||("a"===e.tagName.toLowerCase()||"button"===e.tagName.toLowerCase()?f[0].$el_text=G(e):f[0].$el_text=O(e)),v){var k,y;f[0].attr__href=v;const e=null===(k=(t=>{const e=null==o?void 0:o.createElement("a");return _(e)?null:(e.href=t,e)})(v))||void 0===k?void 0:k.host,n=null==t||null===(y=t.location)||void 0===y?void 0:y.host;e&&n&&e!==n&&(p=v)}return{props:w({$event_type:r.type,$ce_version:1},u?{$elements_chain:B(f)}:{$elements:f},null!==(i=f[0])&&void 0!==i&&i.$el_text?{$el_text:null===(s=f[0])||void 0===s?void 0:s.$el_text}:{},p&&"click"===r.type?{$external_click_url:p}:{},g)}}const J={element_attribute_ignorelist:[],scroll_threshold_ms:100,selection_change_threshold_ms:100,mutation_threshold_ms:2500};function K(t){const e=_((n=t).target)?n.srcElement||null:null!==(i=n.target)&&void 0!==i&&i.shadowRoot?n.composedPath()[0]||null:n.target||null;var n,i;return e?{node:e,originalEvent:t,timestamp:Date.now()}:null}function Q(t,e){return f(t)&&t>=e}class tt{_clicks=[];asRequiredConfig(t){var e,n,i,o;return{element_attribute_ignorelist:null!==(e=null==t?void 0:t.element_attribute_ignorelist)&&void 0!==e?e:J.element_attribute_ignorelist,scroll_threshold_ms:null!==(n=null==t?void 0:t.scroll_threshold_ms)&&void 0!==n?n:J.scroll_threshold_ms,selection_change_threshold_ms:null!==(i=null==t?void 0:t.selection_change_threshold_ms)&&void 0!==i?i:J.selection_change_threshold_ms,mutation_threshold_ms:null!==(o=null==t?void 0:t.mutation_threshold_ms)&&void 0!==o?o:J.mutation_threshold_ms}}constructor(t,e){this.instance=t,this._config=this.asRequiredConfig(e)}start(t){this._startClickObserver(),this._startScrollObserver(),this._startSelectionChangedObserver(),this._startMutationObserver(t)}_startMutationObserver(t){this._mutationObserver||(this._mutationObserver=new MutationObserver((t=>{this.onMutation(t)})),this._mutationObserver.observe(t,{attributes:!0,characterData:!0,childList:!0,subtree:!0}))}stop(){var t;null===(t=this._mutationObserver)||void 0===t||t.disconnect(),this._mutationObserver=void 0,s.removeEventListener("click",this._onClick),s.removeEventListener("scroll",this._onScroll,!0),s.removeEventListener("selectionchange",this._onSelectionChange)}onMutation(t){this._lastMutation=Date.now()}_startClickObserver(){s.addEventListener("click",this._onClick)}_onClick=t=>{const e=K(t);d(e)||this._ignoreClick(e)||this._clicks.push(e),this._clicks.length&&_(this._checkClickTimer)&&(this._checkClickTimer=s.setTimeout((()=>{this._checkClicks()}),1e3))};_startScrollObserver(){s.addEventListener("scroll",this._onScroll,!0)}_onScroll=()=>{const t=Date.now();t%50==0&&this._clicks.forEach((e=>{_(e.scrollDelayMs)&&(e.scrollDelayMs=t-e.timestamp)}))};_startSelectionChangedObserver(){s.addEventListener("selectionchange",this._onSelectionChange)}_onSelectionChange=()=>{this._lastSelectionChanged=Date.now()};_ignoreClick(t){if(!t)return!0;if((e=t.node).id===M||null!==(n=e.closest)&&void 0!==n&&n.call(e,"#"+M))return!0;var e,n;return!!this._clicks.some((e=>e.node===t.node&&Math.abs(e.timestamp-t.timestamp)<1e3))||!(!N(t.node,"html")&&D(t.node)&&!S.includes(t.node.tagName.toLowerCase()))}_checkClicks(){if(!this._clicks.length)return;clearTimeout(this._checkClickTimer),this._checkClickTimer=void 0;const t=this._clicks;this._clicks=[];for(const n of t){var e;n.mutationDelayMs=null!==(e=n.mutationDelayMs)&&void 0!==e?e:this._lastMutation&&n.timestamp<=this._lastMutation?this._lastMutation-n.timestamp:void 0,n.absoluteDelayMs=Date.now()-n.timestamp,n.selectionChangedDelayMs=this._lastSelectionChanged&&n.timestamp<=this._lastSelectionChanged?this._lastSelectionChanged-n.timestamp:void 0;const t=Q(n.scrollDelayMs,this._config.scroll_threshold_ms),i=Q(n.selectionChangedDelayMs,this._config.selection_change_threshold_ms),o=Q(n.mutationDelayMs,this._config.mutation_threshold_ms),s=Q(n.absoluteDelayMs,1.1*this._config.mutation_threshold_ms),r=f(n.scrollDelayMs)&&n.scrollDelayMs<this._config.scroll_threshold_ms,l=f(n.mutationDelayMs)&&n.mutationDelayMs<this._config.mutation_threshold_ms,a=f(n.selectionChangedDelayMs)&&n.selectionChangedDelayMs<this._config.selection_change_threshold_ms;r||l||a||(t||o||s||i?this._captureDeadClick(n,{$dead_click_last_mutation_timestamp:this._lastMutation,$dead_click_event_timestamp:n.timestamp,$dead_click_scroll_timeout:t,$dead_click_mutation_timeout:o,$dead_click_absolute_timeout:s,$dead_click_selection_changed_timeout:i}):n.absoluteDelayMs<this._config.mutation_threshold_ms&&this._clicks.push(n))}this._clicks.length&&_(this._checkClickTimer)&&(this._checkClickTimer=s.setTimeout((()=>{this._checkClicks()}),1e3))}_captureDeadClick(t,e){this.instance.capture("$dead_click",{...e,...Z(t.node,{e:t.originalEvent,maskAllElementAttributes:this.instance.config.mask_all_element_attributes,maskAllText:this.instance.config.mask_all_text,elementAttributeIgnoreList:this._config.element_attribute_ignorelist,elementsChainAsString:!1}).props,$dead_click_scroll_delay_ms:t.scrollDelayMs,$dead_click_mutation_delay_ms:t.mutationDelayMs,$dead_click_absolute_delay_ms:t.absoluteDelayMs,$dead_click_selection_changed_delay_ms:t.selectionChangedDelayMs},{timestamp:new Date(t.timestamp)})}}s.__PosthogExtensions__=s.__PosthogExtensions__||{},s.__PosthogExtensions__.initDeadClicksAutocapture=t=>new tt(t)}(); | ||
!function(){"use strict";const t="undefined"!=typeof window?window:void 0,e="undefined"!=typeof globalThis?globalThis:t,n=Array.prototype.forEach,i=null==e?void 0:e.navigator,o=null==e?void 0:e.document;null==e||e.location,null==e||e.fetch,null!=e&&e.XMLHttpRequest&&"withCredentials"in new e.XMLHttpRequest&&e.XMLHttpRequest,null==e||e.AbortController,null==i||i.userAgent;const r=null!=t?t:{},s=Array.isArray,l=Object.prototype,a=l.hasOwnProperty,c=l.toString,u=s||function(t){return"[object Array]"===c.call(t)},_=function(t){return void 0===t},h=function(t){return"[object String]"==c.call(t)},d=function(t){return null===t},m=function(t){return _(t)||d(t)},f=function(t){return"[object Number]"==c.call(t)},g=t=>t instanceof FormData,p="[PostHog.js]",v={_log:function(e){if(t&&r.POSTHOG_DEBUG&&!_(t.console)&&t.console){const r="__rrweb_original__"in t.console[e]?t.console[e].__rrweb_original__:t.console[e];for(var n=arguments.length,i=new Array(n>1?n-1:0),o=1;o<n;o++)i[o-1]=arguments[o];r(p,...i)}},info:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];v._log("log",...e)},warn:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];v._log("warn",...e)},error:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];v._log("error",...e)},critical:function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];console.error(p,...e)},uninitializedWarning:t=>{v.error(`You must initialize PostHog before calling ${t}`)}},b={},k=function(t){return t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")};function C(t,e,i){if(u(t))if(n&&t.forEach===n)t.forEach(e,i);else if("length"in t&&t.length===+t.length)for(let n=0,o=t.length;n<o;n++)if(n in t&&e.call(i,t[n],n)===b)return}function y(t,e,n){if(!m(t)){if(u(t))return C(t,e,n);if(g(t)){for(const i of t.entries())if(e.call(n,i[1],i[0])===b)return}else for(const i in t)if(a.call(t,i)&&e.call(n,t[i],i)===b)return}}const w=function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),i=1;i<e;i++)n[i-1]=arguments[i];return C(n,(function(e){for(const n in e)void 0!==e[n]&&(t[n]=e[n])})),t};function $(t,e){return-1!==t.indexOf(e)}function x(t){const e=Object.keys(t);let n=e.length;const i=new Array(n);for(;n--;)i[n]=[e[n],t[e[n]]];return i}function M(t){return!!t&&1===t.nodeType}function D(t,e){return!!t&&!!t.tagName&&t.tagName.toLowerCase()===e.toLowerCase()}function N(t){return t?k(t).split(/\s+/):[]}function A(t){let e="";switch(typeof t.className){case"string":e=t.className;break;case"object":e=(t.className&&"baseVal"in t.className?t.className.baseVal:null)||t.getAttribute("class")||"";break;default:e=""}return N(e)}function E(t){let e="";return S(t)&&!L(t)&&t.childNodes&&t.childNodes.length&&y(t.childNodes,(function(t){var n,i;(function(t){return!!t&&3===t.nodeType})(t)&&t.textContent&&(e+=null!==(i=t.textContent,n=m(i)?null:k(i).split(/(\s+)/).filter((t=>q(t))).join("").replace(/[\r\n]/g," ").replace(/[ ]+/g," ").substring(0,255))&&void 0!==n?n:"")})),k(e)}const O=["a","button","form","input","select","textarea","label"];function S(t){for(let e=t;e.parentNode&&!D(e,"body");e=e.parentNode){const t=A(e);if($(t,"ph-sensitive")||$(t,"ph-no-capture"))return!1}if($(A(t),"ph-include"))return!0;const e=t.type||"";if(h(e))switch(e.toLowerCase()){case"hidden":case"password":return!1}const n=t.name||t.id||"";if(h(n)){if(/^cc|cardnum|ccnum|creditcard|csc|cvc|cvv|exp|pass|pwd|routing|seccode|securitycode|securitynum|socialsec|socsec|ssn/i.test(n.replace(/[^a-zA-Z0-9]/g,"")))return!1}return!0}function L(t){return!!(D(t,"input")&&!["button","checkbox","submit","reset"].includes(t.type)||D(t,"select")||D(t,"textarea")||"true"===t.getAttribute("contenteditable"))}const T="(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11})",j=new RegExp(`^(?:${T})$`),R=new RegExp(T),P="\\d{3}-?\\d{2}-?\\d{4}",F=new RegExp(`^(${P})$`),H=new RegExp(`(${P})`);function q(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(m(t))return!1;if(h(t)){t=k(t);if((e?j:R).test((t||"").replace(/[- ]/g,"")))return!1;if((e?F:H).test(t))return!1}return!0}function z(t){let e=E(t);return e=`${e} ${G(t)}`.trim(),q(e)?e:""}function G(t){let e="";return t&&t.childNodes&&t.childNodes.length&&y(t.childNodes,(function(t){var n;if(t&&"span"===(null===(n=t.tagName)||void 0===n?void 0:n.toLowerCase()))try{const n=E(t);e=`${e} ${n}`.trim(),t.childNodes&&t.childNodes.length&&(e=`${e} ${G(t)}`.trim())}catch(t){v.error(t)}})),e}function X(t){return function(t){const e=t.map((t=>{var e,n;let i="";if(t.tag_name&&(i+=t.tag_name),t.attr_class){t.attr_class.sort();for(const e of t.attr_class)i+=`.${e.replace(/"/g,"")}`}const o={...t.text?{text:t.text}:{},"nth-child":null!==(e=t.nth_child)&&void 0!==e?e:0,"nth-of-type":null!==(n=t.nth_of_type)&&void 0!==n?n:0,...t.href?{href:t.href}:{},...t.attr_id?{attr_id:t.attr_id}:{},...t.attributes},r={};return x(o).sort(((t,e)=>{let[n]=t,[i]=e;return n.localeCompare(i)})).forEach((t=>{let[e,n]=t;return r[B(e.toString())]=B(n.toString())})),i+=":",i+=x(o).map((t=>{let[e,n]=t;return`${e}="${n}"`})).join(""),i}));return e.join(";")}(function(t){return t.map((t=>{var e,n;const i={text:null===(e=t.$el_text)||void 0===e?void 0:e.slice(0,400),tag_name:t.tag_name,href:null===(n=t.attr__href)||void 0===n?void 0:n.slice(0,2048),attr_class:I(t),attr_id:t.attr__id,nth_child:t.nth_child,nth_of_type:t.nth_of_type,attributes:{}};return x(t).filter((t=>{let[e]=t;return 0===e.indexOf("attr__")})).forEach((t=>{let[e,n]=t;return i.attributes[e]=n})),i}))}(t))}function B(t){return t.replace(/"|\\"/g,'\\"')}function I(t){const e=t.attr__class;return e?u(e)?e:N(e):void 0}function V(t,e){return e.length>t?e.slice(0,t)+"...":e}function U(t){if(t.previousElementSibling)return t.previousElementSibling;let e=t;do{e=e.previousSibling}while(e&&!M(e));return e}function W(t,e,n,i){const o=t.tagName.toLowerCase(),r={tag_name:o};O.indexOf(o)>-1&&!n&&("a"===o.toLowerCase()||"button"===o.toLowerCase()?r.$el_text=V(1024,z(t)):r.$el_text=V(1024,E(t)));const s=A(t);s.length>0&&(r.classes=s.filter((function(t){return""!==t}))),y(t.attributes,(function(n){var o;if((!L(t)||-1!==["name","id","class","aria-label"].indexOf(n.name))&&((null==i||!i.includes(n.name))&&!e&&q(n.value)&&(o=n.name,!h(o)||"_ngcontent"!==o.substring(0,10)&&"_nghost"!==o.substring(0,7)))){let t=n.value;"class"===n.name&&(t=N(t).join(" ")),r["attr__"+n.name]=V(1024,t)}}));let l=1,a=1,c=t;for(;c=U(c);)l++,c.tagName===t.tagName&&a++;return r.nth_child=l,r.nth_of_type=a,r}function Y(e,n){var i,r;let{e:s,maskAllElementAttributes:l,maskAllText:a,elementAttributeIgnoreList:c,elementsChainAsString:u}=n;const h=[e];let d=e;for(;d.parentNode&&!D(d,"body");)(m=d.parentNode)&&11===m.nodeType?(h.push(d.parentNode.host),d=d.parentNode.host):(h.push(d.parentNode),d=d.parentNode);var m;const f=[],g={};let p,v=!1,b=!1;if(y(h,(t=>{const e=S(t);"a"===t.tagName.toLowerCase()&&(v=t.getAttribute("href"),v=e&&v&&q(v)&&v);$(A(t),"ph-no-capture")&&(b=!0),f.push(W(t,l,a,c));const n=function(t){if(!S(t))return{};const e={};return y(t.attributes,(function(t){if(t.name&&0===t.name.indexOf("data-ph-capture-attribute")){const n=t.name.replace("data-ph-capture-attribute-",""),i=t.value;n&&i&&q(i)&&(e[n]=i)}})),e}(t);w(g,n)})),b)return{props:{},explicitNoCapture:b};if(a||("a"===e.tagName.toLowerCase()||"button"===e.tagName.toLowerCase()?f[0].$el_text=z(e):f[0].$el_text=E(e)),v){var k,C;f[0].attr__href=v;const e=null===(k=(t=>{const e=null==o?void 0:o.createElement("a");return _(e)?null:(e.href=t,e)})(v))||void 0===k?void 0:k.host,n=null==t||null===(C=t.location)||void 0===C?void 0:C.host;e&&n&&e!==n&&(p=v)}return{props:w({$event_type:s.type,$ce_version:1},u?{$elements_chain:X(f)}:{$elements:f},null!==(i=f[0])&&void 0!==i&&i.$el_text?{$el_text:null===(r=f[0])||void 0===r?void 0:r.$el_text}:{},p&&"click"===s.type?{$external_click_url:p}:{},g)}}function Z(t){const e=_((n=t).target)?n.srcElement||null:null!==(i=n.target)&&void 0!==i&&i.shadowRoot?n.composedPath()[0]||null:n.target||null;var n,i;return e?{node:e,originalEvent:t,timestamp:Date.now()}:null}function J(t,e){return f(t)&&t>=e}class K{_clicks=[];_defaultConfig=t=>({element_attribute_ignorelist:[],scroll_threshold_ms:100,selection_change_threshold_ms:100,mutation_threshold_ms:2500,__onCapture:t});asRequiredConfig(t){var e,n,i,o;const r=this._defaultConfig((null==t?void 0:t.__onCapture)||this._captureDeadClick.bind(this));return{element_attribute_ignorelist:null!==(e=null==t?void 0:t.element_attribute_ignorelist)&&void 0!==e?e:r.element_attribute_ignorelist,scroll_threshold_ms:null!==(n=null==t?void 0:t.scroll_threshold_ms)&&void 0!==n?n:r.scroll_threshold_ms,selection_change_threshold_ms:null!==(i=null==t?void 0:t.selection_change_threshold_ms)&&void 0!==i?i:r.selection_change_threshold_ms,mutation_threshold_ms:null!==(o=null==t?void 0:t.mutation_threshold_ms)&&void 0!==o?o:r.mutation_threshold_ms,__onCapture:r.__onCapture}}constructor(t,e){this.instance=t,this._config=this.asRequiredConfig(e),this._onCapture=this._config.__onCapture}start(t){this._startClickObserver(),this._startScrollObserver(),this._startSelectionChangedObserver(),this._startMutationObserver(t)}_startMutationObserver(t){this._mutationObserver||(this._mutationObserver=new MutationObserver((t=>{this.onMutation(t)})),this._mutationObserver.observe(t,{attributes:!0,characterData:!0,childList:!0,subtree:!0}))}stop(){var t;null===(t=this._mutationObserver)||void 0===t||t.disconnect(),this._mutationObserver=void 0,r.removeEventListener("click",this._onClick),r.removeEventListener("scroll",this._onScroll,!0),r.removeEventListener("selectionchange",this._onSelectionChange)}onMutation(t){this._lastMutation=Date.now()}_startClickObserver(){r.addEventListener("click",this._onClick)}_onClick=t=>{const e=Z(t);d(e)||this._ignoreClick(e)||this._clicks.push(e),this._clicks.length&&_(this._checkClickTimer)&&(this._checkClickTimer=r.setTimeout((()=>{this._checkClicks()}),1e3))};_startScrollObserver(){r.addEventListener("scroll",this._onScroll,!0)}_onScroll=()=>{const t=Date.now();t%50==0&&this._clicks.forEach((e=>{_(e.scrollDelayMs)&&(e.scrollDelayMs=t-e.timestamp)}))};_startSelectionChangedObserver(){r.addEventListener("selectionchange",this._onSelectionChange)}_onSelectionChange=()=>{this._lastSelectionChanged=Date.now()};_ignoreClick(t){if(!t)return!0;if("__POSTHOG_TOOLBAR__"===(e=t.node).id||null!==(n=e.closest)&&void 0!==n&&n.call(e,".toolbar-global-fade-container"))return!0;var e,n;return!!this._clicks.some((e=>e.node===t.node&&Math.abs(e.timestamp-t.timestamp)<1e3))||!(!D(t.node,"html")&&M(t.node)&&!O.includes(t.node.tagName.toLowerCase()))}_checkClicks(){if(!this._clicks.length)return;clearTimeout(this._checkClickTimer),this._checkClickTimer=void 0;const t=this._clicks;this._clicks=[];for(const n of t){var e;n.mutationDelayMs=null!==(e=n.mutationDelayMs)&&void 0!==e?e:this._lastMutation&&n.timestamp<=this._lastMutation?this._lastMutation-n.timestamp:void 0,n.absoluteDelayMs=Date.now()-n.timestamp,n.selectionChangedDelayMs=this._lastSelectionChanged&&n.timestamp<=this._lastSelectionChanged?this._lastSelectionChanged-n.timestamp:void 0;const t=J(n.scrollDelayMs,this._config.scroll_threshold_ms),i=J(n.selectionChangedDelayMs,this._config.selection_change_threshold_ms),o=J(n.mutationDelayMs,this._config.mutation_threshold_ms),r=J(n.absoluteDelayMs,1.1*this._config.mutation_threshold_ms),s=f(n.scrollDelayMs)&&n.scrollDelayMs<this._config.scroll_threshold_ms,l=f(n.mutationDelayMs)&&n.mutationDelayMs<this._config.mutation_threshold_ms,a=f(n.selectionChangedDelayMs)&&n.selectionChangedDelayMs<this._config.selection_change_threshold_ms;s||l||a||(t||o||r||i?this._onCapture(n,{$dead_click_last_mutation_timestamp:this._lastMutation,$dead_click_event_timestamp:n.timestamp,$dead_click_scroll_timeout:t,$dead_click_mutation_timeout:o,$dead_click_absolute_timeout:r,$dead_click_selection_changed_timeout:i}):n.absoluteDelayMs<this._config.mutation_threshold_ms&&this._clicks.push(n))}this._clicks.length&&_(this._checkClickTimer)&&(this._checkClickTimer=r.setTimeout((()=>{this._checkClicks()}),1e3))}_captureDeadClick(t,e){this.instance.capture("$dead_click",{...e,...Y(t.node,{e:t.originalEvent,maskAllElementAttributes:this.instance.config.mask_all_element_attributes,maskAllText:this.instance.config.mask_all_text,elementAttributeIgnoreList:this._config.element_attribute_ignorelist,elementsChainAsString:!1}).props,$dead_click_scroll_delay_ms:t.scrollDelayMs,$dead_click_mutation_delay_ms:t.mutationDelayMs,$dead_click_absolute_delay_ms:t.absoluteDelayMs,$dead_click_selection_changed_delay_ms:t.selectionChangedDelayMs},{timestamp:new Date(t.timestamp)})}}r.__PosthogExtensions__=r.__PosthogExtensions__||{},r.__PosthogExtensions__.initDeadClicksAutocapture=(t,e)=>new K(t,e)}(); | ||
//# sourceMappingURL=dead-clicks-autocapture.js.map |
@@ -40,3 +40,4 @@ export declare const PEOPLE_DISTINCT_ID_KEY = "$people_distinct_id"; | ||
export declare const TOOLBAR_ID = "__POSTHOG_TOOLBAR__"; | ||
export declare const TOOLBAR_CONTAINER_CLASS = "toolbar-global-fade-container"; | ||
export declare const WEB_EXPERIMENTS = "$web_experiments"; | ||
export declare const PERSISTENCE_RESERVED_PROPERTIES: string[]; |
@@ -12,2 +12,4 @@ import { LazyLoadedDeadClicksAutocaptureInterface } from '../utils/globals'; | ||
private _config; | ||
private _onCapture; | ||
private _defaultConfig; | ||
private asRequiredConfig; | ||
@@ -14,0 +16,0 @@ constructor(instance: PostHog, config?: DeadClicksAutoCaptureConfig); |
import { PostHog } from '../posthog-core'; | ||
import { LazyLoadedDeadClicksAutocaptureInterface } from '../utils/globals'; | ||
import { DecideResponse } from '../types'; | ||
import { DeadClicksAutoCaptureConfig, DecideResponse } from '../types'; | ||
export declare const isDeadClicksEnabledForHeatmaps: () => boolean; | ||
export declare const isDeadClicksEnabledForAutocapture: (instance: DeadClicksAutocapture) => boolean; | ||
export declare class DeadClicksAutocapture { | ||
readonly instance: PostHog; | ||
readonly isEnabled: (dca: DeadClicksAutocapture) => boolean; | ||
readonly onCapture?: DeadClicksAutoCaptureConfig['__onCapture']; | ||
get lazyLoadedDeadClicksAutocapture(): LazyLoadedDeadClicksAutocaptureInterface | undefined; | ||
private _lazyLoadedDeadClicksAutocapture; | ||
constructor(instance: PostHog); | ||
get isRemoteEnabled(): boolean; | ||
get isEnabled(): boolean; | ||
constructor(instance: PostHog, isEnabled: (dca: DeadClicksAutocapture) => boolean, onCapture?: DeadClicksAutoCaptureConfig['__onCapture']); | ||
afterDecideResponse(response: DecideResponse): void; | ||
@@ -12,0 +14,0 @@ startIfEnabled(): void; |
@@ -15,2 +15,3 @@ import RageClick from './extensions/rageclick'; | ||
private _flushInterval; | ||
private deadClicksCapture; | ||
constructor(instance: PostHog); | ||
@@ -22,2 +23,3 @@ get flushIntervalMilliseconds(): number; | ||
getAndClearBuffer(): HeatmapEventBuffer; | ||
private _onDeadClick; | ||
private _setupListeners; | ||
@@ -24,0 +26,0 @@ private _getProperties; |
@@ -111,2 +111,11 @@ import { PostHog } from './posthog-core'; | ||
} | ||
export interface DeadClickCandidate { | ||
node: Element; | ||
originalEvent: MouseEvent; | ||
timestamp: number; | ||
scrollDelayMs?: number; | ||
mutationDelayMs?: number; | ||
selectionChangedDelayMs?: number; | ||
absoluteDelayMs?: number; | ||
} | ||
export type DeadClicksAutoCaptureConfig = { | ||
@@ -116,2 +125,11 @@ scroll_threshold_ms?: number; | ||
mutation_threshold_ms?: number; | ||
/** | ||
* Allows setting behavior for when a dead click is captured. | ||
* For e.g. to support capture to heatmaps | ||
* | ||
* If not provided the default behavior is to auto-capture dead click events | ||
* | ||
* Only intended to be provided by the SDK | ||
*/ | ||
__onCapture?: ((click: DeadClickCandidate, properties: Properties) => void) | undefined; | ||
} & Pick<AutocaptureConfig, 'element_attribute_ignorelist'>; | ||
@@ -118,0 +136,0 @@ export interface HeatmapConfig { |
@@ -43,3 +43,3 @@ import { ErrorProperties } from '../extensions/exception-autocapture/error-conversion'; | ||
}; | ||
initDeadClicksAutocapture?: (ph: PostHog, config?: DeadClicksAutoCaptureConfig) => LazyLoadedDeadClicksAutocaptureInterface; | ||
initDeadClicksAutocapture?: (ph: PostHog, config: DeadClicksAutoCaptureConfig) => LazyLoadedDeadClicksAutocaptureInterface; | ||
} | ||
@@ -46,0 +46,0 @@ export declare const ArrayProto: any[]; |
{ | ||
"name": "posthog-js", | ||
"version": "1.183.0", | ||
"version": "1.184.0", | ||
"description": "Posthog-js allows you to automatically capture usage and send events to PostHog.", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/PostHog/posthog-js", |
@@ -40,3 +40,4 @@ export declare const PEOPLE_DISTINCT_ID_KEY = "$people_distinct_id"; | ||
export declare const TOOLBAR_ID = "__POSTHOG_TOOLBAR__"; | ||
export declare const TOOLBAR_CONTAINER_CLASS = "toolbar-global-fade-container"; | ||
export declare const WEB_EXPERIMENTS = "$web_experiments"; | ||
export declare const PERSISTENCE_RESERVED_PROPERTIES: string[]; |
@@ -45,2 +45,3 @@ /* | ||
export var TOOLBAR_ID = '__POSTHOG_TOOLBAR__'; | ||
export var TOOLBAR_CONTAINER_CLASS = 'toolbar-global-fade-container'; | ||
export var WEB_EXPERIMENTS = '$web_experiments'; | ||
@@ -47,0 +48,0 @@ // These are properties that are reserved and will not be automatically included in events |
@@ -12,2 +12,4 @@ import { LazyLoadedDeadClicksAutocaptureInterface } from '../utils/globals'; | ||
private _config; | ||
private _onCapture; | ||
private _defaultConfig; | ||
private asRequiredConfig; | ||
@@ -14,0 +16,0 @@ constructor(instance: PostHog, config?: DeadClicksAutoCaptureConfig); |
@@ -28,8 +28,2 @@ var __assign = (this && this.__assign) || function () { | ||
import { isElementInToolbar, isElementNode, isTag } from '../utils/element-utils'; | ||
var DEFAULT_CONFIG = { | ||
element_attribute_ignorelist: [], | ||
scroll_threshold_ms: 100, | ||
selection_change_threshold_ms: 100, | ||
mutation_threshold_ms: 2500, | ||
}; | ||
function asClick(event) { | ||
@@ -54,2 +48,9 @@ var eventTarget = getEventTarget(event); | ||
this._clicks = []; | ||
this._defaultConfig = function (defaultOnCapture) { return ({ | ||
element_attribute_ignorelist: [], | ||
scroll_threshold_ms: 100, | ||
selection_change_threshold_ms: 100, | ||
mutation_threshold_ms: 2500, | ||
__onCapture: defaultOnCapture, | ||
}); }; | ||
this._onClick = function (event) { | ||
@@ -84,10 +85,13 @@ var click = asClick(event); | ||
this._config = this.asRequiredConfig(config); | ||
this._onCapture = this._config.__onCapture; | ||
} | ||
LazyLoadedDeadClicksAutocapture.prototype.asRequiredConfig = function (providedConfig) { | ||
var _a, _b, _c, _d; | ||
var defaultConfig = this._defaultConfig((providedConfig === null || providedConfig === void 0 ? void 0 : providedConfig.__onCapture) || this._captureDeadClick.bind(this)); | ||
return { | ||
element_attribute_ignorelist: (_a = providedConfig === null || providedConfig === void 0 ? void 0 : providedConfig.element_attribute_ignorelist) !== null && _a !== void 0 ? _a : DEFAULT_CONFIG.element_attribute_ignorelist, | ||
scroll_threshold_ms: (_b = providedConfig === null || providedConfig === void 0 ? void 0 : providedConfig.scroll_threshold_ms) !== null && _b !== void 0 ? _b : DEFAULT_CONFIG.scroll_threshold_ms, | ||
selection_change_threshold_ms: (_c = providedConfig === null || providedConfig === void 0 ? void 0 : providedConfig.selection_change_threshold_ms) !== null && _c !== void 0 ? _c : DEFAULT_CONFIG.selection_change_threshold_ms, | ||
mutation_threshold_ms: (_d = providedConfig === null || providedConfig === void 0 ? void 0 : providedConfig.mutation_threshold_ms) !== null && _d !== void 0 ? _d : DEFAULT_CONFIG.mutation_threshold_ms, | ||
element_attribute_ignorelist: (_a = providedConfig === null || providedConfig === void 0 ? void 0 : providedConfig.element_attribute_ignorelist) !== null && _a !== void 0 ? _a : defaultConfig.element_attribute_ignorelist, | ||
scroll_threshold_ms: (_b = providedConfig === null || providedConfig === void 0 ? void 0 : providedConfig.scroll_threshold_ms) !== null && _b !== void 0 ? _b : defaultConfig.scroll_threshold_ms, | ||
selection_change_threshold_ms: (_c = providedConfig === null || providedConfig === void 0 ? void 0 : providedConfig.selection_change_threshold_ms) !== null && _c !== void 0 ? _c : defaultConfig.selection_change_threshold_ms, | ||
mutation_threshold_ms: (_d = providedConfig === null || providedConfig === void 0 ? void 0 : providedConfig.mutation_threshold_ms) !== null && _d !== void 0 ? _d : defaultConfig.mutation_threshold_ms, | ||
__onCapture: defaultConfig.__onCapture, | ||
}; | ||
@@ -198,3 +202,3 @@ }; | ||
if (scrollTimeout || mutationTimeout || absoluteTimeout || selectionChangedTimeout) { | ||
this._captureDeadClick(click, { | ||
this._onCapture(click, { | ||
$dead_click_last_mutation_timestamp: this._lastMutation, | ||
@@ -244,4 +248,6 @@ $dead_click_event_timestamp: click.timestamp, | ||
assignableWindow.__PosthogExtensions__ = assignableWindow.__PosthogExtensions__ || {}; | ||
assignableWindow.__PosthogExtensions__.initDeadClicksAutocapture = function (ph) { return new LazyLoadedDeadClicksAutocapture(ph); }; | ||
assignableWindow.__PosthogExtensions__.initDeadClicksAutocapture = function (ph, config) { | ||
return new LazyLoadedDeadClicksAutocapture(ph, config); | ||
}; | ||
export default LazyLoadedDeadClicksAutocapture; | ||
//# sourceMappingURL=dead-clicks-autocapture.js.map |
import { PostHog } from '../posthog-core'; | ||
import { LazyLoadedDeadClicksAutocaptureInterface } from '../utils/globals'; | ||
import { DecideResponse } from '../types'; | ||
import { DeadClicksAutoCaptureConfig, DecideResponse } from '../types'; | ||
export declare const isDeadClicksEnabledForHeatmaps: () => boolean; | ||
export declare const isDeadClicksEnabledForAutocapture: (instance: DeadClicksAutocapture) => boolean; | ||
export declare class DeadClicksAutocapture { | ||
readonly instance: PostHog; | ||
readonly isEnabled: (dca: DeadClicksAutocapture) => boolean; | ||
readonly onCapture?: DeadClicksAutoCaptureConfig['__onCapture']; | ||
get lazyLoadedDeadClicksAutocapture(): LazyLoadedDeadClicksAutocaptureInterface | undefined; | ||
private _lazyLoadedDeadClicksAutocapture; | ||
constructor(instance: PostHog); | ||
get isRemoteEnabled(): boolean; | ||
get isEnabled(): boolean; | ||
constructor(instance: PostHog, isEnabled: (dca: DeadClicksAutocapture) => boolean, onCapture?: DeadClicksAutoCaptureConfig['__onCapture']); | ||
afterDecideResponse(response: DecideResponse): void; | ||
@@ -12,0 +14,0 @@ startIfEnabled(): void; |
@@ -6,5 +6,16 @@ import { DEAD_CLICKS_ENABLED_SERVER_SIDE } from '../constants'; | ||
var LOGGER_PREFIX = '[Dead Clicks]'; | ||
export var isDeadClicksEnabledForHeatmaps = function () { | ||
return true; | ||
}; | ||
export var isDeadClicksEnabledForAutocapture = function (instance) { | ||
var _a; | ||
var isRemoteEnabled = !!((_a = instance.instance.persistence) === null || _a === void 0 ? void 0 : _a.get_property(DEAD_CLICKS_ENABLED_SERVER_SIDE)); | ||
var clientConfig = instance.instance.config.capture_dead_clicks; | ||
return isBoolean(clientConfig) ? clientConfig : isRemoteEnabled; | ||
}; | ||
var DeadClicksAutocapture = /** @class */ (function () { | ||
function DeadClicksAutocapture(instance) { | ||
function DeadClicksAutocapture(instance, isEnabled, onCapture) { | ||
this.instance = instance; | ||
this.isEnabled = isEnabled; | ||
this.onCapture = onCapture; | ||
this.startIfEnabled(); | ||
@@ -19,18 +30,2 @@ } | ||
}); | ||
Object.defineProperty(DeadClicksAutocapture.prototype, "isRemoteEnabled", { | ||
get: function () { | ||
var _a; | ||
return !!((_a = this.instance.persistence) === null || _a === void 0 ? void 0 : _a.get_property(DEAD_CLICKS_ENABLED_SERVER_SIDE)); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(DeadClicksAutocapture.prototype, "isEnabled", { | ||
get: function () { | ||
var clientConfig = this.instance.config.capture_dead_clicks; | ||
return isBoolean(clientConfig) ? clientConfig : this.isRemoteEnabled; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
DeadClicksAutocapture.prototype.afterDecideResponse = function (response) { | ||
@@ -46,4 +41,7 @@ var _a; | ||
DeadClicksAutocapture.prototype.startIfEnabled = function () { | ||
if (this.isEnabled) { | ||
this.loadScript(this.start.bind(this)); | ||
var _this = this; | ||
if (this.isEnabled(this)) { | ||
this.loadScript(function () { | ||
_this.start(); | ||
}); | ||
} | ||
@@ -73,5 +71,7 @@ }; | ||
((_a = assignableWindow.__PosthogExtensions__) === null || _a === void 0 ? void 0 : _a.initDeadClicksAutocapture)) { | ||
this._lazyLoadedDeadClicksAutocapture = assignableWindow.__PosthogExtensions__.initDeadClicksAutocapture(this.instance, isObject(this.instance.config.capture_dead_clicks) | ||
var config = isObject(this.instance.config.capture_dead_clicks) | ||
? this.instance.config.capture_dead_clicks | ||
: undefined); | ||
: {}; | ||
config.__onCapture = this.onCapture; | ||
this._lazyLoadedDeadClicksAutocapture = assignableWindow.__PosthogExtensions__.initDeadClicksAutocapture(this.instance, config); | ||
this._lazyLoadedDeadClicksAutocapture.start(document); | ||
@@ -78,0 +78,0 @@ logger.info("".concat(LOGGER_PREFIX, " starting...")); |
@@ -15,2 +15,3 @@ import RageClick from './extensions/rageclick'; | ||
private _flushInterval; | ||
private deadClicksCapture; | ||
constructor(instance: PostHog); | ||
@@ -22,2 +23,3 @@ get flushIntervalMilliseconds(): number; | ||
getAndClearBuffer(): HeatmapEventBuffer; | ||
private _onDeadClick; | ||
private _setupListeners; | ||
@@ -24,0 +26,0 @@ private _getProperties; |
@@ -20,2 +20,3 @@ var __assign = (this && this.__assign) || function () { | ||
import { isElementInToolbar, isElementNode, isTag } from './utils/element-utils'; | ||
import { DeadClicksAutocapture, isDeadClicksEnabledForHeatmaps } from './extensions/dead-clicks-autocapture'; | ||
var DEFAULT_FLUSH_INTERVAL = 5000; | ||
@@ -77,3 +78,3 @@ var HEATMAPS = 'heatmaps'; | ||
Heatmaps.prototype.startIfEnabled = function () { | ||
var _a; | ||
var _a, _b; | ||
if (this.isEnabled) { | ||
@@ -92,2 +93,3 @@ // nested if here since we only want to run the else | ||
clearInterval((_a = this._flushInterval) !== null && _a !== void 0 ? _a : undefined); | ||
(_b = this.deadClicksCapture) === null || _b === void 0 ? void 0 : _b.stop(); | ||
this.getAndClearBuffer(); | ||
@@ -113,2 +115,5 @@ } | ||
}; | ||
Heatmaps.prototype._onDeadClick = function (click) { | ||
this._onClick(click.originalEvent, 'deadclick'); | ||
}; | ||
Heatmaps.prototype._setupListeners = function () { | ||
@@ -121,2 +126,4 @@ var _this = this; | ||
registerEvent(document, 'mousemove', function (e) { return _this._onMouseMove((e || (window === null || window === void 0 ? void 0 : window.event))); }, false, true); | ||
this.deadClicksCapture = new DeadClicksAutocapture(this.instance, isDeadClicksEnabledForHeatmaps, this._onDeadClick.bind(this)); | ||
this.deadClicksCapture.startIfEnabled(); | ||
this._initialized = true; | ||
@@ -139,8 +146,9 @@ }; | ||
}; | ||
Heatmaps.prototype._onClick = function (e) { | ||
Heatmaps.prototype._onClick = function (e, type) { | ||
var _a; | ||
if (type === void 0) { type = 'click'; } | ||
if (isElementInToolbar(e.target)) { | ||
return; | ||
} | ||
var properties = this._getProperties(e, 'click'); | ||
var properties = this._getProperties(e, type); | ||
if ((_a = this.rageclicks) === null || _a === void 0 ? void 0 : _a.isRageClick(e.clientX, e.clientY, new Date().getTime())) { | ||
@@ -147,0 +155,0 @@ this._capture(__assign(__assign({}, properties), { type: 'rageclick' })); |
@@ -111,2 +111,11 @@ import { PostHog } from './posthog-core'; | ||
} | ||
export interface DeadClickCandidate { | ||
node: Element; | ||
originalEvent: MouseEvent; | ||
timestamp: number; | ||
scrollDelayMs?: number; | ||
mutationDelayMs?: number; | ||
selectionChangedDelayMs?: number; | ||
absoluteDelayMs?: number; | ||
} | ||
export type DeadClicksAutoCaptureConfig = { | ||
@@ -116,2 +125,11 @@ scroll_threshold_ms?: number; | ||
mutation_threshold_ms?: number; | ||
/** | ||
* Allows setting behavior for when a dead click is captured. | ||
* For e.g. to support capture to heatmaps | ||
* | ||
* If not provided the default behavior is to auto-capture dead click events | ||
* | ||
* Only intended to be provided by the SDK | ||
*/ | ||
__onCapture?: ((click: DeadClickCandidate, properties: Properties) => void) | undefined; | ||
} & Pick<AutocaptureConfig, 'element_attribute_ignorelist'>; | ||
@@ -118,0 +136,0 @@ export interface HeatmapConfig { |
@@ -1,6 +0,6 @@ | ||
import { TOOLBAR_ID } from '../constants'; | ||
import { TOOLBAR_CONTAINER_CLASS, TOOLBAR_ID } from '../constants'; | ||
export function isElementInToolbar(el) { | ||
var _a; | ||
// NOTE: .closest is not supported in IE11 hence the operator check | ||
return el.id === TOOLBAR_ID || !!((_a = el.closest) === null || _a === void 0 ? void 0 : _a.call(el, '#' + TOOLBAR_ID)); | ||
return el.id === TOOLBAR_ID || !!((_a = el.closest) === null || _a === void 0 ? void 0 : _a.call(el, '.' + TOOLBAR_CONTAINER_CLASS)); | ||
} | ||
@@ -7,0 +7,0 @@ /* |
@@ -43,3 +43,3 @@ import { ErrorProperties } from '../extensions/exception-autocapture/error-conversion'; | ||
}; | ||
initDeadClicksAutocapture?: (ph: PostHog, config?: DeadClicksAutoCaptureConfig) => LazyLoadedDeadClicksAutocaptureInterface; | ||
initDeadClicksAutocapture?: (ph: PostHog, config: DeadClicksAutoCaptureConfig) => LazyLoadedDeadClicksAutocaptureInterface; | ||
} | ||
@@ -46,0 +46,0 @@ export declare const ArrayProto: any[]; |
{ | ||
"name": "posthog-js", | ||
"version": "1.183.0", | ||
"version": "1.184.0", | ||
"description": "Posthog-js allows you to automatically capture usage and send events to PostHog.", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/PostHog/posthog-js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18338260
41367