posthog-js 1.158.0 → 1.158.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 (96) 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/exception-autocapture.js.map +1 -1
  6. package/dist/lib/src/entrypoints/web-vitals.d.ts +4 -4
  7. package/dist/lib/src/extensions/replay/config.d.ts +1 -1
  8. package/dist/lib/src/extensions/replay/sessionrecording.d.ts +4 -0
  9. package/dist/lib/src/extensions/surveys.d.ts +2 -2
  10. package/dist/lib/src/utils/globals.d.ts +6 -6
  11. package/dist/lib/src/utils/logger.d.ts +1 -1
  12. package/dist/main.js +1 -1
  13. package/dist/main.js.map +1 -1
  14. package/dist/module.d.ts +4 -0
  15. package/dist/module.js +1 -1
  16. package/dist/module.js.map +1 -1
  17. package/dist/recorder-v2.js.map +1 -1
  18. package/dist/recorder.js.map +1 -1
  19. package/lib/package.json +14 -9
  20. package/lib/src/autocapture-utils.js.map +1 -1
  21. package/lib/src/autocapture.js.map +1 -1
  22. package/lib/src/consent.js +1 -1
  23. package/lib/src/consent.js.map +1 -1
  24. package/lib/src/decide.js.map +1 -1
  25. package/lib/src/entrypoints/exception-autocapture.js.map +1 -1
  26. package/lib/src/entrypoints/recorder.js +12 -12
  27. package/lib/src/entrypoints/recorder.js.map +1 -1
  28. package/lib/src/entrypoints/surveys.js.map +1 -1
  29. package/lib/src/entrypoints/tracing-headers.js.map +1 -1
  30. package/lib/src/entrypoints/web-vitals.d.ts +4 -4
  31. package/lib/src/extensions/exception-autocapture/error-conversion.js +2 -2
  32. package/lib/src/extensions/exception-autocapture/error-conversion.js.map +1 -1
  33. package/lib/src/extensions/exception-autocapture/index.js.map +1 -1
  34. package/lib/src/extensions/exception-autocapture/stack-trace.js.map +1 -1
  35. package/lib/src/extensions/exception-autocapture/type-checking.js +1 -1
  36. package/lib/src/extensions/exception-autocapture/type-checking.js.map +1 -1
  37. package/lib/src/extensions/rageclick.js.map +1 -1
  38. package/lib/src/extensions/replay/config.d.ts +1 -1
  39. package/lib/src/extensions/replay/config.js.map +1 -1
  40. package/lib/src/extensions/replay/external/denylist.js.map +1 -1
  41. package/lib/src/extensions/replay/mutation-rate-limiter.js.map +1 -1
  42. package/lib/src/extensions/replay/rrweb-plugins/patch.js.map +1 -1
  43. package/lib/src/extensions/replay/sessionrecording-utils.js.map +1 -1
  44. package/lib/src/extensions/replay/sessionrecording.d.ts +4 -0
  45. package/lib/src/extensions/replay/sessionrecording.js +22 -13
  46. package/lib/src/extensions/replay/sessionrecording.js.map +1 -1
  47. package/lib/src/extensions/segment-integration.js.map +1 -1
  48. package/lib/src/extensions/sentry-integration.js.map +1 -1
  49. package/lib/src/extensions/surveys/action-matcher.js.map +1 -1
  50. package/lib/src/extensions/surveys/components/BottomSection.jsx.map +1 -1
  51. package/lib/src/extensions/surveys/components/ConfirmationMessage.jsx.map +1 -1
  52. package/lib/src/extensions/surveys/components/QuestionTypes.jsx.map +1 -1
  53. package/lib/src/extensions/surveys/hooks/useContrastingTextColor.js.map +1 -1
  54. package/lib/src/extensions/surveys/surveys-utils.jsx.map +1 -1
  55. package/lib/src/extensions/surveys.d.ts +2 -2
  56. package/lib/src/extensions/surveys.jsx.map +1 -1
  57. package/lib/src/extensions/toolbar.js +2 -2
  58. package/lib/src/extensions/toolbar.js.map +1 -1
  59. package/lib/src/extensions/tracing-headers.js.map +1 -1
  60. package/lib/src/extensions/web-vitals/index.js.map +1 -1
  61. package/lib/src/heatmaps.js.map +1 -1
  62. package/lib/src/page-view.js.map +1 -1
  63. package/lib/src/posthog-core.js +5 -5
  64. package/lib/src/posthog-core.js.map +1 -1
  65. package/lib/src/posthog-featureflags.js.map +1 -1
  66. package/lib/src/posthog-persistence.js.map +1 -1
  67. package/lib/src/posthog-surveys.js.map +1 -1
  68. package/lib/src/rate-limiter.js.map +1 -1
  69. package/lib/src/request-queue.js.map +1 -1
  70. package/lib/src/request.js +2 -2
  71. package/lib/src/request.js.map +1 -1
  72. package/lib/src/retry-queue.js.map +1 -1
  73. package/lib/src/scroll-manager.js.map +1 -1
  74. package/lib/src/session-props.js.map +1 -1
  75. package/lib/src/sessionid.js.map +1 -1
  76. package/lib/src/storage.js +10 -10
  77. package/lib/src/storage.js.map +1 -1
  78. package/lib/src/types.js.map +1 -1
  79. package/lib/src/utils/blocked-uas.js.map +1 -1
  80. package/lib/src/utils/event-utils.js +13 -13
  81. package/lib/src/utils/event-utils.js.map +1 -1
  82. package/lib/src/utils/globals.d.ts +6 -6
  83. package/lib/src/utils/index.js +3 -3
  84. package/lib/src/utils/index.js.map +1 -1
  85. package/lib/src/utils/logger.d.ts +1 -1
  86. package/lib/src/utils/logger.js.map +1 -1
  87. package/lib/src/utils/request-router.js +11 -2
  88. package/lib/src/utils/request-router.js.map +1 -1
  89. package/lib/src/utils/request-utils.js +1 -1
  90. package/lib/src/utils/request-utils.js.map +1 -1
  91. package/lib/src/utils/simple-event-emitter.js.map +1 -1
  92. package/lib/src/utils/survey-event-receiver.js.map +1 -1
  93. package/lib/src/utils/type-utils.js.map +1 -1
  94. package/lib/src/utils/user-agent-utils.js.map +1 -1
  95. package/lib/src/uuidv7.js.map +1 -1
  96. package/package.json +14 -9
