posthog-js 1.138.0 → 1.138.2

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 (57) hide show
  1. package/dist/array.full.js +2 -2
  2. package/dist/array.full.js.map +1 -1
  3. package/dist/array.js +1 -1
  4. package/dist/array.js.map +1 -1
  5. package/dist/es.js +1 -1
  6. package/dist/es.js.map +1 -1
  7. package/dist/lib/src/extensions/replay/rrweb-plugins/patch.d.ts +3 -0
  8. package/dist/lib/src/extensions/sentry-integration.d.ts +22 -2
  9. package/dist/lib/src/extensions/surveys/surveys-utils.d.ts +2 -0
  10. package/dist/lib/src/extensions/tracing-headers.d.ts +10 -0
  11. package/dist/lib/src/loader-recorder.d.ts +0 -3
  12. package/dist/lib/src/loader-tracing-headers.d.ts +1 -0
  13. package/dist/lib/src/posthog-core.d.ts +2 -1
  14. package/dist/lib/src/posthog-surveys-types.d.ts +2 -0
  15. package/dist/lib/src/types.d.ts +5 -0
  16. package/dist/module.d.ts +29 -2
  17. package/dist/module.js +1 -1
  18. package/dist/module.js.map +1 -1
  19. package/dist/recorder-v2.js +1 -1
  20. package/dist/recorder-v2.js.map +1 -1
  21. package/dist/recorder.js +1 -1
  22. package/dist/recorder.js.map +1 -1
  23. package/dist/surveys-module-previews.js +1 -1
  24. package/dist/surveys-module-previews.js.map +1 -1
  25. package/dist/surveys.js +1 -1
  26. package/dist/surveys.js.map +1 -1
  27. package/dist/tracing-headers.js +2 -0
  28. package/dist/tracing-headers.js.map +1 -0
  29. package/lib/package.json +2 -2
  30. package/lib/src/extensions/replay/rrweb-plugins/patch.d.ts +3 -0
  31. package/lib/src/extensions/replay/rrweb-plugins/patch.js +39 -0
  32. package/lib/src/extensions/replay/rrweb-plugins/patch.js.map +1 -0
  33. package/lib/src/extensions/sentry-integration.d.ts +22 -2
  34. package/lib/src/extensions/sentry-integration.js +55 -39
  35. package/lib/src/extensions/sentry-integration.js.map +1 -1
  36. package/lib/src/extensions/surveys/surveys-utils.d.ts +2 -0
  37. package/lib/src/extensions/surveys/surveys-utils.jsx +37 -3
  38. package/lib/src/extensions/surveys/surveys-utils.jsx.map +1 -1
  39. package/lib/src/extensions/surveys.jsx +5 -20
  40. package/lib/src/extensions/surveys.jsx.map +1 -1
  41. package/lib/src/extensions/tracing-headers.d.ts +10 -0
  42. package/lib/src/extensions/tracing-headers.js +51 -0
  43. package/lib/src/extensions/tracing-headers.js.map +1 -0
  44. package/lib/src/loader-recorder.d.ts +0 -3
  45. package/lib/src/loader-recorder.js +2 -42
  46. package/lib/src/loader-recorder.js.map +1 -1
  47. package/lib/src/loader-tracing-headers.d.ts +1 -0
  48. package/lib/src/loader-tracing-headers.js +87 -0
  49. package/lib/src/loader-tracing-headers.js.map +1 -0
  50. package/lib/src/posthog-core.d.ts +2 -1
  51. package/lib/src/posthog-core.js +5 -1
  52. package/lib/src/posthog-core.js.map +1 -1
  53. package/lib/src/posthog-surveys-types.d.ts +2 -0
  54. package/lib/src/posthog-surveys-types.js.map +1 -1
  55. package/lib/src/types.d.ts +5 -0
  56. package/lib/src/types.js.map +1 -1
  57. package/package.json +2 -2
@@ -0,0 +1,2 @@
1
+ !function(){"use strict";function t(){t=function(){return r};var r={},e=Object.prototype,n=e.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{c({},"")}catch(t){c=function(t,r,e){return t[r]=e}}function f(t,r,e,n){var o=r&&r.prototype instanceof s?r:s,i=Object.create(o.prototype),a=new _(n||[]);return i._invoke=function(t,r,e){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return S()}for(e.method=o,e.arg=i;;){var a=e.delegate;if(a){var u=x(a,e);if(u){if(u===l)continue;return u}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if("suspendedStart"===n)throw n="completed",e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n="executing";var c=h(t,r,e);if("normal"===c.type){if(n=e.done?"completed":"suspendedYield",c.arg===l)continue;return{value:c.arg,done:e.done}}"throw"===c.type&&(n="completed",e.method="throw",e.arg=c.arg)}}}(t,e,a),i}function h(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}r.wrap=f;var l={};function s(){}function p(){}function d(){}var v={};c(v,i,(function(){return this}));var y=Object.getPrototypeOf,g=y&&y(y(O([])));g&&g!==e&&n.call(g,i)&&(v=g);var w=d.prototype=s.prototype=Object.create(v);function m(t){["next","throw","return"].forEach((function(r){c(t,r,(function(t){return this._invoke(r,t)}))}))}function L(t,r){function e(o,i,a,u){var c=h(t[o],t,i);if("throw"!==c.type){var f=c.arg,l=f.value;return l&&"object"==typeof l&&n.call(l,"__await")?r.resolve(l.__await).then((function(t){e("next",t,a,u)}),(function(t){e("throw",t,a,u)})):r.resolve(l).then((function(t){f.value=t,a(f)}),(function(t){return e("throw",t,a,u)}))}u(c.arg)}var o;this._invoke=function(t,n){function i(){return new r((function(r,o){e(t,n,r,o)}))}return o=o?o.then(i,i):i()}}function x(t,r){var e=t.iterator[r.method];if(void 0===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=void 0,x(t,r),"throw"===r.method))return l;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=h(e,t.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,l;var o=n.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,l):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,l)}function b(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function E(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function O(t){if(t){var r=t[i];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var e=-1,o=function r(){for(;++e<t.length;)if(n.call(t,e))return r.value=t[e],r.done=!1,r;return r.value=void 0,r.done=!0,r};return o.next=o}}return{next:S}}function S(){return{value:void 0,done:!0}}return p.prototype=d,c(w,"constructor",d),c(d,"constructor",p),p.displayName=c(d,u,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===p||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,c(t,u,"GeneratorFunction")),t.prototype=Object.create(w),t},r.awrap=function(t){return{__await:t}},m(L.prototype),c(L.prototype,a,(function(){return this})),r.AsyncIterator=L,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new L(f(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},m(w),c(w,u,"Generator"),c(w,i,(function(){return this})),c(w,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},r.values=O,_.prototype={constructor:_,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function e(e,n){return a.type="throw",a.arg=t,r.next=e,n&&(r.method="next",r.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return e("end");if(i.tryLoc<=this.prev){var u=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(u&&c){if(this.prev<i.catchLoc)return e(i.catchLoc,!0);if(this.prev<i.finallyLoc)return e(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return e(i.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return e(i.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var o=this.tryEntries[e];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,l):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),l},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),E(e),l}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;E(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,e){return this.delegate={iterator:O(t),resultName:r,nextLoc:e},"next"===this.method&&(this.arg=void 0),l}},r}function r(t,r,e,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void e(t)}u.done?r(c):Promise.resolve(c).then(n,o)}function e(t,r,e){try{if(!(r in t))return function(){};var n=t[r],o=e(n);return"function"==typeof o&&(o.prototype=o.prototype||{},Object.defineProperties(o,{__posthog_wrapped__:{enumerable:!1,value:!0}})),t[r]=o,function(){t[r]=n}}catch(t){return function(){}}}var n="undefined"!=typeof window?window:void 0,o="undefined"!=typeof globalThis?globalThis:n,i=null==o?void 0:o.navigator;null==o||o.document,null==o||o.location,null==o||o.fetch,null!=o&&o.XMLHttpRequest&&"withCredentials"in new o.XMLHttpRequest&&o.XMLHttpRequest,null==o||o.AbortController,null==i||i.userAgent;var a=null!=n?n:{},u=function(t,r){var e=t.checkAndGetSessionAndWindowId(!0),n=e.sessionId,o=e.windowId;r.headers.set("X-POSTHOG-SESSION-ID",n),r.headers.set("X-POSTHOG-WINDOW-ID",o)};a&&(a.postHogTracingHeadersPatchFns={_patchFetch:function(o){return e(n,"fetch",(function(e){return function(){var n,i=(n=t().mark((function r(n,i){var a;return t().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=new Request(n,i),u(o,a),t.abrupt("return",e(a));case 3:case"end":return t.stop()}}),r)})),function(){var t=this,e=arguments;return new Promise((function(o,i){var a=n.apply(t,e);function u(t){r(a,o,i,u,c,"next",t)}function c(t){r(a,o,i,u,c,"throw",t)}u(void 0)}))});return function(t,r){return i.apply(this,arguments)}}()}))},_patchXHR:function(t){return e(n.XMLHttpRequest.prototype,"open",(function(r){return function(e,n){var o=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],i=arguments.length>3?arguments[3]:void 0,a=arguments.length>4?arguments[4]:void 0,c=new Request(n);return u(t,c),r.call(this,e,c.url,o,i,a)}}))}})}();
2
+ //# sourceMappingURL=tracing-headers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracing-headers.js","sources":["../src/extensions/replay/rrweb-plugins/patch.ts","../src/utils/type-utils.ts","../src/utils/globals.ts","../src/loader-tracing-headers.ts"],"sourcesContent":["// import { patch } from 'rrweb/typings/utils'\n// copied from https://github.com/rrweb-io/rrweb/blob/8aea5b00a4dfe5a6f59bd2ae72bb624f45e51e81/packages/rrweb/src/utils.ts#L129\n// which was copied from https://github.com/getsentry/sentry-javascript/blob/b2109071975af8bf0316d3b5b38f519bdaf5dc15/packages/utils/src/object.ts\nimport { isFunction } from '../../../utils/type-utils'\n\nexport function patch(\n source: { [key: string]: any },\n name: string,\n replacement: (...args: unknown[]) => unknown\n): () => void {\n try {\n if (!(name in source)) {\n return () => {\n //\n }\n }\n\n const original = source[name] as () => unknown\n const wrapped = replacement(original)\n\n // Make sure it's a function first, as we need to attach an empty prototype for `defineProperties` to work\n // otherwise it'll throw \"TypeError: Object.defineProperties called on non-object\"\n if (isFunction(wrapped)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n wrapped.prototype = wrapped.prototype || {}\n Object.defineProperties(wrapped, {\n __posthog_wrapped__: {\n enumerable: false,\n value: true,\n },\n })\n }\n\n source[name] = wrapped\n\n return () => {\n source[name] = original\n }\n } catch {\n return () => {\n //\n }\n // This can throw if multiple fill happens on a global object like XMLHttpRequest\n // Fixes https://github.com/getsentry/sentry-javascript/issues/2043\n }\n}\n","// eslint-disable-next-line posthog-js/no-direct-array-check\nconst nativeIsArray = Array.isArray\nconst ObjProto = Object.prototype\nexport const hasOwnProperty = ObjProto.hasOwnProperty\nconst toString = ObjProto.toString\n\nexport const isArray =\n nativeIsArray ||\n function (obj: any): obj is any[] {\n return toString.call(obj) === '[object Array]'\n }\nexport const isUint8Array = function (x: unknown): x is Uint8Array {\n return toString.call(x) === '[object Uint8Array]'\n}\n// from a comment on http://dbj.org/dbj/?p=286\n// fails on only one very rare and deliberate custom object:\n// let bomb = { toString : undefined, valueOf: function(o) { return \"function BOMBA!\"; }};\nexport const isFunction = function (f: any): f is (...args: any[]) => any {\n // eslint-disable-next-line posthog-js/no-direct-function-check\n return typeof f === 'function'\n}\n// Underscore Addons\nexport const isObject = function (x: unknown): x is Record<string, any> {\n // eslint-disable-next-line posthog-js/no-direct-object-check\n return x === Object(x) && !isArray(x)\n}\nexport const isEmptyObject = function (x: unknown): x is Record<string, any> {\n if (isObject(x)) {\n for (const key in x) {\n if (hasOwnProperty.call(x, key)) {\n return false\n }\n }\n return true\n }\n return false\n}\nexport const isUndefined = function (x: unknown): x is undefined {\n return x === void 0\n}\n\nexport const isString = function (x: unknown): x is string {\n // eslint-disable-next-line posthog-js/no-direct-string-check\n return toString.call(x) == '[object String]'\n}\n\nexport const isEmptyString = function (x: unknown): boolean {\n return isString(x) && x.trim().length === 0\n}\n\nexport const isNull = function (x: unknown): x is null {\n // eslint-disable-next-line posthog-js/no-direct-null-check\n return x === null\n}\n\n/*\n sometimes you want to check if something is null or undefined\n that's what this is for\n */\nexport const isNullish = function (x: unknown): x is null | undefined {\n return isUndefined(x) || isNull(x)\n}\n\nexport const isDate = function (x: unknown): x is Date {\n // eslint-disable-next-line posthog-js/no-direct-date-check\n return toString.call(x) == '[object Date]'\n}\nexport const isNumber = function (x: unknown): x is number {\n // eslint-disable-next-line posthog-js/no-direct-number-check\n return toString.call(x) == '[object Number]'\n}\nexport const isBoolean = function (x: unknown): x is boolean {\n // eslint-disable-next-line posthog-js/no-direct-boolean-check\n return toString.call(x) === '[object Boolean]'\n}\n\nexport const isDocument = (x: unknown): x is Document => {\n // eslint-disable-next-line posthog-js/no-direct-document-check\n return x instanceof Document\n}\n\nexport const isFormData = (x: unknown): x is FormData => {\n // eslint-disable-next-line posthog-js/no-direct-form-data-check\n return x instanceof FormData\n}\n\nexport const isFile = (x: unknown): x is File => {\n // eslint-disable-next-line posthog-js/no-direct-file-check\n return x instanceof File\n}\n","/*\n * Global helpers to protect access to browser globals in a way that is safer for different targets\n * like DOM, SSR, Web workers etc.\n *\n * NOTE: Typically we want the \"window\" but globalThis works for both the typical browser context as\n * well as other contexts such as the web worker context. Window is still exported for any bits that explicitly require it.\n * If in doubt - export the global you need from this file and use that as an optional value. This way the code path is forced\n * to handle the case where the global is not available.\n */\n\n// eslint-disable-next-line no-restricted-globals\nconst win: (Window & typeof globalThis) | undefined = typeof window !== 'undefined' ? window : undefined\n\nconst global: typeof globalThis | undefined = typeof globalThis !== 'undefined' ? globalThis : win\n\nexport const ArrayProto = Array.prototype\nexport const nativeForEach = ArrayProto.forEach\nexport const nativeIndexOf = ArrayProto.indexOf\n\nexport const navigator = global?.navigator\nexport const document = global?.document\nexport const location = global?.location\nexport const fetch = global?.fetch\nexport const XMLHttpRequest =\n global?.XMLHttpRequest && 'withCredentials' in new global.XMLHttpRequest() ? global.XMLHttpRequest : undefined\nexport const AbortController = global?.AbortController\nexport const userAgent = navigator?.userAgent\nexport const assignableWindow: Window & typeof globalThis & Record<string, any> = win ?? ({} as any)\n\nexport { win as window }\n","import { SessionIdManager } from './sessionid'\nimport { patch } from './extensions/replay/rrweb-plugins/patch'\nimport { assignableWindow, window } from './utils/globals'\n\nconst addTracingHeaders = (sessionManager: SessionIdManager, req: Request) => {\n const { sessionId, windowId } = sessionManager.checkAndGetSessionAndWindowId(true)\n req.headers.set('X-POSTHOG-SESSION-ID', sessionId)\n req.headers.set('X-POSTHOG-WINDOW-ID', windowId)\n}\n\nconst patchFetch = (sessionManager: SessionIdManager): (() => void) => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return patch(window, 'fetch', (originalFetch: typeof fetch) => {\n return async function (url: URL | RequestInfo, init?: RequestInit | undefined) {\n // check IE earlier than this, we only initialize if Request is present\n // eslint-disable-next-line compat/compat\n const req = new Request(url, init)\n\n addTracingHeaders(sessionManager, req)\n\n return originalFetch(req)\n }\n })\n}\n\nconst patchXHR = (sessionManager: SessionIdManager): (() => void) => {\n return patch(\n // we can assert this is present because we've checked previously\n window!.XMLHttpRequest.prototype,\n 'open',\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n (originalOpen: typeof XMLHttpRequest.prototype.open) => {\n return function (\n method: string,\n url: string | URL,\n async = true,\n username?: string | null,\n password?: string | null\n ) {\n // because this function is returned in its actual context `this` _is_ an XMLHttpRequest\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const xhr = this as XMLHttpRequest\n\n // check IE earlier than this, we only initialize if Request is present\n // eslint-disable-next-line compat/compat\n const req = new Request(url)\n\n addTracingHeaders(sessionManager, req)\n\n return originalOpen.call(xhr, method, req.url, async, username, password)\n }\n }\n )\n}\n\nif (assignableWindow) {\n assignableWindow.postHogTracingHeadersPatchFns = {\n _patchFetch: patchFetch,\n _patchXHR: patchXHR,\n }\n}\n"],"names":["patch","source","name","replacement","original","wrapped","prototype","Object","defineProperties","__posthog_wrapped__","enumerable","value","_unused","win","window","undefined","global","globalThis","navigator","document","location","fetch","XMLHttpRequest","AbortController","userAgent","assignableWindow","addTracingHeaders","sessionManager","req","_sessionManager$check","checkAndGetSessionAndWindowId","sessionId","windowId","headers","set","postHogTracingHeadersPatchFns","_patchFetch","originalFetch","_ref","_regeneratorRuntime","mark","_callee","url","init","wrap","_context","prev","next","Request","abrupt","stop","_x","_x2","apply","this","arguments","_patchXHR","originalOpen","method","async","length","username","password","call"],"mappings":"27MAKO,SAASA,EACZC,EACAC,EACAC,GAEA,IACI,KAAMD,KAAQD,GACV,OAAO,aAKX,IAAMG,EAAWH,EAAOC,GAClBG,EAAUF,EAAYC,GAiB5B,MChBgB,mBDGDC,IAEXA,EAAQC,UAAYD,EAAQC,WAAa,CAAA,EACzCC,OAAOC,iBAAiBH,EAAS,CAC7BI,oBAAqB,CACjBC,YAAY,EACZC,OAAO,MAKnBV,EAAOC,GAAQG,EAER,WACHJ,EAAOC,GAAQE,EAEtB,CAAC,MAAAQ,GACE,OAAO,YAKX,CACJ,CElCA,IAAMC,EAAkE,oBAAXC,OAAyBA,YAASC,EAEzFC,EAA8D,oBAAfC,WAA6BA,WAAaJ,EAMlFK,EAAYF,aAAM,EAANA,EAAQE,UACTF,SAAAA,EAAQG,SACRH,SAAAA,EAAQI,SACXJ,SAAAA,EAAQK,MAEzBL,SAAAA,EAAQM,gBAAkB,oBAAqB,IAAIN,EAAOM,gBAAmBN,EAAOM,eACzDN,SAAAA,EAAQO,gBACdL,SAAAA,EAAWM,UAC7B,IAAMC,EAAqEZ,QA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.138.0",
3
+ "version": "1.138.2",
4
4
  "description": "Posthog-js allows you to automatically capture usage and send events to PostHog.",
