posthog-js 1.316.0 → 1.317.0

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 (86) hide show
  1. package/dist/all-external-dependencies.js +1 -1
  2. package/dist/all-external-dependencies.js.map +1 -1
  3. package/dist/array.full.es5.js +1 -1
  4. package/dist/array.full.es5.js.map +1 -1
  5. package/dist/array.full.js +1 -1
  6. package/dist/array.full.js.map +1 -1
  7. package/dist/array.full.no-external.js +1 -1
  8. package/dist/array.full.no-external.js.map +1 -1
  9. package/dist/array.js +1 -1
  10. package/dist/array.no-external.js +1 -1
  11. package/dist/customizations.full.js +1 -1
  12. package/dist/element-inference.d.ts +21 -0
  13. package/dist/element-inference.js +2 -0
  14. package/dist/element-inference.js.map +1 -0
  15. package/dist/lazy-recorder.js +1 -1
  16. package/dist/main.js +1 -1
  17. package/dist/main.js.map +1 -1
  18. package/dist/module.d.ts +12 -0
  19. package/dist/module.full.d.ts +12 -0
  20. package/dist/module.full.js +1 -1
  21. package/dist/module.full.js.map +1 -1
  22. package/dist/module.full.no-external.d.ts +12 -0
  23. package/dist/module.full.no-external.js +1 -1
  24. package/dist/module.full.no-external.js.map +1 -1
  25. package/dist/module.js +1 -1
  26. package/dist/module.js.map +1 -1
  27. package/dist/module.no-external.d.ts +12 -0
  28. package/dist/module.no-external.js +1 -1
  29. package/dist/module.no-external.js.map +1 -1
  30. package/dist/posthog-recorder.js +1 -1
  31. package/dist/product-tours-preview.d.ts +12 -0
  32. package/dist/product-tours-preview.js +1 -1
  33. package/dist/product-tours-preview.js.map +1 -1
  34. package/dist/product-tours.js +1 -1
  35. package/dist/product-tours.js.map +1 -1
  36. package/dist/src/entrypoints/element-inference.es.d.ts +1 -0
  37. package/dist/src/entrypoints/product-tours.d.ts +2 -0
  38. package/dist/src/extensions/product-tours/element-inference.d.ts +30 -0
  39. package/dist/src/extensions/product-tours/index.d.ts +2 -0
  40. package/dist/src/extensions/product-tours/product-tours-utils.d.ts +2 -1
  41. package/dist/src/extensions/surveys.d.ts +2 -2
  42. package/dist/src/posthog-product-tours-types.d.ts +7 -0
  43. package/dist/src/utils/survey-branching.d.ts +11 -0
  44. package/dist/src/utils/survey-url-prefill.d.ts +7 -5
  45. package/dist/surveys-preview.d.ts +18 -1
  46. package/dist/surveys-preview.js +1 -1
  47. package/dist/surveys-preview.js.map +1 -1
  48. package/dist/surveys.js +1 -1
  49. package/dist/surveys.js.map +1 -1
  50. package/lib/package.json +5 -1
  51. package/lib/src/entrypoints/element-inference.es.d.ts +1 -0
  52. package/lib/src/entrypoints/element-inference.es.js +8 -0
  53. package/lib/src/entrypoints/element-inference.es.js.map +1 -0
  54. package/lib/src/entrypoints/product-tours.d.ts +2 -0
  55. package/lib/src/entrypoints/product-tours.js +5 -0
  56. package/lib/src/entrypoints/product-tours.js.map +1 -1
  57. package/lib/src/extensions/product-tours/components/ProductTourTooltip.js +5 -2
  58. package/lib/src/extensions/product-tours/components/ProductTourTooltip.js.map +1 -1
  59. package/lib/src/extensions/product-tours/components/ProductTourTooltipInner.js +1 -1
  60. package/lib/src/extensions/product-tours/components/ProductTourTooltipInner.js.map +1 -1
  61. package/lib/src/extensions/product-tours/element-inference.d.ts +30 -0
  62. package/lib/src/extensions/product-tours/element-inference.js +296 -0
  63. package/lib/src/extensions/product-tours/element-inference.js.map +1 -0
  64. package/lib/src/extensions/product-tours/index.d.ts +2 -0
  65. package/lib/src/extensions/product-tours/index.js +4 -1
  66. package/lib/src/extensions/product-tours/index.js.map +1 -1
  67. package/lib/src/extensions/product-tours/preview.js +1 -1
  68. package/lib/src/extensions/product-tours/preview.js.map +1 -1
  69. package/lib/src/extensions/product-tours/product-tours-utils.d.ts +2 -1
  70. package/lib/src/extensions/product-tours/product-tours-utils.js +12 -0
  71. package/lib/src/extensions/product-tours/product-tours-utils.js.map +1 -1
  72. package/lib/src/extensions/product-tours/product-tours.js +15 -31
  73. package/lib/src/extensions/product-tours/product-tours.js.map +1 -1
  74. package/lib/src/extensions/surveys.d.ts +2 -2
  75. package/lib/src/extensions/surveys.js +5 -94
  76. package/lib/src/extensions/surveys.js.map +1 -1
  77. package/lib/src/posthog-product-tours-types.d.ts +7 -0
  78. package/lib/src/posthog-product-tours-types.js.map +1 -1
  79. package/lib/src/utils/survey-branching.d.ts +11 -0
  80. package/lib/src/utils/survey-branching.js +106 -0
  81. package/lib/src/utils/survey-branching.js.map +1 -0
  82. package/lib/src/utils/survey-url-prefill.d.ts +7 -5
  83. package/lib/src/utils/survey-url-prefill.js +30 -18
  84. package/lib/src/utils/survey-url-prefill.js.map +1 -1
  85. package/lib/tsconfig.tsbuildinfo +1 -1
  86. package/package.json +7 -3
