UNPKG

posthog-js

Version:

Posthog-js allows you to automatically capture usage and send events to PostHog.

2 lines • 7.21 kB
!function(){const t="u">typeof window?window:void 0,r="u">typeof globalThis?globalThis:t;null!=r&&r.XMLHttpRequest&&new r.XMLHttpRequest;const e="undefined"!=typeof globalThis?globalThis:t;e&&"undefined"==typeof self&&(e.self=e),e&&"undefined"==typeof File&&(e.File=function(){});const n=null!=t?t:{},o=Object.prototype.toString,i=Array.isArray||function(t){return"[object Array]"===o.call(t)},c=t=>"function"==typeof t,u=t=>t===Object(t)&&!i(t);function f(t){return f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},f(t)}function l(t,r,e){return(r=function(t){var r=function(t){if("object"!=f(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var e=r.call(t,"string");if("object"!=f(e))return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==f(r)?r:r+""}(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function a(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable})),e.push.apply(e,n)}return e}function s(t){for(var r=1;arguments.length>r;r++){var e=null!=arguments[r]?arguments[r]:{};r%2?a(Object(e),!0).forEach(function(r){l(t,r,e[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):a(Object(e)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r))})}return t}const b=()=>{},y=t=>{var r;if(c(t))return null!==(r=t.__posthog_layer__)&&void 0!==r?r:t.__rrweb_layer__};function d(t,r,e){try{if(!(r in t))return b;const n={next:t[r]},o=e(function(...t){return n.next.apply(this,t)});return c(o)&&(o.prototype=o.prototype||{},Object.defineProperties(o,{__posthog_wrapped__:{enumerable:!1,value:!0},__posthog_layer__:{enumerable:!1,value:n}})),t[r]=o,()=>{if(t[r]===o)return void(t[r]=n.next);let e=t[r],i=y(e);for(;i;){if(i.next===o)return void(i.next=n.next);e=i.next,i=y(e)}}}catch(t){return b}}const v=t=>{for(;null==t?void 0:t.__rrweb_original__;)t=t.__rrweb_original__;return t},h=1e4,g=(t,r,e)=>e.remaining>0?r.length>e.remaining?(t.push(r.slice(0,e.remaining)),e.remaining=0,e.truncated=!0,!1):(t.push(r),e.remaining-=r.length,!0):(e.truncated=!0,!1),p=(t,r,e)=>{const n=JSON.stringify(t);if(e.remaining>=n.length)return g(r,n,e);if(e.truncated=!0,2>e.remaining)return!1;let o=0,i=Math.min(t.length,e.remaining-2);for(;i>o;){const r=Math.ceil((o+i)/2);JSON.stringify(t.slice(0,r)).length>e.remaining?i=r-1:o=r}return g(r,JSON.stringify(t.slice(0,o)),e)},j=t=>void 0!==t&&"function"!=typeof t&&"symbol"!=typeof t&&"bigint"!=typeof t,m=(t,r,e)=>{if(!e.truncated){if(e.keysRemaining-=1,e.sizeRemaining-=String(r).length+t.length,0>=e.keysRemaining||0>=e.sizeRemaining)return e.truncated=!0,void(e.result.attributes_truncated=!0);e.result[t]=r}},O=(t,r,e)=>{if(!e.truncated)if(u(t)){if(e.seen.has(t))return void m(r||"circular","[Circular]",e);e.seen.add(t);try{for(const n in t)try{if(!{}.hasOwnProperty.call(t,n))continue;if(O(t[n],r?`${r}.${n}`:n,e),e.truncated)break}catch(t){continue}}catch(t){}}else m(r,t,e)},S=(t,r,e,n,f=!1,l)=>{if(!j(t))return!f||g(r,"null",e);if(null===t||(t=>{try{return"[object Number]"==o.call(r=t)&&r==r||(t=>"[object Boolean]"===o.call(t))(t)}catch(t){return!1}var r})(t))return g(r,JSON.stringify(t),e);if("string"==typeof t)return p(t,r,e);if(!u(t)&&!i(t))return g(r,JSON.stringify(t),e);if(n.has(t))return p("[Circular]",r,e);n.add(t);try{const o=t.toJSON;if(c(o))return S(o.call(t),r,e,n,f)}catch(t){}try{const n={}.toString.call(t);if("[object String]"===n)return p(String(t.valueOf()),r,e);if("[object Number]"===n||"[object Boolean]"===n)return g(r,JSON.stringify(t.valueOf()),e)}catch(t){}if(t instanceof Error){const o={};try{for(const r in t)({}).hasOwnProperty.call(t,r)&&(o[r]=t[r])}catch(t){}try{o.name=t.name}catch(t){}try{o.message=t.message}catch(t){}try{o.stack=t.stack}catch(t){}return S(o,r,e,n,f,l)}if(i(t)){if(!g(r,"[",e))return!1;for(let o=0;t.length>o;o++){if(o>0&&!g(r,",",e))return!1;let i;try{i=t[o]}catch(t){i=void 0}if(!S(i,r,e,n,!0))return!1}return g(r,"]",e)}if(!g(r,"{",e))return!1;let a=!0;try{for(const o in t){if(!{}.hasOwnProperty.call(t,o))continue;if(0>=e.remaining)return e.truncated=!0,!1;let i;try{i=t[o]}catch(t){continue}if(l)try{O(i,o,l)}catch(t){}if(!j(i))continue;const c=`${a?"":","}${JSON.stringify(o)}:`;if(c.length>=e.remaining)return e.truncated=!0,!1;const u=r.length,f=e.remaining,s=e.truncated;if(!g(r,c,e))return!1;const b=r.length,y=S(i,r,e,n,!1),d=e.truncated;if(r.length!==b){if(a=!1,!y)return!1}else if(r.length=u,e.remaining=f,e.truncated=y?s:d,!y)return!1}}catch(t){}return g(r,"}",e)},w=(t,r)=>{const e=[],n={remaining:r,truncated:!1},o=u(t[0])?{result:{},keysRemaining:50,sizeRemaining:h,truncated:!1,seen:new WeakSet([t[0]])}:void 0;for(let r=0;t.length>r&&(0>=r||g(e," ",n))&&S(t[r],e,n,new WeakSet,!1,0===r?o:void 0);r++);return{body:e.join("")+(n.truncated?"...":""),truncated:n.truncated,attributes:(null==o?void 0:o.result)||{}}},_={debug:"debug",log:"info",warn:"warn",error:"error",info:"info"},N=t=>"canCapture"in t,C=t=>({console:n.console,hostname:n.location.host,getCapturingLogs(){let r;return r=N(t)?t.canCapture?t.getExtension("logs"):void 0:(c(t.is_capturing)?t.is_capturing():!t.has_opted_out_capturing())?t.logs:void 0,r?{captureConsoleLog:e=>((t,r,e)=>{if(N(t))return void r.captureConsoleLog(e);const n=(t=>{const r=/^1\.(\d+)\.(\d+)$/.exec(t);if(!r)return;const e=Number(r[1]),n=Number(r[2]);return 392>e||e>419?void 0:410===e?n>4?n>10?void 0:"de":"le":418===e?n>3?n>10?n>14?n>17?void 0:"vi":"ci":"ui":"he":419===e?n>2?void 0:"vi":410>e?"le":"he"})(t.version),o=n?r[n]:void 0;n?c(o)&&o.call(r,e):c(r.captureConsoleLog)&&r.captureConsoleLog(e)})(t,r,e),captureBufferedConsoleLog(t,e,n){var o;return null===(o=r.captureBufferedConsoleLog)||void 0===o?void 0:o.call(r,t,e,n)}}:void 0}});n.__PosthogExtensions__=n.__PosthogExtensions__||{},n.__PosthogExtensions__.logs={initializeLogs:t=>(t=>{const r=t.console;let e=t;const n=[],o={host:t.hostname};let i=!1;const c=()=>{e=void 0;for(const t of n)try{t()}catch(t){}};try{for(const t of Object.keys(_)){const c=n=>(...c)=>{let u=!1;try{if(c.length>0&&!i&&e){const r=e.getCapturingLogs();if(r){i=!0,u=!0;const{body:e,truncated:n,attributes:f}=w(c,h),l=s(s({},o),n?{body_truncated:"true"}:{}),a={level:_[t],body:e,attributes:s(s({"log.source":`console.${t}`},l),f)};r.captureConsoleLog(a)}}}catch(t){}finally{u&&(i=!1),n.apply(r,c)}},u=r[t];n.push(d(r,t,t=>{const r=c(t);return r.__rrweb_original__=v(u),r}))}}catch(t){throw c(),t}return c})(C(t)),replayConsoleBuffer:(t,r)=>((t,r)=>{const e=t.getCapturingLogs();if(e)for(const o of r)try{var n;const{body:r,truncated:i,attributes:c}=w(o.args,h);null===(n=e.captureBufferedConsoleLog)||void 0===n||n.call(e,{level:_[o.level],body:r,attributes:s(s({"log.source":`console.${o.level}`,host:t.hostname},i?{body_truncated:"true"}:{}),c)},o.context,o.occurredAtMs)}catch(t){}})(C(t),r)}}(); //# sourceMappingURL=logs.js.map