5
5
  "repository": "https://github.com/PostHog/posthog-js",
6
6
  "author": "hey@posthog.com",
@@ -48,7 +48,7 @@
48
48
  "@rollup/plugin-terser": "^0.4.4",
49
49
  "@rollup/plugin-typescript": "^11.1.6",
50
50
  "@rrweb/types": "2.0.0-alpha.13",
51
- "@sentry/types": "7.37.2",
51
+ "@sentry/types": "8.7.0",
52
52
  "@testing-library/dom": "^9.3.0",
53
53
  "@types/eslint": "^8.44.6",
54
54
  "@types/jest": "^29.5.1",
@@ -0,0 +1,3 @@
1
+ export declare function patch(source: {
2
+ [key: string]: any;
3
+ }, name: string, replacement: (...args: unknown[]) => unknown): () => void;
@@ -0,0 +1,39 @@
1
+ // import { patch } from 'rrweb/typings/utils'
2
+ // copied from https://github.com/rrweb-io/rrweb/blob/8aea5b00a4dfe5a6f59bd2ae72bb624f45e51e81/packages/rrweb/src/utils.ts#L129
3
+ // which was copied from https://github.com/getsentry/sentry-javascript/blob/b2109071975af8bf0316d3b5b38f519bdaf5dc15/packages/utils/src/object.ts
4
+ import { isFunction } from '../../../utils/type-utils';
5
+ export function patch(source, name, replacement) {
6
+ try {
7
+ if (!(name in source)) {
8
+ return function () {
9
+ //
10
+ };
11
+ }
12
+ var original_1 = source[name];
13
+ var wrapped = replacement(original_1);
14
+ // Make sure it's a function first, as we need to attach an empty prototype for `defineProperties` to work
15
+ // otherwise it'll throw "TypeError: Object.defineProperties called on non-object"
16
+ if (isFunction(wrapped)) {
17
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
18
+ wrapped.prototype = wrapped.prototype || {};
19
+ Object.defineProperties(wrapped, {
20
+ __posthog_wrapped__: {
21
+ enumerable: false,
22
+ value: true,
23
+ },
24
+ });
25
+ }
26
+ source[name] = wrapped;
27
+ return function () {
28
+ source[name] = original_1;
29
+ };
30
+ }
31
+ catch (_a) {
32
+ return function () {
33
+ //
34
+ };
35
+ // This can throw if multiple fill happens on a global object like XMLHttpRequest
36
+ // Fixes https://github.com/getsentry/sentry-javascript/issues/2043
37
+ }
38
+ }
39
+ //# sourceMappingURL=patch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patch.js","sourceRoot":"","sources":["../../../../../src/extensions/replay/rrweb-plugins/patch.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,+HAA+H;AAC/H,kJAAkJ;AAClJ,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAEtD,MAAM,UAAU,KAAK,CACjB,MAA8B,EAC9B,IAAY,EACZ,WAA4C;IAE5C,IAAI;QACA,IAAI,CAAC,CAAC,IAAI,IAAI,MAAM,CAAC,EAAE;YACnB,OAAO;gBACH,EAAE;YACN,CAAC,CAAA;SACJ;QAED,IAAM,UAAQ,GAAG,MAAM,CAAC,IAAI,CAAkB,CAAA;QAC9C,IAAM,OAAO,GAAG,WAAW,CAAC,UAAQ,CAAC,CAAA;QAErC,0GAA0G;QAC1G,kFAAkF;QAClF,IAAI,UAAU,CAAC,OAAO,CAAC,EAAE;YACrB,mEAAmE;YACnE,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAA;YAC3C,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE;gBAC7B,mBAAmB,EAAE;oBACjB,UAAU,EAAE,KAAK;oBACjB,KAAK,EAAE,IAAI;iBACd;aACJ,CAAC,CAAA;SACL;QAED,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAA;QAEtB,OAAO;YACH,MAAM,CAAC,IAAI,CAAC,GAAG,UAAQ,CAAA;QAC3B,CAAC,CAAA;KACJ;IAAC,WAAM;QACJ,OAAO;YACH,EAAE;QACN,CAAC,CAAA;QACD,iFAAiF;QACjF,mEAAmE;KACtE;AACL,CAAC","sourcesContent":["// import { patch } from 'rrweb/typings/utils'\n// copied from https://github.com/rrweb-io/rrweb/blob/8aea5b00a4dfe5a6f59bd2ae72bb624f45e51e81/packages/rrweb/src/utils.ts#L129\n// which was copied from https://github.com/getsentry/sentry-javascript/blob/b2109071975af8bf0316d3b5b38f519bdaf5dc15/packages/utils/src/object.ts\nimport { isFunction } from '../../../utils/type-utils'\n\nexport function patch(\n source: { [key: string]: any },\n name: string,\n replacement: (...args: unknown[]) => unknown\n): () => void {\n try {\n if (!(name in source)) {\n return () => {\n //\n }\n }\n\n const original = source[name] as () => unknown\n const wrapped = replacement(original)\n\n // Make sure it's a function first, as we need to attach an empty prototype for `defineProperties` to work\n // otherwise it'll throw \"TypeError: Object.defineProperties called on non-object\"\n if (isFunction(wrapped)) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n wrapped.prototype = wrapped.prototype || {}\n Object.defineProperties(wrapped, {\n __posthog_wrapped__: {\n enumerable: false,\n value: true,\n },\n })\n }\n\n source[name] = wrapped\n\n return () => {\n source[name] = original\n }\n } catch {\n return () => {\n //\n }\n // This can throw if multiple fill happens on a global object like XMLHttpRequest\n // Fixes https://github.com/getsentry/sentry-javascript/issues/2043\n }\n}\n"]}
@@ -16,15 +16,35 @@
16
16
  * @param {string} [prefix] Optional: Url of a self-hosted sentry instance (default: https://sentry.io/organizations/)
17
17
  */
18
18
  import { PostHog } from '../posthog-core';
19
+ type _SentryEvent = any;
19
20
  type _SentryEventProcessor = any;
20
21
  type _SentryHub = any;
21
- interface _SentryIntegration {
22
+ interface _SentryIntegrationClass {
22
23
  name: string;
23
24
  setupOnce(addGlobalEventProcessor: (callback: _SentryEventProcessor) => void, getCurrentHub: () => _SentryHub): void;
24
25
  }
26
+ interface _SentryIntegration {
27
+ name: string;
28
+ processEvent(event: _SentryEvent): _SentryEvent;
29
+ }
25
30
  declare const severityLevels: readonly ["fatal", "error", "warning", "log", "info", "debug"];
26
31
  declare type _SeverityLevel = typeof severityLevels[number];
27
- export declare class SentryIntegration implements _SentryIntegration {
32
+ export type SentryIntegrationOptions = {
33
+ organization?: string;
34
+ projectId?: number;
35
+ prefix?: string;
36
+ /**
37
+ * By default, only errors are sent to PostHog. You can set this to '*' to send all events.
38
+ * Or to an error of SeverityLevel to only send events matching the provided levels.
39
+ * e.g. ['error', 'fatal'] to send only errors and fatals
40
+ * e.g. ['error'] to send only errors -- the default when omitted
41
+ * e.g. '*' to send all events
42
+ */
43
+ severityAllowList?: _SeverityLevel[] | '*';
44
+ };
45
+ export declare function createEventProcessor(_posthog: PostHog, { organization, projectId, prefix, severityAllowList }?: SentryIntegrationOptions): (event: _SentryEvent) => _SentryEvent;
46
+ export declare function sentryIntegration(_posthog: PostHog, options?: SentryIntegrationOptions): _SentryIntegration;
47
+ export declare class SentryIntegration implements _SentryIntegrationClass {
28
48
  name: string;
29
49
  setupOnce: (addGlobalEventProcessor: (callback: _SentryEventProcessor) => void, getCurrentHub: () => _SentryHub) => void;
30
50
  constructor(_posthog: PostHog, organization?: string, projectId?: number, prefix?: string,
@@ -18,6 +18,59 @@
18
18
  // levels copied from Sentry to avoid relying on a frequently changing @sentry/types dependency
19
19
  // but provided as an array of literal types, so we can constrain the level below
20
20
  var severityLevels = ['fatal', 'error', 'warning', 'log', 'info', 'debug'];
21
+ var NAME = 'posthog-js';
22
+ export function createEventProcessor(_posthog, _a) {
23
+ var _b = _a === void 0 ? {} : _a, organization = _b.organization, projectId = _b.projectId, prefix = _b.prefix, _c = _b.severityAllowList, severityAllowList = _c === void 0 ? ['error'] : _c;
24
+ return function (event) {
25
+ var _a, _b, _c, _d, _e;
26
+ var shouldProcessLevel = severityAllowList === '*' || severityAllowList.includes(event.level);
27
+ if (!shouldProcessLevel || !_posthog.__loaded)
28
+ return event;
29
+ if (!event.tags)
30
+ event.tags = {};
31
+ var personUrl = _posthog.requestRouter.endpointFor('ui', "/project/".concat(_posthog.config.token, "/person/").concat(_posthog.get_distinct_id()));
32
+ event.tags['PostHog Person URL'] = personUrl;
33
+ if (_posthog.sessionRecordingStarted()) {
34
+ event.tags['PostHog Recording URL'] = _posthog.get_session_replay_url({ withTimestamp: true });
35
+ }
36
+ var exceptions = ((_a = event.exception) === null || _a === void 0 ? void 0 : _a.values) || [];
37
+ var data = {
38
+ // PostHog Exception Properties,
39
+ $exception_message: ((_b = exceptions[0]) === null || _b === void 0 ? void 0 : _b.value) || event.message,
40
+ $exception_type: (_c = exceptions[0]) === null || _c === void 0 ? void 0 : _c.type,
41
+ $exception_personURL: personUrl,
42
+ // Sentry Exception Properties
43
+ $sentry_event_id: event.event_id,
44
+ $sentry_exception: event.exception,
45
+ $sentry_exception_message: ((_d = exceptions[0]) === null || _d === void 0 ? void 0 : _d.value) || event.message,
46
+ $sentry_exception_type: (_e = exceptions[0]) === null || _e === void 0 ? void 0 : _e.type,
47
+ $sentry_tags: event.tags,
48
+ $level: event.level,
49
+ };
50
+ if (organization && projectId) {
51
+ data['$sentry_url'] =
52
+ (prefix || 'https://sentry.io/organizations/') +
53
+ organization +
54
+ '/issues/?project=' +
55
+ projectId +
56
+ '&query=' +
57
+ event.event_id;
58
+ }
59
+ _posthog.capture('$exception', data);
60
+ return event;
61
+ };
62
+ }
63
+ // V8 integration - function based
64
+ export function sentryIntegration(_posthog, options) {
65
+ var processor = createEventProcessor(_posthog, options);
66
+ return {
67
+ name: NAME,
68
+ processEvent: function (event) {
69
+ return processor(event);
70
+ },
71
+ };
72
+ }
73
+ // V7 integration - class based
21
74
  var SentryIntegration = /** @class */ (function () {
22
75
  function SentryIntegration(_posthog, organization, projectId, prefix,
23
76
  /**
@@ -28,47 +81,10 @@ var SentryIntegration = /** @class */ (function () {
28
81
  * e.g. '*' to send all events
29
82
  */
30
83
  severityAllowList) {
31
- if (severityAllowList === void 0) { severityAllowList = ['error']; }
32
84
  // setupOnce gets called by Sentry when it intializes the plugin
33
- this.name = 'posthog-js';
85
+ this.name = NAME;
34
86
  this.setupOnce = function (addGlobalEventProcessor) {
35
- addGlobalEventProcessor(function (event) {
36
- var _a, _b, _c, _d, _e;
37
- var shouldProcessLevel = severityAllowList === '*' || severityAllowList.includes(event.level);
38
- if (!shouldProcessLevel || !_posthog.__loaded)
39
- return event;
40
- if (!event.tags)
41
- event.tags = {};
42
- var personUrl = _posthog.requestRouter.endpointFor('ui', "/project/".concat(_posthog.config.token, "/person/").concat(_posthog.get_distinct_id()));
43
- event.tags['PostHog Person URL'] = personUrl;
44
- if (_posthog.sessionRecordingStarted()) {
45
- event.tags['PostHog Recording URL'] = _posthog.get_session_replay_url({ withTimestamp: true });
46
- }
47
- var exceptions = ((_a = event.exception) === null || _a === void 0 ? void 0 : _a.values) || [];
48
- var data = {
49
- // PostHog Exception Properties,
50
- $exception_message: ((_b = exceptions[0]) === null || _b === void 0 ? void 0 : _b.value) || event.message,
51
- $exception_type: (_c = exceptions[0]) === null || _c === void 0 ? void 0 : _c.type,
52
- $exception_personURL: personUrl,
53
- // Sentry Exception Properties
54
- $sentry_event_id: event.event_id,
55
- $sentry_exception: event.exception,
56
- $sentry_exception_message: ((_d = exceptions[0]) === null || _d === void 0 ? void 0 : _d.value) || event.message,
57
- $sentry_exception_type: (_e = exceptions[0]) === null || _e === void 0 ? void 0 : _e.type,
58
- $sentry_tags: event.tags,
59
- $level: event.level,
60
- };
61
- if (organization && projectId)
62
- data['$sentry_url'] =
63
- (prefix || 'https://sentry.io/organizations/') +
64
- organization +
65
- '/issues/?project=' +
66
- projectId +
67
- '&query=' +
68
- event.event_id;
69
- _posthog.capture('$exception', data);
70
- return event;
71
- });
87
+ addGlobalEventProcessor(createEventProcessor(_posthog, { organization: organization, projectId: projectId, prefix: prefix, severityAllowList: severityAllowList }));
72
88
  };
73
89
  }
74
90
  return SentryIntegration;
@@ -1 +1 @@
1
- {"version":3,"file":"sentry-integration.js","sourceRoot":"","sources":["../../../src/extensions/sentry-integration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AA0BH,+FAA+F;AAC/F,iFAAiF;AACjF,IAAM,cAAc,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,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,CAAC,0CAAE,IAAI;oBACpC,oBAAoB,EAAE,SAAS;oBAC/B,8BAA8B;oBAC9B,gBAAgB,EAAE,KAAK,CAAC,QAAQ;oBAChC,iBAAiB,EAAE,KAAK,CAAC,SAAS;oBAClC,yBAAyB,EAAE,CAAA,MAAA,UAAU,CAAC,CAAC,CAAC,0CAAE,KAAK,KAAI,KAAK,CAAC,OAAO;oBAChE,sBAAsB,EAAE,MAAA,UAAU,CAAC,CAAC,CAAC,0CAAE,IAAI;oBAC3C,YAAY,EAAE,KAAK,CAAC,IAAI;oBACxB,MAAM,EAAE,KAAK,CAAC,KAAK;iBACtB,CAAA;gBAED,IAAI,YAAY,IAAI,SAAS;oBACzB,IAAI,CAAC,aAAa,CAAC;wBACf,CAAC,MAAM,IAAI,kCAAkC,CAAC;4BAC9C,YAAY;4BACZ,mBAAmB;4BACnB,SAAS;4BACT,SAAS;4BACT,KAAK,CAAC,QAAQ,CAAA;gBACtB,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;gBACpC,OAAO,KAAK,CAAA;YAChB,CAAC,CAAC,CAAA;QACN,CAAC,CAAA;IACL,CAAC;IACL,wBAAC;AAAD,CAAC,AA5ED,IA4EC","sourcesContent":["/**\n * Integrate Sentry with PostHog. This will add a direct link to the person in Sentry, and an $exception event in PostHog\n *\n * ### Usage\n *\n * Sentry.init({\n * dsn: 'https://example',\n * integrations: [\n * new posthog.SentryIntegration(posthog)\n * ]\n * })\n *\n * @param {Object} [posthog] The posthog object\n * @param {string} [organization] Optional: The Sentry organization, used to send a direct link from PostHog to Sentry\n * @param {Number} [projectId] Optional: The Sentry project id, used to send a direct link from PostHog to Sentry\n * @param {string} [prefix] Optional: Url of a self-hosted sentry instance (default: https://sentry.io/organizations/)\n */\n\nimport { PostHog } from '../posthog-core'\n\n// NOTE - we can't import from @sentry/types because it changes frequently and causes clashes\n// We only use a small subset of the types, so we can just define the integration overall and use any for the rest\n\n// import {\n// Event as _SentryEvent,\n// EventProcessor as _SentryEventProcessor,\n// Hub as _SentryHub,\n// Integration as _SentryIntegration,\n// SeverityLevel as _SeverityLevel,\n// } from '@sentry/types'\n\n// Uncomment the above and comment the below to get type checking for development\n\ntype _SentryEvent = any\ntype _SentryEventProcessor = any\ntype _SentryHub = any\n\ninterface _SentryIntegration {\n name: string\n setupOnce(addGlobalEventProcessor: (callback: _SentryEventProcessor) => void, getCurrentHub: () => _SentryHub): void\n}\n\n// levels copied from Sentry to avoid relying on a frequently changing @sentry/types dependency\n// but provided as an array of literal types, so we can constrain the level below\nconst severityLevels = ['fatal', 'error', 'warning', 'log', 'info', 'debug'] as const\ndeclare type _SeverityLevel = typeof severityLevels[number]\n\ninterface SentryExceptionProperties {\n $sentry_event_id: any\n $sentry_exception: any\n $sentry_exception_message: any\n $sentry_exception_type: any\n $sentry_tags: any\n $sentry_url?: string\n}\n\nexport class SentryIntegration implements _SentryIntegration {\n name: string\n\n setupOnce: (\n addGlobalEventProcessor: (callback: _SentryEventProcessor) => void,\n getCurrentHub: () => _SentryHub\n ) => void\n\n constructor(\n _posthog: PostHog,\n organization?: string,\n projectId?: number,\n prefix?: string,\n /**\n * By default, only errors are sent to PostHog. You can set this to '*' to send all events.\n * Or to an error of SeverityLevel to only send events matching the provided levels.\n * e.g. ['error', 'fatal'] to send only errors and fatals\n * e.g. ['error'] to send only errors -- the default when omitted\n * e.g. '*' to send all events\n */\n severityAllowList: _SeverityLevel[] | '*' = ['error']\n ) {\n // setupOnce gets called by Sentry when it intializes the plugin\n this.name = 'posthog-js'\n this.setupOnce = function (addGlobalEventProcessor: (callback: _SentryEventProcessor) => void) {\n addGlobalEventProcessor((event: _SentryEvent) => {\n const shouldProcessLevel =\n severityAllowList === '*' || severityAllowList.includes(event.level as _SeverityLevel)\n if (!shouldProcessLevel || !_posthog.__loaded) return event\n if (!event.tags) event.tags = {}\n\n const personUrl = _posthog.requestRouter.endpointFor(\n 'ui',\n `/project/${_posthog.config.token}/person/${_posthog.get_distinct_id()}`\n )\n event.tags['PostHog Person URL'] = personUrl\n if (_posthog.sessionRecordingStarted()) {\n event.tags['PostHog Recording URL'] = _posthog.get_session_replay_url({ withTimestamp: true })\n }\n\n const exceptions = event.exception?.values || []\n\n const data: SentryExceptionProperties & {\n // two properties added to match any exception auto-capture\n // added manually to avoid any dependency on the lazily loaded content\n $exception_message: any\n $exception_type: any\n $exception_personURL: string\n $level: _SeverityLevel\n } = {\n // PostHog Exception Properties,\n $exception_message: exceptions[0]?.value || event.message,\n $exception_type: exceptions[0]?.type,\n $exception_personURL: personUrl,\n // Sentry Exception Properties\n $sentry_event_id: event.event_id,\n $sentry_exception: event.exception,\n $sentry_exception_message: exceptions[0]?.value || event.message,\n $sentry_exception_type: exceptions[0]?.type,\n $sentry_tags: event.tags,\n $level: event.level,\n }\n\n if (organization && projectId)\n data['$sentry_url'] =\n (prefix || 'https://sentry.io/organizations/') +\n organization +\n '/issues/?project=' +\n projectId +\n '&query=' +\n event.event_id\n _posthog.capture('$exception', data)\n return event\n })\n }\n }\n}\n"]}
1
+ {"version":3,"file":"sentry-integration.js","sourceRoot":"","sources":["../../../src/extensions/sentry-integration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAgCH,+FAA+F;AAC/F,iFAAiF;AACjF,IAAM,cAAc,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAU,CAAA;AA0BrF,IAAM,IAAI,GAAG,YAAY,CAAA;AAEzB,MAAM,UAAU,oBAAoB,CAChC,QAAiB,EACjB,EAAiG;QAAjG,qBAA+F,EAAE,KAAA,EAA/F,YAAY,kBAAA,EAAE,SAAS,eAAA,EAAE,MAAM,YAAA,EAAE,yBAA6B,EAA7B,iBAAiB,mBAAG,CAAC,OAAO,CAAC,KAAA;IAEhE,OAAO,UAAC,KAAK;;QACT,IAAM,kBAAkB,GACpB,iBAAiB,KAAK,GAAG,IAAI,iBAAiB,CAAC,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AAK;SACtB,CAAA;QAED,IAAI,YAAY,IAAI,SAAS,EAAE;YAC3B,IAAI,CAAC,aAAa,CAAC;gBACf,CAAC,MAAM,IAAI,kCAAkC,CAAC;oBAC9C,YAAY;oBACZ,mBAAmB;oBACnB,SAAS;oBACT,SAAS;oBACT,KAAK,CAAC,QAAQ,CAAA;SACrB;QACD,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;QACpC,OAAO,KAAK,CAAA;IAChB,CAAC,CAAA;AACL,CAAC;AAED,kCAAkC;AAClC,MAAM,UAAU,iBAAiB,CAAC,QAAiB,EAAE,OAAkC;IACnF,IAAM,SAAS,GAAG,oBAAoB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IACzD,OAAO;QACH,IAAI,EAAE,IAAI;QACV,YAAY,YAAC,KAAK;YACd,OAAO,SAAS,CAAC,KAAK,CAAC,CAAA;QAC3B,CAAC;KACJ,CAAA;AACL,CAAC;AACD,+BAA+B;AAC/B;IAQI,2BACI,QAAiB,EACjB,YAAqB,EACrB,SAAkB,EAClB,MAAe;IACf;;;;;;OAMG;IACH,iBAA0C;QAE1C,gEAAgE;QAChE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,SAAS,GAAG,UAAU,uBAAkE;YACzF,uBAAuB,CACnB,oBAAoB,CAAC,QAAQ,EAAE,EAAE,YAAY,cAAA,EAAE,SAAS,WAAA,EAAE,MAAM,QAAA,EAAE,iBAAiB,mBAAA,EAAE,CAAC,CACzF,CAAA;QACL,CAAC,CAAA;IACL,CAAC;IACL,wBAAC;AAAD,CAAC,AA9BD,IA8BC","sourcesContent":["/**\n * Integrate Sentry with PostHog. This will add a direct link to the person in Sentry, and an $exception event in PostHog\n *\n * ### Usage\n *\n * Sentry.init({\n * dsn: 'https://example',\n * integrations: [\n * new posthog.SentryIntegration(posthog)\n * ]\n * })\n *\n * @param {Object} [posthog] The posthog object\n * @param {string} [organization] Optional: The Sentry organization, used to send a direct link from PostHog to Sentry\n * @param {Number} [projectId] Optional: The Sentry project id, used to send a direct link from PostHog to Sentry\n * @param {string} [prefix] Optional: Url of a self-hosted sentry instance (default: https://sentry.io/organizations/)\n */\n\nimport { PostHog } from '../posthog-core'\n\n// NOTE - we can't import from @sentry/types because it changes frequently and causes clashes\n// We only use a small subset of the types, so we can just define the integration overall and use any for the rest\n\n// import {\n// Event as _SentryEvent,\n// EventProcessor as _SentryEventProcessor,\n// Hub as _SentryHub,\n// Integration as _SentryIntegration,\n// SeverityLevel as _SeverityLevel,\n// IntegrationClass as _SentryIntegrationClass,\n// } from '@sentry/types'\n\n// Uncomment the above and comment the below to get type checking for development\n\ntype _SentryEvent = any\ntype _SentryEventProcessor = any\ntype _SentryHub = any\n\ninterface _SentryIntegrationClass {\n name: string\n setupOnce(addGlobalEventProcessor: (callback: _SentryEventProcessor) => void, getCurrentHub: () => _SentryHub): void\n}\n\ninterface _SentryIntegration {\n name: string\n processEvent(event: _SentryEvent): _SentryEvent\n}\n\n// levels copied from Sentry to avoid relying on a frequently changing @sentry/types dependency\n// but provided as an array of literal types, so we can constrain the level below\nconst severityLevels = ['fatal', 'error', 'warning', 'log', 'info', 'debug'] as const\ndeclare type _SeverityLevel = typeof severityLevels[number]\n\ninterface SentryExceptionProperties {\n $sentry_event_id: any\n $sentry_exception: any\n $sentry_exception_message: any\n $sentry_exception_type: any\n $sentry_tags: any\n $sentry_url?: string\n}\n\nexport type SentryIntegrationOptions = {\n organization?: string\n projectId?: number\n prefix?: string\n /**\n * By default, only errors are sent to PostHog. You can set this to '*' to send all events.\n * Or to an error of SeverityLevel to only send events matching the provided levels.\n * e.g. ['error', 'fatal'] to send only errors and fatals\n * e.g. ['error'] to send only errors -- the default when omitted\n * e.g. '*' to send all events\n */\n severityAllowList?: _SeverityLevel[] | '*'\n}\n\nconst NAME = 'posthog-js'\n\nexport function createEventProcessor(\n _posthog: PostHog,\n { organization, projectId, prefix, severityAllowList = ['error'] }: SentryIntegrationOptions = {}\n): (event: _SentryEvent) => _SentryEvent {\n return (event) => {\n const shouldProcessLevel =\n severityAllowList === '*' || severityAllowList.includes(event.level as _SeverityLevel)\n if (!shouldProcessLevel || !_posthog.__loaded) return event\n if (!event.tags) event.tags = {}\n\n const personUrl = _posthog.requestRouter.endpointFor(\n 'ui',\n `/project/${_posthog.config.token}/person/${_posthog.get_distinct_id()}`\n )\n event.tags['PostHog Person URL'] = personUrl\n if (_posthog.sessionRecordingStarted()) {\n event.tags['PostHog Recording URL'] = _posthog.get_session_replay_url({ withTimestamp: true })\n }\n\n const exceptions = event.exception?.values || []\n\n const data: SentryExceptionProperties & {\n // two properties added to match any exception auto-capture\n // added manually to avoid any dependency on the lazily loaded content\n $exception_message: any\n $exception_type: any\n $exception_personURL: string\n $level: _SeverityLevel\n } = {\n // PostHog Exception Properties,\n $exception_message: exceptions[0]?.value || event.message,\n $exception_type: exceptions[0]?.type,\n $exception_personURL: personUrl,\n // Sentry Exception Properties\n $sentry_event_id: event.event_id,\n $sentry_exception: event.exception,\n $sentry_exception_message: exceptions[0]?.value || event.message,\n $sentry_exception_type: exceptions[0]?.type,\n $sentry_tags: event.tags,\n $level: event.level,\n }\n\n if (organization && projectId) {\n data['$sentry_url'] =\n (prefix || 'https://sentry.io/organizations/') +\n organization +\n '/issues/?project=' +\n projectId +\n '&query=' +\n event.event_id\n }\n _posthog.capture('$exception', data)\n return event\n }\n}\n\n// V8 integration - function based\nexport function sentryIntegration(_posthog: PostHog, options?: SentryIntegrationOptions): _SentryIntegration {\n const processor = createEventProcessor(_posthog, options)\n return {\n name: NAME,\n processEvent(event) {\n return processor(event)\n },\n }\n}\n// V7 integration - class based\nexport class SentryIntegration implements _SentryIntegrationClass {\n name: string\n\n setupOnce: (\n addGlobalEventProcessor: (callback: _SentryEventProcessor) => void,\n getCurrentHub: () => _SentryHub\n ) => void\n\n constructor(\n _posthog: PostHog,\n organization?: string,\n projectId?: number,\n prefix?: string,\n /**\n * By default, only errors are sent to PostHog. You can set this to '*' to send all events.\n * Or to an error of SeverityLevel to only send events matching the provided levels.\n * e.g. ['error', 'fatal'] to send only errors and fatals\n * e.g. ['error'] to send only errors -- the default when omitted\n * e.g. '*' to send all events\n */\n severityAllowList?: _SeverityLevel[] | '*'\n ) {\n // setupOnce gets called by Sentry when it intializes the plugin\n this.name = NAME\n this.setupOnce = function (addGlobalEventProcessor: (callback: _SentryEventProcessor) => void) {\n addGlobalEventProcessor(\n createEventProcessor(_posthog, { organization, projectId, prefix, severityAllowList })\n )\n }\n }\n}\n"]}
@@ -8,9 +8,11 @@ export declare const defaultSurveyAppearance: SurveyAppearance;
8
8
  export declare const defaultBackgroundColor = "#eeeded";
9
9
  export declare const createShadow: (styleSheet: string, surveyId: string) => ShadowRoot;
10
10
  export declare const sendSurveyEvent: (responses: Record<string, string | number | string[] | null> | undefined, survey: Survey, posthog?: PostHog) => void;
11
+ export declare const dismissedSurveyEvent: (survey: Survey, posthog?: PostHog, readOnly?: boolean) => void;
11
12
  export declare const shuffle: (array: any[]) => any[];
12
13
  export declare const getDisplayOrderChoices: (question: MultipleSurveyQuestion) => string[];
13
14
  export declare const getDisplayOrderQuestions: (survey: Survey) => SurveyQuestion[];
15
+ export declare const getSurveySeenKey: (survey: Survey) => string;
14
16
  export declare const SurveyContext: import("preact").Context<{
15
17
  isPreviewMode: boolean;
16
18
  previewPageIndex: number | undefined;
@@ -249,12 +249,32 @@ export var sendSurveyEvent = function (responses, survey, posthog) {
249
249
  if (responses === void 0) { responses = {}; }
250
250
  if (!posthog)
251
251
  return;
252
- localStorage.setItem("seenSurvey_".concat(survey.id), 'true');
253
- posthog.capture('survey sent', __assign(__assign({ $survey_name: survey.name, $survey_id: survey.id, $survey_questions: survey.questions.map(function (question) { return question.question; }), sessionRecordingUrl: (_b = posthog.get_session_replay_url) === null || _b === void 0 ? void 0 : _b.call(posthog) }, responses), { $set: (_a = {},
254
- _a["$survey_responded/".concat(survey.id)] = true,
252
+ localStorage.setItem(getSurveySeenKey(survey), 'true');
253
+ posthog.capture('survey sent', __assign(__assign({ $survey_name: survey.name, $survey_id: survey.id, $survey_iteration: survey.current_iteration, $survey_iteration_start_date: survey.current_iteration_start_date, $survey_questions: survey.questions.map(function (question) { return question.question; }), sessionRecordingUrl: (_b = posthog.get_session_replay_url) === null || _b === void 0 ? void 0 : _b.call(posthog) }, responses), { $set: (_a = {},
254
+ _a[getSurveyInteractionProperty(survey, 'responded')] = true,
255
255
  _a) }));
256
256
  window.dispatchEvent(new Event('PHSurveySent'));
257
257
  };
258
+ export var dismissedSurveyEvent = function (survey, posthog, readOnly) {
259
+ var _a;
260
+ var _b;
261
+ // TODO: state management and unit tests for this would be nice
262
+ if (readOnly || !posthog) {
263
+ return;
264
+ }
265
+ posthog.capture('survey dismissed', {
266
+ $survey_name: survey.name,
267
+ $survey_id: survey.id,
268
+ $survey_iteration: survey.current_iteration,
269
+ $survey_iteration_start_date: survey.current_iteration_start_date,
270
+ sessionRecordingUrl: (_b = posthog.get_session_replay_url) === null || _b === void 0 ? void 0 : _b.call(posthog),
271
+ $set: (_a = {},
272
+ _a[getSurveyInteractionProperty(survey, 'dismissed')] = true,
273
+ _a),
274
+ });
275
+ localStorage.setItem(getSurveySeenKey(survey), 'true');
276
+ window.dispatchEvent(new Event('PHSurveyClosed'));
277
+ };
258
278
  // Use the Fisher-yates algorithm to shuffle this array
259
279
  // https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
260
280
  export var shuffle = function (array) {
@@ -296,6 +316,20 @@ export var getDisplayOrderQuestions = function (survey) {
296
316
  }
297
317
  return reverseIfUnshuffled(survey.questions, shuffle(survey.questions));
298
318
  };
319
+ export var getSurveySeenKey = function (survey) {
320
+ var surveySeenKey = "seenSurvey_".concat(survey.id);
321
+ if (survey.current_iteration && survey.current_iteration > 0) {
322
+ surveySeenKey = "seenSurvey_".concat(survey.id, "_").concat(survey.current_iteration);
323
+ }
324
+ return surveySeenKey;
325
+ };
326
+ var getSurveyInteractionProperty = function (survey, action) {
327
+ var surveyProperty = "$survey_".concat(action, "/").concat(survey.id);
328
+ if (survey.current_iteration && survey.current_iteration > 0) {
329
+ surveyProperty = "$survey_".concat(action, "/").concat(survey.id, "/").concat(survey.current_iteration);
330
+ }
331
+ return surveyProperty;
332
+ };
299
333
  export var SurveyContext = createContext({
300
334
  isPreviewMode: false,
301
335
  previewPageIndex: 0,
@@ -1 +1 @@
1
- {"version":3,"file":"surveys-utils.jsx","sourceRoot":"","sources":["../../../../src/extensions/surveys/surveys-utils.tsx"],"names":[],"mappings":";;;;;;;;;;;AAEA,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,QAAQ,IAAI,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC9E,OAAO,EAAS,YAAY,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAC3D,gGAAgG;AAChG,IAAM,MAAM,GAAG,OAAqC,CAAA;AACpD,IAAM,QAAQ,GAAG,SAAqB,CAAA;AAEtC,MAAM,CAAC,IAAM,KAAK,GAAG,UAAC,UAAmC;IACrD,IAAM,SAAS,GAAG;QACd,IAAI,EAAE,aAAa;QACnB,KAAK,EAAE,cAAc;QACrB,MAAM,EAAE,gFAGL;KACN,CAAA;IACD,OAAO,2bASgB,QAAQ,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,QAAQ,KAAI,KAAK,CAAC,yCACzC,QAAQ,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,KAAI,OAAO,CAAC,kDAC5B,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,WAAW,KAAI,SAAS,6FAGxD,SAAS,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,QAAQ,KAAI,OAAO,CAAC,IAAI,cAAc,gRAShD,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,eAAe,KAAI,SAAS,gyBAgBtC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE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C,CAAA;AAED,MAAM,CAAC,IAAM,aAAa,GAAG,aAAa,CAIvC;IACC,aAAa,EAAE,KAAK;IACpB,gBAAgB,EAAE,CAAC;IACnB,sBAAsB,EAAE,cAAO,CAAC;CACnC,CAAC,CAAA;AASF,MAAM,CAAC,IAAM,0BAA0B,GAAG,UAAC,EAAyD;QAAvD,SAAS,eAAA,EAAE,QAAQ,cAAA,EAAE,YAAY,kBAAA,EAAE,KAAK,WAAA;IACjF,OAAO,YAAY;QACf,CAAC,CAAC,YAAY,CAAC,SAAS,EAAE;YACpB,uBAAuB,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE;YAC7C,KAAK,OAAA;SACR,CAAC;QACJ,CAAC,CAAC,YAAY,CAAC,SAAS,EAAE;YACpB,QAAQ,UAAA;YACR,KAAK,OAAA;SACR,CAAC,CAAA;AACZ,CAAC,CAAA","sourcesContent":["import { PostHog } from '../../posthog-core'\nimport { Survey, SurveyAppearance, MultipleSurveyQuestion, SurveyQuestion } from '../../posthog-surveys-types'\nimport { window as _window, document as _document } from '../../utils/globals'\nimport { VNode, cloneElement, createContext } from 'preact'\n// We cast the types here which is dangerous but protected by the top level generateSurveys call\nconst window = _window as Window & typeof globalThis\nconst document = _document as Document\n\nexport const style = (appearance: SurveyAppearance | null) => {\n const positions = {\n left: 'left: 30px;',\n right: 'right: 30px;',\n center: `\n left: 50%;\n transform: translateX(-50%);\n `,\n }\n return `\n .survey-form {\n position: fixed;\n margin: 0px;\n bottom: 0px;\n color: black;\n font-weight: normal;\n font-family: -apple-system, BlinkMacSystemFont, \"Inter\", \"Segoe UI\", \"Roboto\", Helvetica, Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\";\n text-align: left;\n max-width: ${parseInt(appearance?.maxWidth || '300')}px;\n z-index: ${parseInt(appearance?.zIndex || '99999')};\n border: 1.5px solid ${appearance?.borderColor || '#c9c6c6'};\n border-bottom: 0px;\n width: 100%;\n ${positions[appearance?.position || 'right'] || 'right: 30px;'}\n }\n .form-submit[disabled] {\n opacity: 0.6;\n filter: grayscale(50%);\n cursor: not-allowed;\n }\n .survey-form {\n flex-direction: column;\n background: ${appearance?.backgroundColor || '#eeeded'};\n border-top-left-radius: 10px;\n border-top-right-radius: 10px;\n box-shadow: -6px 0 16px -8px rgb(0 0 0 / 8%), -9px 0 28px 0 rgb(0 0 0 / 5%), -12px 0 48px 16px rgb(0 0 0 / 3%);\n }\n .survey-form textarea {\n color: #2d2d2d;\n font-size: 14px;\n font-family: -apple-system, BlinkMacSystemFont, \"Inter\", \"Segoe UI\", \"Roboto\", Helvetica, Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\";\n background: white;\n color: black;\n outline: none;\n padding-left: 10px;\n padding-right: 10px;\n padding-top: 10px;\n border-radius: 6px;\n border-color: ${appearance?.borderColor || '#c9c6c6'};\n margin-top: 14px;\n }\n .form-submit {\n box-sizing: border-box;\n margin: 0;\n font-family: inherit;\n overflow: visible;\n text-transform: none;\n position: relative;\n display: inline-block;\n font-weight: 700;\n white-space: nowrap;\n text-align: center;\n border: 1.5px solid transparent;\n cursor: pointer;\n user-select: none;\n touch-action: manipulation;\n padding: 12px;\n font-size: 14px;\n border-radius: 6px;\n outline: 0;\n background: ${appearance?.submitButtonColor || 'black'} !important;\n text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.12);\n box-shadow: 0 2px 0 rgba(0, 0, 0, 0.045);\n width: 100%;\n }\n .form-cancel {\n float: right;\n border: none;\n background: none;\n cursor: pointer;\n }\n .cancel-btn-wrapper {\n position: absolute;\n width: 35px;\n height: 35px;\n border-radius: 100%;\n top: 0;\n right: 0;\n transform: translate(50%, -50%);\n background: white;\n border: 1.5px solid ${appearance?.borderColor || '#c9c6c6'};\n display: flex;\n justify-content: center;\n align-items: center;\n }\n .bolded { font-weight: 600; }\n .buttons {\n display: flex;\n justify-content: center;\n }\n .footer-branding {\n font-size: 11px;\n margin-top: 10px;\n text-align: center;\n display: flex;\n justify-content: center;\n gap: 4px;\n align-items: center;\n font-weight: 500;\n background: ${appearance?.backgroundColor || '#eeeded'};\n text-decoration: none;\n }\n .survey-box {\n padding: 20px 25px 10px;\n display: flex;\n flex-direction: column;\n border-radius: 10px;\n }\n .survey-question {\n font-weight: 500;\n font-size: 14px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n }\n .question-textarea-wrapper {\n display: flex;\n flex-direction: column;\n }\n .description {\n font-size: 13px;\n padding-top: 5px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n }\n .ratings-number {\n background-color: ${appearance?.ratingButtonColor || 'white'};\n font-size: 16px;\n font-weight: 600;\n padding: 8px 0px;\n border: none;\n }\n .ratings-number:hover {\n cursor: pointer;\n }\n .rating-options {\n margin-top: 14px;\n }\n .rating-options-number {\n display: grid;\n border-radius: 6px;\n overflow: hidden;\n border: 1.5px solid ${appearance?.borderColor || '#c9c6c6'};\n }\n .rating-options-number > .ratings-number {\n border-right: 1px solid ${appearance?.borderColor || '#c9c6c6'};\n }\n .rating-options-number > .ratings-number:last-of-type {\n border-right: 0px;\n }\n .rating-options-number .rating-active {\n background: ${appearance?.ratingButtonActiveColor || 'black'};\n }\n .rating-options-emoji {\n display: flex;\n justify-content: space-between;\n }\n .ratings-emoji {\n font-size: 16px;\n background-color: transparent;\n border: none;\n padding: 0px;\n }\n .ratings-emoji:hover {\n cursor: pointer;\n }\n .ratings-emoji.rating-active svg {\n fill: ${appearance?.ratingButtonActiveColor || 'black'};\n }\n .emoji-svg {\n fill: ${appearance?.ratingButtonColor || '#c9c6c6'};\n }\n .rating-text {\n display: flex;\n flex-direction: row;\n font-size: 11px;\n justify-content: space-between;\n margin-top: 6px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n opacity: .60;\n }\n .multiple-choice-options {\n margin-top: 13px;\n font-size: 14px;\n }\n .multiple-choice-options .choice-option {\n display: flex;\n align-items: center;\n gap: 4px;\n font-size: 13px;\n cursor: pointer;\n margin-bottom: 5px;\n position: relative;\n }\n .multiple-choice-options > .choice-option:last-of-type {\n margin-bottom: 0px;\n }\n .multiple-choice-options input {\n cursor: pointer;\n position: absolute;\n opacity: 0;\n }\n .choice-check {\n position: absolute;\n right: 10px;\n background: white;\n }\n .choice-check svg {\n display: none;\n }\n .multiple-choice-options .choice-option:hover .choice-check svg {\n display: inline-block;\n opacity: .25;\n }\n .multiple-choice-options input:checked + label + .choice-check svg {\n display: inline-block;\n opacity: 100% !important;\n }\n .multiple-choice-options input:checked + label {\n font-weight: bold;\n border: 1.5px solid rgba(0,0,0);\n }\n .multiple-choice-options input:checked + label input {\n font-weight: bold;\n }\n .multiple-choice-options label {\n width: 100%;\n cursor: pointer;\n padding: 10px;\n border: 1.5px solid rgba(0,0,0,.25);\n border-radius: 4px;\n background: white;\n }\n .multiple-choice-options .choice-option-open label {\n padding-right: 30px;\n display: flex;\n flex-wrap: wrap;\n gap: 8px;\n max-width: 100%;\n }\n .multiple-choice-options .choice-option-open label span {\n width: 100%;\n }\n .multiple-choice-options .choice-option-open input:disabled + label {\n opacity: 0.6;\n }\n .multiple-choice-options .choice-option-open label input {\n position: relative;\n opacity: 1;\n flex-grow: 1;\n border: 0;\n outline: 0;\n }\n .thank-you-message {\n position: fixed;\n bottom: 0px;\n z-index: ${parseInt(appearance?.zIndex || '99999')};\n box-shadow: -6px 0 16px -8px rgb(0 0 0 / 8%), -9px 0 28px 0 rgb(0 0 0 / 5%), -12px 0 48px 16px rgb(0 0 0 / 3%);\n font-family: -apple-system, BlinkMacSystemFont, \"Inter\", \"Segoe UI\", \"Roboto\", Helvetica, Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\";\n border-top-left-radius: 10px;\n border-top-right-radius: 10px;\n padding: 20px 25px 10px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n border: 1.5px solid ${appearance?.borderColor || '#c9c6c6'};\n text-align: center;\n max-width: ${parseInt(appearance?.maxWidth || '300')}px;\n min-width: 150px;\n width: 100%;\n ${positions[appearance?.position || 'right'] || 'right: 30px;'}\n }\n .thank-you-message-body {\n margin-top: 6px;\n font-size: 14px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n }\n .thank-you-message-header {\n margin: 10px 0px 0px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n }\n .thank-you-message-container .form-submit {\n margin-top: 20px;\n margin-bottom: 10px;\n }\n .thank-you-message-countdown {\n margin-left: 6px;\n }\n .bottom-section {\n margin-top: 14px;\n }\n `\n}\n\nfunction nameToHex(name: string) {\n return {\n aliceblue: '#f0f8ff',\n antiquewhite: '#faebd7',\n aqua: '#00ffff',\n aquamarine: '#7fffd4',\n azure: '#f0ffff',\n beige: '#f5f5dc',\n bisque: '#ffe4c4',\n black: '#000000',\n blanchedalmond: '#ffebcd',\n blue: '#0000ff',\n blueviolet: '#8a2be2',\n brown: '#a52a2a',\n burlywood: '#deb887',\n cadetblue: '#5f9ea0',\n chartreuse: '#7fff00',\n chocolate: '#d2691e',\n coral: '#ff7f50',\n cornflowerblue: '#6495ed',\n cornsilk: '#fff8dc',\n crimson: '#dc143c',\n cyan: '#00ffff',\n darkblue: '#00008b',\n darkcyan: '#008b8b',\n darkgoldenrod: '#b8860b',\n darkgray: '#a9a9a9',\n darkgreen: '#006400',\n darkkhaki: '#bdb76b',\n darkmagenta: '#8b008b',\n darkolivegreen: '#556b2f',\n darkorange: '#ff8c00',\n darkorchid: '#9932cc',\n darkred: '#8b0000',\n darksalmon: '#e9967a',\n darkseagreen: '#8fbc8f',\n darkslateblue: '#483d8b',\n darkslategray: '#2f4f4f',\n darkturquoise: '#00ced1',\n darkviolet: '#9400d3',\n deeppink: '#ff1493',\n deepskyblue: '#00bfff',\n dimgray: '#696969',\n dodgerblue: '#1e90ff',\n firebrick: '#b22222',\n floralwhite: '#fffaf0',\n forestgreen: '#228b22',\n fuchsia: '#ff00ff',\n gainsboro: '#dcdcdc',\n ghostwhite: '#f8f8ff',\n gold: '#ffd700',\n goldenrod: '#daa520',\n gray: '#808080',\n green: '#008000',\n greenyellow: '#adff2f',\n honeydew: '#f0fff0',\n hotpink: '#ff69b4',\n 'indianred ': '#cd5c5c',\n indigo: '#4b0082',\n ivory: '#fffff0',\n khaki: '#f0e68c',\n lavender: '#e6e6fa',\n lavenderblush: '#fff0f5',\n lawngreen: '#7cfc00',\n lemonchiffon: '#fffacd',\n lightblue: '#add8e6',\n lightcoral: '#f08080',\n lightcyan: '#e0ffff',\n lightgoldenrodyellow: '#fafad2',\n lightgrey: '#d3d3d3',\n lightgreen: '#90ee90',\n lightpink: '#ffb6c1',\n lightsalmon: '#ffa07a',\n lightseagreen: '#20b2aa',\n lightskyblue: '#87cefa',\n lightslategray: '#778899',\n lightsteelblue: '#b0c4de',\n lightyellow: '#ffffe0',\n lime: '#00ff00',\n limegreen: '#32cd32',\n linen: '#faf0e6',\n magenta: '#ff00ff',\n maroon: '#800000',\n mediumaquamarine: '#66cdaa',\n mediumblue: '#0000cd',\n mediumorchid: '#ba55d3',\n mediumpurple: '#9370d8',\n mediumseagreen: '#3cb371',\n mediumslateblue: '#7b68ee',\n mediumspringgreen: '#00fa9a',\n mediumturquoise: '#48d1cc',\n mediumvioletred: '#c71585',\n midnightblue: '#191970',\n mintcream: '#f5fffa',\n mistyrose: '#ffe4e1',\n moccasin: '#ffe4b5',\n navajowhite: '#ffdead',\n navy: '#000080',\n oldlace: '#fdf5e6',\n olive: '#808000',\n olivedrab: '#6b8e23',\n orange: '#ffa500',\n orangered: '#ff4500',\n orchid: '#da70d6',\n palegoldenrod: '#eee8aa',\n palegreen: '#98fb98',\n paleturquoise: '#afeeee',\n palevioletred: '#d87093',\n papayawhip: '#ffefd5',\n peachpuff: '#ffdab9',\n peru: '#cd853f',\n pink: '#ffc0cb',\n plum: '#dda0dd',\n powderblue: '#b0e0e6',\n purple: '#800080',\n red: '#ff0000',\n rosybrown: '#bc8f8f',\n royalblue: '#4169e1',\n saddlebrown: '#8b4513',\n salmon: '#fa8072',\n sandybrown: '#f4a460',\n seagreen: '#2e8b57',\n seashell: '#fff5ee',\n sienna: '#a0522d',\n silver: '#c0c0c0',\n skyblue: '#87ceeb',\n slateblue: '#6a5acd',\n slategray: '#708090',\n snow: '#fffafa',\n springgreen: '#00ff7f',\n steelblue: '#4682b4',\n tan: '#d2b48c',\n teal: '#008080',\n thistle: '#d8bfd8',\n tomato: '#ff6347',\n turquoise: '#40e0d0',\n violet: '#ee82ee',\n wheat: '#f5deb3',\n white: '#ffffff',\n whitesmoke: '#f5f5f5',\n yellow: '#ffff00',\n yellowgreen: '#9acd32',\n }[name.toLowerCase()]\n}\n\nfunction hex2rgb(c: string) {\n if (c[0] === '#') {\n const hexColor = c.replace(/^#/, '')\n const r = parseInt(hexColor.slice(0, 2), 16)\n const g = parseInt(hexColor.slice(2, 4), 16)\n const b = parseInt(hexColor.slice(4, 6), 16)\n return 'rgb(' + r + ',' + g + ',' + b + ')'\n }\n return 'rgb(255, 255, 255)'\n}\n\nexport function getContrastingTextColor(color: string = defaultBackgroundColor) {\n let rgb\n if (color[0] === '#') {\n rgb = hex2rgb(color)\n }\n if (color.startsWith('rgb')) {\n rgb = color\n }\n // otherwise it's a color name\n const nameColorToHex = nameToHex(color)\n if (nameColorToHex) {\n rgb = hex2rgb(nameColorToHex)\n }\n if (!rgb) {\n return 'black'\n }\n const colorMatch = rgb.match(/^rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)(?:,\\s*(\\d+(?:\\.\\d+)?))?\\)$/)\n if (colorMatch) {\n const r = parseInt(colorMatch[1])\n const g = parseInt(colorMatch[2])\n const b = parseInt(colorMatch[3])\n const hsp = Math.sqrt(0.299 * (r * r) + 0.587 * (g * g) + 0.114 * (b * b))\n return hsp > 127.5 ? 'black' : 'white'\n }\n return 'black'\n}\nexport function getTextColor(el: HTMLElement) {\n const backgroundColor = window.getComputedStyle(el).backgroundColor\n if (backgroundColor === 'rgba(0, 0, 0, 0)') {\n return 'black'\n }\n const colorMatch = backgroundColor.match(/^rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)(?:,\\s*(\\d+(?:\\.\\d+)?))?\\)$/)\n if (!colorMatch) return 'black'\n\n const r = parseInt(colorMatch[1])\n const g = parseInt(colorMatch[2])\n const b = parseInt(colorMatch[3])\n const hsp = Math.sqrt(0.299 * (r * r) + 0.587 * (g * g) + 0.114 * (b * b))\n return hsp > 127.5 ? 'black' : 'white'\n}\n\nexport const defaultSurveyAppearance: SurveyAppearance = {\n backgroundColor: '#eeeded',\n submitButtonColor: 'black',\n ratingButtonColor: 'white',\n ratingButtonActiveColor: 'black',\n borderColor: '#c9c6c6',\n placeholder: 'Start typing...',\n whiteLabel: false,\n displayThankYouMessage: true,\n thankYouMessageHeader: 'Thank you for your feedback!',\n position: 'right',\n}\n\nexport const defaultBackgroundColor = '#eeeded'\n\nexport const createShadow = (styleSheet: string, surveyId: string) => {\n const div = document.createElement('div')\n div.className = `PostHogSurvey${surveyId}`\n const shadow = div.attachShadow({ mode: 'open' })\n if (styleSheet) {\n const styleElement = Object.assign(document.createElement('style'), {\n innerText: styleSheet,\n })\n shadow.appendChild(styleElement)\n }\n document.body.appendChild(div)\n return shadow\n}\n\nexport const sendSurveyEvent = (\n responses: Record<string, string | number | string[] | null> = {},\n survey: Survey,\n posthog?: PostHog\n) => {\n if (!posthog) return\n\n localStorage.setItem(`seenSurvey_${survey.id}`, 'true')\n posthog.capture('survey sent', {\n $survey_name: survey.name,\n $survey_id: survey.id,\n $survey_questions: survey.questions.map((question) => question.question),\n sessionRecordingUrl: posthog.get_session_replay_url?.(),\n ...responses,\n $set: {\n [`$survey_responded/${survey.id}`]: true,\n },\n })\n window.dispatchEvent(new Event('PHSurveySent'))\n}\n\n// Use the Fisher-yates algorithm to shuffle this array\n// https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle\nexport const shuffle = (array: any[]) => {\n return array\n .map((a) => ({ sort: Math.floor(Math.random() * 10), value: a }))\n .sort((a, b) => a.sort - b.sort)\n .map((a) => a.value)\n}\n\nconst reverseIfUnshuffled = (unshuffled: any[], shuffled: any[]): any[] => {\n if (unshuffled.length === shuffled.length && unshuffled.every((val, index) => val === shuffled[index])) {\n return shuffled.reverse()\n }\n\n return shuffled\n}\n\nexport const getDisplayOrderChoices = (question: MultipleSurveyQuestion): string[] => {\n if (!question.shuffleOptions) {\n return question.choices\n }\n\n const displayOrderChoices = question.choices\n let openEndedChoice = ''\n if (question.hasOpenChoice) {\n // if the question has an open-ended choice, its always the last element in the choices array.\n openEndedChoice = displayOrderChoices.pop()!\n }\n\n const shuffledOptions = reverseIfUnshuffled(displayOrderChoices, shuffle(displayOrderChoices))\n\n if (question.hasOpenChoice) {\n question.choices.push(openEndedChoice)\n shuffledOptions.push(openEndedChoice)\n }\n\n return shuffledOptions\n}\n\nexport const getDisplayOrderQuestions = (survey: Survey): SurveyQuestion[] => {\n // retain the original questionIndex so we can correlate values in the webapp\n survey.questions.forEach((question, idx) => {\n question.originalQuestionIndex = idx\n })\n\n if (!survey.appearance || !survey.appearance.shuffleQuestions) {\n return survey.questions\n }\n\n return reverseIfUnshuffled(survey.questions, shuffle(survey.questions))\n}\n\nexport const SurveyContext = createContext<{\n isPreviewMode: boolean\n previewPageIndex: number | undefined\n handleCloseSurveyPopup: () => void\n}>({\n isPreviewMode: false,\n previewPageIndex: 0,\n handleCloseSurveyPopup: () => {},\n})\n\ninterface RenderProps {\n component: VNode<{ className: string }>\n children: string\n renderAsHtml?: boolean\n style?: React.CSSProperties\n}\n\nexport const renderChildrenAsTextOrHtml = ({ component, children, renderAsHtml, style }: RenderProps) => {\n return renderAsHtml\n ? cloneElement(component, {\n dangerouslySetInnerHTML: { __html: children },\n style,\n })\n : cloneElement(component, {\n children,\n style,\n })\n}\n"]}
1
+ {"version":3,"file":"surveys-utils.jsx","sourceRoot":"","sources":["../../../../src/extensions/surveys/surveys-utils.tsx"],"names":[],"mappings":";;;;;;;;;;;AAEA,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,QAAQ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AAvD,SAAS,eAAA,EAAE,QAAQ,cAAA,EAAE,YAAY,kBAAA,EAAE,KAAK,WAAA;IACjF,OAAO,YAAY;QACf,CAAC,CAAC,YAAY,CAAC,SAAS,EAAE;YACpB,uBAAuB,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE;YAC7C,KAAK,OAAA;SACR,CAAC;QACJ,CAAC,CAAC,YAAY,CAAC,SAAS,EAAE;YACpB,QAAQ,UAAA;YACR,KAAK,OAAA;SACR,CAAC,CAAA;AACZ,CAAC,CAAA","sourcesContent":["import { PostHog } from '../../posthog-core'\nimport { Survey, SurveyAppearance, MultipleSurveyQuestion, SurveyQuestion } from '../../posthog-surveys-types'\nimport { window as _window, document as _document } from '../../utils/globals'\nimport { VNode, cloneElement, createContext } from 'preact'\n// We cast the types here which is dangerous but protected by the top level generateSurveys call\nconst window = _window as Window & typeof globalThis\nconst document = _document as Document\n\nexport const style = (appearance: SurveyAppearance | null) => {\n const positions = {\n left: 'left: 30px;',\n right: 'right: 30px;',\n center: `\n left: 50%;\n transform: translateX(-50%);\n `,\n }\n return `\n .survey-form {\n position: fixed;\n margin: 0px;\n bottom: 0px;\n color: black;\n font-weight: normal;\n font-family: -apple-system, BlinkMacSystemFont, \"Inter\", \"Segoe UI\", \"Roboto\", Helvetica, Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\";\n text-align: left;\n max-width: ${parseInt(appearance?.maxWidth || '300')}px;\n z-index: ${parseInt(appearance?.zIndex || '99999')};\n border: 1.5px solid ${appearance?.borderColor || '#c9c6c6'};\n border-bottom: 0px;\n width: 100%;\n ${positions[appearance?.position || 'right'] || 'right: 30px;'}\n }\n .form-submit[disabled] {\n opacity: 0.6;\n filter: grayscale(50%);\n cursor: not-allowed;\n }\n .survey-form {\n flex-direction: column;\n background: ${appearance?.backgroundColor || '#eeeded'};\n border-top-left-radius: 10px;\n border-top-right-radius: 10px;\n box-shadow: -6px 0 16px -8px rgb(0 0 0 / 8%), -9px 0 28px 0 rgb(0 0 0 / 5%), -12px 0 48px 16px rgb(0 0 0 / 3%);\n }\n .survey-form textarea {\n color: #2d2d2d;\n font-size: 14px;\n font-family: -apple-system, BlinkMacSystemFont, \"Inter\", \"Segoe UI\", \"Roboto\", Helvetica, Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\";\n background: white;\n color: black;\n outline: none;\n padding-left: 10px;\n padding-right: 10px;\n padding-top: 10px;\n border-radius: 6px;\n border-color: ${appearance?.borderColor || '#c9c6c6'};\n margin-top: 14px;\n }\n .form-submit {\n box-sizing: border-box;\n margin: 0;\n font-family: inherit;\n overflow: visible;\n text-transform: none;\n position: relative;\n display: inline-block;\n font-weight: 700;\n white-space: nowrap;\n text-align: center;\n border: 1.5px solid transparent;\n cursor: pointer;\n user-select: none;\n touch-action: manipulation;\n padding: 12px;\n font-size: 14px;\n border-radius: 6px;\n outline: 0;\n background: ${appearance?.submitButtonColor || 'black'} !important;\n text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.12);\n box-shadow: 0 2px 0 rgba(0, 0, 0, 0.045);\n width: 100%;\n }\n .form-cancel {\n float: right;\n border: none;\n background: none;\n cursor: pointer;\n }\n .cancel-btn-wrapper {\n position: absolute;\n width: 35px;\n height: 35px;\n border-radius: 100%;\n top: 0;\n right: 0;\n transform: translate(50%, -50%);\n background: white;\n border: 1.5px solid ${appearance?.borderColor || '#c9c6c6'};\n display: flex;\n justify-content: center;\n align-items: center;\n }\n .bolded { font-weight: 600; }\n .buttons {\n display: flex;\n justify-content: center;\n }\n .footer-branding {\n font-size: 11px;\n margin-top: 10px;\n text-align: center;\n display: flex;\n justify-content: center;\n gap: 4px;\n align-items: center;\n font-weight: 500;\n background: ${appearance?.backgroundColor || '#eeeded'};\n text-decoration: none;\n }\n .survey-box {\n padding: 20px 25px 10px;\n display: flex;\n flex-direction: column;\n border-radius: 10px;\n }\n .survey-question {\n font-weight: 500;\n font-size: 14px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n }\n .question-textarea-wrapper {\n display: flex;\n flex-direction: column;\n }\n .description {\n font-size: 13px;\n padding-top: 5px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n }\n .ratings-number {\n background-color: ${appearance?.ratingButtonColor || 'white'};\n font-size: 16px;\n font-weight: 600;\n padding: 8px 0px;\n border: none;\n }\n .ratings-number:hover {\n cursor: pointer;\n }\n .rating-options {\n margin-top: 14px;\n }\n .rating-options-number {\n display: grid;\n border-radius: 6px;\n overflow: hidden;\n border: 1.5px solid ${appearance?.borderColor || '#c9c6c6'};\n }\n .rating-options-number > .ratings-number {\n border-right: 1px solid ${appearance?.borderColor || '#c9c6c6'};\n }\n .rating-options-number > .ratings-number:last-of-type {\n border-right: 0px;\n }\n .rating-options-number .rating-active {\n background: ${appearance?.ratingButtonActiveColor || 'black'};\n }\n .rating-options-emoji {\n display: flex;\n justify-content: space-between;\n }\n .ratings-emoji {\n font-size: 16px;\n background-color: transparent;\n border: none;\n padding: 0px;\n }\n .ratings-emoji:hover {\n cursor: pointer;\n }\n .ratings-emoji.rating-active svg {\n fill: ${appearance?.ratingButtonActiveColor || 'black'};\n }\n .emoji-svg {\n fill: ${appearance?.ratingButtonColor || '#c9c6c6'};\n }\n .rating-text {\n display: flex;\n flex-direction: row;\n font-size: 11px;\n justify-content: space-between;\n margin-top: 6px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n opacity: .60;\n }\n .multiple-choice-options {\n margin-top: 13px;\n font-size: 14px;\n }\n .multiple-choice-options .choice-option {\n display: flex;\n align-items: center;\n gap: 4px;\n font-size: 13px;\n cursor: pointer;\n margin-bottom: 5px;\n position: relative;\n }\n .multiple-choice-options > .choice-option:last-of-type {\n margin-bottom: 0px;\n }\n .multiple-choice-options input {\n cursor: pointer;\n position: absolute;\n opacity: 0;\n }\n .choice-check {\n position: absolute;\n right: 10px;\n background: white;\n }\n .choice-check svg {\n display: none;\n }\n .multiple-choice-options .choice-option:hover .choice-check svg {\n display: inline-block;\n opacity: .25;\n }\n .multiple-choice-options input:checked + label + .choice-check svg {\n display: inline-block;\n opacity: 100% !important;\n }\n .multiple-choice-options input:checked + label {\n font-weight: bold;\n border: 1.5px solid rgba(0,0,0);\n }\n .multiple-choice-options input:checked + label input {\n font-weight: bold;\n }\n .multiple-choice-options label {\n width: 100%;\n cursor: pointer;\n padding: 10px;\n border: 1.5px solid rgba(0,0,0,.25);\n border-radius: 4px;\n background: white;\n }\n .multiple-choice-options .choice-option-open label {\n padding-right: 30px;\n display: flex;\n flex-wrap: wrap;\n gap: 8px;\n max-width: 100%;\n }\n .multiple-choice-options .choice-option-open label span {\n width: 100%;\n }\n .multiple-choice-options .choice-option-open input:disabled + label {\n opacity: 0.6;\n }\n .multiple-choice-options .choice-option-open label input {\n position: relative;\n opacity: 1;\n flex-grow: 1;\n border: 0;\n outline: 0;\n }\n .thank-you-message {\n position: fixed;\n bottom: 0px;\n z-index: ${parseInt(appearance?.zIndex || '99999')};\n box-shadow: -6px 0 16px -8px rgb(0 0 0 / 8%), -9px 0 28px 0 rgb(0 0 0 / 5%), -12px 0 48px 16px rgb(0 0 0 / 3%);\n font-family: -apple-system, BlinkMacSystemFont, \"Inter\", \"Segoe UI\", \"Roboto\", Helvetica, Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\";\n border-top-left-radius: 10px;\n border-top-right-radius: 10px;\n padding: 20px 25px 10px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n border: 1.5px solid ${appearance?.borderColor || '#c9c6c6'};\n text-align: center;\n max-width: ${parseInt(appearance?.maxWidth || '300')}px;\n min-width: 150px;\n width: 100%;\n ${positions[appearance?.position || 'right'] || 'right: 30px;'}\n }\n .thank-you-message-body {\n margin-top: 6px;\n font-size: 14px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n }\n .thank-you-message-header {\n margin: 10px 0px 0px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n }\n .thank-you-message-container .form-submit {\n margin-top: 20px;\n margin-bottom: 10px;\n }\n .thank-you-message-countdown {\n margin-left: 6px;\n }\n .bottom-section {\n margin-top: 14px;\n }\n `\n}\n\nfunction nameToHex(name: string) {\n return {\n aliceblue: '#f0f8ff',\n antiquewhite: '#faebd7',\n aqua: '#00ffff',\n aquamarine: '#7fffd4',\n azure: '#f0ffff',\n beige: '#f5f5dc',\n bisque: '#ffe4c4',\n black: '#000000',\n blanchedalmond: '#ffebcd',\n blue: '#0000ff',\n blueviolet: '#8a2be2',\n brown: '#a52a2a',\n burlywood: '#deb887',\n cadetblue: '#5f9ea0',\n chartreuse: '#7fff00',\n chocolate: '#d2691e',\n coral: '#ff7f50',\n cornflowerblue: '#6495ed',\n cornsilk: '#fff8dc',\n crimson: '#dc143c',\n cyan: '#00ffff',\n darkblue: '#00008b',\n darkcyan: '#008b8b',\n darkgoldenrod: '#b8860b',\n darkgray: '#a9a9a9',\n darkgreen: '#006400',\n darkkhaki: '#bdb76b',\n darkmagenta: '#8b008b',\n darkolivegreen: '#556b2f',\n darkorange: '#ff8c00',\n darkorchid: '#9932cc',\n darkred: '#8b0000',\n darksalmon: '#e9967a',\n darkseagreen: '#8fbc8f',\n darkslateblue: '#483d8b',\n darkslategray: '#2f4f4f',\n darkturquoise: '#00ced1',\n darkviolet: '#9400d3',\n deeppink: '#ff1493',\n deepskyblue: '#00bfff',\n dimgray: '#696969',\n dodgerblue: '#1e90ff',\n firebrick: '#b22222',\n floralwhite: '#fffaf0',\n forestgreen: '#228b22',\n fuchsia: '#ff00ff',\n gainsboro: '#dcdcdc',\n ghostwhite: '#f8f8ff',\n gold: '#ffd700',\n goldenrod: '#daa520',\n gray: '#808080',\n green: '#008000',\n greenyellow: '#adff2f',\n honeydew: '#f0fff0',\n hotpink: '#ff69b4',\n 'indianred ': '#cd5c5c',\n indigo: '#4b0082',\n ivory: '#fffff0',\n khaki: '#f0e68c',\n lavender: '#e6e6fa',\n lavenderblush: '#fff0f5',\n lawngreen: '#7cfc00',\n lemonchiffon: '#fffacd',\n lightblue: '#add8e6',\n lightcoral: '#f08080',\n lightcyan: '#e0ffff',\n lightgoldenrodyellow: '#fafad2',\n lightgrey: '#d3d3d3',\n lightgreen: '#90ee90',\n lightpink: '#ffb6c1',\n lightsalmon: '#ffa07a',\n lightseagreen: '#20b2aa',\n lightskyblue: '#87cefa',\n lightslategray: '#778899',\n lightsteelblue: '#b0c4de',\n lightyellow: '#ffffe0',\n lime: '#00ff00',\n limegreen: '#32cd32',\n linen: '#faf0e6',\n magenta: '#ff00ff',\n maroon: '#800000',\n mediumaquamarine: '#66cdaa',\n mediumblue: '#0000cd',\n mediumorchid: '#ba55d3',\n mediumpurple: '#9370d8',\n mediumseagreen: '#3cb371',\n mediumslateblue: '#7b68ee',\n mediumspringgreen: '#00fa9a',\n mediumturquoise: '#48d1cc',\n mediumvioletred: '#c71585',\n midnightblue: '#191970',\n mintcream: '#f5fffa',\n mistyrose: '#ffe4e1',\n moccasin: '#ffe4b5',\n navajowhite: '#ffdead',\n navy: '#000080',\n oldlace: '#fdf5e6',\n olive: '#808000',\n olivedrab: '#6b8e23',\n orange: '#ffa500',\n orangered: '#ff4500',\n orchid: '#da70d6',\n palegoldenrod: '#eee8aa',\n palegreen: '#98fb98',\n paleturquoise: '#afeeee',\n palevioletred: '#d87093',\n papayawhip: '#ffefd5',\n peachpuff: '#ffdab9',\n peru: '#cd853f',\n pink: '#ffc0cb',\n plum: '#dda0dd',\n powderblue: '#b0e0e6',\n purple: '#800080',\n red: '#ff0000',\n rosybrown: '#bc8f8f',\n royalblue: '#4169e1',\n saddlebrown: '#8b4513',\n salmon: '#fa8072',\n sandybrown: '#f4a460',\n seagreen: '#2e8b57',\n seashell: '#fff5ee',\n sienna: '#a0522d',\n silver: '#c0c0c0',\n skyblue: '#87ceeb',\n slateblue: '#6a5acd',\n slategray: '#708090',\n snow: '#fffafa',\n springgreen: '#00ff7f',\n steelblue: '#4682b4',\n tan: '#d2b48c',\n teal: '#008080',\n thistle: '#d8bfd8',\n tomato: '#ff6347',\n turquoise: '#40e0d0',\n violet: '#ee82ee',\n wheat: '#f5deb3',\n white: '#ffffff',\n whitesmoke: '#f5f5f5',\n yellow: '#ffff00',\n yellowgreen: '#9acd32',\n }[name.toLowerCase()]\n}\n\nfunction hex2rgb(c: string) {\n if (c[0] === '#') {\n const hexColor = c.replace(/^#/, '')\n const r = parseInt(hexColor.slice(0, 2), 16)\n const g = parseInt(hexColor.slice(2, 4), 16)\n const b = parseInt(hexColor.slice(4, 6), 16)\n return 'rgb(' + r + ',' + g + ',' + b + ')'\n }\n return 'rgb(255, 255, 255)'\n}\n\nexport function getContrastingTextColor(color: string = defaultBackgroundColor) {\n let rgb\n if (color[0] === '#') {\n rgb = hex2rgb(color)\n }\n if (color.startsWith('rgb')) {\n rgb = color\n }\n // otherwise it's a color name\n const nameColorToHex = nameToHex(color)\n if (nameColorToHex) {\n rgb = hex2rgb(nameColorToHex)\n }\n if (!rgb) {\n return 'black'\n }\n const colorMatch = rgb.match(/^rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)(?:,\\s*(\\d+(?:\\.\\d+)?))?\\)$/)\n if (colorMatch) {\n const r = parseInt(colorMatch[1])\n const g = parseInt(colorMatch[2])\n const b = parseInt(colorMatch[3])\n const hsp = Math.sqrt(0.299 * (r * r) + 0.587 * (g * g) + 0.114 * (b * b))\n return hsp > 127.5 ? 'black' : 'white'\n }\n return 'black'\n}\nexport function getTextColor(el: HTMLElement) {\n const backgroundColor = window.getComputedStyle(el).backgroundColor\n if (backgroundColor === 'rgba(0, 0, 0, 0)') {\n return 'black'\n }\n const colorMatch = backgroundColor.match(/^rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)(?:,\\s*(\\d+(?:\\.\\d+)?))?\\)$/)\n if (!colorMatch) return 'black'\n\n const r = parseInt(colorMatch[1])\n const g = parseInt(colorMatch[2])\n const b = parseInt(colorMatch[3])\n const hsp = Math.sqrt(0.299 * (r * r) + 0.587 * (g * g) + 0.114 * (b * b))\n return hsp > 127.5 ? 'black' : 'white'\n}\n\nexport const defaultSurveyAppearance: SurveyAppearance = {\n backgroundColor: '#eeeded',\n submitButtonColor: 'black',\n ratingButtonColor: 'white',\n ratingButtonActiveColor: 'black',\n borderColor: '#c9c6c6',\n placeholder: 'Start typing...',\n whiteLabel: false,\n displayThankYouMessage: true,\n thankYouMessageHeader: 'Thank you for your feedback!',\n position: 'right',\n}\n\nexport const defaultBackgroundColor = '#eeeded'\n\nexport const createShadow = (styleSheet: string, surveyId: string) => {\n const div = document.createElement('div')\n div.className = `PostHogSurvey${surveyId}`\n const shadow = div.attachShadow({ mode: 'open' })\n if (styleSheet) {\n const styleElement = Object.assign(document.createElement('style'), {\n innerText: styleSheet,\n })\n shadow.appendChild(styleElement)\n }\n document.body.appendChild(div)\n return shadow\n}\n\nexport const sendSurveyEvent = (\n responses: Record<string, string | number | string[] | null> = {},\n survey: Survey,\n posthog?: PostHog\n) => {\n if (!posthog) return\n localStorage.setItem(getSurveySeenKey(survey), 'true')\n\n posthog.capture('survey sent', {\n $survey_name: survey.name,\n $survey_id: survey.id,\n $survey_iteration: survey.current_iteration,\n $survey_iteration_start_date: survey.current_iteration_start_date,\n $survey_questions: survey.questions.map((question) => question.question),\n sessionRecordingUrl: posthog.get_session_replay_url?.(),\n ...responses,\n $set: {\n [getSurveyInteractionProperty(survey, 'responded')]: true,\n },\n })\n window.dispatchEvent(new Event('PHSurveySent'))\n}\n\nexport const dismissedSurveyEvent = (survey: Survey, posthog?: PostHog, readOnly?: boolean) => {\n // TODO: state management and unit tests for this would be nice\n if (readOnly || !posthog) {\n return\n }\n posthog.capture('survey dismissed', {\n $survey_name: survey.name,\n $survey_id: survey.id,\n $survey_iteration: survey.current_iteration,\n $survey_iteration_start_date: survey.current_iteration_start_date,\n sessionRecordingUrl: posthog.get_session_replay_url?.(),\n $set: {\n [getSurveyInteractionProperty(survey, 'dismissed')]: true,\n },\n })\n localStorage.setItem(getSurveySeenKey(survey), 'true')\n window.dispatchEvent(new Event('PHSurveyClosed'))\n}\n\n// Use the Fisher-yates algorithm to shuffle this array\n// https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle\nexport const shuffle = (array: any[]) => {\n return array\n .map((a) => ({ sort: Math.floor(Math.random() * 10), value: a }))\n .sort((a, b) => a.sort - b.sort)\n .map((a) => a.value)\n}\n\nconst reverseIfUnshuffled = (unshuffled: any[], shuffled: any[]): any[] => {\n if (unshuffled.length === shuffled.length && unshuffled.every((val, index) => val === shuffled[index])) {\n return shuffled.reverse()\n }\n\n return shuffled\n}\n\nexport const getDisplayOrderChoices = (question: MultipleSurveyQuestion): string[] => {\n if (!question.shuffleOptions) {\n return question.choices\n }\n\n const displayOrderChoices = question.choices\n let openEndedChoice = ''\n if (question.hasOpenChoice) {\n // if the question has an open-ended choice, its always the last element in the choices array.\n openEndedChoice = displayOrderChoices.pop()!\n }\n\n const shuffledOptions = reverseIfUnshuffled(displayOrderChoices, shuffle(displayOrderChoices))\n\n if (question.hasOpenChoice) {\n question.choices.push(openEndedChoice)\n shuffledOptions.push(openEndedChoice)\n }\n\n return shuffledOptions\n}\n\nexport const getDisplayOrderQuestions = (survey: Survey): SurveyQuestion[] => {\n // retain the original questionIndex so we can correlate values in the webapp\n survey.questions.forEach((question, idx) => {\n question.originalQuestionIndex = idx\n })\n\n if (!survey.appearance || !survey.appearance.shuffleQuestions) {\n return survey.questions\n }\n\n return reverseIfUnshuffled(survey.questions, shuffle(survey.questions))\n}\n\nexport const getSurveySeenKey = (survey: Survey): string => {\n let surveySeenKey = `seenSurvey_${survey.id}`\n if (survey.current_iteration && survey.current_iteration > 0) {\n surveySeenKey = `seenSurvey_${survey.id}_${survey.current_iteration}`\n }\n\n return surveySeenKey\n}\n\nconst getSurveyInteractionProperty = (survey: Survey, action: string): string => {\n let surveyProperty = `$survey_${action}/${survey.id}`\n if (survey.current_iteration && survey.current_iteration > 0) {\n surveyProperty = `$survey_${action}/${survey.id}/${survey.current_iteration}`\n }\n\n return surveyProperty\n}\n\nexport const SurveyContext = createContext<{\n isPreviewMode: boolean\n previewPageIndex: number | undefined\n handleCloseSurveyPopup: () => void\n}>({\n isPreviewMode: false,\n previewPageIndex: 0,\n handleCloseSurveyPopup: () => {},\n})\n\ninterface RenderProps {\n component: VNode<{ className: string }>\n children: string\n renderAsHtml?: boolean\n style?: React.CSSProperties\n}\n\nexport const renderChildrenAsTextOrHtml = ({ component, children, renderAsHtml, style }: RenderProps) => {\n return renderAsHtml\n ? cloneElement(component, {\n dangerouslySetInnerHTML: { __html: children },\n style,\n })\n : cloneElement(component, {\n children,\n style,\n })\n}\n"]}