@@ -1 +1 @@
1
- {"version":3,"file":"posthog-product-tours-types.js","sourceRoot":"","sources":["../../src/posthog-product-tours-types.ts"],"names":[],"mappings":";;;AAmGa,QAAA,+BAA+B,GAAoC;IAC5E,eAAe,EAAE,SAAS;IAC1B,SAAS,EAAE,SAAS;IACpB,WAAW,EAAE,SAAS;IACtB,YAAY,EAAE,CAAC;IACf,kBAAkB,EAAE,CAAC;IACrB,WAAW,EAAE,SAAS;IACtB,UAAU,EAAE,WAAW;IACvB,SAAS,EAAE,gCAAgC;IAC3C,WAAW,EAAE,IAAI;IACjB,UAAU,EAAE,KAAK;CACpB,CAAA","sourcesContent":["import { PropertyMatchType } from './types'\nimport { SurveyActionType, SurveyEventWithFilters } from './posthog-surveys-types'\n\nexport interface JSONContent {\n type?: string\n attrs?: Record<string, any>\n content?: JSONContent[]\n marks?: { type: string; attrs?: Record<string, any> }[]\n text?: string\n}\n\nexport type ProductTourStepType = 'element' | 'modal' | 'survey'\n\nexport type ProductTourSurveyQuestionType = 'open' | 'rating'\n\nexport interface ProductTourSurveyQuestion {\n type: ProductTourSurveyQuestionType\n questionText: string\n /** Rating display type - emoji or number */\n display?: 'emoji' | 'number'\n /** Rating scale - 3 or 5 for emoji, 5 or 10 for number */\n scale?: 3 | 5 | 10\n /** Label for low end of rating scale (e.g., \"Not likely\") */\n lowerBoundLabel?: string\n /** Label for high end of rating scale (e.g., \"Very likely\") */\n upperBoundLabel?: string\n}\n\nexport interface ProductTourStep {\n id: string\n type: ProductTourStepType\n selector?: string\n progressionTrigger: 'button' | 'click'\n content: JSONContent | null\n /** Inline survey question config - if present, this is a survey step */\n survey?: ProductTourSurveyQuestion\n /** ID of the auto-created survey for this step (set by backend) */\n linkedSurveyId?: string\n /** ID of the survey question (set by backend, used for event tracking) */\n linkedSurveyQuestionId?: string\n}\n\nexport interface ProductTourConditions {\n url?: string\n urlMatchType?: PropertyMatchType\n selector?: string\n autoShowDelaySeconds?: number\n events?: {\n values: SurveyEventWithFilters[]\n } | null\n cancelEvents?: {\n values: SurveyEventWithFilters[]\n } | null\n actions?: {\n values: SurveyActionType[]\n } | null\n}\n\nexport interface ProductTourAppearance {\n backgroundColor?: string\n textColor?: string\n buttonColor?: string\n borderRadius?: number\n buttonBorderRadius?: number\n borderColor?: string\n fontFamily?: string\n boxShadow?: string\n showOverlay?: boolean\n whiteLabel?: boolean\n}\n\nexport interface ProductTour {\n id: string\n name: string\n description?: string\n type: 'product_tour'\n auto_launch?: boolean\n start_date: string | null\n end_date: string | null\n current_iteration?: number\n conditions?: ProductTourConditions\n appearance?: ProductTourAppearance\n steps: ProductTourStep[]\n internal_targeting_flag_key?: string\n linked_flag_key?: string\n}\n\nexport type ProductTourCallback = (tours: ProductTour[], context?: { isLoaded: boolean; error?: string }) => void\n\nexport type ProductTourSelectorError = 'not_found' | 'multiple_matches' | 'not_visible'\n\nexport type ProductTourDismissReason =\n | 'user_clicked_skip'\n | 'user_clicked_outside'\n | 'escape_key'\n | 'element_unavailable'\n\nexport type ProductTourRenderReason = 'auto' | 'api' | 'trigger' | 'event'\n\nexport const DEFAULT_PRODUCT_TOUR_APPEARANCE: Required<ProductTourAppearance> = {\n backgroundColor: '#ffffff',\n textColor: '#1d1f27',\n buttonColor: '#1d1f27',\n borderRadius: 8,\n buttonBorderRadius: 6,\n borderColor: '#e5e7eb',\n fontFamily: 'system-ui',\n boxShadow: '0 4px 12px rgba(0, 0, 0, 0.15)',\n showOverlay: true,\n whiteLabel: false,\n}\n\nexport interface ShowTourOptions {\n reason?: ProductTourRenderReason\n enableStrictValidation?: boolean\n}\n"]}
1
+ {"version":3,"file":"posthog-product-tours-types.js","sourceRoot":"","sources":["../../src/posthog-product-tours-types.ts"],"names":[],"mappings":";;;AA0Ga,QAAA,+BAA+B,GAAoC;IAC5E,eAAe,EAAE,SAAS;IAC1B,SAAS,EAAE,SAAS;IACpB,WAAW,EAAE,SAAS;IACtB,YAAY,EAAE,CAAC;IACf,kBAAkB,EAAE,CAAC;IACrB,WAAW,EAAE,SAAS;IACtB,UAAU,EAAE,WAAW;IACvB,SAAS,EAAE,gCAAgC;IAC3C,WAAW,EAAE,IAAI;IACjB,UAAU,EAAE,KAAK;CACpB,CAAA","sourcesContent":["import { PropertyMatchType } from './types'\nimport { SurveyActionType, SurveyEventWithFilters } from './posthog-surveys-types'\nimport type { InferredSelector } from './extensions/product-tours/element-inference'\n\nexport interface JSONContent {\n type?: string\n attrs?: Record<string, any>\n content?: JSONContent[]\n marks?: { type: string; attrs?: Record<string, any> }[]\n text?: string\n}\n\nexport type ProductTourStepType = 'element' | 'modal' | 'survey'\n\nexport type ProductTourSurveyQuestionType = 'open' | 'rating'\n\nexport interface ProductTourSurveyQuestion {\n type: ProductTourSurveyQuestionType\n questionText: string\n /** Rating display type - emoji or number */\n display?: 'emoji' | 'number'\n /** Rating scale - 3 or 5 for emoji, 5 or 10 for number */\n scale?: 3 | 5 | 10\n /** Label for low end of rating scale (e.g., \"Not likely\") */\n lowerBoundLabel?: string\n /** Label for high end of rating scale (e.g., \"Very likely\") */\n upperBoundLabel?: string\n}\n\nexport interface ProductTourStep {\n id: string\n type: ProductTourStepType\n selector?: string\n progressionTrigger: 'button' | 'click'\n content: JSONContent | null\n /** Pre-rendered HTML content from the editor. If present, SDK should use this instead of rendering from JSONContent. */\n contentHtml?: string\n /** Inline survey question config - if present, this is a survey step */\n survey?: ProductTourSurveyQuestion\n /** ID of the auto-created survey for this step (set by backend) */\n linkedSurveyId?: string\n /** ID of the survey question (set by backend, used for event tracking) */\n linkedSurveyQuestionId?: string\n /** Enhanced element data for more reliable lookup at runtime */\n inferenceData?: InferredSelector\n /** Maximum tooltip width in pixels (defaults to 320px) */\n maxWidth?: number\n}\n\nexport interface ProductTourConditions {\n url?: string\n urlMatchType?: PropertyMatchType\n selector?: string\n autoShowDelaySeconds?: number\n events?: {\n values: SurveyEventWithFilters[]\n } | null\n cancelEvents?: {\n values: SurveyEventWithFilters[]\n } | null\n actions?: {\n values: SurveyActionType[]\n } | null\n}\n\nexport interface ProductTourAppearance {\n backgroundColor?: string\n textColor?: string\n buttonColor?: string\n borderRadius?: number\n buttonBorderRadius?: number\n borderColor?: string\n fontFamily?: string\n boxShadow?: string\n showOverlay?: boolean\n whiteLabel?: boolean\n}\n\nexport interface ProductTour {\n id: string\n name: string\n description?: string\n type: 'product_tour'\n auto_launch?: boolean\n start_date: string | null\n end_date: string | null\n current_iteration?: number\n conditions?: ProductTourConditions\n appearance?: ProductTourAppearance\n steps: ProductTourStep[]\n internal_targeting_flag_key?: string\n linked_flag_key?: string\n}\n\nexport type ProductTourCallback = (tours: ProductTour[], context?: { isLoaded: boolean; error?: string }) => void\n\nexport type ProductTourSelectorError = 'not_found' | 'multiple_matches' | 'not_visible'\n\nexport type ProductTourDismissReason =\n | 'user_clicked_skip'\n | 'user_clicked_outside'\n | 'escape_key'\n | 'element_unavailable'\n\nexport type ProductTourRenderReason = 'auto' | 'api' | 'trigger' | 'event'\n\nexport const DEFAULT_PRODUCT_TOUR_APPEARANCE: Required<ProductTourAppearance> = {\n backgroundColor: '#ffffff',\n textColor: '#1d1f27',\n buttonColor: '#1d1f27',\n borderRadius: 8,\n buttonBorderRadius: 6,\n borderColor: '#e5e7eb',\n fontFamily: 'system-ui',\n boxShadow: '0 4px 12px rgba(0, 0, 0, 0.15)',\n showOverlay: true,\n whiteLabel: false,\n}\n\nexport interface ShowTourOptions {\n reason?: ProductTourRenderReason\n enableStrictValidation?: boolean\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import { Survey, SurveyQuestionBranchingType } from '../posthog-surveys-types';
2
+ /**
3
+ * Get the rating bucket (detractors/passives/promoters or negative/neutral/positive)
4
+ * based on the response value and scale.
5
+ */
6
+ export declare function getRatingBucketForResponseValue(responseValue: number, scale: number): string;
7
+ /**
8
+ * Determine the next survey step based on branching configuration.
9
+ * Returns the next question index, or SurveyQuestionBranchingType.End if the survey should end.
10
+ */
11
+ export declare function getNextSurveyStep(survey: Survey, currentQuestionIndex: number, response: string | string[] | number | null): number | SurveyQuestionBranchingType.End;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRatingBucketForResponseValue = getRatingBucketForResponseValue;
4
+ exports.getNextSurveyStep = getNextSurveyStep;
5
+ var posthog_surveys_types_1 = require("../posthog-surveys-types");
6
+ var logger_1 = require("./logger");
7
+ var logger = (0, logger_1.createLogger)('[Surveys]');
8
+ /**
9
+ * Get the rating bucket (detractors/passives/promoters or negative/neutral/positive)
10
+ * based on the response value and scale.
11
+ */
12
+ function getRatingBucketForResponseValue(responseValue, scale) {
13
+ if (scale === 3) {
14
+ if (responseValue < 1 || responseValue > 3) {
15
+ throw new Error('The response must be in range 1-3');
16
+ }
17
+ return responseValue === 1 ? 'negative' : responseValue === 2 ? 'neutral' : 'positive';
18
+ }
19
+ else if (scale === 5) {
20
+ if (responseValue < 1 || responseValue > 5) {
21
+ throw new Error('The response must be in range 1-5');
22
+ }
23
+ return responseValue <= 2 ? 'negative' : responseValue === 3 ? 'neutral' : 'positive';
24
+ }
25
+ else if (scale === 7) {
26
+ if (responseValue < 1 || responseValue > 7) {
27
+ throw new Error('The response must be in range 1-7');
28
+ }
29
+ return responseValue <= 3 ? 'negative' : responseValue === 4 ? 'neutral' : 'positive';
30
+ }
31
+ else if (scale === 10) {
32
+ if (responseValue < 0 || responseValue > 10) {
33
+ throw new Error('The response must be in range 0-10');
34
+ }
35
+ return responseValue <= 6 ? 'detractors' : responseValue <= 8 ? 'passives' : 'promoters';
36
+ }
37
+ throw new Error('The scale must be one of: 3, 5, 7, 10');
38
+ }
39
+ /**
40
+ * Determine the next survey step based on branching configuration.
41
+ * Returns the next question index, or SurveyQuestionBranchingType.End if the survey should end.
42
+ */
43
+ function getNextSurveyStep(survey, currentQuestionIndex, response) {
44
+ var _a, _b, _c, _d, _e;
45
+ var question = survey.questions[currentQuestionIndex];
46
+ var nextQuestionIndex = currentQuestionIndex + 1;
47
+ if (!((_a = question.branching) === null || _a === void 0 ? void 0 : _a.type)) {
48
+ if (currentQuestionIndex === survey.questions.length - 1) {
49
+ return posthog_surveys_types_1.SurveyQuestionBranchingType.End;
50
+ }
51
+ return nextQuestionIndex;
52
+ }
53
+ if (question.branching.type === posthog_surveys_types_1.SurveyQuestionBranchingType.End) {
54
+ return posthog_surveys_types_1.SurveyQuestionBranchingType.End;
55
+ }
56
+ else if (question.branching.type === posthog_surveys_types_1.SurveyQuestionBranchingType.SpecificQuestion) {
57
+ if (Number.isInteger(question.branching.index)) {
58
+ return question.branching.index;
59
+ }
60
+ }
61
+ else if (question.branching.type === posthog_surveys_types_1.SurveyQuestionBranchingType.ResponseBased) {
62
+ // Single choice
63
+ if (question.type === posthog_surveys_types_1.SurveyQuestionType.SingleChoice) {
64
+ // KLUDGE: for now, look up the choiceIndex based on the response
65
+ // TODO: once QuestionTypes.MultipleChoiceQuestion is refactored, pass the selected choiceIndex into this method
66
+ var selectedChoiceIndex = question.choices.indexOf("".concat(response));
67
+ if (selectedChoiceIndex === -1 && question.hasOpenChoice) {
68
+ // if the response is not found in the choices, it must be the open choice,
69
+ // which is always the last choice
70
+ selectedChoiceIndex = question.choices.length - 1;
71
+ }
72
+ if ((_c = (_b = question.branching) === null || _b === void 0 ? void 0 : _b.responseValues) === null || _c === void 0 ? void 0 : _c.hasOwnProperty(selectedChoiceIndex)) {
73
+ var nextStep = question.branching.responseValues[selectedChoiceIndex];
74
+ // Specific question
75
+ if (Number.isInteger(nextStep)) {
76
+ return nextStep;
77
+ }
78
+ if (nextStep === posthog_surveys_types_1.SurveyQuestionBranchingType.End) {
79
+ return posthog_surveys_types_1.SurveyQuestionBranchingType.End;
80
+ }
81
+ return nextQuestionIndex;
82
+ }
83
+ }
84
+ else if (question.type === posthog_surveys_types_1.SurveyQuestionType.Rating) {
85
+ if (typeof response !== 'number' || !Number.isInteger(response)) {
86
+ throw new Error('The response type must be an integer');
87
+ }
88
+ var ratingBucket = getRatingBucketForResponseValue(response, question.scale);
89
+ if ((_e = (_d = question.branching) === null || _d === void 0 ? void 0 : _d.responseValues) === null || _e === void 0 ? void 0 : _e.hasOwnProperty(ratingBucket)) {
90
+ var nextStep = question.branching.responseValues[ratingBucket];
91
+ // Specific question
92
+ if (Number.isInteger(nextStep)) {
93
+ return nextStep;
94
+ }
95
+ if (nextStep === posthog_surveys_types_1.SurveyQuestionBranchingType.End) {
96
+ return posthog_surveys_types_1.SurveyQuestionBranchingType.End;
97
+ }
98
+ return nextQuestionIndex;
99
+ }
100
+ }
101
+ return nextQuestionIndex;
102
+ }
103
+ logger.warn('Falling back to next question index due to unexpected branching type');
104
+ return nextQuestionIndex;
105
+ }
106
+ //# sourceMappingURL=survey-branching.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"survey-branching.js","sourceRoot":"","sources":["../../../src/utils/survey-branching.ts"],"names":[],"mappings":";;AASA,0EA4BC;AAMD,8CA6EC;AAxHD,kEAAkG;AAClG,mCAAuC;AAEvC,IAAM,MAAM,GAAG,IAAA,qBAAY,EAAC,WAAW,CAAC,CAAA;AAExC;;;GAGG;AACH,SAAgB,+BAA+B,CAAC,aAAqB,EAAE,KAAa;IAChF,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;QACd,IAAI,aAAa,GAAG,CAAC,IAAI,aAAa,GAAG,CAAC,EA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AAK,mDAA2B,CAAC,GAAG,EAAE,CAAC;oBAC/C,OAAO,mDAA2B,CAAC,GAAG,CAAA;gBAC1C,CAAC;gBAED,OAAO,iBAAiB,CAAA;YAC5B,CAAC;QACL,CAAC;QAED,OAAO,iBAAiB,CAAA;IAC5B,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,sEAAsE,CAAC,CAAA;IACnF,OAAO,iBAAiB,CAAA;AAC5B,CAAC","sourcesContent":["import { Survey, SurveyQuestionBranchingType, SurveyQuestionType } from '../posthog-surveys-types'\nimport { createLogger } from './logger'\n\nconst logger = createLogger('[Surveys]')\n\n/**\n * Get the rating bucket (detractors/passives/promoters or negative/neutral/positive)\n * based on the response value and scale.\n */\nexport function getRatingBucketForResponseValue(responseValue: number, scale: number): string {\n if (scale === 3) {\n if (responseValue < 1 || responseValue > 3) {\n throw new Error('The response must be in range 1-3')\n }\n\n return responseValue === 1 ? 'negative' : responseValue === 2 ? 'neutral' : 'positive'\n } else if (scale === 5) {\n if (responseValue < 1 || responseValue > 5) {\n throw new Error('The response must be in range 1-5')\n }\n\n return responseValue <= 2 ? 'negative' : responseValue === 3 ? 'neutral' : 'positive'\n } else if (scale === 7) {\n if (responseValue < 1 || responseValue > 7) {\n throw new Error('The response must be in range 1-7')\n }\n\n return responseValue <= 3 ? 'negative' : responseValue === 4 ? 'neutral' : 'positive'\n } else if (scale === 10) {\n if (responseValue < 0 || responseValue > 10) {\n throw new Error('The response must be in range 0-10')\n }\n\n return responseValue <= 6 ? 'detractors' : responseValue <= 8 ? 'passives' : 'promoters'\n }\n\n throw new Error('The scale must be one of: 3, 5, 7, 10')\n}\n\n/**\n * Determine the next survey step based on branching configuration.\n * Returns the next question index, or SurveyQuestionBranchingType.End if the survey should end.\n */\nexport function getNextSurveyStep(\n survey: Survey,\n currentQuestionIndex: number,\n response: string | string[] | number | null\n): number | SurveyQuestionBranchingType.End {\n const question = survey.questions[currentQuestionIndex]\n const nextQuestionIndex = currentQuestionIndex + 1\n\n if (!question.branching?.type) {\n if (currentQuestionIndex === survey.questions.length - 1) {\n return SurveyQuestionBranchingType.End\n }\n\n return nextQuestionIndex\n }\n\n if (question.branching.type === SurveyQuestionBranchingType.End) {\n return SurveyQuestionBranchingType.End\n } else if (question.branching.type === SurveyQuestionBranchingType.SpecificQuestion) {\n if (Number.isInteger(question.branching.index)) {\n return question.branching.index\n }\n } else if (question.branching.type === SurveyQuestionBranchingType.ResponseBased) {\n // Single choice\n if (question.type === SurveyQuestionType.SingleChoice) {\n // KLUDGE: for now, look up the choiceIndex based on the response\n // TODO: once QuestionTypes.MultipleChoiceQuestion is refactored, pass the selected choiceIndex into this method\n let selectedChoiceIndex = question.choices.indexOf(`${response}`)\n\n if (selectedChoiceIndex === -1 && question.hasOpenChoice) {\n // if the response is not found in the choices, it must be the open choice,\n // which is always the last choice\n selectedChoiceIndex = question.choices.length - 1\n }\n\n if (question.branching?.responseValues?.hasOwnProperty(selectedChoiceIndex)) {\n const nextStep = question.branching.responseValues[selectedChoiceIndex]\n\n // Specific question\n if (Number.isInteger(nextStep)) {\n return nextStep\n }\n\n if (nextStep === SurveyQuestionBranchingType.End) {\n return SurveyQuestionBranchingType.End\n }\n\n return nextQuestionIndex\n }\n } else if (question.type === SurveyQuestionType.Rating) {\n if (typeof response !== 'number' || !Number.isInteger(response)) {\n throw new Error('The response type must be an integer')\n }\n\n const ratingBucket = getRatingBucketForResponseValue(response, question.scale)\n\n if (question.branching?.responseValues?.hasOwnProperty(ratingBucket)) {\n const nextStep = question.branching.responseValues[ratingBucket]\n\n // Specific question\n if (Number.isInteger(nextStep)) {\n return nextStep\n }\n\n if (nextStep === SurveyQuestionBranchingType.End) {\n return SurveyQuestionBranchingType.End\n }\n\n return nextQuestionIndex\n }\n }\n\n return nextQuestionIndex\n }\n\n logger.warn('Falling back to next question index due to unexpected branching type')\n return nextQuestionIndex\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { Survey, SurveyQuestion } from '../posthog-surveys-types';
1
+ import { Survey } from '../posthog-surveys-types';
2
2
  /**
3
3
  * Extracted URL prefill parameters by question index
4
4
  */
@@ -20,14 +20,16 @@ export declare function extractPrefillParamsFromUrl(searchString: string): {
20
20
  export declare function convertPrefillToResponses(survey: Survey, prefillParams: PrefillParams): Record<string, any>;
21
21
  /**
22
22
  * Calculate which question index to start at based on prefilled questions.
23
- * Only advances past consecutive prefilled questions (starting from index 0)
24
- * that have skipSubmitButton enabled.
23
+ * Advances past consecutive prefilled questions (starting from index 0)
24
+ * that have skipSubmitButton enabled, respecting any branching logic configured
25
+ * on those questions.
25
26
  *
26
- * @param questions - The survey questions array
27
+ * @param survey - The full survey object (needed for branching logic)
27
28
  * @param prefilledIndices - Array of question indices that have been prefilled
29
+ * @param responses - Map of response keys to response values
28
30
  * @returns Object with startQuestionIndex and map of questions which have been skipped
29
31
  */
30
- export declare function calculatePrefillStartIndex(questions: SurveyQuestion[], prefilledIndices: number[], responses: Record<string, any>): {
32
+ export declare function calculatePrefillStartIndex(survey: Survey, prefilledIndices: number[], responses: Record<string, any>): {
31
33
  startQuestionIndex: number;
32
34
  skippedResponses: Record<string, any>;
33
35
  };
@@ -43,6 +43,7 @@ var posthog_surveys_types_1 = require("../posthog-surveys-types");
43
43
  var surveys_extension_utils_1 = require("../extensions/surveys/surveys-extension-utils");
44
44
  var logger_1 = require("./logger");
45
45
  var core_1 = require("@posthog/core");
46
+ var survey_branching_1 = require("./survey-branching");
46
47
  /**
47
48
  * Extract prefill parameters from URL search string
48
49
  * Format: ?q0=1&q1=8&q2=0&q2=2&auto_submit=true
@@ -161,37 +162,48 @@ function convertPrefillToResponses(survey, prefillParams) {
161
162
  }
162
163
  /**
163
164
  * Calculate which question index to start at based on prefilled questions.
164
- * Only advances past consecutive prefilled questions (starting from index 0)
165
- * that have skipSubmitButton enabled.
165
+ * Advances past consecutive prefilled questions (starting from index 0)
166
+ * that have skipSubmitButton enabled, respecting any branching logic configured
167
+ * on those questions.
166
168
  *
167
- * @param questions - The survey questions array
169
+ * @param survey - The full survey object (needed for branching logic)
168
170
  * @param prefilledIndices - Array of question indices that have been prefilled
171
+ * @param responses - Map of response keys to response values
169
172
  * @returns Object with startQuestionIndex and map of questions which have been skipped
170
173
  */
171
- function calculatePrefillStartIndex(questions, prefilledIndices, responses) {
172
- var startQuestionIndex = 0;
174
+ function calculatePrefillStartIndex(survey, prefilledIndices, responses) {
175
+ var currentIndex = 0;
173
176
  var skippedResponses = {};
174
- for (var i = 0; i < questions.length; i++) {
175
- // stop at the first question that is not prefilled
176
- if (!prefilledIndices.includes(i)) {
177
+ var MAX_ITERATIONS = survey.questions.length + 1;
178
+ var iterations = 0;
179
+ while (currentIndex < survey.questions.length && iterations < MAX_ITERATIONS) {
180
+ // Stop if current question is not prefilled
181
+ if (!prefilledIndices.includes(currentIndex)) {
177
182
  break;
178
183
  }
179
- var question = questions[i];
180
- // only advance if the prefilled question has skipSubmitButton
181
- if (question && 'skipSubmitButton' in question && question.skipSubmitButton) {
182
- startQuestionIndex = i + 1;
183
- if (!question.id)
184
- continue;
184
+ var question = survey.questions[currentIndex];
185
+ // Only advance if the prefilled question has skipSubmitButton
186
+ if (!question || !('skipSubmitButton' in question) || !question.skipSubmitButton) {
187
+ // Show question if skipSubmitButton is false, even if prefilled
188
+ break;
189
+ }
190
+ // Record the skipped response
191
+ if (question.id) {
185
192
  var responseKey = (0, surveys_extension_utils_1.getSurveyResponseKey)(question.id);
186
193
  if (!(0, core_1.isUndefined)(responses[responseKey])) {
187
194
  skippedResponses[responseKey] = responses[responseKey];
188
195
  }
189
196
  }
190
- else {
191
- // show question if skipSubmitButton is false, even if prefilled
192
- break;
197
+ // Use branching logic to determine the next question
198
+ var response = question.id ? responses[(0, surveys_extension_utils_1.getSurveyResponseKey)(question.id)] : null;
199
+ var nextStep = (0, survey_branching_1.getNextSurveyStep)(survey, currentIndex, response);
200
+ if (nextStep === posthog_surveys_types_1.SurveyQuestionBranchingType.End) {
201
+ // Survey is complete - return questions.length to indicate completion
202
+ return { startQuestionIndex: survey.questions.length, skippedResponses: skippedResponses };
193
203
  }
204
+ // Move to the next question (respecting branching)
205
+ currentIndex = nextStep;
194
206
  }
195
- return { startQuestionIndex: startQuestionIndex, skippedResponses: skippedResponses };
207
+ return { startQuestionIndex: currentIndex, skippedResponses: skippedResponses };
196
208
  }
197
209
  //# sourceMappingURL=survey-url-prefill.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"survey-url-prefill.js","sourceRoot":"","sources":["../../../src/utils/survey-url-prefill.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,kEA2CC;AAKD,8DAuEC;AAWD,gEA8BC;AAjLD,kEAAqF;AACrF,yFAAoF;AACpF,mCAAiC;AACjC,sCAA2C;AAS3C;;;;GAIG;AACH,SAAgB,2BAA2B,CAAC,YAAoB;;IAI5D,IAAM,MAAM,GAAkB,EAAE,CAAA;IAChC,IAAI,UAAU,GAAG,KAAK,CAAA;IAEtB,8BAA8B;IAC9B,IAAM,WAAW,GAAG,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;IACnD,IAAI,CAAC,WAAW,EAAE,CAAC;QACf,OAAO,EAAE,MAAM,QAAA,EAAE,UAAU,YAAA,EAAE,CAAA;IACjC,CAAC;IAED,oCAAoC;IACpC,IAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;;QAEpC,KAAmB,IAAA,UAAA,SAAA,KAAK,CAAA,4BAAA,+CAAE,CAAC;YAAtB,IAAM,IAAI,kBAAA;YACL,IAAA,KAAA,OAAe,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAA,EAA7B,GAAG,QAAA,EAAE,KAAK,QAAmB,CAAA;YACpC,IAAI,CAAC,GAAG,IAAI,IAAA,kBAAW,EAAC,KAAK,CAAC,EAAE,CAAC;gBAC7B,SAAQ;YACZ,CAAC;YAED,IAAM,UAAU,GAAG,kBAAkB,CAAC,GAAG,CAAC,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AAS,CAAA;AACpB,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,0BAA0B,CACtC,SAA2B,EAC3B,gBAA0B,EAC1B,SAA8B;IAE9B,IAAI,kBAAkB,GAAG,CAAC,CAAA;IAC1B,IAAM,gBAAgB,GAAwB,EAAE,CAAA;IAEhD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,mDAAmD;QACnD,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;YAChC,MAAK;QACT,CAAC;QAED,IAAM,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA;QAC7B,8DAA8D;QAC9D,IAAI,QAAQ,IAAI,kBAAkB,IAAI,QAAQ,IAAI,QAAQ,CAAC,gBAAgB,EAAE,CAAC;YAC1E,kBAAkB,GAAG,CAAC,GAAG,CAAC,CAAA;YAC1B,IAAI,CAAC,QAAQ,CAAC,EAAE;gBAAE,SAAQ;YAC1B,IAAM,WAAW,GAAG,IAAA,8CAAoB,EAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;YACrD,IAAI,CAAC,IAAA,kBAAW,EAAC,SAAS,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC;gBACvC,gBAAgB,CAAC,WAAW,CAAC,GAAG,SAAS,CAAC,WAAW,CAAC,CAAA;YAC1D,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,gEAAgE;YAChE,MAAK;QACT,CAAC;IACL,CAAC;IAED,OAAO,EAAE,kBAAkB,oBAAA,EAAE,gBAAgB,kBAAA,EAAE,CAAA;AACnD,CAAC","sourcesContent":["import { Survey, SurveyQuestion, SurveyQuestionType } from '../posthog-surveys-types'\nimport { getSurveyResponseKey } from '../extensions/surveys/surveys-extension-utils'\nimport { logger } from './logger'\nimport { isUndefined } from '@posthog/core'\n\n/**\n * Extracted URL prefill parameters by question index\n */\nexport interface PrefillParams {\n [questionIndex: number]: string[]\n}\n\n/**\n * Extract prefill parameters from URL search string\n * Format: ?q0=1&q1=8&q2=0&q2=2&auto_submit=true\n * NOTE: Manual parsing for IE11/op_mini compatibility (no URLSearchParams)\n */\nexport function extractPrefillParamsFromUrl(searchString: string): {\n params: PrefillParams\n autoSubmit: boolean\n} {\n const params: PrefillParams = {}\n let autoSubmit = false\n\n // Remove leading ? if present\n const cleanSearch = searchString.replace(/^\\?/, '')\n if (!cleanSearch) {\n return { params, autoSubmit }\n }\n\n // Split by & to get key-value pairs\n const pairs = cleanSearch.split('&')\n\n for (const pair of pairs) {\n const [key, value] = pair.split('=')\n if (!key || isUndefined(value)) {\n continue\n }\n\n const decodedKey = decodeURIComponent(key)\n const decodedValue = decodeURIComponent(value)\n\n // Check for auto_submit parameter\n if (decodedKey === 'auto_submit' && decodedValue === 'true') {\n autoSubmit = true\n continue\n }\n\n // Check for question parameters (q0, q1, etc.)\n const match = decodedKey.match(/^q(\\d+)$/)\n if (match) {\n const questionIndex = parseInt(match[1], 10)\n if (!params[questionIndex]) {\n params[questionIndex] = []\n }\n params[questionIndex].push(decodedValue)\n }\n }\n\n return { params, autoSubmit }\n}\n\n/**\n * Convert URL prefill values to SDK response format\n */\nexport function convertPrefillToResponses(survey: Survey, prefillParams: PrefillParams): Record<string, any> {\n const responses: Record<string, any> = {}\n\n survey.questions.forEach((question: SurveyQuestion, index: number) => {\n if (!prefillParams[index] || !question.id) {\n return\n }\n\n const values = prefillParams[index]\n const responseKey = getSurveyResponseKey(question.id)\n\n try {\n switch (question.type) {\n case SurveyQuestionType.SingleChoice: {\n if (!question.choices || question.choices.length === 0) {\n logger.warn(`[Survey Prefill] Question ${index} has no choices`)\n return\n }\n const choiceIndex = parseInt(values[0], 10)\n if (isNaN(choiceIndex) || choiceIndex < 0 || choiceIndex >= question.choices.length) {\n logger.warn(`[Survey Prefill] Invalid choice index for q${index}: ${values[0]}`)\n return\n }\n responses[responseKey] = question.choices[choiceIndex]\n break\n }\n\n case SurveyQuestionType.MultipleChoice: {\n if (!question.choices || question.choices.length === 0) {\n logger.warn(`[Survey Prefill] Question ${index} has no choices`)\n return\n }\n const choiceIndices = values\n .map((v) => parseInt(v, 10))\n .filter((i) => !isNaN(i) && i >= 0 && i < question.choices.length)\n\n if (choiceIndices.length === 0) {\n logger.warn(`[Survey Prefill] No valid choices for q${index}`)\n return\n }\n\n // Remove duplicates and map to choice values\n const uniqueChoices = [...new Set(choiceIndices.map((i) => question.choices[i]))]\n if (uniqueChoices.length < choiceIndices.length) {\n logger.warn(`[Survey Prefill] Removed duplicate choices for q${index}`)\n }\n responses[responseKey] = uniqueChoices\n break\n }\n\n case SurveyQuestionType.Rating: {\n const rating = parseInt(values[0], 10)\n const scale = question.scale || 10\n\n if (isNaN(rating) || rating < 0 || rating > scale) {\n logger.warn(`[Survey Prefill] Invalid rating for q${index}: ${values[0]} (scale: 0-${scale})`)\n return\n }\n responses[responseKey] = rating\n break\n }\n\n default:\n logger.info(`[Survey Prefill] Question type ${question.type} does not support prefill`)\n }\n } catch (error) {\n logger.error(`[Survey Prefill] Error converting q${index}:`, error)\n }\n })\n\n return responses\n}\n\n/**\n * Calculate which question index to start at based on prefilled questions.\n * Only advances past consecutive prefilled questions (starting from index 0)\n * that have skipSubmitButton enabled.\n *\n * @param questions - The survey questions array\n * @param prefilledIndices - Array of question indices that have been prefilled\n * @returns Object with startQuestionIndex and map of questions which have been skipped\n */\nexport function calculatePrefillStartIndex(\n questions: SurveyQuestion[],\n prefilledIndices: number[],\n responses: Record<string, any>\n): { startQuestionIndex: number; skippedResponses: Record<string, any> } {\n let startQuestionIndex = 0\n const skippedResponses: Record<string, any> = {}\n\n for (let i = 0; i < questions.length; i++) {\n // stop at the first question that is not prefilled\n if (!prefilledIndices.includes(i)) {\n break\n }\n\n const question = questions[i]\n // only advance if the prefilled question has skipSubmitButton\n if (question && 'skipSubmitButton' in question && question.skipSubmitButton) {\n startQuestionIndex = i + 1\n if (!question.id) continue\n const responseKey = getSurveyResponseKey(question.id)\n if (!isUndefined(responses[responseKey])) {\n skippedResponses[responseKey] = responses[responseKey]\n }\n } else {\n // show question if skipSubmitButton is false, even if prefilled\n break\n }\n }\n\n return { startQuestionIndex, skippedResponses }\n}\n"]}
1
+ {"version":3,"file":"survey-url-prefill.js","sourceRoot":"","sources":["../../../src/utils/survey-url-prefill.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,kEA2CC;AAKD,8DAuEC;AAaD,gEA8CC;AApMD,kEAAkH;AAClH,yFAAoF;AACpF,mCAAiC;AACjC,sCAA2C;AAC3C,uDAAsD;AAStD;;;;GAIG;AACH,SAAgB,2BAA2B,CAAC,YAAoB;;IAI5D,IAAM,MAAM,GAAkB,EAAE,CAAA;IAChC,IAAI,UAAU,GAAG,KAAK,CAAA;IAEtB,8BAA8B;IAC9B,IAAM,WAAW,GAAG,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;IACnD,IAAI,CAAC,WAAW,EAAE,CAAC;QACf,OAAO,EAAE,MAAM,QAAA,EAAE,UAAU,YAAA,EAAE,CAAA;IACjC,CAAC;IAED,oCAAoC;IACpC,IAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;;QAEpC,KAAmB,IAAA,UAAA,SAAA,KAAK,CAAA,4BAAA,+CAAE,CAAC;YAAtB,IAAM,IAAI,kBAAA;YACL,IAAA,KAAA,OAAe,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAA,EAA7B,GAAG,QAAA,EAAE,KAAK,QAAmB,CAAA;YACpC,IAAI,CAAC,GAAG,IAAI,IAAA,kBAAW,EAAC,KAAK,CAAC,EAAE,CAAC;gBAC7B,SAAQ;YACZ,CAAC;YAED,IAAM,UAAU,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAA;YAC1C,IAAM,YAAY,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAA;YAE9C,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AI,QAAQ,KAAK,mDAA2B,CAAC,GAAG,EAAE,CAAC;YAC/C,sEAAsE;YACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,gBAAgB,kBAAA,EAAE,CAAA;QAC5E,CAAC;QAED,mDAAmD;QACnD,YAAY,GAAG,QAAQ,CAAA;IAC3B,CAAC;IAED,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,gBAAgB,kBAAA,EAAE,CAAA;AACjE,CAAC","sourcesContent":["import { Survey, SurveyQuestion, SurveyQuestionBranchingType, SurveyQuestionType } from '../posthog-surveys-types'\nimport { getSurveyResponseKey } from '../extensions/surveys/surveys-extension-utils'\nimport { logger } from './logger'\nimport { isUndefined } from '@posthog/core'\nimport { getNextSurveyStep } from './survey-branching'\n\n/**\n * Extracted URL prefill parameters by question index\n */\nexport interface PrefillParams {\n [questionIndex: number]: string[]\n}\n\n/**\n * Extract prefill parameters from URL search string\n * Format: ?q0=1&q1=8&q2=0&q2=2&auto_submit=true\n * NOTE: Manual parsing for IE11/op_mini compatibility (no URLSearchParams)\n */\nexport function extractPrefillParamsFromUrl(searchString: string): {\n params: PrefillParams\n autoSubmit: boolean\n} {\n const params: PrefillParams = {}\n let autoSubmit = false\n\n // Remove leading ? if present\n const cleanSearch = searchString.replace(/^\\?/, '')\n if (!cleanSearch) {\n return { params, autoSubmit }\n }\n\n // Split by & to get key-value pairs\n const pairs = cleanSearch.split('&')\n\n for (const pair of pairs) {\n const [key, value] = pair.split('=')\n if (!key || isUndefined(value)) {\n continue\n }\n\n const decodedKey = decodeURIComponent(key)\n const decodedValue = decodeURIComponent(value)\n\n // Check for auto_submit parameter\n if (decodedKey === 'auto_submit' && decodedValue === 'true') {\n autoSubmit = true\n continue\n }\n\n // Check for question parameters (q0, q1, etc.)\n const match = decodedKey.match(/^q(\\d+)$/)\n if (match) {\n const questionIndex = parseInt(match[1], 10)\n if (!params[questionIndex]) {\n params[questionIndex] = []\n }\n params[questionIndex].push(decodedValue)\n }\n }\n\n return { params, autoSubmit }\n}\n\n/**\n * Convert URL prefill values to SDK response format\n */\nexport function convertPrefillToResponses(survey: Survey, prefillParams: PrefillParams): Record<string, any> {\n const responses: Record<string, any> = {}\n\n survey.questions.forEach((question: SurveyQuestion, index: number) => {\n if (!prefillParams[index] || !question.id) {\n return\n }\n\n const values = prefillParams[index]\n const responseKey = getSurveyResponseKey(question.id)\n\n try {\n switch (question.type) {\n case SurveyQuestionType.SingleChoice: {\n if (!question.choices || question.choices.length === 0) {\n logger.warn(`[Survey Prefill] Question ${index} has no choices`)\n return\n }\n const choiceIndex = parseInt(values[0], 10)\n if (isNaN(choiceIndex) || choiceIndex < 0 || choiceIndex >= question.choices.length) {\n logger.warn(`[Survey Prefill] Invalid choice index for q${index}: ${values[0]}`)\n return\n }\n responses[responseKey] = question.choices[choiceIndex]\n break\n }\n\n case SurveyQuestionType.MultipleChoice: {\n if (!question.choices || question.choices.length === 0) {\n logger.warn(`[Survey Prefill] Question ${index} has no choices`)\n return\n }\n const choiceIndices = values\n .map((v) => parseInt(v, 10))\n .filter((i) => !isNaN(i) && i >= 0 && i < question.choices.length)\n\n if (choiceIndices.length === 0) {\n logger.warn(`[Survey Prefill] No valid choices for q${index}`)\n return\n }\n\n // Remove duplicates and map to choice values\n const uniqueChoices = [...new Set(choiceIndices.map((i) => question.choices[i]))]\n if (uniqueChoices.length < choiceIndices.length) {\n logger.warn(`[Survey Prefill] Removed duplicate choices for q${index}`)\n }\n responses[responseKey] = uniqueChoices\n break\n }\n\n case SurveyQuestionType.Rating: {\n const rating = parseInt(values[0], 10)\n const scale = question.scale || 10\n\n if (isNaN(rating) || rating < 0 || rating > scale) {\n logger.warn(`[Survey Prefill] Invalid rating for q${index}: ${values[0]} (scale: 0-${scale})`)\n return\n }\n responses[responseKey] = rating\n break\n }\n\n default:\n logger.info(`[Survey Prefill] Question type ${question.type} does not support prefill`)\n }\n } catch (error) {\n logger.error(`[Survey Prefill] Error converting q${index}:`, error)\n }\n })\n\n return responses\n}\n\n/**\n * Calculate which question index to start at based on prefilled questions.\n * Advances past consecutive prefilled questions (starting from index 0)\n * that have skipSubmitButton enabled, respecting any branching logic configured\n * on those questions.\n *\n * @param survey - The full survey object (needed for branching logic)\n * @param prefilledIndices - Array of question indices that have been prefilled\n * @param responses - Map of response keys to response values\n * @returns Object with startQuestionIndex and map of questions which have been skipped\n */\nexport function calculatePrefillStartIndex(\n survey: Survey,\n prefilledIndices: number[],\n responses: Record<string, any>\n): { startQuestionIndex: number; skippedResponses: Record<string, any> } {\n let currentIndex = 0\n const skippedResponses: Record<string, any> = {}\n\n const MAX_ITERATIONS = survey.questions.length + 1\n const iterations = 0\n while (currentIndex < survey.questions.length && iterations < MAX_ITERATIONS) {\n // Stop if current question is not prefilled\n if (!prefilledIndices.includes(currentIndex)) {\n break\n }\n\n const question = survey.questions[currentIndex]\n\n // Only advance if the prefilled question has skipSubmitButton\n if (!question || !('skipSubmitButton' in question) || !question.skipSubmitButton) {\n // Show question if skipSubmitButton is false, even if prefilled\n break\n }\n\n // Record the skipped response\n if (question.id) {\n const responseKey = getSurveyResponseKey(question.id)\n if (!isUndefined(responses[responseKey])) {\n skippedResponses[responseKey] = responses[responseKey]\n }\n }\n\n // Use branching logic to determine the next question\n const response = question.id ? responses[getSurveyResponseKey(question.id)] : null\n const nextStep = getNextSurveyStep(survey, currentIndex, response)\n\n if (nextStep === SurveyQuestionBranchingType.End) {\n // Survey is complete - return questions.length to indicate completion\n return { startQuestionIndex: survey.questions.length, skippedResponses }\n }\n\n // Move to the next question (respecting branching)\n currentIndex = nextStep\n }\n\n return { startQuestionIndex: currentIndex, skippedResponses }\n}\n"]}
@@ -1 +1 @@
1
- {"root":["../src/autocapture-utils.ts","../src/autocapture.ts","../src/config.ts","../src/consent.ts","../src/constants.ts","../src/declaration.d.ts","../src/heatmaps.ts","../src/page-view.ts","../src/posthog-conversations-types.ts","../src/posthog-core.ts","../src/posthog-exceptions.ts","../src/posthog-featureflags.ts","../src/posthog-persistence.ts","../src/posthog-product-tours-types.ts","../src/posthog-product-tours.ts","../src/posthog-surveys-types.ts","../src/posthog-surveys.ts","../src/rate-limiter.ts","../src/remote-config.ts","../src/request-queue.ts","../src/request.ts","../src/retry-queue.ts","../src/scroll-manager.ts","../src/session-props.ts","../src/sessionid.ts","../src/site-apps.ts","../src/storage.ts","../src/types.ts","../src/uuidv7.ts","../src/web-experiments-types.ts","../src/web-experiments.ts","../src/web-types.d.ts","../src/customizations/before-send.ts","../src/customizations/index.ts","../src/customizations/posthogReduxLogger.ts","../src/customizations/setAllPersonProfilePropertiesAsPersonPropertiesForFlags.ts","../src/entrypoints/all-external-dependencies.ts","../src/entrypoints/array.full.es5.ts","../src/entrypoints/array.full.no-external.ts","../src/entrypoints/array.full.ts","../src/entrypoints/array.no-external.ts","../src/entrypoints/array.ts","../src/entrypoints/conversations.ts","../src/entrypoints/crisp-chat-integration.ts","../src/entrypoints/customizations.full.ts","../src/entrypoints/dead-clicks-autocapture.ts","../src/entrypoints/exception-autocapture.ts","../src/entrypoints/external-scripts-loader.ts","../src/entrypoints/intercom-integration.ts","../src/entrypoints/lazy-recorder.ts","../src/entrypoints/main.cjs.ts","../src/entrypoints/module.es.ts","../src/entrypoints/module.full.es.ts","../src/entrypoints/module.full.no-external.es.ts","../src/entrypoints/module.no-external.es.ts","../src/entrypoints/posthog-recorder.ts","../src/entrypoints/product-tours-preview.es.ts","../src/entrypoints/product-tours.ts","../src/entrypoints/recorder-v2.ts","../src/entrypoints/recorder.ts","../src/entrypoints/surveys-preview.es.ts","../src/entrypoints/surveys.ts","../src/entrypoints/tracing-headers.ts","../src/entrypoints/web-vitals.ts","../src/extensions/dead-clicks-autocapture.ts","../src/extensions/external-integration.ts","../src/extensions/history-autocapture.ts","../src/extensions/rageclick.ts","../src/extensions/sampling.ts","../src/extensions/segment-integration.ts","../src/extensions/sentry-integration.ts","../src/extensions/surveys.tsx","../src/extensions/toolbar.ts","../src/extensions/tracing-headers.ts","../src/extensions/conversations/posthog-conversations.ts","../src/extensions/conversations/external/index.tsx","../src/extensions/conversations/external/persistence.ts","../src/extensions/conversations/external/components/CloseChatButton.tsx","../src/extensions/conversations/external/components/ConversationsWidget.tsx","../src/extensions/conversations/external/components/OpenChatButton.tsx","../src/extensions/conversations/external/components/SendMessageButton.tsx","../src/extensions/conversations/external/components/styles.ts","../src/extensions/exception-autocapture/index.ts","../src/extensions/product-tours/constants.ts","../src/extensions/product-tours/index.ts","../src/extensions/product-tours/preview.tsx","../src/extensions/product-tours/product-tours-utils.ts","../src/extensions/product-tours/product-tours.tsx","../src/extensions/product-tours/components/ProductTourSurveyStepInner.tsx","../src/extensions/product-tours/components/ProductTourTooltip.tsx","../src/extensions/product-tours/components/ProductTourTooltipInner.tsx","../src/extensions/replay/session-recording.ts","../src/extensions/replay/external/config.ts","../src/extensions/replay/external/denylist.ts","../src/extensions/replay/external/flushed-size-tracker.ts","../src/extensions/replay/external/lazy-loaded-session-recorder.ts","../src/extensions/replay/external/mutation-throttler.ts","../src/extensions/replay/external/network-plugin.ts","../src/extensions/replay/external/sessionrecording-utils.ts","../src/extensions/replay/external/triggerMatching.ts","../src/extensions/replay/rrweb-plugins/patch.ts","../src/extensions/replay/types/rrweb-types.ts","../src/extensions/replay/types/rrweb.ts","../src/extensions/surveys/action-matcher.ts","../src/extensions/surveys/icons.tsx","../src/extensions/surveys/surveys-extension-utils.tsx","../src/extensions/surveys/components/BottomSection.tsx","../src/extensions/surveys/components/ConfirmationMessage.tsx","../src/extensions/surveys/components/PostHogLogo.tsx","../src/extensions/surveys/components/QuestionHeader.tsx","../src/extensions/surveys/components/QuestionTypes.tsx","../src/extensions/utils/stylesheet-loader.ts","../src/extensions/web-vitals/index.ts","../src/utils/blocked-uas.ts","../src/utils/element-utils.ts","../src/utils/elements-chain-utils.ts","../src/utils/encode-utils.ts","../src/utils/event-receiver.ts","../src/utils/event-utils.ts","../src/utils/globals.ts","../src/utils/index.ts","../src/utils/logger.ts","../src/utils/product-tour-event-receiver.ts","../src/utils/product-tour-utils.ts","../src/utils/property-utils.ts","../src/utils/prototype-utils.ts","../src/utils/regex-utils.ts","../src/utils/request-router.ts","../src/utils/request-utils.ts","../src/utils/simple-event-emitter.ts","../src/utils/survey-event-receiver.ts","../src/utils/survey-url-prefill.ts","../src/utils/survey-utils.ts","../src/utils/type-utils.ts"],"version":"5.8.2"}
1
+ {"root":["../src/autocapture-utils.ts","../src/autocapture.ts","../src/config.ts","../src/consent.ts","../src/constants.ts","../src/declaration.d.ts","../src/heatmaps.ts","../src/page-view.ts","../src/posthog-conversations-types.ts","../src/posthog-core.ts","../src/posthog-exceptions.ts","../src/posthog-featureflags.ts","../src/posthog-persistence.ts","../src/posthog-product-tours-types.ts","../src/posthog-product-tours.ts","../src/posthog-surveys-types.ts","../src/posthog-surveys.ts","../src/rate-limiter.ts","../src/remote-config.ts","../src/request-queue.ts","../src/request.ts","../src/retry-queue.ts","../src/scroll-manager.ts","../src/session-props.ts","../src/sessionid.ts","../src/site-apps.ts","../src/storage.ts","../src/types.ts","../src/uuidv7.ts","../src/web-experiments-types.ts","../src/web-experiments.ts","../src/web-types.d.ts","../src/customizations/before-send.ts","../src/customizations/index.ts","../src/customizations/posthogReduxLogger.ts","../src/customizations/setAllPersonProfilePropertiesAsPersonPropertiesForFlags.ts","../src/entrypoints/all-external-dependencies.ts","../src/entrypoints/array.full.es5.ts","../src/entrypoints/array.full.no-external.ts","../src/entrypoints/array.full.ts","../src/entrypoints/array.no-external.ts","../src/entrypoints/array.ts","../src/entrypoints/conversations.ts","../src/entrypoints/crisp-chat-integration.ts","../src/entrypoints/customizations.full.ts","../src/entrypoints/dead-clicks-autocapture.ts","../src/entrypoints/element-inference.es.ts","../src/entrypoints/exception-autocapture.ts","../src/entrypoints/external-scripts-loader.ts","../src/entrypoints/intercom-integration.ts","../src/entrypoints/lazy-recorder.ts","../src/entrypoints/main.cjs.ts","../src/entrypoints/module.es.ts","../src/entrypoints/module.full.es.ts","../src/entrypoints/module.full.no-external.es.ts","../src/entrypoints/module.no-external.es.ts","../src/entrypoints/posthog-recorder.ts","../src/entrypoints/product-tours-preview.es.ts","../src/entrypoints/product-tours.ts","../src/entrypoints/recorder-v2.ts","../src/entrypoints/recorder.ts","../src/entrypoints/surveys-preview.es.ts","../src/entrypoints/surveys.ts","../src/entrypoints/tracing-headers.ts","../src/entrypoints/web-vitals.ts","../src/extensions/dead-clicks-autocapture.ts","../src/extensions/external-integration.ts","../src/extensions/history-autocapture.ts","../src/extensions/rageclick.ts","../src/extensions/sampling.ts","../src/extensions/segment-integration.ts","../src/extensions/sentry-integration.ts","../src/extensions/surveys.tsx","../src/extensions/toolbar.ts","../src/extensions/tracing-headers.ts","../src/extensions/conversations/posthog-conversations.ts","../src/extensions/conversations/external/index.tsx","../src/extensions/conversations/external/persistence.ts","../src/extensions/conversations/external/components/CloseChatButton.tsx","../src/extensions/conversations/external/components/ConversationsWidget.tsx","../src/extensions/conversations/external/components/OpenChatButton.tsx","../src/extensions/conversations/external/components/SendMessageButton.tsx","../src/extensions/conversations/external/components/styles.ts","../src/extensions/exception-autocapture/index.ts","../src/extensions/product-tours/constants.ts","../src/extensions/product-tours/element-inference.ts","../src/extensions/product-tours/index.ts","../src/extensions/product-tours/preview.tsx","../src/extensions/product-tours/product-tours-utils.ts","../src/extensions/product-tours/product-tours.tsx","../src/extensions/product-tours/components/ProductTourSurveyStepInner.tsx","../src/extensions/product-tours/components/ProductTourTooltip.tsx","../src/extensions/product-tours/components/ProductTourTooltipInner.tsx","../src/extensions/replay/session-recording.ts","../src/extensions/replay/external/config.ts","../src/extensions/replay/external/denylist.ts","../src/extensions/replay/external/flushed-size-tracker.ts","../src/extensions/replay/external/lazy-loaded-session-recorder.ts","../src/extensions/replay/external/mutation-throttler.ts","../src/extensions/replay/external/network-plugin.ts","../src/extensions/replay/external/sessionrecording-utils.ts","../src/extensions/replay/external/triggerMatching.ts","../src/extensions/replay/rrweb-plugins/patch.ts","../src/extensions/replay/types/rrweb-types.ts","../src/extensions/replay/types/rrweb.ts","../src/extensions/surveys/action-matcher.ts","../src/extensions/surveys/icons.tsx","../src/extensions/surveys/surveys-extension-utils.tsx","../src/extensions/surveys/components/BottomSection.tsx","../src/extensions/surveys/components/ConfirmationMessage.tsx","../src/extensions/surveys/components/PostHogLogo.tsx","../src/extensions/surveys/components/QuestionHeader.tsx","../src/extensions/surveys/components/QuestionTypes.tsx","../src/extensions/utils/stylesheet-loader.ts","../src/extensions/web-vitals/index.ts","../src/utils/blocked-uas.ts","../src/utils/element-utils.ts","../src/utils/elements-chain-utils.ts","../src/utils/encode-utils.ts","../src/utils/event-receiver.ts","../src/utils/event-utils.ts","../src/utils/globals.ts","../src/utils/index.ts","../src/utils/logger.ts","../src/utils/product-tour-event-receiver.ts","../src/utils/product-tour-utils.ts","../src/utils/property-utils.ts","../src/utils/prototype-utils.ts","../src/utils/regex-utils.ts","../src/utils/request-router.ts","../src/utils/request-utils.ts","../src/utils/simple-event-emitter.ts","../src/utils/survey-branching.ts","../src/utils/survey-event-receiver.ts","../src/utils/survey-url-prefill.ts","../src/utils/survey-utils.ts","../src/utils/type-utils.ts"],"version":"5.8.2"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "posthog-js",
3
- "version": "1.316.0",
3
+ "version": "1.317.0",
4
4
  "description": "Posthog-js allows you to automatically capture usage and send events to PostHog.",
5
5
  "repository": "https://github.com/PostHog/posthog-js",
6
6
  "author": "hey@posthog.com",
@@ -17,11 +17,13 @@
17
17
  ],
18
18
  "dependencies": {
19
19
  "core-js": "^3.38.1",
20
+ "dompurify": "^3.3.1",
20
21
  "fflate": "^0.4.8",
21
22
  "preact": "^10.19.3",
23
+ "query-selector-shadow-dom": "^1.0.1",
22
24
  "web-vitals": "^4.2.4",
23
- "@posthog/core": "1.9.1",
24
- "@posthog/types": "1.316.0"
25
+ "@posthog/types": "1.317.0",
26
+ "@posthog/core": "1.9.1"
25
27
  },
26
28
  "devDependencies": {
27
29
  "@babel/core": "^7.27.1",
@@ -49,9 +51,11 @@
49
51
  "@testing-library/dom": "^10.4.1",
50
52
  "@testing-library/jest-dom": "^6.9.1",
51
53
  "@testing-library/preact": "^3.2.4",
54
+ "@types/dompurify": "^3.2.0",
52
55
  "@types/dotenv": "^8.2.3",
53
56
  "@types/jest": "^29.5.14",
54
57
  "@types/node": "^22.5.0",
58
+ "@types/query-selector-shadow-dom": "^1.0.4",
55
59
  "@types/sinon": "^17.0.1",
56
60
  "@types/web": "^0.0.222",
57
61
  "babel-jest": "^29.7.0",