@@ -1 +1 @@
1
- {"version":3,"file":"surveys.jsx","sourceRoot":"","sources":["../../../src/extensions/surveys.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAIH,2BAA2B,EAC3B,kBAAkB,EAElB,UAAU,GACb,MAAM,0BAA0B,CAAA;AAEjC,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,QAAQ,IAAI,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC3E,OAAO,EACH,KAAK,EACL,uBAAuB,EACvB,eAAe,EACf,oBAAoB,EACpB,YAAY,EACZ,uBAAuB,EACvB,aAAa,EACb,w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,GAAG,UAAC,EAMF;;QALxB,QAAQ,cAAA,EACR,gBAAgB,sBAAA,EAChB,oBAAoB,0BAAA,EACpB,UAAU,gBAAA,EACV,QAAQ,cAAA;IAER,IAAM,kBAAkB;QACpB,GAAC,kBAAkB,CAAC,IAAI,IAAG,gBAAgB;QAC3C,GAAC,kBAAkB,CAAC,IAAI,IAAG,YAAY;QACvC,GAAC,kBAAkB,CAAC,MAAM,IAAG,cAAc;QAC3C,GAAC,kBAAkB,CAAC,YAAY,IAAG,sBAAsB;QACzD,GAAC,kBAAkB,CAAC,cAAc,IAAG,sBAAsB;WAC9D,CAAA;IAED,IAAM,WAAW,GAAG;QAChB,QAAQ,UAAA;QACR,gBAAgB,kBAAA;QAChB,UAAU,YAAA;QACV,QAAQ,UAAA;KACX,CAAA;IAED,IAAM,eAAe;QACjB,GAAC,kBAAkB,CAAC,IAAI,IAAG,EAAE;QAC7B,GAAC,kBAAkB,CAAC,IAAI,IAAG,EAAE;QAC7B,GAAC,kBAAkB,CAAC,MAAM,IAAG,EAAE,oBAAoB,sBAAA,EAAE;QACrD,GAAC,kBAAkB,CAAC,YAAY,IAAG,EAAE,oBAAoB,sBAAA,EAAE;QAC3D,GAAC,kBAAkB,CAAC,cAAc,IAAG,EAAE,oBAAoB,sBAAA,EAAE;WAChE,CAAA;IAED,IAAM,SAAS,GAAG,kBAAkB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IACnD,IAAM,cAAc,yBAAQ,WAAW,GAAK,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAE,CAAA;IAE5E,OAAO,CAAC,SAAS,CAAC,IAAI,cAAc,CAAC,EAAG,CAAA;AAC5C,CAAC,CAAA","sourcesContent":["import { PostHog } from '../posthog-core'\nimport {\n Survey,\n SurveyAppearance,\n SurveyQuestion,\n SurveyQuestionBranchingType,\n SurveyQuestionType,\n SurveyRenderReason,\n SurveyType,\n} from '../posthog-surveys-types'\n\nimport { window as _window, document as _document } from '../utils/globals'\nimport {\n style,\n defaultSurveyAppearance,\n sendSurveyEvent,\n dismissedSurveyEvent,\n createShadow,\n getContrastingTextColor,\n SurveyContext,\n getDisplayOrderQuestions,\n getSurveySeen,\n} from './surveys/surveys-utils'\nimport * as Preact from 'preact'\nimport { createWidgetShadow, createWidgetStyle } from './surveys-widget'\nimport { useState, useEffect, useRef, useContext, useMemo } from 'preact/hooks'\nimport { isNull, isNumber } from '../utils/type-utils'\nimport { ConfirmationMessage } from './surveys/components/ConfirmationMessage'\nimport {\n OpenTextQuestion,\n LinkQuestion,\n RatingQuestion,\n MultipleChoiceQuestion,\n} from './surveys/components/QuestionTypes'\nimport { logger } from '../utils/logger'\nimport { Cancel } from './surveys/components/QuestionHeader'\n\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 class SurveyManager {\n private posthog: PostHog\n private surveyInFocus: string | null\n\n constructor(posthog: PostHog) {\n this.posthog = posthog\n // This is used to track the survey that is currently in focus. We only show one survey at a time.\n this.surveyInFocus = null\n }\n\n private canShowNextEventBasedSurvey = (): boolean => {\n // with event based surveys, we need to show the next survey without reloading the page.\n // A simple check for div elements with the class name pattern of PostHogSurvey_xyz doesn't work here\n // because preact leaves behind the div element for any surveys responded/dismissed with a <style> node.\n // To alleviate this, we check the last div in the dom and see if it has any elements other than a Style node.\n // if the last PostHogSurvey_xyz div has only one style node, we can show the next survey in the queue\n // without reloading the page.\n const surveyPopups = document.querySelectorAll(`div[class^=PostHogSurvey]`)\n if (surveyPopups.length > 0) {\n return surveyPopups[surveyPopups.length - 1].shadowRoot?.childElementCount === 1\n }\n return true\n }\n\n private handlePopoverSurvey = (survey: Survey): void => {\n const surveyWaitPeriodInDays = survey.conditions?.seenSurveyWaitPeriodInDays\n const lastSeenSurveyDate = localStorage.getItem(`lastSeenSurveyDate`)\n if (surveyWaitPeriodInDays && lastSeenSurveyDate) {\n const today = new Date()\n const diff = Math.abs(today.getTime() - new Date(lastSeenSurveyDate).getTime())\n const diffDaysFromToday = Math.ceil(diff / (1000 * 3600 * 24))\n if (diffDaysFromToday < surveyWaitPeriodInDays) {\n return\n }\n }\n\n const surveySeen = getSurveySeen(survey)\n if (!surveySeen) {\n this.addSurveyToFocus(survey.id)\n const shadow = createShadow(style(survey?.appearance), survey.id)\n Preact.render(\n <SurveyPopup\n key={'popover-survey'}\n posthog={this.posthog}\n survey={survey}\n removeSurveyFromFocus={this.removeSurveyFromFocus}\n isPopup={true}\n />,\n shadow\n )\n }\n }\n\n private handleWidget = (survey: Survey): void => {\n const shadow = createWidgetShadow(survey)\n const surveyStyleSheet = style(survey.appearance)\n shadow.appendChild(Object.assign(document.createElement('style'), { innerText: surveyStyleSheet }))\n Preact.render(\n <FeedbackWidget\n key={'feedback-survey'}\n posthog={this.posthog}\n survey={survey}\n removeSurveyFromFocus={this.removeSurveyFromFocus}\n />,\n shadow\n )\n }\n\n private handleWidgetSelector = (survey: Survey): void => {\n const selectorOnPage =\n survey.appearance?.widgetSelector && document.querySelector(survey.appearance.widgetSelector)\n if (selectorOnPage) {\n if (document.querySelectorAll(`.PostHogWidget${survey.id}`).length === 0) {\n this.handleWidget(survey)\n } else if (document.querySelectorAll(`.PostHogWidget${survey.id}`).length === 1) {\n // we have to check if user selector already has a survey listener attached to it because we always have to check if it's on the page or not\n if (!selectorOnPage.getAttribute('PHWidgetSurveyClickListener')) {\n const surveyPopup = document\n .querySelector(`.PostHogWidget${survey.id}`)\n ?.shadowRoot?.querySelector(`.survey-form`) as HTMLFormElement\n selectorOnPage.addEventListener('click', () => {\n if (surveyPopup) {\n surveyPopup.style.display = surveyPopup.style.display === 'none' ? 'block' : 'none'\n surveyPopup.addEventListener('PHSurveyClosed', () => {\n this.removeSurveyFromFocus(survey.id)\n surveyPopup.style.display = 'none'\n })\n }\n })\n selectorOnPage.setAttribute('PHWidgetSurveyClickListener', 'true')\n }\n }\n }\n }\n\n /**\n * Sorts surveys by their appearance delay in ascending order. If a survey does not have an appearance delay,\n * it is considered to have a delay of 0.\n * @param surveys\n * @returns The surveys sorted by their appearance delay\n */\n private sortSurveysByAppearanceDelay(surveys: Survey[]): Survey[] {\n return surveys.sort(\n (a, b) => (a.appearance?.surveyPopupDelaySeconds || 0) - (b.appearance?.surveyPopupDelaySeconds || 0)\n )\n }\n\n /**\n * Checks the feature flags associated with this Survey to see if the survey can be rendered.\n * @param survey\n * @param instance\n */\n public canRenderSurvey = (survey: Survey): SurveyRenderReason => {\n const renderReason: SurveyRenderReason = {\n visible: false,\n }\n\n if (survey.end_date) {\n renderReason.disabledReason = `survey was completed on ${survey.end_date}`\n return renderReason\n }\n\n if (survey.type != SurveyType.Popover) {\n renderReason.disabledReason = `Only Popover survey types can be rendered`\n return renderReason\n }\n\n const linkedFlagCheck = survey.linked_flag_key\n ? this.posthog.featureFlags.isFeatureEnabled(survey.linked_flag_key)\n : true\n\n if (!linkedFlagCheck) {\n renderReason.disabledReason = `linked feature flag ${survey.linked_flag_key} is false`\n return renderReason\n }\n\n const targetingFlagCheck = survey.targeting_flag_key\n ? this.posthog.featureFlags.isFeatureEnabled(survey.targeting_flag_key)\n : true\n\n if (!targetingFlagCheck) {\n renderReason.disabledReason = `targeting feature flag ${survey.targeting_flag_key} is false`\n return renderReason\n }\n\n const internalTargetingFlagCheck = survey.internal_targeting_flag_key\n ? this.posthog.featureFlags.isFeatureEnabled(survey.internal_targeting_flag_key)\n : true\n\n if (!internalTargetingFlagCheck) {\n renderReason.disabledReason = `internal targeting feature flag ${survey.internal_targeting_flag_key} is false`\n return renderReason\n }\n\n renderReason.visible = true\n return renderReason\n }\n\n public renderSurvey = (survey: Survey, selector: Element): void => {\n Preact.render(\n <SurveyPopup\n key={'popover-survey'}\n posthog={this.posthog}\n survey={survey}\n removeSurveyFromFocus={this.removeSurveyFromFocus}\n isPopup={false}\n />,\n selector\n )\n }\n\n public callSurveysAndEvaluateDisplayLogic = (forceReload: boolean = false): void => {\n this.posthog?.getActiveMatchingSurveys((surveys) => {\n const nonAPISurveys = surveys.filter((survey) => survey.type !== 'api')\n\n // Create a queue of surveys sorted by their appearance delay. We will evaluate the display logic\n // for each survey in the queue in order, and only display one survey at a time.\n const nonAPISurveyQueue = this.sortSurveysByAppearanceDelay(nonAPISurveys)\n\n nonAPISurveyQueue.forEach((survey) => {\n // We only evaluate the display logic for one survey at a time\n if (!isNull(this.surveyInFocus)) {\n return\n }\n if (survey.type === SurveyType.Widget) {\n if (\n survey.appearance?.widgetType === 'tab' &&\n document.querySelectorAll(`.PostHogWidget${survey.id}`).length === 0\n ) {\n this.handleWidget(survey)\n }\n if (survey.appearance?.widgetType === 'selector' && survey.appearance?.widgetSelector) {\n this.handleWidgetSelector(survey)\n }\n }\n\n if (survey.type === SurveyType.Popover && this.canShowNextEventBasedSurvey()) {\n this.handlePopoverSurvey(survey)\n }\n })\n }, forceReload)\n }\n\n private addSurveyToFocus = (id: string): void => {\n if (!isNull(this.surveyInFocus)) {\n logger.error(`Survey ${[...this.surveyInFocus]} already in focus. Cannot add survey ${id}.`)\n }\n this.surveyInFocus = id\n }\n\n private removeSurveyFromFocus = (id: string): void => {\n if (this.surveyInFocus !== id) {\n logger.error(`Survey ${id} is not in focus. Cannot remove survey ${id}.`)\n }\n this.surveyInFocus = null\n }\n\n // Expose internal state and methods for testing\n public getTestAPI() {\n return {\n addSurveyToFocus: this.addSurveyToFocus,\n removeSurveyFromFocus: this.removeSurveyFromFocus,\n surveyInFocus: this.surveyInFocus,\n canShowNextEventBasedSurvey: this.canShowNextEventBasedSurvey,\n handleWidget: this.handleWidget,\n handlePopoverSurvey: this.handlePopoverSurvey,\n handleWidgetSelector: this.handleWidgetSelector,\n sortSurveysByAppearanceDelay: this.sortSurveysByAppearanceDelay,\n }\n }\n}\n\nexport const renderSurveysPreview = ({\n survey,\n parentElement,\n previewPageIndex,\n forceDisableHtml,\n}: {\n survey: Survey\n parentElement: HTMLElement\n previewPageIndex: number\n forceDisableHtml?: boolean\n}) => {\n const surveyStyleSheet = style(survey.appearance)\n const styleElement = Object.assign(document.createElement('style'), { innerText: surveyStyleSheet })\n\n // Remove previously attached <style>\n Array.from(parentElement.children).forEach((child) => {\n if (child instanceof HTMLStyleElement) {\n parentElement.removeChild(child)\n }\n })\n\n parentElement.appendChild(styleElement)\n const textColor = getContrastingTextColor(\n survey.appearance?.backgroundColor || defaultSurveyAppearance.backgroundColor || 'white'\n )\n\n Preact.render(\n <SurveyPopup\n key=\"surveys-render-preview\"\n survey={survey}\n forceDisableHtml={forceDisableHtml}\n style={{\n position: 'relative',\n right: 0,\n borderBottom: `1px solid ${survey.appearance?.borderColor}`,\n borderRadius: 10,\n color: textColor,\n }}\n previewPageIndex={previewPageIndex}\n removeSurveyFromFocus={() => {}}\n isPopup={true}\n />,\n parentElement\n )\n}\n\nexport const renderFeedbackWidgetPreview = ({\n survey,\n root,\n forceDisableHtml,\n}: {\n survey: Survey\n root: HTMLElement\n forceDisableHtml?: boolean\n}) => {\n const widgetStyleSheet = createWidgetStyle(survey.appearance?.widgetColor)\n const styleElement = Object.assign(document.createElement('style'), { innerText: widgetStyleSheet })\n root.appendChild(styleElement)\n Preact.render(\n <FeedbackWidget\n key={'feedback-render-preview'}\n forceDisableHtml={forceDisableHtml}\n survey={survey}\n readOnly={true}\n removeSurveyFromFocus={() => {}}\n />,\n root\n )\n}\n\n// This is the main exported function\nexport function generateSurveys(posthog: PostHog) {\n // NOTE: Important to ensure we never try and run surveys without a window environment\n if (!document || !window) {\n return\n }\n\n const surveyManager = new SurveyManager(posthog)\n surveyManager.callSurveysAndEvaluateDisplayLogic(true)\n\n // recalculate surveys every second to check if URL or selectors have changed\n setInterval(() => {\n surveyManager.callSurveysAndEvaluateDisplayLogic(false)\n }, 1000)\n return surveyManager\n}\n\nexport function usePopupVisibility(\n survey: Survey,\n posthog: PostHog | undefined,\n millisecondDelay: number,\n isPreviewMode: boolean,\n removeSurveyFromFocus: (id: string) => void\n) {\n const [isPopupVisible, setIsPopupVisible] = useState(isPreviewMode || millisecondDelay === 0)\n const [isSurveySent, setIsSurveySent] = useState(false)\n\n useEffect(() => {\n if (isPreviewMode || !posthog) {\n return\n }\n\n const handleSurveyClosed = () => {\n removeSurveyFromFocus(survey.id)\n setIsPopupVisible(false)\n }\n\n const handleSurveySent = () => {\n if (!survey.appearance?.displayThankYouMessage) {\n removeSurveyFromFocus(survey.id)\n setIsPopupVisible(false)\n } else {\n setIsSurveySent(true)\n removeSurveyFromFocus(survey.id)\n if (survey.appearance?.autoDisappear) {\n setTimeout(() => {\n setIsPopupVisible(false)\n }, 5000)\n }\n }\n }\n\n const showSurvey = () => {\n setIsPopupVisible(true)\n window.dispatchEvent(new Event('PHSurveyShown'))\n posthog.capture('survey shown', {\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 })\n localStorage.setItem('lastSeenSurveyDate', new Date().toISOString())\n }\n\n const handleShowSurveyWithDelay = () => {\n const timeoutId = setTimeout(() => {\n showSurvey()\n }, millisecondDelay)\n\n return () => {\n clearTimeout(timeoutId)\n window.removeEventListener('PHSurveyClosed', handleSurveyClosed)\n window.removeEventListener('PHSurveySent', handleSurveySent)\n }\n }\n\n const handleShowSurveyImmediately = () => {\n showSurvey()\n return () => {\n window.removeEventListener('PHSurveyClosed', handleSurveyClosed)\n window.removeEventListener('PHSurveySent', handleSurveySent)\n }\n }\n\n window.addEventListener('PHSurveyClosed', handleSurveyClosed)\n window.addEventListener('PHSurveySent', handleSurveySent)\n\n if (millisecondDelay > 0) {\n return handleShowSurveyWithDelay()\n } else {\n return handleShowSurveyImmediately()\n }\n }, [])\n\n return { isPopupVisible, isSurveySent, setIsPopupVisible }\n}\n\nexport function SurveyPopup({\n survey,\n forceDisableHtml,\n posthog,\n style,\n previewPageIndex,\n removeSurveyFromFocus,\n isPopup,\n}: {\n survey: Survey\n forceDisableHtml?: boolean\n posthog?: PostHog\n style?: React.CSSProperties\n previewPageIndex?: number | undefined\n removeSurveyFromFocus: (id: string) => void\n isPopup?: boolean\n}) {\n const isPreviewMode = Number.isInteger(previewPageIndex)\n // NB: The client-side code passes the millisecondDelay in seconds, but setTimeout expects milliseconds, so we multiply by 1000\n const surveyPopupDelayMilliseconds = survey.appearance?.surveyPopupDelaySeconds\n ? survey.appearance.surveyPopupDelaySeconds * 1000\n : 0\n const { isPopupVisible, isSurveySent, setIsPopupVisible } = usePopupVisibility(\n survey,\n posthog,\n surveyPopupDelayMilliseconds,\n isPreviewMode,\n removeSurveyFromFocus\n )\n const shouldShowConfirmation = isSurveySent || previewPageIndex === survey.questions.length\n const confirmationBoxLeftStyle = style?.left && isNumber(style?.left) ? { left: style.left - 40 } : {}\n\n if (isPreviewMode) {\n style = style || {}\n style.left = 'unset'\n style.right = 'unset'\n style.transform = 'unset'\n }\n\n return isPopupVisible ? (\n <SurveyContext.Provider\n value={{\n isPreviewMode,\n previewPageIndex: previewPageIndex,\n handleCloseSurveyPopup: () => dismissedSurveyEvent(survey, posthog, isPreviewMode),\n isPopup: isPopup || false,\n }}\n >\n {!shouldShowConfirmation ? (\n <Questions\n survey={survey}\n forceDisableHtml={!!forceDisableHtml}\n posthog={posthog}\n styleOverrides={style}\n />\n ) : (\n <ConfirmationMessage\n header={survey.appearance?.thankYouMessageHeader || 'Thank you!'}\n description={survey.appearance?.thankYouMessageDescription || ''}\n forceDisableHtml={!!forceDisableHtml}\n contentType={survey.appearance?.thankYouMessageDescriptionContentType}\n appearance={survey.appearance || defaultSurveyAppearance}\n styleOverrides={{ ...style, ...confirmationBoxLeftStyle }}\n onClose={() => setIsPopupVisible(false)}\n />\n )}\n </SurveyContext.Provider>\n ) : (\n <></>\n )\n}\n\nexport function Questions({\n survey,\n forceDisableHtml,\n posthog,\n styleOverrides,\n}: {\n survey: Survey\n forceDisableHtml: boolean\n posthog?: PostHog\n styleOverrides?: React.CSSProperties\n}) {\n const textColor = getContrastingTextColor(\n survey.appearance?.backgroundColor || defaultSurveyAppearance.backgroundColor\n )\n const [questionsResponses, setQuestionsResponses] = useState({})\n const { isPreviewMode, previewPageIndex, handleCloseSurveyPopup, isPopup } = useContext(SurveyContext)\n const [currentQuestionIndex, setCurrentQuestionIndex] = useState(previewPageIndex || 0)\n const surveyQuestions = useMemo(() => getDisplayOrderQuestions(survey), [survey])\n\n // Sync preview state\n useEffect(() => {\n setCurrentQuestionIndex(previewPageIndex ?? 0)\n }, [previewPageIndex])\n\n const onNextButtonClick = ({\n res,\n originalQuestionIndex,\n displayQuestionIndex,\n }: {\n res: string | string[] | number | null\n originalQuestionIndex: number\n displayQuestionIndex: number\n }) => {\n if (!posthog) {\n return\n }\n\n const responseKey =\n originalQuestionIndex === 0 ? `$survey_response` : `$survey_response_${originalQuestionIndex}`\n\n setQuestionsResponses({ ...questionsResponses, [responseKey]: res })\n\n // Old SDK, no branching\n if (!posthog.getNextSurveyStep) {\n const isLastDisplayedQuestion = displayQuestionIndex === survey.questions.length - 1\n if (isLastDisplayedQuestion) {\n sendSurveyEvent({ ...questionsResponses, [responseKey]: res }, survey, posthog)\n } else {\n setCurrentQuestionIndex(displayQuestionIndex + 1)\n }\n return\n }\n\n const nextStep = posthog.getNextSurveyStep(survey, displayQuestionIndex, res)\n if (nextStep === SurveyQuestionBranchingType.End) {\n sendSurveyEvent({ ...questionsResponses, [responseKey]: res }, survey, posthog)\n } else {\n setCurrentQuestionIndex(nextStep)\n }\n }\n\n return (\n <form\n className=\"survey-form\"\n style={\n isPopup\n ? {\n color: textColor,\n borderColor: survey.appearance?.borderColor,\n ...styleOverrides,\n }\n : {}\n }\n >\n {surveyQuestions.map((question, displayQuestionIndex) => {\n const { originalQuestionIndex } = question\n\n const isVisible = isPreviewMode\n ? currentQuestionIndex === originalQuestionIndex\n : currentQuestionIndex === displayQuestionIndex\n return (\n isVisible && (\n <div\n className=\"survey-box\"\n style={\n isPopup\n ? {\n backgroundColor:\n survey.appearance?.backgroundColor ||\n defaultSurveyAppearance.backgroundColor,\n }\n : {}\n }\n >\n {isPopup && <Cancel onClick={() => handleCloseSurveyPopup()} />}\n {getQuestionComponent({\n question,\n forceDisableHtml,\n displayQuestionIndex,\n appearance: survey.appearance || defaultSurveyAppearance,\n onSubmit: (res) =>\n onNextButtonClick({\n res,\n originalQuestionIndex,\n displayQuestionIndex,\n }),\n })}\n </div>\n )\n )\n })}\n </form>\n )\n}\n\nexport function FeedbackWidget({\n survey,\n forceDisableHtml,\n posthog,\n readOnly,\n removeSurveyFromFocus,\n}: {\n survey: Survey\n forceDisableHtml?: boolean\n posthog?: PostHog\n readOnly?: boolean\n removeSurveyFromFocus: (id: string) => void\n}): JSX.Element {\n const [showSurvey, setShowSurvey] = useState(false)\n const [styleOverrides, setStyle] = useState({})\n const widgetRef = useRef<HTMLDivElement>(null)\n\n useEffect(() => {\n if (readOnly || !posthog) {\n return\n }\n\n if (survey.appearance?.widgetType === 'tab') {\n if (widgetRef.current) {\n const widgetPos = widgetRef.current.getBoundingClientRect()\n const style = {\n top: '50%',\n left: parseInt(`${widgetPos.right - 360}`),\n bottom: 'auto',\n borderRadius: 10,\n borderBottom: `1.5px solid ${survey.appearance?.borderColor || '#c9c6c6'}`,\n }\n setStyle(style)\n }\n }\n if (survey.appearance?.widgetType === 'selector') {\n const widget = document.querySelector(survey.appearance.widgetSelector || '')\n widget?.addEventListener('click', () => {\n setShowSurvey(!showSurvey)\n })\n widget?.setAttribute('PHWidgetSurveyClickListener', 'true')\n }\n }, [])\n\n return (\n <>\n {survey.appearance?.widgetType === 'tab' && (\n <div\n className=\"ph-survey-widget-tab\"\n ref={widgetRef}\n onClick={() => !readOnly && setShowSurvey(!showSurvey)}\n style={{ color: getContrastingTextColor(survey.appearance.widgetColor) }}\n >\n <div className=\"ph-survey-widget-tab-icon\"></div>\n {survey.appearance?.widgetLabel || ''}\n </div>\n )}\n {showSurvey && (\n <SurveyPopup\n key={'feedback-widget-survey'}\n posthog={posthog}\n survey={survey}\n forceDisableHtml={forceDisableHtml}\n style={styleOverrides}\n removeSurveyFromFocus={removeSurveyFromFocus}\n isPopup={true}\n />\n )}\n </>\n )\n}\n\ninterface GetQuestionComponentProps {\n question: SurveyQuestion\n forceDisableHtml: boolean\n displayQuestionIndex: number\n appearance: SurveyAppearance\n onSubmit: (res: string | string[] | number | null) => void\n}\n\nconst getQuestionComponent = ({\n question,\n forceDisableHtml,\n displayQuestionIndex,\n appearance,\n onSubmit,\n}: GetQuestionComponentProps): JSX.Element => {\n const questionComponents = {\n [SurveyQuestionType.Open]: OpenTextQuestion,\n [SurveyQuestionType.Link]: LinkQuestion,\n [SurveyQuestionType.Rating]: RatingQuestion,\n [SurveyQuestionType.SingleChoice]: MultipleChoiceQuestion,\n [SurveyQuestionType.MultipleChoice]: MultipleChoiceQuestion,\n }\n\n const commonProps = {\n question,\n forceDisableHtml,\n appearance,\n onSubmit,\n }\n\n const additionalProps: Record<SurveyQuestionType, any> = {\n [SurveyQuestionType.Open]: {},\n [SurveyQuestionType.Link]: {},\n [SurveyQuestionType.Rating]: { displayQuestionIndex },\n [SurveyQuestionType.SingleChoice]: { displayQuestionIndex },\n [SurveyQuestionType.MultipleChoice]: { displayQuestionIndex },\n }\n\n const Component = questionComponents[question.type]\n const componentProps = { ...commonProps, ...additionalProps[question.type] }\n\n return <Component {...componentProps} />\n}\n"]}
1
+ {"version":3,"file":"surveys.jsx","sourceRoot":"","sources":["../../../src/extensions/surveys.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAIH,2BAA2B,EAC3B,kBAAkB,EAElB,UAAU,GACb,MAAM,0BAA0B,CAAA;AAEjC,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,QAAQ,IAAI,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC3E,OAAO,EACH,KAAK,EACL,uBAAuB,EACvB,eAAe,EACf,oBAAoB,EACpB,YAAY,EACZ,uBAAuB,EACvB,aAAa,EACb,wBAAwB,EACxB,aAA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,cAAc,IAAG,EAAE,oBAAoB,sBAAA,EAAE;WAChE,CAAA;IAED,IAAM,SAAS,GAAG,kBAAkB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;IACnD,IAAM,cAAc,yBAAQ,WAAW,GAAK,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAE,CAAA;IAE5E,OAAO,CAAC,SAAS,CAAC,IAAI,cAAc,CAAC,EAAG,CAAA;AAC5C,CAAC,CAAA","sourcesContent":["import { PostHog } from '../posthog-core'\nimport {\n Survey,\n SurveyAppearance,\n SurveyQuestion,\n SurveyQuestionBranchingType,\n SurveyQuestionType,\n SurveyRenderReason,\n SurveyType,\n} from '../posthog-surveys-types'\n\nimport { window as _window, document as _document } from '../utils/globals'\nimport {\n style,\n defaultSurveyAppearance,\n sendSurveyEvent,\n dismissedSurveyEvent,\n createShadow,\n getContrastingTextColor,\n SurveyContext,\n getDisplayOrderQuestions,\n getSurveySeen,\n} from './surveys/surveys-utils'\nimport * as Preact from 'preact'\nimport { createWidgetShadow, createWidgetStyle } from './surveys-widget'\nimport { useState, useEffect, useRef, useContext, useMemo } from 'preact/hooks'\nimport { isNull, isNumber } from '../utils/type-utils'\nimport { ConfirmationMessage } from './surveys/components/ConfirmationMessage'\nimport {\n OpenTextQuestion,\n LinkQuestion,\n RatingQuestion,\n MultipleChoiceQuestion,\n} from './surveys/components/QuestionTypes'\nimport { logger } from '../utils/logger'\nimport { Cancel } from './surveys/components/QuestionHeader'\n\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 class SurveyManager {\n private posthog: PostHog\n private surveyInFocus: string | null\n\n constructor(posthog: PostHog) {\n this.posthog = posthog\n // This is used to track the survey that is currently in focus. We only show one survey at a time.\n this.surveyInFocus = null\n }\n\n private canShowNextEventBasedSurvey = (): boolean => {\n // with event based surveys, we need to show the next survey without reloading the page.\n // A simple check for div elements with the class name pattern of PostHogSurvey_xyz doesn't work here\n // because preact leaves behind the div element for any surveys responded/dismissed with a <style> node.\n // To alleviate this, we check the last div in the dom and see if it has any elements other than a Style node.\n // if the last PostHogSurvey_xyz div has only one style node, we can show the next survey in the queue\n // without reloading the page.\n const surveyPopups = document.querySelectorAll(`div[class^=PostHogSurvey]`)\n if (surveyPopups.length > 0) {\n return surveyPopups[surveyPopups.length - 1].shadowRoot?.childElementCount === 1\n }\n return true\n }\n\n private handlePopoverSurvey = (survey: Survey): void => {\n const surveyWaitPeriodInDays = survey.conditions?.seenSurveyWaitPeriodInDays\n const lastSeenSurveyDate = localStorage.getItem(`lastSeenSurveyDate`)\n if (surveyWaitPeriodInDays && lastSeenSurveyDate) {\n const today = new Date()\n const diff = Math.abs(today.getTime() - new Date(lastSeenSurveyDate).getTime())\n const diffDaysFromToday = Math.ceil(diff / (1000 * 3600 * 24))\n if (diffDaysFromToday < surveyWaitPeriodInDays) {\n return\n }\n }\n\n const surveySeen = getSurveySeen(survey)\n if (!surveySeen) {\n this.addSurveyToFocus(survey.id)\n const shadow = createShadow(style(survey?.appearance), survey.id)\n Preact.render(\n <SurveyPopup\n key={'popover-survey'}\n posthog={this.posthog}\n survey={survey}\n removeSurveyFromFocus={this.removeSurveyFromFocus}\n isPopup={true}\n />,\n shadow\n )\n }\n }\n\n private handleWidget = (survey: Survey): void => {\n const shadow = createWidgetShadow(survey)\n const surveyStyleSheet = style(survey.appearance)\n shadow.appendChild(Object.assign(document.createElement('style'), { innerText: surveyStyleSheet }))\n Preact.render(\n <FeedbackWidget\n key={'feedback-survey'}\n posthog={this.posthog}\n survey={survey}\n removeSurveyFromFocus={this.removeSurveyFromFocus}\n />,\n shadow\n )\n }\n\n private handleWidgetSelector = (survey: Survey): void => {\n const selectorOnPage =\n survey.appearance?.widgetSelector && document.querySelector(survey.appearance.widgetSelector)\n if (selectorOnPage) {\n if (document.querySelectorAll(`.PostHogWidget${survey.id}`).length === 0) {\n this.handleWidget(survey)\n } else if (document.querySelectorAll(`.PostHogWidget${survey.id}`).length === 1) {\n // we have to check if user selector already has a survey listener attached to it because we always have to check if it's on the page or not\n if (!selectorOnPage.getAttribute('PHWidgetSurveyClickListener')) {\n const surveyPopup = document\n .querySelector(`.PostHogWidget${survey.id}`)\n ?.shadowRoot?.querySelector(`.survey-form`) as HTMLFormElement\n selectorOnPage.addEventListener('click', () => {\n if (surveyPopup) {\n surveyPopup.style.display = surveyPopup.style.display === 'none' ? 'block' : 'none'\n surveyPopup.addEventListener('PHSurveyClosed', () => {\n this.removeSurveyFromFocus(survey.id)\n surveyPopup.style.display = 'none'\n })\n }\n })\n selectorOnPage.setAttribute('PHWidgetSurveyClickListener', 'true')\n }\n }\n }\n }\n\n /**\n * Sorts surveys by their appearance delay in ascending order. If a survey does not have an appearance delay,\n * it is considered to have a delay of 0.\n * @param surveys\n * @returns The surveys sorted by their appearance delay\n */\n private sortSurveysByAppearanceDelay(surveys: Survey[]): Survey[] {\n return surveys.sort(\n (a, b) => (a.appearance?.surveyPopupDelaySeconds || 0) - (b.appearance?.surveyPopupDelaySeconds || 0)\n )\n }\n\n /**\n * Checks the feature flags associated with this Survey to see if the survey can be rendered.\n * @param survey\n * @param instance\n */\n public canRenderSurvey = (survey: Survey): SurveyRenderReason => {\n const renderReason: SurveyRenderReason = {\n visible: false,\n }\n\n if (survey.end_date) {\n renderReason.disabledReason = `survey was completed on ${survey.end_date}`\n return renderReason\n }\n\n if (survey.type != SurveyType.Popover) {\n renderReason.disabledReason = `Only Popover survey types can be rendered`\n return renderReason\n }\n\n const linkedFlagCheck = survey.linked_flag_key\n ? this.posthog.featureFlags.isFeatureEnabled(survey.linked_flag_key)\n : true\n\n if (!linkedFlagCheck) {\n renderReason.disabledReason = `linked feature flag ${survey.linked_flag_key} is false`\n return renderReason\n }\n\n const targetingFlagCheck = survey.targeting_flag_key\n ? this.posthog.featureFlags.isFeatureEnabled(survey.targeting_flag_key)\n : true\n\n if (!targetingFlagCheck) {\n renderReason.disabledReason = `targeting feature flag ${survey.targeting_flag_key} is false`\n return renderReason\n }\n\n const internalTargetingFlagCheck = survey.internal_targeting_flag_key\n ? this.posthog.featureFlags.isFeatureEnabled(survey.internal_targeting_flag_key)\n : true\n\n if (!internalTargetingFlagCheck) {\n renderReason.disabledReason = `internal targeting feature flag ${survey.internal_targeting_flag_key} is false`\n return renderReason\n }\n\n renderReason.visible = true\n return renderReason\n }\n\n public renderSurvey = (survey: Survey, selector: Element): void => {\n Preact.render(\n <SurveyPopup\n key={'popover-survey'}\n posthog={this.posthog}\n survey={survey}\n removeSurveyFromFocus={this.removeSurveyFromFocus}\n isPopup={false}\n />,\n selector\n )\n }\n\n public callSurveysAndEvaluateDisplayLogic = (forceReload: boolean = false): void => {\n this.posthog?.getActiveMatchingSurveys((surveys) => {\n const nonAPISurveys = surveys.filter((survey) => survey.type !== 'api')\n\n // Create a queue of surveys sorted by their appearance delay. We will evaluate the display logic\n // for each survey in the queue in order, and only display one survey at a time.\n const nonAPISurveyQueue = this.sortSurveysByAppearanceDelay(nonAPISurveys)\n\n nonAPISurveyQueue.forEach((survey) => {\n // We only evaluate the display logic for one survey at a time\n if (!isNull(this.surveyInFocus)) {\n return\n }\n if (survey.type === SurveyType.Widget) {\n if (\n survey.appearance?.widgetType === 'tab' &&\n document.querySelectorAll(`.PostHogWidget${survey.id}`).length === 0\n ) {\n this.handleWidget(survey)\n }\n if (survey.appearance?.widgetType === 'selector' && survey.appearance?.widgetSelector) {\n this.handleWidgetSelector(survey)\n }\n }\n\n if (survey.type === SurveyType.Popover && this.canShowNextEventBasedSurvey()) {\n this.handlePopoverSurvey(survey)\n }\n })\n }, forceReload)\n }\n\n private addSurveyToFocus = (id: string): void => {\n if (!isNull(this.surveyInFocus)) {\n logger.error(`Survey ${[...this.surveyInFocus]} already in focus. Cannot add survey ${id}.`)\n }\n this.surveyInFocus = id\n }\n\n private removeSurveyFromFocus = (id: string): void => {\n if (this.surveyInFocus !== id) {\n logger.error(`Survey ${id} is not in focus. Cannot remove survey ${id}.`)\n }\n this.surveyInFocus = null\n }\n\n // Expose internal state and methods for testing\n public getTestAPI() {\n return {\n addSurveyToFocus: this.addSurveyToFocus,\n removeSurveyFromFocus: this.removeSurveyFromFocus,\n surveyInFocus: this.surveyInFocus,\n canShowNextEventBasedSurvey: this.canShowNextEventBasedSurvey,\n handleWidget: this.handleWidget,\n handlePopoverSurvey: this.handlePopoverSurvey,\n handleWidgetSelector: this.handleWidgetSelector,\n sortSurveysByAppearanceDelay: this.sortSurveysByAppearanceDelay,\n }\n }\n}\n\nexport const renderSurveysPreview = ({\n survey,\n parentElement,\n previewPageIndex,\n forceDisableHtml,\n}: {\n survey: Survey\n parentElement: HTMLElement\n previewPageIndex: number\n forceDisableHtml?: boolean\n}) => {\n const surveyStyleSheet = style(survey.appearance)\n const styleElement = Object.assign(document.createElement('style'), { innerText: surveyStyleSheet })\n\n // Remove previously attached <style>\n Array.from(parentElement.children).forEach((child) => {\n if (child instanceof HTMLStyleElement) {\n parentElement.removeChild(child)\n }\n })\n\n parentElement.appendChild(styleElement)\n const textColor = getContrastingTextColor(\n survey.appearance?.backgroundColor || defaultSurveyAppearance.backgroundColor || 'white'\n )\n\n Preact.render(\n <SurveyPopup\n key=\"surveys-render-preview\"\n survey={survey}\n forceDisableHtml={forceDisableHtml}\n style={{\n position: 'relative',\n right: 0,\n borderBottom: `1px solid ${survey.appearance?.borderColor}`,\n borderRadius: 10,\n color: textColor,\n }}\n previewPageIndex={previewPageIndex}\n removeSurveyFromFocus={() => {}}\n isPopup={true}\n />,\n parentElement\n )\n}\n\nexport const renderFeedbackWidgetPreview = ({\n survey,\n root,\n forceDisableHtml,\n}: {\n survey: Survey\n root: HTMLElement\n forceDisableHtml?: boolean\n}) => {\n const widgetStyleSheet = createWidgetStyle(survey.appearance?.widgetColor)\n const styleElement = Object.assign(document.createElement('style'), { innerText: widgetStyleSheet })\n root.appendChild(styleElement)\n Preact.render(\n <FeedbackWidget\n key={'feedback-render-preview'}\n forceDisableHtml={forceDisableHtml}\n survey={survey}\n readOnly={true}\n removeSurveyFromFocus={() => {}}\n />,\n root\n )\n}\n\n// This is the main exported function\nexport function generateSurveys(posthog: PostHog) {\n // NOTE: Important to ensure we never try and run surveys without a window environment\n if (!document || !window) {\n return\n }\n\n const surveyManager = new SurveyManager(posthog)\n surveyManager.callSurveysAndEvaluateDisplayLogic(true)\n\n // recalculate surveys every second to check if URL or selectors have changed\n setInterval(() => {\n surveyManager.callSurveysAndEvaluateDisplayLogic(false)\n }, 1000)\n return surveyManager\n}\n\nexport function usePopupVisibility(\n survey: Survey,\n posthog: PostHog | undefined,\n millisecondDelay: number,\n isPreviewMode: boolean,\n removeSurveyFromFocus: (id: string) => void\n) {\n const [isPopupVisible, setIsPopupVisible] = useState(isPreviewMode || millisecondDelay === 0)\n const [isSurveySent, setIsSurveySent] = useState(false)\n\n useEffect(() => {\n if (isPreviewMode || !posthog) {\n return\n }\n\n const handleSurveyClosed = () => {\n removeSurveyFromFocus(survey.id)\n setIsPopupVisible(false)\n }\n\n const handleSurveySent = () => {\n if (!survey.appearance?.displayThankYouMessage) {\n removeSurveyFromFocus(survey.id)\n setIsPopupVisible(false)\n } else {\n setIsSurveySent(true)\n removeSurveyFromFocus(survey.id)\n if (survey.appearance?.autoDisappear) {\n setTimeout(() => {\n setIsPopupVisible(false)\n }, 5000)\n }\n }\n }\n\n const showSurvey = () => {\n setIsPopupVisible(true)\n window.dispatchEvent(new Event('PHSurveyShown'))\n posthog.capture('survey shown', {\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 })\n localStorage.setItem('lastSeenSurveyDate', new Date().toISOString())\n }\n\n const handleShowSurveyWithDelay = () => {\n const timeoutId = setTimeout(() => {\n showSurvey()\n }, millisecondDelay)\n\n return () => {\n clearTimeout(timeoutId)\n window.removeEventListener('PHSurveyClosed', handleSurveyClosed)\n window.removeEventListener('PHSurveySent', handleSurveySent)\n }\n }\n\n const handleShowSurveyImmediately = () => {\n showSurvey()\n return () => {\n window.removeEventListener('PHSurveyClosed', handleSurveyClosed)\n window.removeEventListener('PHSurveySent', handleSurveySent)\n }\n }\n\n window.addEventListener('PHSurveyClosed', handleSurveyClosed)\n window.addEventListener('PHSurveySent', handleSurveySent)\n\n if (millisecondDelay > 0) {\n return handleShowSurveyWithDelay()\n } else {\n return handleShowSurveyImmediately()\n }\n }, [])\n\n return { isPopupVisible, isSurveySent, setIsPopupVisible }\n}\n\nexport function SurveyPopup({\n survey,\n forceDisableHtml,\n posthog,\n style,\n previewPageIndex,\n removeSurveyFromFocus,\n isPopup,\n}: {\n survey: Survey\n forceDisableHtml?: boolean\n posthog?: PostHog\n style?: React.CSSProperties\n previewPageIndex?: number | undefined\n removeSurveyFromFocus: (id: string) => void\n isPopup?: boolean\n}) {\n const isPreviewMode = Number.isInteger(previewPageIndex)\n // NB: The client-side code passes the millisecondDelay in seconds, but setTimeout expects milliseconds, so we multiply by 1000\n const surveyPopupDelayMilliseconds = survey.appearance?.surveyPopupDelaySeconds\n ? survey.appearance.surveyPopupDelaySeconds * 1000\n : 0\n const { isPopupVisible, isSurveySent, setIsPopupVisible } = usePopupVisibility(\n survey,\n posthog,\n surveyPopupDelayMilliseconds,\n isPreviewMode,\n removeSurveyFromFocus\n )\n const shouldShowConfirmation = isSurveySent || previewPageIndex === survey.questions.length\n const confirmationBoxLeftStyle = style?.left && isNumber(style?.left) ? { left: style.left - 40 } : {}\n\n if (isPreviewMode) {\n style = style || {}\n style.left = 'unset'\n style.right = 'unset'\n style.transform = 'unset'\n }\n\n return isPopupVisible ? (\n <SurveyContext.Provider\n value={{\n isPreviewMode,\n previewPageIndex: previewPageIndex,\n handleCloseSurveyPopup: () => dismissedSurveyEvent(survey, posthog, isPreviewMode),\n isPopup: isPopup || false,\n }}\n >\n {!shouldShowConfirmation ? (\n <Questions\n survey={survey}\n forceDisableHtml={!!forceDisableHtml}\n posthog={posthog}\n styleOverrides={style}\n />\n ) : (\n <ConfirmationMessage\n header={survey.appearance?.thankYouMessageHeader || 'Thank you!'}\n description={survey.appearance?.thankYouMessageDescription || ''}\n forceDisableHtml={!!forceDisableHtml}\n contentType={survey.appearance?.thankYouMessageDescriptionContentType}\n appearance={survey.appearance || defaultSurveyAppearance}\n styleOverrides={{ ...style, ...confirmationBoxLeftStyle }}\n onClose={() => setIsPopupVisible(false)}\n />\n )}\n </SurveyContext.Provider>\n ) : (\n <></>\n )\n}\n\nexport function Questions({\n survey,\n forceDisableHtml,\n posthog,\n styleOverrides,\n}: {\n survey: Survey\n forceDisableHtml: boolean\n posthog?: PostHog\n styleOverrides?: React.CSSProperties\n}) {\n const textColor = getContrastingTextColor(\n survey.appearance?.backgroundColor || defaultSurveyAppearance.backgroundColor\n )\n const [questionsResponses, setQuestionsResponses] = useState({})\n const { isPreviewMode, previewPageIndex, handleCloseSurveyPopup, isPopup } = useContext(SurveyContext)\n const [currentQuestionIndex, setCurrentQuestionIndex] = useState(previewPageIndex || 0)\n const surveyQuestions = useMemo(() => getDisplayOrderQuestions(survey), [survey])\n\n // Sync preview state\n useEffect(() => {\n setCurrentQuestionIndex(previewPageIndex ?? 0)\n }, [previewPageIndex])\n\n const onNextButtonClick = ({\n res,\n originalQuestionIndex,\n displayQuestionIndex,\n }: {\n res: string | string[] | number | null\n originalQuestionIndex: number\n displayQuestionIndex: number\n }) => {\n if (!posthog) {\n return\n }\n\n const responseKey =\n originalQuestionIndex === 0 ? `$survey_response` : `$survey_response_${originalQuestionIndex}`\n\n setQuestionsResponses({ ...questionsResponses, [responseKey]: res })\n\n // Old SDK, no branching\n if (!posthog.getNextSurveyStep) {\n const isLastDisplayedQuestion = displayQuestionIndex === survey.questions.length - 1\n if (isLastDisplayedQuestion) {\n sendSurveyEvent({ ...questionsResponses, [responseKey]: res }, survey, posthog)\n } else {\n setCurrentQuestionIndex(displayQuestionIndex + 1)\n }\n return\n }\n\n const nextStep = posthog.getNextSurveyStep(survey, displayQuestionIndex, res)\n if (nextStep === SurveyQuestionBranchingType.End) {\n sendSurveyEvent({ ...questionsResponses, [responseKey]: res }, survey, posthog)\n } else {\n setCurrentQuestionIndex(nextStep)\n }\n }\n\n return (\n <form\n className=\"survey-form\"\n style={\n isPopup\n ? {\n color: textColor,\n borderColor: survey.appearance?.borderColor,\n ...styleOverrides,\n }\n : {}\n }\n >\n {surveyQuestions.map((question, displayQuestionIndex) => {\n const { originalQuestionIndex } = question\n\n const isVisible = isPreviewMode\n ? currentQuestionIndex === originalQuestionIndex\n : currentQuestionIndex === displayQuestionIndex\n return (\n isVisible && (\n <div\n className=\"survey-box\"\n style={\n isPopup\n ? {\n backgroundColor:\n survey.appearance?.backgroundColor ||\n defaultSurveyAppearance.backgroundColor,\n }\n : {}\n }\n >\n {isPopup && <Cancel onClick={() => handleCloseSurveyPopup()} />}\n {getQuestionComponent({\n question,\n forceDisableHtml,\n displayQuestionIndex,\n appearance: survey.appearance || defaultSurveyAppearance,\n onSubmit: (res) =>\n onNextButtonClick({\n res,\n originalQuestionIndex,\n displayQuestionIndex,\n }),\n })}\n </div>\n )\n )\n })}\n </form>\n )\n}\n\nexport function FeedbackWidget({\n survey,\n forceDisableHtml,\n posthog,\n readOnly,\n removeSurveyFromFocus,\n}: {\n survey: Survey\n forceDisableHtml?: boolean\n posthog?: PostHog\n readOnly?: boolean\n removeSurveyFromFocus: (id: string) => void\n}): JSX.Element {\n const [showSurvey, setShowSurvey] = useState(false)\n const [styleOverrides, setStyle] = useState({})\n const widgetRef = useRef<HTMLDivElement>(null)\n\n useEffect(() => {\n if (readOnly || !posthog) {\n return\n }\n\n if (survey.appearance?.widgetType === 'tab') {\n if (widgetRef.current) {\n const widgetPos = widgetRef.current.getBoundingClientRect()\n const style = {\n top: '50%',\n left: parseInt(`${widgetPos.right - 360}`),\n bottom: 'auto',\n borderRadius: 10,\n borderBottom: `1.5px solid ${survey.appearance?.borderColor || '#c9c6c6'}`,\n }\n setStyle(style)\n }\n }\n if (survey.appearance?.widgetType === 'selector') {\n const widget = document.querySelector(survey.appearance.widgetSelector || '')\n widget?.addEventListener('click', () => {\n setShowSurvey(!showSurvey)\n })\n widget?.setAttribute('PHWidgetSurveyClickListener', 'true')\n }\n }, [])\n\n return (\n <>\n {survey.appearance?.widgetType === 'tab' && (\n <div\n className=\"ph-survey-widget-tab\"\n ref={widgetRef}\n onClick={() => !readOnly && setShowSurvey(!showSurvey)}\n style={{ color: getContrastingTextColor(survey.appearance.widgetColor) }}\n >\n <div className=\"ph-survey-widget-tab-icon\"></div>\n {survey.appearance?.widgetLabel || ''}\n </div>\n )}\n {showSurvey && (\n <SurveyPopup\n key={'feedback-widget-survey'}\n posthog={posthog}\n survey={survey}\n forceDisableHtml={forceDisableHtml}\n style={styleOverrides}\n removeSurveyFromFocus={removeSurveyFromFocus}\n isPopup={true}\n />\n )}\n </>\n )\n}\n\ninterface GetQuestionComponentProps {\n question: SurveyQuestion\n forceDisableHtml: boolean\n displayQuestionIndex: number\n appearance: SurveyAppearance\n onSubmit: (res: string | string[] | number | null) => void\n}\n\nconst getQuestionComponent = ({\n question,\n forceDisableHtml,\n displayQuestionIndex,\n appearance,\n onSubmit,\n}: GetQuestionComponentProps): JSX.Element => {\n const questionComponents = {\n [SurveyQuestionType.Open]: OpenTextQuestion,\n [SurveyQuestionType.Link]: LinkQuestion,\n [SurveyQuestionType.Rating]: RatingQuestion,\n [SurveyQuestionType.SingleChoice]: MultipleChoiceQuestion,\n [SurveyQuestionType.MultipleChoice]: MultipleChoiceQuestion,\n }\n\n const commonProps = {\n question,\n forceDisableHtml,\n appearance,\n onSubmit,\n }\n\n const additionalProps: Record<SurveyQuestionType, any> = {\n [SurveyQuestionType.Open]: {},\n [SurveyQuestionType.Link]: {},\n [SurveyQuestionType.Rating]: { displayQuestionIndex },\n [SurveyQuestionType.SingleChoice]: { displayQuestionIndex },\n [SurveyQuestionType.MultipleChoice]: { displayQuestionIndex },\n }\n\n const Component = questionComponents[question.type]\n const componentProps = { ...commonProps, ...additionalProps[question.type] }\n\n return <Component {...componentProps} />\n}\n"]}
@@ -59,7 +59,7 @@ var Toolbar = /** @class */ (function () {
59
59
  window.localStorage.setItem('test', 'test');
60
60
  window.localStorage.removeItem('test');
61
61
  }
62
- catch (error) {
62
+ catch (_a) {
63
63
  return false;
64
64
  }
65
65
  // If localStorage was undefined, and localStorage is supported we set the default value
@@ -113,7 +113,7 @@ var Toolbar = /** @class */ (function () {
113
113
  return false;
114
114
  }
115
115
  }
116
- catch (e) {
116
+ catch (_b) {
117
117
  return false;
118
118
  }
119
119
  };
@@ -1 +1 @@
1
- {"version":3,"file":"toolbar.js","sourceRoot":"","sources":["../../../src/extensions/toolbar.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAGjD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,wGAAwG;AACxG,sEAAsE;AACtE,IAAM,iBAAiB,GAAG,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ;IACtC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,aAAa,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAC3F,CAAC,CAAC,IAAI,CAAA;AAEV,IAAM,gBAAgB,GAAG,uBAAuB,CAAA;AAEhD,IAAK,YAIJ;AAJD,WAAK,YAAY;IACb,iEAAiB,CAAA;IACjB,qDAAW,CAAA;IACX,mDAAU,CAAA;AACd,CAAC,EAJI,YAAY,KAAZ,YAAY,QAIhB;AAED;IAGI,iBAAY,QAAi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IAED,6CAA6C;IAC7C,6BAAW,GAAX,UAAY,MAAqB;QAC7B,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IACnC,CAAC;IAED,kDAAkD;IAClD,iCAAe,GAAf,UACI,QAA0C,EAC1C,YAA6C,EAC7C,OAAwC;QAFxC,yBAAA,EAAA,oBAA0C;QAC1C,6BAAA,EAAA,wBAA6C;QAC7C,wBAAA,EAAA,mBAAwC;QAExC,OAAO,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,YAAY,EAAE,OAAO,CAAC,CAAA;IACjE,CAAC;IACL,cAAC;AAAD,CAAC,AAlLD,IAkLC","sourcesContent":["import { registerEvent, trySafe } from '../utils'\nimport { PostHog } from '../posthog-core'\nimport { ToolbarParams } from '../types'\nimport { _getHashParam } from '../utils/request-utils'\nimport { logger } from '../utils/logger'\nimport { window, document, assignableWindow } from '../utils/globals'\nimport { TOOLBAR_ID } from '../constants'\n\n// TRICKY: Many web frameworks will modify the route on load, potentially before posthog is initialized.\n// To get ahead of this we grab it as soon as the posthog-js is parsed\nconst STATE_FROM_WINDOW = window?.location\n ? _getHashParam(window.location.hash, '__posthog') || _getHashParam(location.hash, 'state')\n : null\n\nconst LOCALSTORAGE_KEY = '_postHogToolbarParams'\n\nenum ToolbarState {\n UNINITIALIZED = 0,\n LOADING = 1,\n LOADED = 2,\n}\n\nexport class Toolbar {\n instance: PostHog\n\n constructor(instance: PostHog) {\n this.instance = instance\n }\n\n // NOTE: We store the state of the toolbar in the global scope to avoid multiple instances of the SDK loading the toolbar\n private setToolbarState(state: ToolbarState) {\n assignableWindow['ph_toolbar_state'] = state\n }\n\n private getToolbarState(): ToolbarState {\n return assignableWindow['ph_toolbar_state'] ?? ToolbarState.UNINITIALIZED\n }\n\n /**\n * To load the toolbar, we need an access token and other state. That state comes from one of three places:\n * 1. In the URL hash params\n * 2. From session storage under the key `toolbarParams` if the toolbar was initialized on a previous page\n */\n maybeLoadToolbar(\n location: Location | undefined = undefined,\n localStorage: Storage | undefined = undefined,\n history: History | undefined = undefined\n ): boolean {\n if (!window || !document) {\n return false\n }\n location = location ?? window.location\n history = history ?? window.history\n\n try {\n // Before running the code we check if we can access localStorage, if not we opt-out\n if (!localStorage) {\n try {\n window.localStorage.setItem('test', 'test')\n window.localStorage.removeItem('test')\n } catch (error) {\n return false\n }\n\n // If localStorage was undefined, and localStorage is supported we set the default value\n localStorage = window?.localStorage\n }\n\n /**\n * Info about the state\n * The state is a json object\n * 1. (Legacy) The state can be `state={}` as a urlencoded object of info. In this case\n * 2. The state should now be found in `__posthog={}` and can be base64 encoded or urlencoded.\n * 3. Base64 encoding is preferred and will gradually be rolled out everywhere\n */\n\n const stateHash =\n STATE_FROM_WINDOW || _getHashParam(location.hash, '__posthog') || _getHashParam(location.hash, 'state')\n\n let toolbarParams: ToolbarParams\n const state = stateHash\n ? trySafe(() => JSON.parse(atob(decodeURIComponent(stateHash)))) ||\n trySafe(() => JSON.parse(decodeURIComponent(stateHash)))\n : null\n\n const parseFromUrl = state && state['action'] === 'ph_authorize'\n\n if (parseFromUrl) {\n // happens if they are initializing the toolbar using an old snippet\n toolbarParams = state\n toolbarParams.source = 'url'\n\n if (toolbarParams && Object.keys(toolbarParams).length > 0) {\n if (state['desiredHash']) {\n // hash that was in the url before the redirect\n location.hash = state['desiredHash']\n } else if (history) {\n // second param is unused see https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState\n history.replaceState(history.state, '', location.pathname + location.search) // completely remove hash\n } else {\n location.hash = '' // clear hash (but leaves # unfortunately)\n }\n }\n } else {\n // get credentials from localStorage from a previous initialization\n\n toolbarParams = JSON.parse(localStorage.getItem(LOCALSTORAGE_KEY) || '{}')\n toolbarParams.source = 'localstorage'\n\n // delete \"add-action\" or other intent from toolbarParams, otherwise we'll have the same intent\n // every time we open the page (e.g. you just visiting your own site an hour later)\n delete toolbarParams.userIntent\n }\n\n if (toolbarParams['token'] && this.instance.config.token === toolbarParams['token']) {\n this.loadToolbar(toolbarParams)\n return true\n } else {\n return false\n }\n } catch (e) {\n return false\n }\n }\n\n private _callLoadToolbar(params: ToolbarParams) {\n ;(assignableWindow['ph_load_toolbar'] || assignableWindow['ph_load_editor'])(params, this.instance)\n }\n\n loadToolbar(params?: ToolbarParams): boolean {\n const toolbarRunning = !!document?.getElementById(TOOLBAR_ID)\n\n if (!window || toolbarRunning) {\n // The toolbar will clear the localStorage key when it's done with it. If it is present that indicates the toolbar is already open and running\n return false\n }\n\n const disableToolbarMetrics =\n this.instance.requestRouter.region === 'custom' && this.instance.config.advanced_disable_toolbar_metrics\n\n const toolbarParams = {\n token: this.instance.config.token,\n ...params,\n apiURL: this.instance.requestRouter.endpointFor('ui'),\n ...(disableToolbarMetrics ? { instrument: false } : {}),\n }\n window.localStorage.setItem(\n LOCALSTORAGE_KEY,\n JSON.stringify({\n ...toolbarParams,\n source: undefined,\n })\n )\n\n if (this.getToolbarState() === ToolbarState.LOADED) {\n this._callLoadToolbar(toolbarParams)\n } else if (this.getToolbarState() === ToolbarState.UNINITIALIZED) {\n // only load the toolbar once, even if there are multiple instances of PostHogLib\n this.setToolbarState(ToolbarState.LOADING)\n\n // toolbar.js is served from the PostHog CDN, this has a TTL of 24 hours.\n // the toolbar asset includes a rotating \"token\" that is valid for 5 minutes.\n const fiveMinutesInMillis = 5 * 60 * 1000\n // this ensures that we bust the cache periodically\n const timestampToNearestFiveMinutes = Math.floor(Date.now() / fiveMinutesInMillis) * fiveMinutesInMillis\n\n this.instance.requestRouter.loadScript(`/static/toolbar.js?t=${timestampToNearestFiveMinutes}`, (err) => {\n if (err) {\n logger.error('Failed to load toolbar', err)\n this.setToolbarState(ToolbarState.UNINITIALIZED)\n return\n }\n this.setToolbarState(ToolbarState.LOADED)\n this._callLoadToolbar(toolbarParams)\n })\n\n // Turbolinks doesn't fire an onload event but does replace the entire body, including the toolbar.\n // Thus, we ensure the toolbar is only loaded inside the body, and then reloaded on turbolinks:load.\n registerEvent(window, 'turbolinks:load', () => {\n this.setToolbarState(ToolbarState.UNINITIALIZED)\n this.loadToolbar(toolbarParams)\n })\n }\n\n return true\n }\n\n /** @deprecated Use \"loadToolbar\" instead. */\n _loadEditor(params: ToolbarParams): boolean {\n return this.loadToolbar(params)\n }\n\n /** @deprecated Use \"maybeLoadToolbar\" instead. */\n maybeLoadEditor(\n location: Location | undefined = undefined,\n localStorage: Storage | undefined = undefined,\n history: History | undefined = undefined\n ): boolean {\n return this.maybeLoadToolbar(location, localStorage, history)\n }\n}\n"]}
1
+ {"version":3,"file":"toolbar.js","sourceRoot":"","sources":["../../../src/extensions/toolbar.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAGjD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,wGAAwG;AACxG,sEAAsE;AACtE,IAAM,iBAAiB,GAAG,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ;IACtC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,aAAa,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAC3F,CAAC,CAAC,IAAI,CAAA;AAEV,IAAM,gBAAgB,GAAG,uBAAuB,CAAA;AAEhD,IAAK,YAIJ;AAJD,WAAK,YAAY;IACb,iEAAiB,CAAA;IACjB,qDAAW,CAAA;IACX,mDAAU,CAAA;AACd,CAAC,EAJI,YAAY,KAAZ,YAAY,QAIhB;AAED;IAGI,iBAAY,QAAiB;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAC5B,CAAC;IAED,yHA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a,CAAC,CAAA;gBAChD,KAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAA;YACnC,CAAC,CAAC,CAAA;QACN,CAAC;QAED,OAAO,IAAI,CAAA;IACf,CAAC;IAED,6CAA6C;IAC7C,6BAAW,GAAX,UAAY,MAAqB;QAC7B,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IACnC,CAAC;IAED,kDAAkD;IAClD,iCAAe,GAAf,UACI,QAA0C,EAC1C,YAA6C,EAC7C,OAAwC;QAFxC,yBAAA,EAAA,oBAA0C;QAC1C,6BAAA,EAAA,wBAA6C;QAC7C,wBAAA,EAAA,mBAAwC;QAExC,OAAO,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,YAAY,EAAE,OAAO,CAAC,CAAA;IACjE,CAAC;IACL,cAAC;AAAD,CAAC,AAlLD,IAkLC","sourcesContent":["import { registerEvent, trySafe } from '../utils'\nimport { PostHog } from '../posthog-core'\nimport { ToolbarParams } from '../types'\nimport { _getHashParam } from '../utils/request-utils'\nimport { logger } from '../utils/logger'\nimport { window, document, assignableWindow } from '../utils/globals'\nimport { TOOLBAR_ID } from '../constants'\n\n// TRICKY: Many web frameworks will modify the route on load, potentially before posthog is initialized.\n// To get ahead of this we grab it as soon as the posthog-js is parsed\nconst STATE_FROM_WINDOW = window?.location\n ? _getHashParam(window.location.hash, '__posthog') || _getHashParam(location.hash, 'state')\n : null\n\nconst LOCALSTORAGE_KEY = '_postHogToolbarParams'\n\nenum ToolbarState {\n UNINITIALIZED = 0,\n LOADING = 1,\n LOADED = 2,\n}\n\nexport class Toolbar {\n instance: PostHog\n\n constructor(instance: PostHog) {\n this.instance = instance\n }\n\n // NOTE: We store the state of the toolbar in the global scope to avoid multiple instances of the SDK loading the toolbar\n private setToolbarState(state: ToolbarState) {\n assignableWindow['ph_toolbar_state'] = state\n }\n\n private getToolbarState(): ToolbarState {\n return assignableWindow['ph_toolbar_state'] ?? ToolbarState.UNINITIALIZED\n }\n\n /**\n * To load the toolbar, we need an access token and other state. That state comes from one of three places:\n * 1. In the URL hash params\n * 2. From session storage under the key `toolbarParams` if the toolbar was initialized on a previous page\n */\n maybeLoadToolbar(\n location: Location | undefined = undefined,\n localStorage: Storage | undefined = undefined,\n history: History | undefined = undefined\n ): boolean {\n if (!window || !document) {\n return false\n }\n location = location ?? window.location\n history = history ?? window.history\n\n try {\n // Before running the code we check if we can access localStorage, if not we opt-out\n if (!localStorage) {\n try {\n window.localStorage.setItem('test', 'test')\n window.localStorage.removeItem('test')\n } catch {\n return false\n }\n\n // If localStorage was undefined, and localStorage is supported we set the default value\n localStorage = window?.localStorage\n }\n\n /**\n * Info about the state\n * The state is a json object\n * 1. (Legacy) The state can be `state={}` as a urlencoded object of info. In this case\n * 2. The state should now be found in `__posthog={}` and can be base64 encoded or urlencoded.\n * 3. Base64 encoding is preferred and will gradually be rolled out everywhere\n */\n\n const stateHash =\n STATE_FROM_WINDOW || _getHashParam(location.hash, '__posthog') || _getHashParam(location.hash, 'state')\n\n let toolbarParams: ToolbarParams\n const state = stateHash\n ? trySafe(() => JSON.parse(atob(decodeURIComponent(stateHash)))) ||\n trySafe(() => JSON.parse(decodeURIComponent(stateHash)))\n : null\n\n const parseFromUrl = state && state['action'] === 'ph_authorize'\n\n if (parseFromUrl) {\n // happens if they are initializing the toolbar using an old snippet\n toolbarParams = state\n toolbarParams.source = 'url'\n\n if (toolbarParams && Object.keys(toolbarParams).length > 0) {\n if (state['desiredHash']) {\n // hash that was in the url before the redirect\n location.hash = state['desiredHash']\n } else if (history) {\n // second param is unused see https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState\n history.replaceState(history.state, '', location.pathname + location.search) // completely remove hash\n } else {\n location.hash = '' // clear hash (but leaves # unfortunately)\n }\n }\n } else {\n // get credentials from localStorage from a previous initialization\n\n toolbarParams = JSON.parse(localStorage.getItem(LOCALSTORAGE_KEY) || '{}')\n toolbarParams.source = 'localstorage'\n\n // delete \"add-action\" or other intent from toolbarParams, otherwise we'll have the same intent\n // every time we open the page (e.g. you just visiting your own site an hour later)\n delete toolbarParams.userIntent\n }\n\n if (toolbarParams['token'] && this.instance.config.token === toolbarParams['token']) {\n this.loadToolbar(toolbarParams)\n return true\n } else {\n return false\n }\n } catch {\n return false\n }\n }\n\n private _callLoadToolbar(params: ToolbarParams) {\n ;(assignableWindow['ph_load_toolbar'] || assignableWindow['ph_load_editor'])(params, this.instance)\n }\n\n loadToolbar(params?: ToolbarParams): boolean {\n const toolbarRunning = !!document?.getElementById(TOOLBAR_ID)\n\n if (!window || toolbarRunning) {\n // The toolbar will clear the localStorage key when it's done with it. If it is present that indicates the toolbar is already open and running\n return false\n }\n\n const disableToolbarMetrics =\n this.instance.requestRouter.region === 'custom' && this.instance.config.advanced_disable_toolbar_metrics\n\n const toolbarParams = {\n token: this.instance.config.token,\n ...params,\n apiURL: this.instance.requestRouter.endpointFor('ui'),\n ...(disableToolbarMetrics ? { instrument: false } : {}),\n }\n window.localStorage.setItem(\n LOCALSTORAGE_KEY,\n JSON.stringify({\n ...toolbarParams,\n source: undefined,\n })\n )\n\n if (this.getToolbarState() === ToolbarState.LOADED) {\n this._callLoadToolbar(toolbarParams)\n } else if (this.getToolbarState() === ToolbarState.UNINITIALIZED) {\n // only load the toolbar once, even if there are multiple instances of PostHogLib\n this.setToolbarState(ToolbarState.LOADING)\n\n // toolbar.js is served from the PostHog CDN, this has a TTL of 24 hours.\n // the toolbar asset includes a rotating \"token\" that is valid for 5 minutes.\n const fiveMinutesInMillis = 5 * 60 * 1000\n // this ensures that we bust the cache periodically\n const timestampToNearestFiveMinutes = Math.floor(Date.now() / fiveMinutesInMillis) * fiveMinutesInMillis\n\n this.instance.requestRouter.loadScript(`/static/toolbar.js?t=${timestampToNearestFiveMinutes}`, (err) => {\n if (err) {\n logger.error('Failed to load toolbar', err)\n this.setToolbarState(ToolbarState.UNINITIALIZED)\n return\n }\n this.setToolbarState(ToolbarState.LOADED)\n this._callLoadToolbar(toolbarParams)\n })\n\n // Turbolinks doesn't fire an onload event but does replace the entire body, including the toolbar.\n // Thus, we ensure the toolbar is only loaded inside the body, and then reloaded on turbolinks:load.\n registerEvent(window, 'turbolinks:load', () => {\n this.setToolbarState(ToolbarState.UNINITIALIZED)\n this.loadToolbar(toolbarParams)\n })\n }\n\n return true\n }\n\n /** @deprecated Use \"loadToolbar\" instead. */\n _loadEditor(params: ToolbarParams): boolean {\n return this.loadToolbar(params)\n }\n\n /** @deprecated Use \"maybeLoadToolbar\" instead. */\n maybeLoadEditor(\n location: Location | undefined = undefined,\n localStorage: Storage | undefined = undefined,\n history: History | undefined = undefined\n ): boolean {\n return this.maybeLoadToolbar(location, localStorage, history)\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"tracing-headers.js","sourceRoot":"","sources":["../../../src/extensions/tracing-headers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,MAAM,MAAM,WAAW,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAEjD,IAAM,aAAa,GAAG,mBAAmB,CAAA;AAEzC;IAII,wBAA6B,QAAiB;QAA9C,iBAAkD;QAArB,aAAQ,GAAR,QAAQ,CAAS;QAHtC,qBAAgB,GAA6B,SAAS,CAAA;QACtD,uBAAkB,GAA6B,SAAS,CAAA;QA6BxD,oBAAe,GAAG;YACtB,oFAAoF;YACpF,IAAI,WAAW,CAAC,KAAI,CAAC,gBAAgB,CAAC,EAAE;gBACpC,gBAAgB,CAAC,6BAA6B,CAAC,SAAS,CAAC,KAAI,CAAC,QAAQ,CAAC,cAAe,CAAC,CAAA;aAC1F;YACD,IAAI,WAAW,CAAC,KAAI,CAAC,kBAAkB,CAAC,EAAE;gBACtC,gBAAgB,CAAC,6BAA6B,CAAC,WAAW,CAAC,KAAI,CAAC,QAAQ,CAAC,cAAe,CAAC,CAAA;aAC5F;QACL,CAAC,CAAA;IAnCgD,CAAC;IAE1C,oCAAW,GAAnB,UAAoB,EAAc;QAC9B,IAAI,gBAAgB,CAAC,6BAA6B,EAAE;YAChD,iBAAiB;YACjB,EAAE,EAAE,CAAA;SACP;QAED,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,uCAAgC,MAAM,CAAC,WAAW,CAAE,EAAE,UAAC,GAAG;YAC7F,IAAI,GAAG,EAAE;gBACL,OAAO,MAAM,CAAC,KAAK,CAAC,aAAa,GAAG,wBAAwB,EAAE,GAAG,CAAC,CAAA;aACrE;YACD,EAAE,EAAE,CAAA;QACR,CAAC,CAAC,CAAA;IACN,CAAC;IACM,6CAAoB,GAA3B;;QACI,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,qBAAqB,EAAE;YAC5C,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;SACzC;aAAM;YACH,MAAA,IAAI,CAAC,gBAAgB,oDAAI,CAAA;YACzB,MAAA,IAAI,CAAC,kBAAkB,oDAAI,CAAA;YAC3B,qDAAqD;YACrD,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAA;YACjC,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAA;SACtC;IACL,CAAC;IAWL,qBAAC;AAAD,CAAC,AAxCD,IAwCC","sourcesContent":["import { PostHog } from '../posthog-core'\nimport { assignableWindow } from '../utils/globals'\nimport { logger } from '../utils/logger'\nimport Config from '../config'\nimport { isUndefined } from '../utils/type-utils'\n\nconst LOGGER_PREFIX = '[TRACING-HEADERS]'\n\nexport class TracingHeaders {\n private _restoreXHRPatch: (() => void) | undefined = undefined\n private _restoreFetchPatch: (() => void) | undefined = undefined\n\n constructor(private readonly instance: PostHog) {}\n\n private _loadScript(cb: () => void): void {\n if (assignableWindow.postHogTracingHeadersPatchFns) {\n // already loaded\n cb()\n }\n\n this.instance.requestRouter.loadScript(`/static/tracing-headers.js?v=${Config.LIB_VERSION}`, (err) => {\n if (err) {\n return logger.error(LOGGER_PREFIX + ' failed to load script', err)\n }\n cb()\n })\n }\n public startIfEnabledOrStop() {\n if (this.instance.config.__add_tracing_headers) {\n this._loadScript(this._startCapturing)\n } else {\n this._restoreXHRPatch?.()\n this._restoreFetchPatch?.()\n // we don't want to call these twice so we reset them\n this._restoreXHRPatch = undefined\n this._restoreFetchPatch = undefined\n }\n }\n\n private _startCapturing = () => {\n // NB: we can assert sessionManager is present only because we've checked previously\n if (isUndefined(this._restoreXHRPatch)) {\n assignableWindow.postHogTracingHeadersPatchFns._patchXHR(this.instance.sessionManager!)\n }\n if (isUndefined(this._restoreFetchPatch)) {\n assignableWindow.postHogTracingHeadersPatchFns._patchFetch(this.instance.sessionManager!)\n }\n }\n}\n"]}
1
+ {"version":3,"file":"tracing-headers.js","sourceRoot":"","sources":["../../../src/extensions/tracing-headers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,MAAM,MAAM,WAAW,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAEjD,IAAM,aAAa,GAAG,mBAAmB,CAAA;AAEzC;IAII,wBAA6B,QAAiB;QAA9C,iBAAkD;QAArB,aAAQ,GAAR,QAAQ,CAAS;QAHtC,qBAAgB,GAA6B,SAAS,CAAA;QACtD,uBAAkB,GAA6B,SAAS,CAAA;QA6BxD,oBAAe,GAAG;YACtB,oFAAoF;YACpF,IAAI,WAAW,CAAC,KAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC;gBACrC,gBAAgB,CAAC,6BAA6B,CAAC,SAAS,CAAC,KAAI,CAAC,QAAQ,CAAC,cAAe,CAAC,CAAA;YAC3F,CAAC;YACD,IAAI,WAAW,CAAC,KAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC;gBACvC,gBAAgB,CAAC,6BAA6B,CAAC,WAAW,CAAC,KAAI,CAAC,QAAQ,CAAC,cAAe,CAAC,CAAA;YAC7F,CAAC;QACL,CAAC,CAAA;IAnCgD,CAAC;IAE1C,oCAAW,GAAnB,UAAoB,EAAc;QAC9B,IAAI,gBAAgB,CAAC,6BAA6B,EAAE,CAAC;YACjD,iBAAiB;YACjB,EAAE,EAAE,CAAA;QACR,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,uCAAgC,MAAM,CAAC,WAAW,CAAE,EAAE,UAAC,GAAG;YAC7F,IAAI,GAAG,EAAE,CAAC;gBACN,OAAO,MAAM,CAAC,KAAK,CAAC,aAAa,GAAG,wBAAwB,EAAE,GAAG,CAAC,CAAA;YACtE,CAAC;YACD,EAAE,EAAE,CAAA;QACR,CAAC,CAAC,CAAA;IACN,CAAC;IACM,6CAAoB,GAA3B;;QACI,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,qBAAqB,EAAE,CAAC;YAC7C,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,eAAe,CAAC,CAAA;QAC1C,CAAC;aAAM,CAAC;YACJ,MAAA,IAAI,CAAC,gBAAgB,oDAAI,CAAA;YACzB,MAAA,IAAI,CAAC,kBAAkB,oDAAI,CAAA;YAC3B,qDAAqD;YACrD,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAA;YACjC,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAA;QACvC,CAAC;IACL,CAAC;IAWL,qBAAC;AAAD,CAAC,AAxCD,IAwCC","sourcesContent":["import { PostHog } from '../posthog-core'\nimport { assignableWindow } from '../utils/globals'\nimport { logger } from '../utils/logger'\nimport Config from '../config'\nimport { isUndefined } from '../utils/type-utils'\n\nconst LOGGER_PREFIX = '[TRACING-HEADERS]'\n\nexport class TracingHeaders {\n private _restoreXHRPatch: (() => void) | undefined = undefined\n private _restoreFetchPatch: (() => void) | undefined = undefined\n\n constructor(private readonly instance: PostHog) {}\n\n private _loadScript(cb: () => void): void {\n if (assignableWindow.postHogTracingHeadersPatchFns) {\n // already loaded\n cb()\n }\n\n this.instance.requestRouter.loadScript(`/static/tracing-headers.js?v=${Config.LIB_VERSION}`, (err) => {\n if (err) {\n return logger.error(LOGGER_PREFIX + ' failed to load script', err)\n }\n cb()\n })\n }\n public startIfEnabledOrStop() {\n if (this.instance.config.__add_tracing_headers) {\n this._loadScript(this._startCapturing)\n } else {\n this._restoreXHRPatch?.()\n this._restoreFetchPatch?.()\n // we don't want to call these twice so we reset them\n this._restoreXHRPatch = undefined\n this._restoreFetchPatch = undefined\n }\n }\n\n private _startCapturing = () => {\n // NB: we can assert sessionManager is present only because we've checked previously\n if (isUndefined(this._restoreXHRPatch)) {\n assignableWindow.postHogTracingHeadersPatchFns._patchXHR(this.instance.sessionManager!)\n }\n if (isUndefined(this._restoreFetchPatch)) {\n assignableWindow.postHogTracingHeadersPatchFns._patchFetch(this.instance.sessionManager!)\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extensions/web-vitals/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAC9F,OAAO,EAAE,8BAA8B,EAAE,MAAM,iBAAiB,CAAA;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,MAAM,MAAM,cAAc,CAAA;AAEjC,MAAM,CAAC,IAAM,qCAAqC,GAAG,IAAI,CAAA;AACzD,IAAM,oBAAoB,GAAG,EAAE,GAAG,IAAI,CAAA;AACtC,MAAM,CAAC,IAAM,yBAAyB,GAAG,EAAE,GAAG,oBAAoB,CAAA;AAElE,IAAM,aAAa,GAAG,cAAc,CAAA;A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AG,cAAc;oBAClD,CAAA;SACL;QACD,uDAAuD;QACvD,IAAI,CAAC,kBAAkB,GAAG,cAAc,CAAA;QAExC,IAAI,CAAC,cAAc,EAAE,CAAA;IACzB,CAAC;IAEO,yCAAU,GAAlB,UAAmB,EAAc;QAC7B,IAAK,MAAc,CAAC,yBAAyB,EAAE;YAC3C,iBAAiB;YACjB,EAAE,EAAE,CAAA;SACP;QAED,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,kCAA2B,MAAM,CAAC,WAAW,CAAE,EAAE,UAAC,GAAG;YACxF,IAAI,GAAG,EAAE;gBACL,MAAM,CAAC,KAAK,CAAC,aAAa,GAAG,wBAAwB,EAAE,GAAG,CAAC,CAAA;gBAC3D,OAAM;aACT;YACD,EAAE,EAAE,CAAA;QACR,CAAC,CAAC,CAAA;IACN,CAAC;IAEO,0CAAW,GAAnB;QACI,+CAA+C;QAC/C,IAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;QACtD,IAAI,CAAC,IAAI,EAAE;YACP,MAAM,CAAC,KAAK,CAAC,aAAa,GAAG,iCAAiC,CAAC,CAAA;SAClE;QACD,OAAO,IAAI,CAAA;IACf,CAAC;IAkGL,2BAAC;AAAD,CAAC,AA3KD,IA2KC","sourcesContent":["import { PostHog } from '../../posthog-core'\nimport { DecideResponse } from '../../types'\nimport { logger } from '../../utils/logger'\nimport { isBoolean, isNullish, isNumber, isObject, isUndefined } from '../../utils/type-utils'\nimport { WEB_VITALS_ENABLED_SERVER_SIDE } from '../../constants'\nimport { assignableWindow, window } from '../../utils/globals'\nimport Config from '../../config'\n\nexport const FLUSH_TO_CAPTURE_TIMEOUT_MILLISECONDS = 8000\nconst ONE_MINUTE_IN_MILLIS = 60 * 1000\nexport const FIFTEEN_MINUTES_IN_MILLIS = 15 * ONE_MINUTE_IN_MILLIS\n\nconst LOGGER_PREFIX = '[Web Vitals]'\ntype WebVitalsEventBuffer = { url: string | undefined; metrics: any[]; firstMetricTimestamp: number | undefined }\n\nexport class WebVitalsAutocapture {\n private _enabledServerSide: boolean = false\n private _initialized = false\n\n private buffer: WebVitalsEventBuffer = { url: undefined, metrics: [], firstMetricTimestamp: undefined }\n private _delayedFlushTimer: number | undefined\n\n constructor(private readonly instance: PostHog) {\n this._enabledServerSide = !!this.instance.persistence?.props[WEB_VITALS_ENABLED_SERVER_SIDE]\n this.startIfEnabled()\n }\n\n public get _maxAllowedValue(): number {\n const configured =\n isObject(this.instance.config.capture_performance) &&\n isNumber(this.instance.config.capture_performance.__web_vitals_max_value)\n ? this.instance.config.capture_performance.__web_vitals_max_value\n : FIFTEEN_MINUTES_IN_MILLIS\n // you can set to 0 to disable the check or any value over ten seconds\n // 1 milli to 1 minute will be set to 15 minutes, cos that would be a silly low maximum\n return 0 < configured && configured <= ONE_MINUTE_IN_MILLIS ? FIFTEEN_MINUTES_IN_MILLIS : configured\n }\n\n public get isEnabled(): boolean {\n const clientConfig = isObject(this.instance.config.capture_performance)\n ? this.instance.config.capture_performance.web_vitals\n : undefined\n return isBoolean(clientConfig) ? clientConfig : this._enabledServerSide\n }\n\n public startIfEnabled(): void {\n if (this.isEnabled && !this._initialized) {\n logger.info(LOGGER_PREFIX + ' enabled, starting...')\n this.loadScript(this._startCapturing)\n }\n }\n\n public afterDecideResponse(response: DecideResponse) {\n const webVitalsOptIn = isObject(response.capturePerformance) && !!response.capturePerformance.web_vitals\n\n if (this.instance.persistence) {\n this.instance.persistence.register({\n [WEB_VITALS_ENABLED_SERVER_SIDE]: webVitalsOptIn,\n })\n }\n // store this in-memory in case persistence is disabled\n this._enabledServerSide = webVitalsOptIn\n\n this.startIfEnabled()\n }\n\n private loadScript(cb: () => void): void {\n if ((window as any).postHogWebVitalsCallbacks) {\n // already loaded\n cb()\n }\n\n this.instance.requestRouter.loadScript(`/static/web-vitals.js?v=${Config.LIB_VERSION}`, (err) => {\n if (err) {\n logger.error(LOGGER_PREFIX + ' failed to load script', err)\n return\n }\n cb()\n })\n }\n\n private _currentURL(): string | undefined {\n // TODO you should be able to mask the URL here\n const href = window ? window.location.href : undefined\n if (!href) {\n logger.error(LOGGER_PREFIX + 'Could not determine current URL')\n }\n return href\n }\n\n private _flushToCapture = () => {\n clearTimeout(this._delayedFlushTimer)\n if (this.buffer.metrics.length === 0) {\n return\n }\n\n this.instance.capture(\n '$web_vitals',\n this.buffer.metrics.reduce(\n (acc, metric) => ({\n ...acc,\n // the entire event so we can use it in the future e.g. includes google's rating\n [`$web_vitals_${metric.name}_event`]: { ...metric },\n [`$web_vitals_${metric.name}_value`]: metric.value,\n }),\n {}\n )\n )\n this.buffer = { url: undefined, metrics: [], firstMetricTimestamp: undefined }\n }\n\n private _addToBuffer = (metric: any) => {\n const sessionIds = this.instance.sessionManager?.checkAndGetSessionAndWindowId(true)\n if (isUndefined(sessionIds)) {\n logger.error(LOGGER_PREFIX + 'Could not read session ID. Dropping metrics!')\n return\n }\n\n this.buffer = this.buffer || { url: undefined, metrics: [], firstMetricTimestamp: undefined }\n\n const $currentUrl = this._currentURL()\n if (isUndefined($currentUrl)) {\n return\n }\n\n if (isNullish(metric?.name) || isNullish(metric?.value)) {\n logger.error(LOGGER_PREFIX + 'Invalid metric received', metric)\n return\n }\n\n // we observe some very large values sometimes, we'll ignore them\n // since the likelihood of LCP > 1 hour being correct is very low\n if (this._maxAllowedValue && metric.value >= this._maxAllowedValue) {\n logger.error(LOGGER_PREFIX + 'Ignoring metric with value >= ' + this._maxAllowedValue, metric)\n return\n }\n\n const urlHasChanged = this.buffer.url !== $currentUrl\n\n if (urlHasChanged) {\n // we need to send what we have\n this._flushToCapture()\n // poor performance is >4s, we wait twice that time to send\n // this is in case we haven't received all metrics\n // we'll at least gather some\n this._delayedFlushTimer = setTimeout(this._flushToCapture, FLUSH_TO_CAPTURE_TIMEOUT_MILLISECONDS)\n }\n\n if (isUndefined(this.buffer.url)) {\n this.buffer.url = $currentUrl\n }\n\n this.buffer.firstMetricTimestamp = isUndefined(this.buffer.firstMetricTimestamp)\n ? Date.now()\n : this.buffer.firstMetricTimestamp\n\n this.buffer.metrics.push({\n ...metric,\n $current_url: $currentUrl,\n $session_id: sessionIds.sessionId,\n $window_id: sessionIds.windowId,\n timestamp: Date.now(),\n })\n\n if (this.buffer.metrics.length === 4) {\n // we have all 4 metrics\n this._flushToCapture()\n }\n }\n\n private _startCapturing = () => {\n const { onLCP, onCLS, onFCP, onINP } = assignableWindow.postHogWebVitalsCallbacks\n\n if (!onLCP || !onCLS || !onFCP || !onINP) {\n logger.error(LOGGER_PREFIX + 'web vitals callbacks not loaded - not starting')\n return\n }\n\n // register performance observers\n onLCP(this._addToBuffer)\n onCLS(this._addToBuffer)\n onFCP(this._addToBuffer)\n onINP(this._addToBuffer)\n\n this._initialized = true\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/extensions/web-vitals/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAC9F,OAAO,EAAE,8BAA8B,EAAE,MAAM,iBAAiB,CAAA;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,MAAM,MAAM,cAAc,CAAA;AAEjC,MAAM,CAAC,IAAM,qCAAqC,GAAG,IAAI,CAAA;AACzD,IAAM,oBAAoB,GAAG,EAAE,GAAG,IAAI,CAAA;AACtC,MAAM,CAAC,IAAM,yBAAyB,GAAG,EAAE,GAAG,oBAAoB,CAAA;AAElE,IAAM,aAAa,GAAG,cAAc,CAAA;AAGpC;IAOI,8BAA6B,QAAiB;QAA9C,iBAGC;;QAH4B,aAAQ,GAAR,QAAQ,CAAS;QANtC,uBAAkB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,CAAC,QAAQ;gBAC9B,GAAC,8BAA8B,IAAG,cAAc;oBAClD,CAAA;QACN,CAAC;QACD,uDAAuD;QACvD,IAAI,CAAC,kBAAkB,GAAG,cAAc,CAAA;QAExC,IAAI,CAAC,cAAc,EAAE,CAAA;IACzB,CAAC;IAEO,yCAAU,GAAlB,UAAmB,EAAc;QAC7B,IAAK,MAAc,CAAC,yBAAyB,EAAE,CAAC;YAC5C,iBAAiB;YACjB,EAAE,EAAE,CAAA;QACR,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAC,kCAA2B,MAAM,CAAC,WAAW,CAAE,EAAE,UAAC,GAAG;YACxF,IAAI,GAAG,EAAE,CAAC;gBACN,MAAM,CAAC,KAAK,CAAC,aAAa,GAAG,wBAAwB,EAAE,GAAG,CAAC,CAAA;gBAC3D,OAAM;YACV,CAAC;YACD,EAAE,EAAE,CAAA;QACR,CAAC,CAAC,CAAA;IACN,CAAC;IAEO,0CAAW,GAAnB;QACI,+CAA+C;QAC/C,IAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;QACtD,IAAI,CAAC,IAAI,EAAE,CAAC;YACR,MAAM,CAAC,KAAK,CAAC,aAAa,GAAG,iCAAiC,CAAC,CAAA;QACnE,CAAC;QACD,OAAO,IAAI,CAAA;IACf,CAAC;IAkGL,2BAAC;AAAD,CAAC,AA3KD,IA2KC","sourcesContent":["import { PostHog } from '../../posthog-core'\nimport { DecideResponse } from '../../types'\nimport { logger } from '../../utils/logger'\nimport { isBoolean, isNullish, isNumber, isObject, isUndefined } from '../../utils/type-utils'\nimport { WEB_VITALS_ENABLED_SERVER_SIDE } from '../../constants'\nimport { assignableWindow, window } from '../../utils/globals'\nimport Config from '../../config'\n\nexport const FLUSH_TO_CAPTURE_TIMEOUT_MILLISECONDS = 8000\nconst ONE_MINUTE_IN_MILLIS = 60 * 1000\nexport const FIFTEEN_MINUTES_IN_MILLIS = 15 * ONE_MINUTE_IN_MILLIS\n\nconst LOGGER_PREFIX = '[Web Vitals]'\ntype WebVitalsEventBuffer = { url: string | undefined; metrics: any[]; firstMetricTimestamp: number | undefined }\n\nexport class WebVitalsAutocapture {\n private _enabledServerSide: boolean = false\n private _initialized = false\n\n private buffer: WebVitalsEventBuffer = { url: undefined, metrics: [], firstMetricTimestamp: undefined }\n private _delayedFlushTimer: ReturnType<typeof setTimeout> | undefined\n\n constructor(private readonly instance: PostHog) {\n this._enabledServerSide = !!this.instance.persistence?.props[WEB_VITALS_ENABLED_SERVER_SIDE]\n this.startIfEnabled()\n }\n\n public get _maxAllowedValue(): number {\n const configured =\n isObject(this.instance.config.capture_performance) &&\n isNumber(this.instance.config.capture_performance.__web_vitals_max_value)\n ? this.instance.config.capture_performance.__web_vitals_max_value\n : FIFTEEN_MINUTES_IN_MILLIS\n // you can set to 0 to disable the check or any value over ten seconds\n // 1 milli to 1 minute will be set to 15 minutes, cos that would be a silly low maximum\n return 0 < configured && configured <= ONE_MINUTE_IN_MILLIS ? FIFTEEN_MINUTES_IN_MILLIS : configured\n }\n\n public get isEnabled(): boolean {\n const clientConfig = isObject(this.instance.config.capture_performance)\n ? this.instance.config.capture_performance.web_vitals\n : undefined\n return isBoolean(clientConfig) ? clientConfig : this._enabledServerSide\n }\n\n public startIfEnabled(): void {\n if (this.isEnabled && !this._initialized) {\n logger.info(LOGGER_PREFIX + ' enabled, starting...')\n this.loadScript(this._startCapturing)\n }\n }\n\n public afterDecideResponse(response: DecideResponse) {\n const webVitalsOptIn = isObject(response.capturePerformance) && !!response.capturePerformance.web_vitals\n\n if (this.instance.persistence) {\n this.instance.persistence.register({\n [WEB_VITALS_ENABLED_SERVER_SIDE]: webVitalsOptIn,\n })\n }\n // store this in-memory in case persistence is disabled\n this._enabledServerSide = webVitalsOptIn\n\n this.startIfEnabled()\n }\n\n private loadScript(cb: () => void): void {\n if ((window as any).postHogWebVitalsCallbacks) {\n // already loaded\n cb()\n }\n\n this.instance.requestRouter.loadScript(`/static/web-vitals.js?v=${Config.LIB_VERSION}`, (err) => {\n if (err) {\n logger.error(LOGGER_PREFIX + ' failed to load script', err)\n return\n }\n cb()\n })\n }\n\n private _currentURL(): string | undefined {\n // TODO you should be able to mask the URL here\n const href = window ? window.location.href : undefined\n if (!href) {\n logger.error(LOGGER_PREFIX + 'Could not determine current URL')\n }\n return href\n }\n\n private _flushToCapture = () => {\n clearTimeout(this._delayedFlushTimer)\n if (this.buffer.metrics.length === 0) {\n return\n }\n\n this.instance.capture(\n '$web_vitals',\n this.buffer.metrics.reduce(\n (acc, metric) => ({\n ...acc,\n // the entire event so we can use it in the future e.g. includes google's rating\n [`$web_vitals_${metric.name}_event`]: { ...metric },\n [`$web_vitals_${metric.name}_value`]: metric.value,\n }),\n {}\n )\n )\n this.buffer = { url: undefined, metrics: [], firstMetricTimestamp: undefined }\n }\n\n private _addToBuffer = (metric: any) => {\n const sessionIds = this.instance.sessionManager?.checkAndGetSessionAndWindowId(true)\n if (isUndefined(sessionIds)) {\n logger.error(LOGGER_PREFIX + 'Could not read session ID. Dropping metrics!')\n return\n }\n\n this.buffer = this.buffer || { url: undefined, metrics: [], firstMetricTimestamp: undefined }\n\n const $currentUrl = this._currentURL()\n if (isUndefined($currentUrl)) {\n return\n }\n\n if (isNullish(metric?.name) || isNullish(metric?.value)) {\n logger.error(LOGGER_PREFIX + 'Invalid metric received', metric)\n return\n }\n\n // we observe some very large values sometimes, we'll ignore them\n // since the likelihood of LCP > 1 hour being correct is very low\n if (this._maxAllowedValue && metric.value >= this._maxAllowedValue) {\n logger.error(LOGGER_PREFIX + 'Ignoring metric with value >= ' + this._maxAllowedValue, metric)\n return\n }\n\n const urlHasChanged = this.buffer.url !== $currentUrl\n\n if (urlHasChanged) {\n // we need to send what we have\n this._flushToCapture()\n // poor performance is >4s, we wait twice that time to send\n // this is in case we haven't received all metrics\n // we'll at least gather some\n this._delayedFlushTimer = setTimeout(this._flushToCapture, FLUSH_TO_CAPTURE_TIMEOUT_MILLISECONDS)\n }\n\n if (isUndefined(this.buffer.url)) {\n this.buffer.url = $currentUrl\n }\n\n this.buffer.firstMetricTimestamp = isUndefined(this.buffer.firstMetricTimestamp)\n ? Date.now()\n : this.buffer.firstMetricTimestamp\n\n this.buffer.metrics.push({\n ...metric,\n $current_url: $currentUrl,\n $session_id: sessionIds.sessionId,\n $window_id: sessionIds.windowId,\n timestamp: Date.now(),\n })\n\n if (this.buffer.metrics.length === 4) {\n // we have all 4 metrics\n this._flushToCapture()\n }\n }\n\n private _startCapturing = () => {\n const { onLCP, onCLS, onFCP, onINP } = assignableWindow.postHogWebVitalsCallbacks\n\n if (!onLCP || !onCLS || !onFCP || !onINP) {\n logger.error(LOGGER_PREFIX + 'web vitals callbacks not loaded - not starting')\n return\n }\n\n // register performance observers\n onLCP(this._addToBuffer)\n onCLS(this._addToBuffer)\n onFCP(this._addToBuffer)\n onINP(this._addToBuffer)\n\n this._initialized = true\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"heatmaps.js","sourceRoot":"","sources":["../../src/heatmaps.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACjD,OAAO,SAAS,MAAM,wBAAwB,CAAA;AAI9C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,EAAE,4BAA4B,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACtE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEvC,IAAM,sBAAsB,GAAG,IAAI,CAAA;AACnC,IAAM,QAAQ,GAAG,UAAU,CAAA;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gB,CAAC,CAAC,CAAC,MAAiB,CAAC,EAAE;YACvC,OAAM;SACT;QACD,YAAY,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;QAEpC,IAAI,CAAC,iBAAiB,GAAG,UAAU,CAAC;YAChC,KAAI,CAAC,QAAQ,CAAC,KAAI,CAAC,cAAc,CAAC,CAAe,EAAE,WAAW,CAAC,CAAC,CAAA;QACpE,CAAC,EAAE,GAAG,CAAC,CAAA;IACX,CAAC;IAEO,2BAAQ,GAAhB,UAAiB,UAAsB;QACnC,IAAI,CAAC,MAAM,EAAE;YACT,OAAM;SACT;QAED,sCAAsC;QACtC,IAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAA;QAEhC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAA;QAE/B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;YACnB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAA;SACxB;QAED,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IACrC,CAAC;IAEO,wBAAK,GAAb;QACI,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;YAC5C,OAAM;SACT;QAED,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE;YAC/B,aAAa,EAAE,IAAI,CAAC,iBAAiB,EAAE;SAC1C,CAAC,CAAA;IACN,CAAC;IACL,eAAC;AAAD,CAAC,AAlKD,IAkKC","sourcesContent":["import { includes, registerEvent } from './utils'\nimport RageClick from './extensions/rageclick'\nimport { DecideResponse, Properties } from './types'\nimport { PostHog } from './posthog-core'\n\nimport { document, window } from './utils/globals'\nimport { getParentElement, isTag } from './autocapture-utils'\nimport { HEATMAPS_ENABLED_SERVER_SIDE, TOOLBAR_ID } from './constants'\nimport { isEmptyObject, isObject, isUndefined } from './utils/type-utils'\nimport { logger } from './utils/logger'\n\nconst DEFAULT_FLUSH_INTERVAL = 5000\nconst HEATMAPS = 'heatmaps'\nconst LOGGER_PREFIX = '[' + HEATMAPS + ']'\n\ntype HeatmapEventBuffer =\n | {\n [key: string]: Properties[]\n }\n | undefined\n\nfunction elementOrParentPositionMatches(el: Element, matches: string[], breakOnElement?: Element): boolean {\n let curEl: Element | false = el\n\n while (curEl && !isTag(curEl, 'body')) {\n if (curEl === breakOnElement) {\n return false\n }\n\n if (includes(matches, window?.getComputedStyle(curEl).position)) {\n return true\n }\n\n curEl = getParentElement(curEl)\n }\n\n return false\n}\n\nfunction elementInToolbar(el: Element): boolean {\n // NOTE: .closest is not supported in IE11 hence the operator check\n return el.id === TOOLBAR_ID || !!el.closest?.('#' + TOOLBAR_ID)\n}\n\nexport class Heatmaps {\n instance: PostHog\n rageclicks = new RageClick()\n _enabledServerSide: boolean = false\n _initialized = false\n _mouseMoveTimeout: ReturnType<typeof setTimeout> | undefined\n\n // TODO: Periodically flush this if no other event has taken care of it\n private buffer: HeatmapEventBuffer\n private _flushInterval: number | null = null\n\n constructor(instance: PostHog) {\n this.instance = instance\n this._enabledServerSide = !!this.instance.persistence?.props[HEATMAPS_ENABLED_SERVER_SIDE]\n\n window?.addEventListener('beforeunload', () => {\n this.flush()\n })\n }\n\n public get flushIntervalMilliseconds(): number {\n let flushInterval = DEFAULT_FLUSH_INTERVAL\n if (\n isObject(this.instance.config.capture_heatmaps) &&\n this.instance.config.capture_heatmaps.flush_interval_milliseconds\n ) {\n flushInterval = this.instance.config.capture_heatmaps.flush_interval_milliseconds\n }\n return flushInterval\n }\n\n public get isEnabled(): boolean {\n if (!isUndefined(this.instance.config.capture_heatmaps)) {\n return this.instance.config.capture_heatmaps !== false\n }\n if (!isUndefined(this.instance.config.enable_heatmaps)) {\n return this.instance.config.enable_heatmaps\n }\n return this._enabledServerSide\n }\n\n public startIfEnabled(): void {\n if (this.isEnabled) {\n // nested if here since we only want to run the else\n // if this.enabled === false\n // not if this method is called more than once\n if (this._initialized) {\n return\n }\n logger.info(LOGGER_PREFIX + ' starting...')\n this._setupListeners()\n this._flushInterval = setInterval(this.flush.bind(this), this.flushIntervalMilliseconds)\n } else {\n clearInterval(this._flushInterval ?? undefined)\n this.getAndClearBuffer()\n }\n }\n\n public afterDecideResponse(response: DecideResponse) {\n const optIn = !!response['heatmaps']\n\n if (this.instance.persistence) {\n this.instance.persistence.register({\n [HEATMAPS_ENABLED_SERVER_SIDE]: optIn,\n })\n }\n // store this in-memory in case persistence is disabled\n this._enabledServerSide = optIn\n this.startIfEnabled()\n }\n\n public getAndClearBuffer(): HeatmapEventBuffer {\n const buffer = this.buffer\n this.buffer = undefined\n return buffer\n }\n\n private _setupListeners(): void {\n if (!window || !document) {\n return\n }\n\n registerEvent(document, 'click', (e) => this._onClick((e || window?.event) as MouseEvent), false, true)\n registerEvent(document, 'mousemove', (e) => this._onMouseMove((e || window?.event) as MouseEvent), false, true)\n\n this._initialized = true\n }\n\n private _getProperties(e: MouseEvent, type: string): Properties {\n // We need to know if the target element is fixed or not\n // If fixed then we won't account for scrolling\n // If not then we will account for scrolling\n\n const scrollY = this.instance.scrollManager.scrollY()\n const scrollX = this.instance.scrollManager.scrollX()\n const scrollElement = this.instance.scrollManager.scrollElement()\n\n const isFixedOrSticky = elementOrParentPositionMatches(e.target as Element, ['fixed', 'sticky'], scrollElement)\n\n return {\n x: e.clientX + (isFixedOrSticky ? 0 : scrollX),\n y: e.clientY + (isFixedOrSticky ? 0 : scrollY),\n target_fixed: isFixedOrSticky,\n type,\n }\n }\n\n private _onClick(e: MouseEvent): void {\n if (elementInToolbar(e.target as Element)) {\n return\n }\n const properties = this._getProperties(e, 'click')\n\n if (this.rageclicks?.isRageClick(e.clientX, e.clientY, new Date().getTime())) {\n this._capture({\n ...properties,\n type: 'rageclick',\n })\n }\n\n // TODO: Detect deadclicks\n\n this._capture(properties)\n }\n\n private _onMouseMove(e: Event): void {\n if (elementInToolbar(e.target as Element)) {\n return\n }\n clearTimeout(this._mouseMoveTimeout)\n\n this._mouseMoveTimeout = setTimeout(() => {\n this._capture(this._getProperties(e as MouseEvent, 'mousemove'))\n }, 500)\n }\n\n private _capture(properties: Properties): void {\n if (!window) {\n return\n }\n\n // TODO we should be able to mask this\n const url = window.location.href\n\n this.buffer = this.buffer || {}\n\n if (!this.buffer[url]) {\n this.buffer[url] = []\n }\n\n this.buffer[url].push(properties)\n }\n\n private flush(): void {\n if (!this.buffer || isEmptyObject(this.buffer)) {\n return\n }\n\n this.instance.capture('$$heatmap', {\n $heatmap_data: this.getAndClearBuffer(),\n })\n }\n}\n"]}
1
+ {"version":3,"file":"heatmaps.js","sourceRoot":"","sources":["../../src/heatmaps.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACjD,OAAO,SAAS,MAAM,wBAAwB,CAAA;AAI9C,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,EAAE,4BAA4B,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACtE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEvC,IAAM,sBAAsB,GAAG,IAAI,CAAA;AACnC,IAAM,QAAQ,GAAG,UAAU,CAAA;AAC3B,IAAM,aAAa,GAAG,GAAG,GAAG,QAAQ,GAAG,GAAG,CAAA;AAQ1C,SAAS,8BAA8B,CAAC,EAAW,EAAE,OAAiB,EAAE,cAAwB;IAC5F,IAAI,KAAK,GAAoB,EAAE,CAAA;IAE/B,OAAO,KAAK,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,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QACD,YAAY,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;QAEpC,IAAI,CAAC,iBAAiB,GAAG,UAAU,CAAC;YAChC,KAAI,CAAC,QAAQ,CAAC,KAAI,CAAC,cAAc,CAAC,CAAe,EAAE,WAAW,CAAC,CAAC,CAAA;QACpE,CAAC,EAAE,GAAG,CAAC,CAAA;IACX,CAAC;IAEO,2BAAQ,GAAhB,UAAiB,UAAsB;QACnC,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,OAAM;QACV,CAAC;QAED,sCAAsC;QACtC,IAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAA;QAEhC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAA;QAE/B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YACpB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAA;QACzB,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IACrC,CAAC;IAEO,wBAAK,GAAb;QACI,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YAC7C,OAAM;QACV,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE;YAC/B,aAAa,EAAE,IAAI,CAAC,iBAAiB,EAAE;SAC1C,CAAC,CAAA;IACN,CAAC;IACL,eAAC;AAAD,CAAC,AAlKD,IAkKC","sourcesContent":["import { includes, registerEvent } from './utils'\nimport RageClick from './extensions/rageclick'\nimport { DecideResponse, Properties } from './types'\nimport { PostHog } from './posthog-core'\n\nimport { document, window } from './utils/globals'\nimport { getParentElement, isTag } from './autocapture-utils'\nimport { HEATMAPS_ENABLED_SERVER_SIDE, TOOLBAR_ID } from './constants'\nimport { isEmptyObject, isObject, isUndefined } from './utils/type-utils'\nimport { logger } from './utils/logger'\n\nconst DEFAULT_FLUSH_INTERVAL = 5000\nconst HEATMAPS = 'heatmaps'\nconst LOGGER_PREFIX = '[' + HEATMAPS + ']'\n\ntype HeatmapEventBuffer =\n | {\n [key: string]: Properties[]\n }\n | undefined\n\nfunction elementOrParentPositionMatches(el: Element, matches: string[], breakOnElement?: Element): boolean {\n let curEl: Element | false = el\n\n while (curEl && !isTag(curEl, 'body')) {\n if (curEl === breakOnElement) {\n return false\n }\n\n if (includes(matches, window?.getComputedStyle(curEl).position)) {\n return true\n }\n\n curEl = getParentElement(curEl)\n }\n\n return false\n}\n\nfunction elementInToolbar(el: Element): boolean {\n // NOTE: .closest is not supported in IE11 hence the operator check\n return el.id === TOOLBAR_ID || !!el.closest?.('#' + TOOLBAR_ID)\n}\n\nexport class Heatmaps {\n instance: PostHog\n rageclicks = new RageClick()\n _enabledServerSide: boolean = false\n _initialized = false\n _mouseMoveTimeout: ReturnType<typeof setTimeout> | undefined\n\n // TODO: Periodically flush this if no other event has taken care of it\n private buffer: HeatmapEventBuffer\n private _flushInterval: ReturnType<typeof setInterval> | null = null\n\n constructor(instance: PostHog) {\n this.instance = instance\n this._enabledServerSide = !!this.instance.persistence?.props[HEATMAPS_ENABLED_SERVER_SIDE]\n\n window?.addEventListener('beforeunload', () => {\n this.flush()\n })\n }\n\n public get flushIntervalMilliseconds(): number {\n let flushInterval = DEFAULT_FLUSH_INTERVAL\n if (\n isObject(this.instance.config.capture_heatmaps) &&\n this.instance.config.capture_heatmaps.flush_interval_milliseconds\n ) {\n flushInterval = this.instance.config.capture_heatmaps.flush_interval_milliseconds\n }\n return flushInterval\n }\n\n public get isEnabled(): boolean {\n if (!isUndefined(this.instance.config.capture_heatmaps)) {\n return this.instance.config.capture_heatmaps !== false\n }\n if (!isUndefined(this.instance.config.enable_heatmaps)) {\n return this.instance.config.enable_heatmaps\n }\n return this._enabledServerSide\n }\n\n public startIfEnabled(): void {\n if (this.isEnabled) {\n // nested if here since we only want to run the else\n // if this.enabled === false\n // not if this method is called more than once\n if (this._initialized) {\n return\n }\n logger.info(LOGGER_PREFIX + ' starting...')\n this._setupListeners()\n this._flushInterval = setInterval(this.flush.bind(this), this.flushIntervalMilliseconds)\n } else {\n clearInterval(this._flushInterval ?? undefined)\n this.getAndClearBuffer()\n }\n }\n\n public afterDecideResponse(response: DecideResponse) {\n const optIn = !!response['heatmaps']\n\n if (this.instance.persistence) {\n this.instance.persistence.register({\n [HEATMAPS_ENABLED_SERVER_SIDE]: optIn,\n })\n }\n // store this in-memory in case persistence is disabled\n this._enabledServerSide = optIn\n this.startIfEnabled()\n }\n\n public getAndClearBuffer(): HeatmapEventBuffer {\n const buffer = this.buffer\n this.buffer = undefined\n return buffer\n }\n\n private _setupListeners(): void {\n if (!window || !document) {\n return\n }\n\n registerEvent(document, 'click', (e) => this._onClick((e || window?.event) as MouseEvent), false, true)\n registerEvent(document, 'mousemove', (e) => this._onMouseMove((e || window?.event) as MouseEvent), false, true)\n\n this._initialized = true\n }\n\n private _getProperties(e: MouseEvent, type: string): Properties {\n // We need to know if the target element is fixed or not\n // If fixed then we won't account for scrolling\n // If not then we will account for scrolling\n\n const scrollY = this.instance.scrollManager.scrollY()\n const scrollX = this.instance.scrollManager.scrollX()\n const scrollElement = this.instance.scrollManager.scrollElement()\n\n const isFixedOrSticky = elementOrParentPositionMatches(e.target as Element, ['fixed', 'sticky'], scrollElement)\n\n return {\n x: e.clientX + (isFixedOrSticky ? 0 : scrollX),\n y: e.clientY + (isFixedOrSticky ? 0 : scrollY),\n target_fixed: isFixedOrSticky,\n type,\n }\n }\n\n private _onClick(e: MouseEvent): void {\n if (elementInToolbar(e.target as Element)) {\n return\n }\n const properties = this._getProperties(e, 'click')\n\n if (this.rageclicks?.isRageClick(e.clientX, e.clientY, new Date().getTime())) {\n this._capture({\n ...properties,\n type: 'rageclick',\n })\n }\n\n // TODO: Detect deadclicks\n\n this._capture(properties)\n }\n\n private _onMouseMove(e: Event): void {\n if (elementInToolbar(e.target as Element)) {\n return\n }\n clearTimeout(this._mouseMoveTimeout)\n\n this._mouseMoveTimeout = setTimeout(() => {\n this._capture(this._getProperties(e as MouseEvent, 'mousemove'))\n }, 500)\n }\n\n private _capture(properties: Properties): void {\n if (!window) {\n return\n }\n\n // TODO we should be able to mask this\n const url = window.location.href\n\n this.buffer = this.buffer || {}\n\n if (!this.buffer[url]) {\n this.buffer[url] = []\n }\n\n this.buffer[url].push(properties)\n }\n\n private flush(): void {\n if (!this.buffer || isEmptyObject(this.buffer)) {\n return\n }\n\n this.instance.capture('$$heatmap', {\n $heatmap_data: this.getAndClearBuffer(),\n })\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"page-view.js","sourceRoot":"","sources":["../../src/page-view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAehD;IAKI,yBAAY,QAAiB;QACzB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAA;IAC7B,CAAC;IAED,oCAAU,GAAV,UAAW,SAAe;;QACtB,IAAM,QAAQ,GAAG,IAAI,CAAC,2BAA2B,CAAC,SAAS,CAAC,CAAA;QAE5D,sCAAsC;QACtC,IAAI,CAAC,YAAY,GAAG,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,CAAC,QAAQ,mCAAI,EAAE,CAAA;QACnD,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,YAAY,EAAE,CAAA;QAC3C,IAAI,CAAC,sBAAsB,GAAG,SAAS,CAAA;QAEvC,OAAO,QAAQ,CAAA;IACnB,CAAC;IAED,qCAAW,GAAX,UAAY,SAAe;QACvB,OAAO,IAAI,CAAC,2BAA2B,CAAC,SAAS,CAAC,CAAA;IACtD,CAAC;IAEO,qDAA2B,GAAnC,UAAoC,SAAe;QAC/C,IAAM,YAAY,GAAG,IAAI,CAAC,YAAY,C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G,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAA;AAC1C,CAAC","sourcesContent":["import { window } from './utils/globals'\nimport { PostHog } from './posthog-core'\nimport { isUndefined } from './utils/type-utils'\n\ninterface PageViewEventProperties {\n $prev_pageview_pathname?: string\n $prev_pageview_duration?: number // seconds\n $prev_pageview_last_scroll?: number\n $prev_pageview_last_scroll_percentage?: number\n $prev_pageview_max_scroll?: number\n $prev_pageview_max_scroll_percentage?: number\n $prev_pageview_last_content?: number\n $prev_pageview_last_content_percentage?: number\n $prev_pageview_max_content?: number\n $prev_pageview_max_content_percentage?: number\n}\n\nexport class PageViewManager {\n _currentPath?: string\n _prevPageviewTimestamp?: Date\n _instance: PostHog\n\n constructor(instance: PostHog) {\n this._instance = instance\n }\n\n doPageView(timestamp: Date): PageViewEventProperties {\n const response = this._previousPageViewProperties(timestamp)\n\n // On a pageview we reset the contexts\n this._currentPath = window?.location.pathname ?? ''\n this._instance.scrollManager.resetContext()\n this._prevPageviewTimestamp = timestamp\n\n return response\n }\n\n doPageLeave(timestamp: Date): PageViewEventProperties {\n return this._previousPageViewProperties(timestamp)\n }\n\n private _previousPageViewProperties(timestamp: Date): PageViewEventProperties {\n const previousPath = this._currentPath\n const previousTimestamp = this._prevPageviewTimestamp\n const scrollContext = this._instance.scrollManager.getContext()\n\n if (!previousTimestamp) {\n // this means there was no previous pageview\n return {}\n }\n\n let properties: PageViewEventProperties = {}\n if (scrollContext) {\n let { maxScrollHeight, lastScrollY, maxScrollY, maxContentHeight, lastContentY, maxContentY } =\n scrollContext\n\n if (\n !isUndefined(maxScrollHeight) &&\n !isUndefined(lastScrollY) &&\n !isUndefined(maxScrollY) &&\n !isUndefined(maxContentHeight) &&\n !isUndefined(lastContentY) &&\n !isUndefined(maxContentY)\n ) {\n // Use ceil, so that e.g. scrolling 999.5px of a 1000px page is considered 100% scrolled\n maxScrollHeight = Math.ceil(maxScrollHeight)\n lastScrollY = Math.ceil(lastScrollY)\n maxScrollY = Math.ceil(maxScrollY)\n maxContentHeight = Math.ceil(maxContentHeight)\n lastContentY = Math.ceil(lastContentY)\n maxContentY = Math.ceil(maxContentY)\n\n // if the maximum scroll height is near 0, then the percentage is 1\n const lastScrollPercentage = maxScrollHeight <= 1 ? 1 : clamp(lastScrollY / maxScrollHeight, 0, 1)\n const maxScrollPercentage = maxScrollHeight <= 1 ? 1 : clamp(maxScrollY / maxScrollHeight, 0, 1)\n const lastContentPercentage = maxContentHeight <= 1 ? 1 : clamp(lastContentY / maxContentHeight, 0, 1)\n const maxContentPercentage = maxContentHeight <= 1 ? 1 : clamp(maxContentY / maxContentHeight, 0, 1)\n\n properties = {\n $prev_pageview_last_scroll: lastScrollY,\n $prev_pageview_last_scroll_percentage: lastScrollPercentage,\n $prev_pageview_max_scroll: maxScrollY,\n $prev_pageview_max_scroll_percentage: maxScrollPercentage,\n $prev_pageview_last_content: lastContentY,\n $prev_pageview_last_content_percentage: lastContentPercentage,\n $prev_pageview_max_content: maxContentY,\n $prev_pageview_max_content_percentage: maxContentPercentage,\n }\n }\n }\n\n if (previousPath) {\n properties.$prev_pageview_pathname = previousPath\n }\n if (previousTimestamp) {\n // Use seconds, for consistency with our other duration-related properties like $duration\n properties.$prev_pageview_duration = (timestamp.getTime() - previousTimestamp.getTime()) / 1000\n }\n\n return properties\n }\n}\n\nfunction clamp(x: number, min: number, max: number) {\n return Math.max(min, Math.min(x, max))\n}\n"]}
1
+ {"version":3,"file":"page-view.js","sourceRoot":"","sources":["../../src/page-view.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAehD;IAKI,yBAAY,QAAiB;QACzB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAA;IAC7B,CAAC;IAED,oCAAU,GAAV,UAAW,SAAe;;QACtB,IAAM,QAAQ,GAAG,IAAI,CAAC,2BAA2B,CAAC,SAAS,CAAC,CAAA;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AqC,EAAE,oBAAoB;iBAC9D,CAAA;YACL,CAAC;QACL,CAAC;QAED,IAAI,YAAY,EAAE,CAAC;YACf,UAAU,CAAC,uBAAuB,GAAG,YAAY,CAAA;QACrD,CAAC;QACD,IAAI,iBAAiB,EAAE,CAAC;YACpB,yFAAyF;YACzF,UAAU,CAAC,uBAAuB,GAAG,CAAC,SAAS,CAAC,OAAO,EAAE,GAAG,iBAAiB,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAA;QACnG,CAAC;QAED,OAAO,UAAU,CAAA;IACrB,CAAC;IACL,sBAAC;AAAD,CAAC,AApFD,IAoFC;;AAED,SAAS,KAAK,CAAC,CAAS,EAAE,GAAW,EAAE,GAAW;IAC9C,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAA;AAC1C,CAAC","sourcesContent":["import { window } from './utils/globals'\nimport { PostHog } from './posthog-core'\nimport { isUndefined } from './utils/type-utils'\n\ninterface PageViewEventProperties {\n $prev_pageview_pathname?: string\n $prev_pageview_duration?: number // seconds\n $prev_pageview_last_scroll?: number\n $prev_pageview_last_scroll_percentage?: number\n $prev_pageview_max_scroll?: number\n $prev_pageview_max_scroll_percentage?: number\n $prev_pageview_last_content?: number\n $prev_pageview_last_content_percentage?: number\n $prev_pageview_max_content?: number\n $prev_pageview_max_content_percentage?: number\n}\n\nexport class PageViewManager {\n _currentPath?: string\n _prevPageviewTimestamp?: Date\n _instance: PostHog\n\n constructor(instance: PostHog) {\n this._instance = instance\n }\n\n doPageView(timestamp: Date): PageViewEventProperties {\n const response = this._previousPageViewProperties(timestamp)\n\n // On a pageview we reset the contexts\n this._currentPath = window?.location.pathname ?? ''\n this._instance.scrollManager.resetContext()\n this._prevPageviewTimestamp = timestamp\n\n return response\n }\n\n doPageLeave(timestamp: Date): PageViewEventProperties {\n return this._previousPageViewProperties(timestamp)\n }\n\n private _previousPageViewProperties(timestamp: Date): PageViewEventProperties {\n const previousPath = this._currentPath\n const previousTimestamp = this._prevPageviewTimestamp\n const scrollContext = this._instance.scrollManager.getContext()\n\n if (!previousTimestamp) {\n // this means there was no previous pageview\n return {}\n }\n\n let properties: PageViewEventProperties = {}\n if (scrollContext) {\n let { maxScrollHeight, lastScrollY, maxScrollY, maxContentHeight, lastContentY, maxContentY } =\n scrollContext\n\n if (\n !isUndefined(maxScrollHeight) &&\n !isUndefined(lastScrollY) &&\n !isUndefined(maxScrollY) &&\n !isUndefined(maxContentHeight) &&\n !isUndefined(lastContentY) &&\n !isUndefined(maxContentY)\n ) {\n // Use ceil, so that e.g. scrolling 999.5px of a 1000px page is considered 100% scrolled\n maxScrollHeight = Math.ceil(maxScrollHeight)\n lastScrollY = Math.ceil(lastScrollY)\n maxScrollY = Math.ceil(maxScrollY)\n maxContentHeight = Math.ceil(maxContentHeight)\n lastContentY = Math.ceil(lastContentY)\n maxContentY = Math.ceil(maxContentY)\n\n // if the maximum scroll height is near 0, then the percentage is 1\n const lastScrollPercentage = maxScrollHeight <= 1 ? 1 : clamp(lastScrollY / maxScrollHeight, 0, 1)\n const maxScrollPercentage = maxScrollHeight <= 1 ? 1 : clamp(maxScrollY / maxScrollHeight, 0, 1)\n const lastContentPercentage = maxContentHeight <= 1 ? 1 : clamp(lastContentY / maxContentHeight, 0, 1)\n const maxContentPercentage = maxContentHeight <= 1 ? 1 : clamp(maxContentY / maxContentHeight, 0, 1)\n\n properties = {\n $prev_pageview_last_scroll: lastScrollY,\n $prev_pageview_last_scroll_percentage: lastScrollPercentage,\n $prev_pageview_max_scroll: maxScrollY,\n $prev_pageview_max_scroll_percentage: maxScrollPercentage,\n $prev_pageview_last_content: lastContentY,\n $prev_pageview_last_content_percentage: lastContentPercentage,\n $prev_pageview_max_content: maxContentY,\n $prev_pageview_max_content_percentage: maxContentPercentage,\n }\n }\n }\n\n if (previousPath) {\n properties.$prev_pageview_pathname = previousPath\n }\n if (previousTimestamp) {\n // Use seconds, for consistency with our other duration-related properties like $duration\n properties.$prev_pageview_duration = (timestamp.getTime() - previousTimestamp.getTime()) / 1000\n }\n\n return properties\n }\n}\n\nfunction clamp(x: number, min: number, max: number) {\n return Math.max(min, Math.min(x, max))\n}\n"]}
@@ -91,7 +91,7 @@ export var defaultConfig = function () {
91
91
  autocapture: true,
92
92
  rageclick: true,
93
93
  cross_subdomain_cookie: isCrossDomainCookie(document === null || document === void 0 ? void 0 : document.location),
94
- persistence: 'localStorage+cookie',
94
+ persistence: 'localStorage+cookie', // up to 1.92.0 this was 'cookie'. It's easy to migrate as 'localStorage+cookie' will migrate data from cookie storage
95
95
  persistence_name: '',
96
96
  loaded: __NOOP,
97
97
  store_google: true,
@@ -99,7 +99,7 @@ export var defaultConfig = function () {
99
99
  custom_blocked_useragents: [],
100
100
  save_referrer: true,
101
101
  capture_pageview: true,
102
- capture_pageleave: 'if_capture_pageview',
102
+ capture_pageleave: 'if_capture_pageview', // We'll only capture pageleave events if capture_pageview is also true
103
103
  debug: (location && isString(location === null || location === void 0 ? void 0 : location.search) && location.search.indexOf('__posthog_debug=true') !== -1) || false,
104
104
  verbose: false,
105
105
  cookie_expiration: 365,
@@ -107,7 +107,7 @@ export var defaultConfig = function () {
107
107
  disable_session_recording: false,
108
108
  disable_persistence: false,
109
109
  disable_surveys: false,
110
- enable_recording_console_log: undefined,
110
+ enable_recording_console_log: undefined, // When undefined, it falls back to the server-side setting
111
111
  secure_cookie: ((_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.protocol) === 'https:',
112
112
  ip: true,
113
113
  opt_out_capturing_by_default: false,
@@ -119,7 +119,7 @@ export var defaultConfig = function () {
119
119
  property_denylist: [],
120
120
  respect_dnt: false,
121
121
  sanitize_properties: null,
122
- request_headers: {},
122
+ request_headers: {}, // { header: value, header2: value }
123
123
  inapp_protocol: '//',
124
124
  inapp_link_new_window: false,
125
125
  request_batching: true,
@@ -143,7 +143,7 @@ export var defaultConfig = function () {
143
143
  name: 'posthog',
144
144
  bootstrap: {},
145
145
  disable_compression: false,
146
- session_idle_timeout_seconds: 30 * 60,
146
+ session_idle_timeout_seconds: 30 * 60, // 30 minutes
147
147
  person_profiles: 'always',
148
148
  __add_tracing_headers: false,
149
149
  });