@posthog/browser-common 0.9.4 → 0.9.6
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.
- package/dist/client.d.ts +6 -0
- package/dist/config.js +1 -1
- package/dist/config.mjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +58 -10
- package/dist/index.mjs +1 -0
- package/dist/survey-action-matcher.d.ts +27 -0
- package/dist/survey-action-matcher.js +169 -0
- package/dist/survey-action-matcher.mjs +131 -0
- package/dist/survey-constants.d.ts +86 -0
- package/dist/survey-constants.js +144 -0
- package/dist/survey-constants.mjs +76 -0
- package/dist/survey-event-host.d.ts +15 -0
- package/dist/survey-event-host.js +18 -0
- package/dist/survey-event-host.mjs +1 -0
- package/dist/survey-event-receiver-base.d.ts +180 -0
- package/dist/survey-event-receiver-base.js +354 -0
- package/dist/survey-event-receiver-base.mjs +316 -0
- package/dist/survey-event-receiver.d.ts +36 -0
- package/dist/survey-event-receiver.js +133 -0
- package/dist/survey-event-receiver.mjs +95 -0
- package/dist/survey-render-context.d.ts +13 -0
- package/dist/survey-render-context.js +45 -0
- package/dist/survey-render-context.mjs +7 -0
- package/dist/surveys/components/BottomSection.d.ts +12 -0
- package/dist/surveys/components/BottomSection.js +82 -0
- package/dist/surveys/components/BottomSection.mjs +44 -0
- package/dist/surveys/components/ConfirmationMessage.d.ts +10 -0
- package/dist/surveys/components/ConfirmationMessage.js +92 -0
- package/dist/surveys/components/ConfirmationMessage.mjs +54 -0
- package/dist/surveys/components/IntroScreen.d.ts +10 -0
- package/dist/surveys/components/IntroScreen.js +78 -0
- package/dist/surveys/components/IntroScreen.mjs +40 -0
- package/dist/surveys/components/PostHogLogo.d.ts +5 -0
- package/dist/surveys/components/PostHogLogo.js +54 -0
- package/dist/surveys/components/PostHogLogo.mjs +16 -0
- package/dist/surveys/components/QuestionHeader.d.ts +10 -0
- package/dist/surveys/components/QuestionHeader.js +82 -0
- package/dist/surveys/components/QuestionHeader.mjs +41 -0
- package/dist/surveys/components/QuestionTypes.d.ts +31 -0
- package/dist/surveys/components/QuestionTypes.js +519 -0
- package/dist/surveys/components/QuestionTypes.mjs +469 -0
- package/dist/surveys/icons.d.ts +12 -0
- package/dist/surveys/icons.js +212 -0
- package/dist/surveys/icons.mjs +147 -0
- package/dist/surveys/survey-branching.d.ts +12 -0
- package/dist/surveys/survey-branching.js +101 -0
- package/dist/surveys/survey-branching.mjs +60 -0
- package/dist/surveys/survey-styles.d.ts +1 -0
- package/dist/surveys/survey-styles.js +40 -0
- package/dist/surveys/survey-styles.mjs +2 -0
- package/dist/surveys/survey-translations.d.ts +22 -0
- package/dist/surveys/survey-translations.js +68 -0
- package/dist/surveys/survey-translations.mjs +27 -0
- package/dist/surveys/survey-url-prefill.d.ts +36 -0
- package/dist/surveys/survey-url-prefill.js +162 -0
- package/dist/surveys/survey-url-prefill.mjs +118 -0
- package/dist/surveys/surveys-extension-utils.d.ts +133 -0
- package/dist/surveys/surveys-extension-utils.js +739 -0
- package/dist/surveys/surveys-extension-utils.mjs +608 -0
- package/dist/surveys-config.d.ts +60 -0
- package/dist/surveys-config.js +68 -0
- package/dist/surveys-config.mjs +9 -0
- package/dist/surveys-renderer.d.ts +248 -0
- package/dist/surveys-renderer.js +1299 -0
- package/dist/surveys-renderer.mjs +1230 -0
- package/dist/surveys.d.ts +117 -0
- package/dist/surveys.js +566 -0
- package/dist/surveys.mjs +495 -0
- package/dist/types/surveys.d.ts +83 -86
- package/dist/types/surveys.js +1 -127
- package/dist/types/surveys.mjs +1 -76
- package/dist/utils/autocapture-utils.js +8 -9
- package/dist/utils/autocapture-utils.mjs +8 -9
- package/dist/utils/event-utils.js +1 -0
- package/dist/utils/event-utils.mjs +1 -0
- package/dist/utils/matcher-utils.d.ts +1 -1
- package/dist/utils/matcher-utils.js +13 -10
- package/dist/utils/matcher-utils.mjs +10 -7
- package/dist/utils/survey-utils.d.ts +16 -0
- package/dist/utils/survey-utils.js +121 -0
- package/dist/utils/survey-utils.mjs +38 -0
- package/dist/utils/url-targeting-utils.d.ts +3 -1
- package/dist/utils/url-targeting-utils.js +1 -2
- package/dist/utils/url-targeting-utils.mjs +1 -2
- package/dist/utils/uuidv7.js +4 -4
- package/dist/utils/uuidv7.mjs +4 -4
- package/package.json +97 -3
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const surveyStyles = ':host{--ph-survey-font-family:-apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", "Roboto", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";--ph-survey-box-padding:20px 24px;--ph-survey-max-width:300px;--ph-survey-z-index:calc(2147480000 + 3645);--ph-survey-border-color:#dcdcdc;--ph-survey-border-bottom:1.5px solid var(--ph-survey-border-color);--ph-survey-border-radius:10px;--ph-survey-background-color:#eeeded;--ph-survey-box-shadow:0 4px 12px #00000026;--ph-survey-submit-button-color:black;--ph-survey-submit-button-text-color:white;--ph-survey-rating-bg-color:white;--ph-survey-rating-text-color:#020617;--ph-survey-rating-active-bg-color:black;--ph-survey-rating-active-text-color:white;--ph-survey-text-primary-color:#020617;--ph-survey-text-subtle-color:#939393;--ph-widget-color:#e0a045;--ph-widget-text-color:white;--ph-survey-scrollbar-thumb-color:var(--ph-survey-border-color);--ph-survey-scrollbar-track-color:var(--ph-survey-background-color);--ph-survey-outline-color:#3b82f6cc;--ph-survey-input-background:white;--ph-survey-input-text-color:#020617;--ph-survey-disabled-button-opacity:.6}.ph-survey{min-width:300px;width:var(--ph-survey-max-width);max-width:85%;z-index:var(--ph-survey-z-index);height:fit-content;margin:0;position:fixed;bottom:0}.ph-survey h3,.ph-survey p{margin:0}.ph-survey *{box-sizing:border-box;font-family:var(--ph-survey-font-family);color:var(--ph-survey-text-primary-color)}.ph-survey textarea,.ph-survey input[type=text],.ph-survey .multiple-choice-options label{color:var(--ph-survey-input-text-color);background:var(--ph-survey-input-background);border:1.5px solid var(--ph-survey-border-color);border-radius:4px;padding:10px;transition:border-color .2s ease-out,box-shadow .2s ease-out,transform .15s ease-out}.ph-survey textarea,.ph-survey input[type=text]{transition:border-color .2s ease-out,box-shadow .2s ease-out,transform .15s ease-out}.ph-survey input{margin:0}.ph-survey textarea:focus,.ph-survey textarea:focus-visible,.ph-survey input[type=text]:focus,.ph-survey input[type=text]:focus-visible,.ph-survey .form-submit:focus,.ph-survey .form-submit:focus-visible,.ph-survey input[type=checkbox]:focus,.ph-survey input[type=radio]:focus,.ph-survey input[type=checkbox]:focus-visible,.ph-survey input[type=radio]:focus-visible{outline:1.5px solid var(--ph-survey-outline-color);border-color:var(--ph-survey-rating-active-bg-color);outline-offset:2px}.ph-survey textarea:focus:not(:focus-visible),.ph-survey input[type=text]:focus:not(:focus-visible),.ph-survey button:focus:not(:focus-visible),.ph-survey input[type=checkbox]:focus:not(:focus-visible),.ph-survey input[type=radio]:focus:not(:focus-visible){outline:none}.ph-survey textarea:hover:not(:focus),.ph-survey input[type=text]:hover:not(:focus){border-color:var(--ph-survey-rating-active-bg-color)}@media (max-width:768px){.ph-survey textarea,.ph-survey input[type=text]{font-size:1rem}}.ph-survey .multiple-choice-options label,.ph-survey .rating-options-number,.ph-survey .form-cancel,.ph-survey input[type=checkbox],.ph-survey input[type=radio]{border:1.5px solid var(--ph-survey-border-color)}.ph-survey label,.ph-survey input[type=checkbox],.ph-survey input[type=radio],.ph-survey .ratings-emoji,.ph-survey .ratings-number,.ph-survey .footer-branding,.ph-survey .form-cancel,.ph-survey .form-submit{transition:all .2s ease-out}@media (prefers-reduced-motion:no-preference){.ph-survey button:active,.ph-survey input[type=checkbox]:active,.ph-survey input[type=radio]:active,.ph-survey label:active{transition-duration:.1s}}.ph-survey-widget-tab{background:var(--ph-widget-color);color:var(--ph-widget-text-color);text-align:center;cursor:pointer;z-index:var(--ph-survey-z-index);border:none;border-radius:3px 3px 0 0;padding:10px 12px;transition:padding .2s ease-out;position:fixed}.ph-survey-widget-tab:hover:not(.widget-tab-top){padding-bottom:16px}.ph-survey-widget-tab.widget-tab-top{border-radius:0 0 3px 3px}.ph-survey-widget-tab.widget-tab-top:hover{padding-top:16px}@keyframes ph-survey-fade-in{0%{opacity:0}to{opacity:1}}.survey-box{flex-direction:column;gap:16px;display:flex}.bottom-section{flex-direction:column;gap:8px;display:flex}.thank-you-message-header~.bottom-section,.intro-screen-header~.bottom-section{padding-top:16px}.question-container,.thank-you-message,.intro-screen{flex-direction:column;gap:8px;display:flex}.survey-question{font-size:14px;font-weight:500}.survey-question-description{opacity:.8;padding-top:4px;font-size:13px}.survey-question-description,.thank-you-message-body,.intro-screen-body{word-wrap:break-word;overflow-wrap:break-word}:is(.survey-question-description,.thank-you-message-body,.intro-screen-body) img,:is(.survey-question-description,.thank-you-message-body,.intro-screen-body) video,:is(.survey-question-description,.thank-you-message-body,.intro-screen-body) iframe,:is(.survey-question-description,.thank-you-message-body,.intro-screen-body) embed,:is(.survey-question-description,.thank-you-message-body,.intro-screen-body) object,:is(.survey-question-description,.thank-you-message-body,.intro-screen-body) svg{max-width:100%;height:auto}.question-textarea-wrapper{flex-direction:column;display:flex}.survey-form{animation:.3s ease-out forwards ph-survey-fade-in}.survey-form,.thank-you-message,.intro-screen{text-align:left;width:100%;z-index:var(--ph-survey-z-index);border:1.5px solid var(--ph-survey-border-color);border-bottom:var(--ph-survey-border-bottom);background:var(--ph-survey-background-color);border-radius:var(--ph-survey-border-radius);box-shadow:var(--ph-survey-box-shadow);padding:var(--ph-survey-box-padding);margin:0;position:relative}.survey-form textarea,.survey-form input[type=text]{min-width:100%}.survey-form textarea:focus,.survey-form textarea:focus-visible{box-shadow:0 4px 12px #00000014}.survey-form textarea:focus:not(:focus-visible){box-shadow:none}.survey-box .question-header--empty~.multiple-choice-options,.survey-box .question-header--empty~textarea{margin-top:0}.multiple-choice-options{border:none;flex-direction:column;gap:8px;margin:0;padding:1px 0;font-size:14px;display:flex}.multiple-choice-options label,.multiple-choice-options .response-choice{color:inherit;align-items:center;gap:8px;display:flex}.multiple-choice-options label{cursor:pointer;font-size:13px}.multiple-choice-options label:hover:not(:has(input:checked)){border-color:var(--ph-survey-text-subtle-color);box-shadow:0 2px 8px #00000014}.multiple-choice-options label:has(input:checked){border-color:var(--ph-survey-rating-active-bg-color);box-shadow:0 1px 4px #0000000d}.multiple-choice-options label.choice-option-open{flex-wrap:wrap}.multiple-choice-options label span{color:inherit}.multiple-choice-options input[type=checkbox],.multiple-choice-options input[type=radio]{-webkit-appearance:none;-moz-appearance:none;appearance:none;background:var(--ph-survey-input-background);cursor:pointer;z-index:1;border-radius:3px;flex-shrink:0;width:1rem;height:1rem;transition:all .2s cubic-bezier(.4,0,.2,1),transform .15s ease-out;position:relative}:is(.multiple-choice-options input[type=checkbox],.multiple-choice-options input[type=radio]):focus{transform:scale(1.05)}:is(.multiple-choice-options input[type=checkbox],.multiple-choice-options input[type=radio]):hover{border-color:var(--ph-survey-rating-active-bg-color);transform:scale(1.05)}:is(.multiple-choice-options input[type=checkbox],.multiple-choice-options input[type=radio]):active{transform:scale(.95)}:is(.multiple-choice-options input[type=checkbox],.multiple-choice-options input[type=radio]):checked{background:var(--ph-survey-rating-active-bg-color);border-color:var(--ph-survey-rating-active-bg-color);transform:scale(1)}:is(.multiple-choice-options input[type=checkbox],.multiple-choice-options input[type=radio]):checked:hover{transform:scale(1.05)}.multiple-choice-options input[type=checkbox]:checked:after{border:solid var(--ph-survey-rating-active-text-color);border-width:0 2px 2px 0;width:4px;height:8px;animation:.2s ease-out .1s forwards ph-survey-checkmark-reveal;left:4px;transform:rotate(45deg)scale(0)}.multiple-choice-options input[type=radio]:checked:after{background:var(--ph-survey-rating-active-text-color);border-radius:50%;width:6px;height:6px;animation:.15s ease-out 50ms forwards ph-survey-radio-reveal;top:5px;left:5px;transform:scale(0)}.multiple-choice-options input[type=checkbox]:checked:after,.multiple-choice-options input[type=radio]:checked:after{content:"";box-sizing:content-box;position:absolute}.multiple-choice-options input[type=radio]{border-radius:50%}.multiple-choice-options input[type=radio]:checked{border:none}:is(.multiple-choice-options input[type=checkbox]:checked,.multiple-choice-options input[type=radio]:checked)~*{font-weight:700}.multiple-choice-options .choice-option-open input[type=text]::placeholder{color:var(--ph-survey-text-subtle-color);font-weight:400}.rating-options-emoji{justify-content:space-between;display:flex}.rating-options-emoji-2{justify-content:space-around}.ratings-emoji{opacity:.5;background-color:#0000;border:none;padding:0;font-size:16px}.ratings-emoji:hover{cursor:pointer;opacity:1;transform:scale(1.15)}.ratings-emoji.rating-active{opacity:1}.ratings-emoji svg{fill:var(--ph-survey-text-primary-color);transition:fill .2s ease-out}.rating-options-number{border-radius:6px;grid-auto-columns:1fr;grid-auto-flow:column;display:grid;overflow:hidden}.rating-options-number .ratings-number{border-right:1px solid var(--ph-survey-border-color);text-align:center;cursor:pointer;color:var(--ph-survey-rating-text-color);border-top:none;border-bottom:none;border-left:none;font-weight:700}.rating-options-number .ratings-number:last-of-type{border-right:0}.rating-options-number .ratings-number.rating-active{background:var(--ph-survey-rating-active-bg-color);color:var(--ph-survey-rating-active-text-color)}.ratings-number{background-color:var(--ph-survey-rating-bg-color);border:none;padding:8px 0}.ratings-number .rating-active{background-color:var(--ph-survey-rating-active-bg-color)}.ratings-number{cursor:pointer}@media (hover:hover) and (pointer:fine){.ratings-number:hover:not(.rating-active){background-color:color-mix(in srgb, var(--ph-survey-rating-active-bg-color) 14%, var(--ph-survey-rating-bg-color))}}.rating-text{opacity:.7;flex-direction:row;justify-content:space-between;font-size:11px;display:flex}.form-buttons{flex-direction:row;gap:8px;width:100%;display:flex}.form-buttons-with-back>.form-submit{flex:auto;min-width:0}.form-submit{text-align:center;cursor:pointer;user-select:none;background:var(--ph-survey-submit-button-color);color:var(--ph-survey-submit-button-text-color);border:none;border-radius:6px;min-width:100%;padding:12px;font-weight:700;box-shadow:0 2px #0000000b}.form-submit:not([disabled]):hover{transform:scale(1.02);box-shadow:0 4px 8px #0000001a}.form-submit:not([disabled]):active{transform:scale(.98);box-shadow:0 1px 2px #0000000d}.form-submit[disabled]{opacity:var(--ph-survey-disabled-button-opacity);cursor:not-allowed}.form-back{text-align:center;cursor:pointer;user-select:none;color:var(--ph-survey-text-primary-color);border:1.5px solid var(--ph-survey-border-color);background:0 0;border-radius:6px;flex:none;padding:12px 16px;font-weight:600}.form-back:hover{transform:scale(1.02)}.form-back:active{transform:scale(.98)}.validation-hint{opacity:.7;margin-top:4px;font-size:12px}.form-cancel{cursor:pointer;background:#fff;border-radius:100%;padding:12px;line-height:0;position:absolute;top:0;right:0;transform:translate(50%,-50%)}.form-cancel:hover{opacity:.7;transform:translate(50%,-50%)scale(1.1)}.footer-branding{opacity:.6;justify-content:center;align-items:center;gap:4px;font-size:11px;font-weight:500;text-decoration:none;display:flex}.footer-branding:hover{opacity:1}.footer-branding a{text-decoration:none}.thank-you-message{text-align:center}.thank-you-message-header{margin:10px 0 0}.thank-you-message-body{opacity:.8;font-size:14px}.intro-screen{text-align:center;animation:.3s ease-out forwards ph-survey-fade-in}.intro-screen-header{margin:10px 0 0}.intro-screen-body{opacity:.8;font-size:14px}.limit-height{scrollbar-width:thin;scrollbar-color:var(--ph-survey-scrollbar-thumb-color) var(--ph-survey-scrollbar-track-color);max-height:256px;overflow:hidden auto}.limit-height::-webkit-scrollbar{width:8px}.limit-height::-webkit-scrollbar-track{background:var(--ph-survey-scrollbar-track-color);border-radius:4px}.limit-height::-webkit-scrollbar-thumb{background-color:var(--ph-survey-scrollbar-thumb-color);border:2px solid var(--ph-survey-scrollbar-track-color);border-radius:4px}.limit-height::-webkit-scrollbar-thumb:hover{background-color:var(--ph-survey-text-subtle-color)}.sr-only{clip:rect(0, 0, 0, 0);white-space:nowrap;border:0;width:1px;height:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}@media (prefers-reduced-motion:reduce){.ph-survey *{scroll-behavior:auto!important;transition-duration:.01ms!important;animation-duration:.01ms!important;animation-iteration-count:1!important}}@keyframes ph-survey-checkmark-reveal{0%{opacity:0;transform:rotate(45deg)scale(0)}50%{opacity:1;transform:rotate(45deg)scale(1.2)}to{opacity:1;transform:rotate(45deg)scale(1)}}@keyframes ph-survey-radio-reveal{0%{opacity:0;transform:scale(0)}50%{opacity:1;transform:scale(1.3)}to{opacity:1;transform:scale(1)}}';
|
|
2
|
+
export { surveyStyles };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SurveyRenderContext } from '../survey-render-context';
|
|
2
|
+
import type { Survey } from '../types/surveys';
|
|
3
|
+
/**
|
|
4
|
+
* Detects the user's language using priority order:
|
|
5
|
+
* 1. config.override_display_language (explicit override)
|
|
6
|
+
* 2. person properties 'language' (allows programmatic control via posthog.identify())
|
|
7
|
+
* 3. navigator.language or navigator.userLanguage (browser language)
|
|
8
|
+
*
|
|
9
|
+
* @param instance - SurveyRenderContext instance to retrieve config and person properties
|
|
10
|
+
* @returns The detected language code (e.g., 'fr', 'es', 'en-US') or null if not found
|
|
11
|
+
*/
|
|
12
|
+
export declare function detectUserLanguage(instance: SurveyRenderContext): string | null;
|
|
13
|
+
/**
|
|
14
|
+
* Applies translations to a survey based on the user's language from person properties
|
|
15
|
+
* @param survey - The original survey object
|
|
16
|
+
* @param instance - SurveyRenderContext instance to retrieve person properties
|
|
17
|
+
* @returns An object containing the translated survey and the language used (or null if no translation applied)
|
|
18
|
+
*/
|
|
19
|
+
export declare function applySurveyTranslationForUser(survey: Survey, instance: SurveyRenderContext): {
|
|
20
|
+
survey: Survey;
|
|
21
|
+
language: string | null;
|
|
22
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
applySurveyTranslationForUser: ()=>applySurveyTranslationForUser,
|
|
32
|
+
detectUserLanguage: ()=>detectUserLanguage
|
|
33
|
+
});
|
|
34
|
+
const external_constants_js_namespaceObject = require("../constants.js");
|
|
35
|
+
const logger_js_namespaceObject = require("../utils/logger.js");
|
|
36
|
+
const surveys_namespaceObject = require("@posthog/core/surveys");
|
|
37
|
+
const logger = (0, logger_js_namespaceObject.createLogger)('[SurveyTranslations]');
|
|
38
|
+
function detectUserLanguage(instance) {
|
|
39
|
+
return (0, surveys_namespaceObject.detectSurveyLanguage)({
|
|
40
|
+
overrideLanguage: instance.config.overrideLanguage,
|
|
41
|
+
storedPersonProperties: instance.client?.kv.get(external_constants_js_namespaceObject.STORED_PERSON_PROPERTIES_KEY),
|
|
42
|
+
locale: "u" > typeof navigator ? navigator.language || navigator.userLanguage : void 0
|
|
43
|
+
}, logger);
|
|
44
|
+
}
|
|
45
|
+
function applySurveyTranslationForUser(survey, instance) {
|
|
46
|
+
const userLanguage = detectUserLanguage(instance);
|
|
47
|
+
if (!userLanguage) {
|
|
48
|
+
logger.info('No user language detected');
|
|
49
|
+
return {
|
|
50
|
+
survey,
|
|
51
|
+
language: null
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const result = (0, surveys_namespaceObject.applySurveyTranslation)(survey, userLanguage, logger);
|
|
55
|
+
return {
|
|
56
|
+
survey: result.survey,
|
|
57
|
+
language: result.matchedKey
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
exports.applySurveyTranslationForUser = __webpack_exports__.applySurveyTranslationForUser;
|
|
61
|
+
exports.detectUserLanguage = __webpack_exports__.detectUserLanguage;
|
|
62
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
63
|
+
"applySurveyTranslationForUser",
|
|
64
|
+
"detectUserLanguage"
|
|
65
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
66
|
+
Object.defineProperty(exports, '__esModule', {
|
|
67
|
+
value: true
|
|
68
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { STORED_PERSON_PROPERTIES_KEY } from "../constants.mjs";
|
|
2
|
+
import { createLogger } from "../utils/logger.mjs";
|
|
3
|
+
import { applySurveyTranslation, detectSurveyLanguage } from "@posthog/core/surveys";
|
|
4
|
+
const logger = createLogger('[SurveyTranslations]');
|
|
5
|
+
function detectUserLanguage(instance) {
|
|
6
|
+
return detectSurveyLanguage({
|
|
7
|
+
overrideLanguage: instance.config.overrideLanguage,
|
|
8
|
+
storedPersonProperties: instance.client?.kv.get(STORED_PERSON_PROPERTIES_KEY),
|
|
9
|
+
locale: "u" > typeof navigator ? navigator.language || navigator.userLanguage : void 0
|
|
10
|
+
}, logger);
|
|
11
|
+
}
|
|
12
|
+
function applySurveyTranslationForUser(survey, instance) {
|
|
13
|
+
const userLanguage = detectUserLanguage(instance);
|
|
14
|
+
if (!userLanguage) {
|
|
15
|
+
logger.info('No user language detected');
|
|
16
|
+
return {
|
|
17
|
+
survey,
|
|
18
|
+
language: null
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const result = applySurveyTranslation(survey, userLanguage, logger);
|
|
22
|
+
return {
|
|
23
|
+
survey: result.survey,
|
|
24
|
+
language: result.matchedKey
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export { applySurveyTranslationForUser, detectUserLanguage };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Survey } from '../types/surveys';
|
|
2
|
+
/**
|
|
3
|
+
* Extracted URL prefill parameters by question index
|
|
4
|
+
*/
|
|
5
|
+
export interface PrefillParams {
|
|
6
|
+
[questionIndex: number]: string[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Extract prefill parameters from URL search string
|
|
10
|
+
* Format: ?q0=1&q1=8&q2=0&q2=2&auto_submit=true
|
|
11
|
+
* NOTE: Manual parsing for IE11/op_mini compatibility (no URLSearchParams)
|
|
12
|
+
*/
|
|
13
|
+
export declare function extractPrefillParamsFromUrl(searchString: string): {
|
|
14
|
+
params: PrefillParams;
|
|
15
|
+
autoSubmit: boolean;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Convert URL prefill values to SDK response format
|
|
19
|
+
*/
|
|
20
|
+
export declare function convertPrefillToResponses(survey: Survey, prefillParams: PrefillParams): Record<string, any>;
|
|
21
|
+
/**
|
|
22
|
+
* Calculate which question index to start at based on prefilled questions.
|
|
23
|
+
* Advances past consecutive prefilled questions (starting from index 0)
|
|
24
|
+
* that have skipSubmitButton enabled, respecting any branching logic configured
|
|
25
|
+
* on those questions.
|
|
26
|
+
*
|
|
27
|
+
* @param survey - The full survey object (needed for branching logic)
|
|
28
|
+
* @param prefilledIndices - Array of question indices that have been prefilled
|
|
29
|
+
* @param responses - Map of response keys to response values
|
|
30
|
+
* @returns Object with startQuestionIndex and map of questions which have been skipped
|
|
31
|
+
*/
|
|
32
|
+
export declare function calculatePrefillStartIndex(survey: Survey, prefilledIndices: number[], responses: Record<string, any>): {
|
|
33
|
+
startQuestionIndex: number;
|
|
34
|
+
skippedResponses: Record<string, any>;
|
|
35
|
+
skippedIndices: number[];
|
|
36
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
calculatePrefillStartIndex: ()=>calculatePrefillStartIndex,
|
|
32
|
+
convertPrefillToResponses: ()=>convertPrefillToResponses,
|
|
33
|
+
extractPrefillParamsFromUrl: ()=>extractPrefillParamsFromUrl
|
|
34
|
+
});
|
|
35
|
+
const external_survey_constants_js_namespaceObject = require("../survey-constants.js");
|
|
36
|
+
const external_surveys_extension_utils_js_namespaceObject = require("./surveys-extension-utils.js");
|
|
37
|
+
const logger_js_namespaceObject = require("../utils/logger.js");
|
|
38
|
+
const core_namespaceObject = require("@posthog/core");
|
|
39
|
+
const external_survey_branching_js_namespaceObject = require("./survey-branching.js");
|
|
40
|
+
function extractPrefillParamsFromUrl(searchString) {
|
|
41
|
+
const params = {};
|
|
42
|
+
let autoSubmit = false;
|
|
43
|
+
const cleanSearch = searchString.replace(/^\?/, '');
|
|
44
|
+
if (!cleanSearch) return {
|
|
45
|
+
params,
|
|
46
|
+
autoSubmit
|
|
47
|
+
};
|
|
48
|
+
const pairs = cleanSearch.split('&');
|
|
49
|
+
for (const pair of pairs){
|
|
50
|
+
const separator = pair.indexOf('=');
|
|
51
|
+
if (separator <= 0) continue;
|
|
52
|
+
let decodedKey;
|
|
53
|
+
let decodedValue;
|
|
54
|
+
try {
|
|
55
|
+
decodedKey = decodeURIComponent(pair.slice(0, separator));
|
|
56
|
+
decodedValue = decodeURIComponent(pair.slice(separator + 1));
|
|
57
|
+
} catch {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if ('auto_submit' === decodedKey && 'true' === decodedValue) {
|
|
61
|
+
autoSubmit = true;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const match = decodedKey.match(/^q(\d+)$/);
|
|
65
|
+
if (match) {
|
|
66
|
+
const questionIndex = parseInt(match[1], 10);
|
|
67
|
+
if (!params[questionIndex]) params[questionIndex] = [];
|
|
68
|
+
params[questionIndex].push(decodedValue);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
params,
|
|
73
|
+
autoSubmit
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function convertPrefillToResponses(survey, prefillParams) {
|
|
77
|
+
const responses = {};
|
|
78
|
+
survey.questions.forEach((question, index)=>{
|
|
79
|
+
if (!prefillParams[index] || !question.id) return;
|
|
80
|
+
const values = prefillParams[index];
|
|
81
|
+
const responseKey = (0, external_surveys_extension_utils_js_namespaceObject.getSurveyResponseKey)(question.id);
|
|
82
|
+
try {
|
|
83
|
+
switch(question.type){
|
|
84
|
+
case external_survey_constants_js_namespaceObject.SurveyQuestionType.SingleChoice:
|
|
85
|
+
{
|
|
86
|
+
if (!question.choices || 0 === question.choices.length) return void logger_js_namespaceObject.logger.warn(`[Survey Prefill] Question ${index} has no choices`);
|
|
87
|
+
const choiceIndex = parseInt(values[0], 10);
|
|
88
|
+
if (isNaN(choiceIndex) || choiceIndex < 0 || choiceIndex >= question.choices.length) return void logger_js_namespaceObject.logger.warn(`[Survey Prefill] Invalid choice index for q${index}: ${values[0]}`);
|
|
89
|
+
responses[responseKey] = question.choices[choiceIndex];
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
case external_survey_constants_js_namespaceObject.SurveyQuestionType.MultipleChoice:
|
|
93
|
+
{
|
|
94
|
+
if (!question.choices || 0 === question.choices.length) return void logger_js_namespaceObject.logger.warn(`[Survey Prefill] Question ${index} has no choices`);
|
|
95
|
+
const choiceIndices = values.map((v)=>parseInt(v, 10)).filter((i)=>!isNaN(i) && i >= 0 && i < question.choices.length);
|
|
96
|
+
if (0 === choiceIndices.length) return void logger_js_namespaceObject.logger.warn(`[Survey Prefill] No valid choices for q${index}`);
|
|
97
|
+
const uniqueChoices = [
|
|
98
|
+
...new Set(choiceIndices.map((i)=>question.choices[i]))
|
|
99
|
+
];
|
|
100
|
+
if (uniqueChoices.length < choiceIndices.length) logger_js_namespaceObject.logger.warn(`[Survey Prefill] Removed duplicate choices for q${index}`);
|
|
101
|
+
responses[responseKey] = uniqueChoices;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
case external_survey_constants_js_namespaceObject.SurveyQuestionType.Rating:
|
|
105
|
+
{
|
|
106
|
+
const rating = parseInt(values[0], 10);
|
|
107
|
+
const scale = question.scale || 10;
|
|
108
|
+
if (isNaN(rating) || rating < 0 || rating > scale) return void logger_js_namespaceObject.logger.warn(`[Survey Prefill] Invalid rating for q${index}: ${values[0]} (scale: 0-${scale})`);
|
|
109
|
+
responses[responseKey] = rating;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
default:
|
|
113
|
+
logger_js_namespaceObject.logger.info(`[Survey Prefill] Question type ${question.type} does not support prefill`);
|
|
114
|
+
}
|
|
115
|
+
} catch (error) {
|
|
116
|
+
logger_js_namespaceObject.logger.error(`[Survey Prefill] Error converting q${index}:`, error);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
return responses;
|
|
120
|
+
}
|
|
121
|
+
function calculatePrefillStartIndex(survey, prefilledIndices, responses) {
|
|
122
|
+
let currentIndex = 0;
|
|
123
|
+
const skippedResponses = {};
|
|
124
|
+
const skippedIndices = [];
|
|
125
|
+
const MAX_ITERATIONS = survey.questions.length + 1;
|
|
126
|
+
let iterations = 0;
|
|
127
|
+
while(currentIndex < survey.questions.length && iterations < MAX_ITERATIONS){
|
|
128
|
+
iterations++;
|
|
129
|
+
if (!prefilledIndices.includes(currentIndex)) break;
|
|
130
|
+
const question = survey.questions[currentIndex];
|
|
131
|
+
if (!question || !('skipSubmitButton' in question) || !question.skipSubmitButton) break;
|
|
132
|
+
if (question.id) {
|
|
133
|
+
const responseKey = (0, external_surveys_extension_utils_js_namespaceObject.getSurveyResponseKey)(question.id);
|
|
134
|
+
if (!(0, core_namespaceObject.isUndefined)(responses[responseKey])) skippedResponses[responseKey] = responses[responseKey];
|
|
135
|
+
}
|
|
136
|
+
skippedIndices.push(currentIndex);
|
|
137
|
+
const response = question.id ? responses[(0, external_surveys_extension_utils_js_namespaceObject.getSurveyResponseKey)(question.id)] : null;
|
|
138
|
+
const nextStep = (0, external_survey_branching_js_namespaceObject.getNextSurveyStep)(survey, currentIndex, response);
|
|
139
|
+
if (nextStep === external_survey_constants_js_namespaceObject.SurveyQuestionBranchingType.End) return {
|
|
140
|
+
startQuestionIndex: survey.questions.length,
|
|
141
|
+
skippedResponses,
|
|
142
|
+
skippedIndices
|
|
143
|
+
};
|
|
144
|
+
currentIndex = nextStep;
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
startQuestionIndex: currentIndex,
|
|
148
|
+
skippedResponses,
|
|
149
|
+
skippedIndices
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
exports.calculatePrefillStartIndex = __webpack_exports__.calculatePrefillStartIndex;
|
|
153
|
+
exports.convertPrefillToResponses = __webpack_exports__.convertPrefillToResponses;
|
|
154
|
+
exports.extractPrefillParamsFromUrl = __webpack_exports__.extractPrefillParamsFromUrl;
|
|
155
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
156
|
+
"calculatePrefillStartIndex",
|
|
157
|
+
"convertPrefillToResponses",
|
|
158
|
+
"extractPrefillParamsFromUrl"
|
|
159
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
160
|
+
Object.defineProperty(exports, '__esModule', {
|
|
161
|
+
value: true
|
|
162
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { SurveyQuestionBranchingType, SurveyQuestionType } from "../survey-constants.mjs";
|
|
2
|
+
import { getSurveyResponseKey } from "./surveys-extension-utils.mjs";
|
|
3
|
+
import { logger } from "../utils/logger.mjs";
|
|
4
|
+
import { isUndefined } from "@posthog/core";
|
|
5
|
+
import { getNextSurveyStep } from "./survey-branching.mjs";
|
|
6
|
+
function extractPrefillParamsFromUrl(searchString) {
|
|
7
|
+
const params = {};
|
|
8
|
+
let autoSubmit = false;
|
|
9
|
+
const cleanSearch = searchString.replace(/^\?/, '');
|
|
10
|
+
if (!cleanSearch) return {
|
|
11
|
+
params,
|
|
12
|
+
autoSubmit
|
|
13
|
+
};
|
|
14
|
+
const pairs = cleanSearch.split('&');
|
|
15
|
+
for (const pair of pairs){
|
|
16
|
+
const separator = pair.indexOf('=');
|
|
17
|
+
if (separator <= 0) continue;
|
|
18
|
+
let decodedKey;
|
|
19
|
+
let decodedValue;
|
|
20
|
+
try {
|
|
21
|
+
decodedKey = decodeURIComponent(pair.slice(0, separator));
|
|
22
|
+
decodedValue = decodeURIComponent(pair.slice(separator + 1));
|
|
23
|
+
} catch {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if ('auto_submit' === decodedKey && 'true' === decodedValue) {
|
|
27
|
+
autoSubmit = true;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const match = decodedKey.match(/^q(\d+)$/);
|
|
31
|
+
if (match) {
|
|
32
|
+
const questionIndex = parseInt(match[1], 10);
|
|
33
|
+
if (!params[questionIndex]) params[questionIndex] = [];
|
|
34
|
+
params[questionIndex].push(decodedValue);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
params,
|
|
39
|
+
autoSubmit
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function convertPrefillToResponses(survey, prefillParams) {
|
|
43
|
+
const responses = {};
|
|
44
|
+
survey.questions.forEach((question, index)=>{
|
|
45
|
+
if (!prefillParams[index] || !question.id) return;
|
|
46
|
+
const values = prefillParams[index];
|
|
47
|
+
const responseKey = getSurveyResponseKey(question.id);
|
|
48
|
+
try {
|
|
49
|
+
switch(question.type){
|
|
50
|
+
case SurveyQuestionType.SingleChoice:
|
|
51
|
+
{
|
|
52
|
+
if (!question.choices || 0 === question.choices.length) return void logger.warn(`[Survey Prefill] Question ${index} has no choices`);
|
|
53
|
+
const choiceIndex = parseInt(values[0], 10);
|
|
54
|
+
if (isNaN(choiceIndex) || choiceIndex < 0 || choiceIndex >= question.choices.length) return void logger.warn(`[Survey Prefill] Invalid choice index for q${index}: ${values[0]}`);
|
|
55
|
+
responses[responseKey] = question.choices[choiceIndex];
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case SurveyQuestionType.MultipleChoice:
|
|
59
|
+
{
|
|
60
|
+
if (!question.choices || 0 === question.choices.length) return void logger.warn(`[Survey Prefill] Question ${index} has no choices`);
|
|
61
|
+
const choiceIndices = values.map((v)=>parseInt(v, 10)).filter((i)=>!isNaN(i) && i >= 0 && i < question.choices.length);
|
|
62
|
+
if (0 === choiceIndices.length) return void logger.warn(`[Survey Prefill] No valid choices for q${index}`);
|
|
63
|
+
const uniqueChoices = [
|
|
64
|
+
...new Set(choiceIndices.map((i)=>question.choices[i]))
|
|
65
|
+
];
|
|
66
|
+
if (uniqueChoices.length < choiceIndices.length) logger.warn(`[Survey Prefill] Removed duplicate choices for q${index}`);
|
|
67
|
+
responses[responseKey] = uniqueChoices;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case SurveyQuestionType.Rating:
|
|
71
|
+
{
|
|
72
|
+
const rating = parseInt(values[0], 10);
|
|
73
|
+
const scale = question.scale || 10;
|
|
74
|
+
if (isNaN(rating) || rating < 0 || rating > scale) return void logger.warn(`[Survey Prefill] Invalid rating for q${index}: ${values[0]} (scale: 0-${scale})`);
|
|
75
|
+
responses[responseKey] = rating;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
default:
|
|
79
|
+
logger.info(`[Survey Prefill] Question type ${question.type} does not support prefill`);
|
|
80
|
+
}
|
|
81
|
+
} catch (error) {
|
|
82
|
+
logger.error(`[Survey Prefill] Error converting q${index}:`, error);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
return responses;
|
|
86
|
+
}
|
|
87
|
+
function calculatePrefillStartIndex(survey, prefilledIndices, responses) {
|
|
88
|
+
let currentIndex = 0;
|
|
89
|
+
const skippedResponses = {};
|
|
90
|
+
const skippedIndices = [];
|
|
91
|
+
const MAX_ITERATIONS = survey.questions.length + 1;
|
|
92
|
+
let iterations = 0;
|
|
93
|
+
while(currentIndex < survey.questions.length && iterations < MAX_ITERATIONS){
|
|
94
|
+
iterations++;
|
|
95
|
+
if (!prefilledIndices.includes(currentIndex)) break;
|
|
96
|
+
const question = survey.questions[currentIndex];
|
|
97
|
+
if (!question || !('skipSubmitButton' in question) || !question.skipSubmitButton) break;
|
|
98
|
+
if (question.id) {
|
|
99
|
+
const responseKey = getSurveyResponseKey(question.id);
|
|
100
|
+
if (!isUndefined(responses[responseKey])) skippedResponses[responseKey] = responses[responseKey];
|
|
101
|
+
}
|
|
102
|
+
skippedIndices.push(currentIndex);
|
|
103
|
+
const response = question.id ? responses[getSurveyResponseKey(question.id)] : null;
|
|
104
|
+
const nextStep = getNextSurveyStep(survey, currentIndex, response);
|
|
105
|
+
if (nextStep === SurveyQuestionBranchingType.End) return {
|
|
106
|
+
startQuestionIndex: survey.questions.length,
|
|
107
|
+
skippedResponses,
|
|
108
|
+
skippedIndices
|
|
109
|
+
};
|
|
110
|
+
currentIndex = nextStep;
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
startQuestionIndex: currentIndex,
|
|
114
|
+
skippedResponses,
|
|
115
|
+
skippedIndices
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
export { calculatePrefillStartIndex, convertPrefillToResponses, extractPrefillParamsFromUrl };
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { type VNode, type JSX } from 'preact';
|
|
2
|
+
import type { SurveyRenderContext } from '../survey-render-context';
|
|
3
|
+
import type { Survey, SurveyAppearance, SurveyQuestion } from '../types/surveys';
|
|
4
|
+
import { SurveyPosition, SurveyType, SurveyWidgetType } from '../survey-constants';
|
|
5
|
+
import { type SurveyResponses } from '@posthog/core';
|
|
6
|
+
import { getSurveyResponseKey } from '@posthog/core/surveys';
|
|
7
|
+
import type { Properties } from '@posthog/types';
|
|
8
|
+
export declare function getFontFamily(fontFamily?: string): string;
|
|
9
|
+
export { getSurveyResponseKey };
|
|
10
|
+
export declare const defaultSurveyAppearance: {
|
|
11
|
+
readonly fontFamily: 'inherit';
|
|
12
|
+
readonly backgroundColor: '#eeeded';
|
|
13
|
+
readonly submitButtonColor: 'black';
|
|
14
|
+
readonly submitButtonTextColor: 'white';
|
|
15
|
+
readonly ratingButtonColor: 'white';
|
|
16
|
+
readonly ratingButtonActiveColor: 'black';
|
|
17
|
+
readonly borderColor: '#c9c6c6';
|
|
18
|
+
readonly whiteLabel: false;
|
|
19
|
+
readonly displayThankYouMessage: true;
|
|
20
|
+
readonly thankYouMessageHeader: 'Thank you for your feedback!';
|
|
21
|
+
readonly position: "right";
|
|
22
|
+
readonly widgetType: "tab";
|
|
23
|
+
readonly widgetLabel: 'Feedback';
|
|
24
|
+
readonly widgetColor: 'black';
|
|
25
|
+
readonly zIndex: string;
|
|
26
|
+
readonly disabledButtonOpacity: '0.6';
|
|
27
|
+
readonly maxWidth: '300px';
|
|
28
|
+
readonly textSubtleColor: '#939393';
|
|
29
|
+
readonly boxPadding: '20px 24px';
|
|
30
|
+
readonly boxShadow: '0 4px 12px rgba(0, 0, 0, 0.15)';
|
|
31
|
+
readonly borderRadius: '10px';
|
|
32
|
+
readonly shuffleQuestions: false;
|
|
33
|
+
readonly outlineColor: 'rgba(59, 130, 246, 0.8)';
|
|
34
|
+
readonly inputBackground: 'white';
|
|
35
|
+
readonly inputTextColor: "#020617";
|
|
36
|
+
readonly scrollbarThumbColor: 'var(--ph-survey-border-color)';
|
|
37
|
+
readonly scrollbarTrackColor: 'var(--ph-survey-background-color)';
|
|
38
|
+
};
|
|
39
|
+
export declare const addSurveyCSSVariablesToElement: (element: HTMLElement, type: SurveyType, appearance?: SurveyAppearance | null) => void;
|
|
40
|
+
export declare function hex2rgb(c: string): string;
|
|
41
|
+
export declare function hexToRgba(hex: string, opacity: number): string;
|
|
42
|
+
export declare function getContrastingTextColor(color?: string): "#020617" | "white";
|
|
43
|
+
export declare function getSurveyStylesheet(posthog?: SurveyRenderContext): HTMLStyleElement | null;
|
|
44
|
+
export declare const retrieveSurveyShadow: (survey: Pick<Survey, 'id' | 'appearance' | 'type'>, posthog?: SurveyRenderContext, element?: Element) => {
|
|
45
|
+
shadow: ShadowRoot;
|
|
46
|
+
isNewlyCreated: boolean;
|
|
47
|
+
};
|
|
48
|
+
interface SendSurveyEventArgs {
|
|
49
|
+
responses: SurveyResponses;
|
|
50
|
+
survey: Survey;
|
|
51
|
+
surveySubmissionId: string;
|
|
52
|
+
isSurveyCompleted: boolean;
|
|
53
|
+
posthog?: SurveyRenderContext | undefined;
|
|
54
|
+
/** Additional properties to include in the survey event */
|
|
55
|
+
properties?: Properties | undefined;
|
|
56
|
+
/** The language that was applied to the survey. */
|
|
57
|
+
surveyLanguage?: (string | null) | undefined;
|
|
58
|
+
/** Question text as displayed to the user at answer time, keyed by question id. */
|
|
59
|
+
questionSnapshots?: Record<string, string> | undefined;
|
|
60
|
+
}
|
|
61
|
+
export declare const sendSurveyEvent: ({ responses, survey, surveySubmissionId, posthog, isSurveyCompleted, properties, surveyLanguage, questionSnapshots, }: SendSurveyEventArgs) => void;
|
|
62
|
+
export declare const dismissedSurveyEvent: (survey: Survey, posthog?: SurveyRenderContext, readOnly?: boolean, surveyLanguage?: string | null) => void;
|
|
63
|
+
export declare const sendSurveyAbandonedEvent: (survey: Survey, posthog?: SurveyRenderContext) => void;
|
|
64
|
+
export { getDisplayOrderChoices, shuffle } from '@posthog/core/surveys';
|
|
65
|
+
/** Question ids in the given order, or undefined when any question lacks an id to record. */
|
|
66
|
+
export declare const getQuestionOrder: (questions: SurveyQuestion[]) => string[] | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Branching rules hold the position of their target question in survey.questions, so a survey that
|
|
69
|
+
* uses branching is always read in the configured order. The API rejects surveys that set both
|
|
70
|
+
* shuffleQuestions and branching, so that covers rows predating the validation.
|
|
71
|
+
*
|
|
72
|
+
* A survey the respondent has already started keeps the order its persisted indices point into.
|
|
73
|
+
* Without a recorded order those indices came from a build that did not store one, and the order
|
|
74
|
+
* that produced them is unknowable, so the configured order is the only safe reading.
|
|
75
|
+
*/
|
|
76
|
+
export declare const getDisplayOrderQuestions: (survey: Survey, inProgressState?: InProgressSurveyState | null) => SurveyQuestion[];
|
|
77
|
+
export declare const canActivateRepeatedly: (survey: Pick<Survey, 'schedule' | 'conditions' | 'id' | 'current_iteration'>) => boolean;
|
|
78
|
+
/**
|
|
79
|
+
* getSurveySeen checks local storage for the surveySeen Key a
|
|
80
|
+
* and overrides this value if the survey can be repeatedly activated by its events.
|
|
81
|
+
* @param survey
|
|
82
|
+
*/
|
|
83
|
+
export declare const getSurveySeen: (survey: Survey) => boolean;
|
|
84
|
+
export declare const hasWaitPeriodPassed: (waitPeriodInDays: number | undefined) => boolean;
|
|
85
|
+
interface SurveyContextProps {
|
|
86
|
+
isPreviewMode: boolean;
|
|
87
|
+
previewPageIndex: number | undefined;
|
|
88
|
+
onPopupSurveyDismissed: () => void;
|
|
89
|
+
isPopup: boolean;
|
|
90
|
+
onPreviewSubmit: (res: string | string[] | number | null) => void;
|
|
91
|
+
onPreviewBack: () => void;
|
|
92
|
+
surveySubmissionId: string;
|
|
93
|
+
/** Additional properties to include in all survey events */
|
|
94
|
+
properties?: Properties | undefined;
|
|
95
|
+
/** The language that was applied to the survey. */
|
|
96
|
+
surveyLanguage?: (string | null) | undefined;
|
|
97
|
+
}
|
|
98
|
+
export declare const SurveyContext: import("preact").Context<SurveyContextProps>;
|
|
99
|
+
export declare const useSurveyContext: () => SurveyContextProps;
|
|
100
|
+
interface RenderProps {
|
|
101
|
+
component: VNode<{
|
|
102
|
+
className: string;
|
|
103
|
+
}>;
|
|
104
|
+
children: string;
|
|
105
|
+
renderAsHtml?: boolean | undefined;
|
|
106
|
+
style?: JSX.CSSProperties | undefined;
|
|
107
|
+
}
|
|
108
|
+
export declare const renderChildrenAsTextOrHtml: ({ component, children, renderAsHtml, style }: RenderProps) => VNode<{
|
|
109
|
+
className: string;
|
|
110
|
+
}>;
|
|
111
|
+
export declare function doesSurveyUrlMatch(survey: Pick<Survey, 'conditions'>, posthog?: SurveyRenderContext): boolean;
|
|
112
|
+
export declare function doesSurveyDeviceTypesMatch(survey: Survey): boolean;
|
|
113
|
+
export declare function doesSurveyMatchSelector(survey: Survey): boolean;
|
|
114
|
+
interface InProgressSurveyState {
|
|
115
|
+
surveySubmissionId: string;
|
|
116
|
+
lastQuestionIndex: number;
|
|
117
|
+
questionOrder?: string[] | undefined;
|
|
118
|
+
visitedIndices?: number[] | undefined;
|
|
119
|
+
responses: SurveyResponses;
|
|
120
|
+
surveyLanguage?: (string | null) | undefined;
|
|
121
|
+
questionSnapshots?: Record<string, string> | undefined;
|
|
122
|
+
}
|
|
123
|
+
export declare const clearAllInMemoryInProgressSurveyState: () => void;
|
|
124
|
+
export declare const setInProgressSurveyState: (survey: Pick<Survey, 'id' | 'current_iteration'>, state: InProgressSurveyState) => void;
|
|
125
|
+
export declare const getInProgressSurveyState: (survey: Pick<Survey, 'id' | 'current_iteration'>) => InProgressSurveyState | null;
|
|
126
|
+
export declare const isSurveyInProgress: (survey: Pick<Survey, 'id' | 'current_iteration'>) => boolean;
|
|
127
|
+
export declare const clearInProgressSurveyState: (survey: Pick<Survey, 'id' | 'current_iteration'>) => void;
|
|
128
|
+
export declare function getSurveyContainerClass(survey: Pick<Survey, 'id'>, asSelector?: boolean): string;
|
|
129
|
+
/**
|
|
130
|
+
* Get CSS position styles for a popover/modal based on SurveyPosition
|
|
131
|
+
* Used by both surveys and product tours for consistent positioning
|
|
132
|
+
*/
|
|
133
|
+
export declare function getPopoverPosition(type?: SurveyType, position?: SurveyPosition, surveyWidgetType?: SurveyWidgetType): Record<string, string>;
|