:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(surveys): add intro screen appearance fields and version gating (#116323)
Lucas Fariacd0a7c0364f7
diff --git a/docs/published/docs/surveys/sdk-feature-support.mdx b/docs/published/docs/surveys/sdk-feature-support.mdxindex 86ab3c3295a1..255b92f1a7ef 100644--- a/docs/published/docs/surveys/sdk-feature-support.mdx+++ b/docs/published/docs/surveys/sdk-feature-support.mdx@@ -17,6 +17,7 @@ For setup instructions, see the [installation guides](/docs/surveys/installation| Device types targeting | <IconCheck className="w-4 h-4 inline text-green" /> 1.214.0+ | <IconCheck className="w-4 h-4 inline text-green" /> 4.3.0+ | <IconCheck className="w-4 h-4 inline text-green" /> 3.22.0+ | <IconCheck className="w-4 h-4 inline text-green" /> 3.21.0+ | <IconCheck className="w-4 h-4 inline text-green" /> 5.1.0+ || Custom font selection | <IconCheck className="w-4 h-4 inline text-green" /> 1.223.4+ | <a href="https://github.com/PostHog/posthog-js/issues/2959"><IconWrench className="w-4 h-4 inline text-muted" /></a> | <IconCheck className="w-4 h-4 inline text-green" /> 3.22.0+ | <IconX className="w-4 h-4 inline text-red" /> | <a href="https://github.com/PostHog/posthog-flutter/issues/258"><IconWrench className="w-4 h-4 inline text-muted" /></a> || Repeated survey activation (show every time) | <IconCheck className="w-4 h-4 inline text-green" /> 1.234.11+ | <IconCheck className="w-4 h-4 inline text-green" /> 4.27.0+ | <IconCheck className="w-4 h-4 inline text-green" /> 3.43.0+ | <IconCheck className="w-4 h-4 inline text-green" /> 3.35.0+ | <IconCheck className="w-4 h-4 inline text-green" /> 5.18.0+ |+| Intro screen | <IconCheck className="w-4 h-4 inline text-green" /> 1.415.0+ | <IconCheck className="w-4 h-4 inline text-green" /> 4.63.0+ | <IconCheck className="w-4 h-4 inline text-green" /> 3.70.0+ | <IconCheck className="w-4 h-4 inline text-green" /> 3.61.0+ | <IconCheck className="w-4 h-4 inline text-green" /> 5.39.0+ || Feedback button surveys | <IconCheck className="w-4 h-4 inline text-green" /> 1.294.0+ | <IconX className="w-4 h-4 inline text-red" /> | <IconX className="w-4 h-4 inline text-red" /> | <IconX className="w-4 h-4 inline text-red" /> | <IconX className="w-4 h-4 inline text-red" /> || Custom survey position | <IconCheck className="w-4 h-4 inline text-green" /> 1.245.0+ | <IconCheck className="w-4 h-4 inline text-green" /> 4.43.13+ | <a href="https://github.com/PostHog/posthog-ios/issues/581"><IconWrench className="w-4 h-4 inline text-muted" /></a> | <a href="https://github.com/PostHog/posthog-android/issues/502"><IconWrench className="w-4 h-4 inline text-muted" /></a> | <a href="https://github.com/PostHog/posthog-flutter/issues/379"><IconWrench className="w-4 h-4 inline text-muted" /></a> || Partial response collection | <IconCheck className="w-4 h-4 inline text-green" /> 1.240.0+ | <a href="https://github.com/PostHog/posthog-js/issues/2962"><IconWrench className="w-4 h-4 inline text-muted" /></a> | <a href="https://github.com/PostHog/posthog-ios/issues/447"><IconWrench className="w-4 h-4 inline text-muted" /></a> | <a href="https://github.com/PostHog/posthog-android/issues/390"><IconWrench className="w-4 h-4 inline text-muted" /></a> | <a href="https://github.com/PostHog/posthog-flutter/issues/261"><IconWrench className="w-4 h-4 inline text-muted" /></a> |diff --git a/frontend/package.json b/frontend/package.jsonindex f32cdea688dd..0d735c32c290 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -56,7 +56,7 @@"mobile-replay:web:schema:build:json": "ts-json-schema-generator -f ./tsconfig.json --path 'node_modules/posthog-js/dist/rrweb-types.d.ts' --type 'eventWithTime' --expose all --no-top-ref --no-type-check --out ./src/scenes/session-recordings/mobile-replay/schema/web/rr-web-schema.json && oxfmt ./src/scenes/session-recordings/mobile-replay/schema/web/rr-web-schema.json","mobile-replay:mobile:schema:build:json": "ts-json-schema-generator -f ./tsconfig.json --path './src/scenes/session-recordings/mobile-replay/mobile.types.ts' --type 'mobileEventWithTime' --expose all --no-top-ref --no-type-check --out ./src/scenes/session-recordings/mobile-replay/schema/mobile/rr-mobile-schema.json && oxfmt ./src/scenes/session-recordings/mobile-replay/schema/mobile/rr-mobile-schema.json","mobile-replay:schema:build:json": "pnpm mobile-replay:web:schema:build:json && pnpm mobile-replay:mobile:schema:build:json",- "build:survey-sdk-docs": "ts-node -r tsconfig-paths/register --transpile-only ./bin/docs/build-survey-sdk-docs.ts"+ "build:survey-sdk-docs": "TS_NODE_BASEURL=.. ts-node -r tsconfig-paths/register --transpile-only -O '{\"rootDir\":\".\"}' ./bin/docs/build-survey-sdk-docs.ts"},"dependencies": {"@base-ui/react": "catalog:",diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex 6b3a49418395..6f4428bb8d2a 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -54736,12 +54736,27 @@"buttonTextColor": {"type": "string"},+ "displayIntroScreen": {+ "type": "boolean"+ },"inputBackground": {"type": "string"},"inputTextColor": {"type": "string"},+ "introScreenButtonText": {+ "type": "string"+ },+ "introScreenDescription": {+ "type": "string"+ },+ "introScreenDescriptionContentType": {+ "$ref": "#/definitions/SurveyQuestionDescriptionContentType"+ },+ "introScreenHeader": {+ "type": "string"+ },"maxWidth": {"type": "string"},diff --git a/frontend/src/queries/schema/schema-surveys.ts b/frontend/src/queries/schema/schema-surveys.tsindex 34da9041cec1..7981ff16bdb5 100644--- a/frontend/src/queries/schema/schema-surveys.ts+++ b/frontend/src/queries/schema/schema-surveys.ts@@ -92,6 +92,11 @@ export interface SurveyAppearanceSchema {position?: SurveyPositiontabPosition?: SurveyTabPositionwhiteLabel?: boolean+ displayIntroScreen?: boolean+ introScreenHeader?: string+ introScreenDescription?: string+ introScreenDescriptionContentType?: SurveyQuestionDescriptionContentType+ introScreenButtonText?: stringthankYouMessageHeader?: stringthankYouMessageDescription?: stringthankYouMessageDescriptionContentType?: SurveyQuestionDescriptionContentTypediff --git a/frontend/src/scenes/surveys/constants.tsx b/frontend/src/scenes/surveys/constants.tsxindex a55b2559286f..438088fe32cd 100644--- a/frontend/src/scenes/surveys/constants.tsx+++ b/frontend/src/scenes/surveys/constants.tsx@@ -56,6 +56,9 @@ export const SURVEY_RATING_SCALE = {export type SurveyRatingScaleValue = (typeof SURVEY_RATING_SCALE)[keyof typeof SURVEY_RATING_SCALE]+// Leading page sentinel: the confirmation message trails at questions.length, so the intro sits at -1 and question indices never shift.+export const INTRO_SCREEN_PAGE_INDEX = -1+// Create SurveyMatchTypeLabels using allOperatorsMappingexport const SurveyMatchTypeLabels = {[SurveyMatchType.Exact]: allOperatorsMapping[SurveyMatchType.Exact],diff --git a/frontend/src/scenes/surveys/surveyActivityDescriber.tsx b/frontend/src/scenes/surveys/surveyActivityDescriber.tsxindex 3c45405bfaae..e8b1fd544598 100644--- a/frontend/src/scenes/surveys/surveyActivityDescriber.tsx+++ b/frontend/src/scenes/surveys/surveyActivityDescriber.tsx@@ -182,6 +182,11 @@ const surveyActionsMapping: Record<borderColor: 'border color',placeholder: 'placeholder text',whiteLabel: 'white label option',+ displayIntroScreen: 'intro screen display',+ introScreenHeader: 'intro screen header',+ introScreenDescription: 'intro screen description',+ introScreenDescriptionContentType: 'intro screen content type',+ introScreenButtonText: 'intro screen button text',displayThankYouMessage: 'thank you message display',thankYouMessageHeader: 'thank you message header',thankYouMessageDescription: 'thank you message description',diff --git a/frontend/src/scenes/surveys/surveyIntroScreen.test.ts b/frontend/src/scenes/surveys/surveyIntroScreen.test.tsnew file mode 100644index 000000000000..7b25b189316d--- /dev/null+++ b/frontend/src/scenes/surveys/surveyIntroScreen.test.ts@@ -0,0 +1,34 @@+import { SurveyAppearance } from '~/types'++import { getIntroScreenDescriptionContentType, isIntroScreenShown } from './surveyIntroScreen'++describe('surveyIntroScreen', () => {+ describe('isIntroScreenShown', () => {+ it.each([+ ['no appearance', undefined, false],+ ['intro off with content', { displayIntroScreen: false, introScreenHeader: 'Welcome' }, false],+ ['intro on without content', { displayIntroScreen: true }, false],+ [+ 'intro on with empty strings',+ { displayIntroScreen: true, introScreenHeader: '', introScreenDescription: '' },+ false,+ ],+ ['intro on with only a button text', { displayIntroScreen: true, introScreenButtonText: 'Go' }, false],+ ['intro on with a header', { displayIntroScreen: true, introScreenHeader: 'Welcome' }, true],+ ['intro on with a description', { displayIntroScreen: true, introScreenDescription: 'One minute' }, true],+ ] as [string, SurveyAppearance | undefined, boolean][])('%s', (_name, appearance, expected) => {+ expect(isIntroScreenShown(appearance)).toBe(expected)+ })+ })++ describe('getIntroScreenDescriptionContentType', () => {+ it.each([+ ['no appearance', undefined, 'html'],+ ['no content type', {}, 'html'],+ ['html', { introScreenDescriptionContentType: 'html' }, 'html'],+ ['text', { introScreenDescriptionContentType: 'text' }, 'text'],+ ] as [string, SurveyAppearance | undefined, string][])('%s', (_name, appearance, expected) => {+ expect(getIntroScreenDescriptionContentType(appearance)).toBe(expected)+ })+ })+})diff --git a/frontend/src/scenes/surveys/surveyIntroScreen.ts b/frontend/src/scenes/surveys/surveyIntroScreen.tsnew file mode 100644index 000000000000..f7dc94d3fb6f--- /dev/null+++ b/frontend/src/scenes/surveys/surveyIntroScreen.ts@@ -0,0 +1,11 @@+import { SurveyAppearance, SurveyQuestionDescriptionContentType } from '~/types'++export function isIntroScreenShown(appearance?: SurveyAppearance | null): boolean {+ return !!appearance?.displayIntroScreen && !!(appearance.introScreenHeader || appearance.introScreenDescription)+}++export function getIntroScreenDescriptionContentType(+ appearance?: SurveyAppearance | null+): SurveyQuestionDescriptionContentType {+ return appearance?.introScreenDescriptionContentType ?? 'html'+}diff --git a/frontend/src/scenes/surveys/surveyLogic.tsx b/frontend/src/scenes/surveys/surveyLogic.tsxindex 0b9017f37f05..d54a6bceff23 100644--- a/frontend/src/scenes/surveys/surveyLogic.tsx+++ b/frontend/src/scenes/surveys/surveyLogic.tsx@@ -197,6 +197,9 @@ type SurveyTranslationDraftPayload = {thankYouMessageHeader?: stringthankYouMessageDescription?: stringthankYouMessageCloseButtonText?: string+ introScreenHeader?: string+ introScreenDescription?: string+ introScreenButtonText?: string}questions?: SurveyTranslationDraftQuestion[]translations?: Survey['translations']@@ -248,6 +251,9 @@ function getSurveyTranslationDraftPayload(survey: Survey | NewSurvey): SurveyTrathankYouMessageHeader: survey.appearance?.thankYouMessageHeader,thankYouMessageDescription: survey.appearance?.thankYouMessageDescription,thankYouMessageCloseButtonText: survey.appearance?.thankYouMessageCloseButtonText,+ introScreenHeader: survey.appearance?.introScreenHeader,+ introScreenDescription: survey.appearance?.introScreenDescription,+ introScreenButtonText: survey.appearance?.introScreenButtonText,},questions: survey.questions.map((question, index): SurveyTranslationDraftQuestion => {const draftQuestion: SurveyTranslationDraftQuestion = {@@ -1059,6 +1065,9 @@ export interface surveyLogicActions {string,{backButtonText?: string | undefined+ introScreenButtonText?: string | undefined+ introScreenDescription?: string | undefined+ introScreenHeader?: string | undefinedname?: string | undefinedsubmitButtonText?: string | undefinedthankYouMessageCloseButtonText?: string | undefined@@ -1115,6 +1124,9 @@ export interface surveyLogicActions {string,{backButtonText?: string | undefined+ introScreenButtonText?: string | undefined+ introScreenDescription?: string | undefined+ introScreenHeader?: string | undefinedname?: string | undefinedsubmitButtonText?: string | undefinedthankYouMessageCloseButtonText?: string | undefineddiff --git a/frontend/src/scenes/surveys/surveyNotificationModalLogic.ts b/frontend/src/scenes/surveys/surveyNotificationModalLogic.tsindex db545225968a..293b25981f39 100644--- a/frontend/src/scenes/surveys/surveyNotificationModalLogic.ts+++ b/frontend/src/scenes/surveys/surveyNotificationModalLogic.ts@@ -1077,6 +1077,9 @@ export interface surveyNotificationModalLogicActions {string,{backButtonText?: string | undefined+ introScreenButtonText?: string | undefined+ introScreenDescription?: string | undefined+ introScreenHeader?: string | undefinedname?: string | undefinedsubmitButtonText?: string | undefinedthankYouMessageCloseButtonText?: string | undefined@@ -1134,6 +1137,9 @@ export interface surveyNotificationModalLogicActions {string,{backButtonText?: string | undefined+ introScreenButtonText?: string | undefined+ introScreenDescription?: string | undefined+ introScreenHeader?: string | undefinedname?: string | undefinedsubmitButtonText?: string | undefinedthankYouMessageCloseButtonText?: string | undefineddiff --git a/frontend/src/scenes/surveys/surveyVersionRequirements.test.ts b/frontend/src/scenes/surveys/surveyVersionRequirements.test.tsindex caf258849ff2..00550a50787e 100644--- a/frontend/src/scenes/surveys/surveyVersionRequirements.test.ts+++ b/frontend/src/scenes/surveys/surveyVersionRequirements.test.ts@@ -1,3 +1,5 @@+import { Survey } from '~/types'+import { SURVEY_SDK_REQUIREMENTS, SurveySdkType } from './surveyVersionRequirements'const ALL_SDK_TYPES: SurveySdkType[] = [@@ -21,4 +23,13 @@ describe('SURVEY_SDK_REQUIREMENTS', () => {expect(missing).toEqual([])})++ it.each([+ ['an intro that renders', { displayIntroScreen: true, introScreenHeader: 'Welcome' }, true],+ ['an intro with no header or description', { displayIntroScreen: true }, false],+ ])('flags the Intro screen requirement for %s', (_name, appearance, expected) => {+ const requirement = SURVEY_SDK_REQUIREMENTS.find((req) => req.feature === 'Intro screen')++ expect(requirement?.check({ appearance } as Survey)).toBe(expected)+ })})diff --git a/frontend/src/scenes/surveys/surveyVersionRequirements.ts b/frontend/src/scenes/surveys/surveyVersionRequirements.tsindex 569ac81f2842..4a2a7031e863 100644--- a/frontend/src/scenes/surveys/surveyVersionRequirements.ts+++ b/frontend/src/scenes/surveys/surveyVersionRequirements.ts@@ -13,6 +13,7 @@ import {} from '~/types'import { SURVEY_RATING_SCALE } from './constants'+import { isIntroScreenShown } from './surveyIntroScreen'export type SurveySdkType =| 'posthog-js'@@ -116,6 +117,18 @@ export const SURVEY_SDK_REQUIREMENTS: SurveyFeatureRequirement[] = [unsupportedSdks: [],check: (s) => s.schedule === SurveySchedule.Always,},+ {+ feature: 'Intro screen',+ sdkVersions: {+ 'posthog-js': '1.415.0',+ 'posthog-react-native': '4.63.0',+ 'posthog-ios': '3.70.0',+ 'posthog-android': '3.61.0',+ posthog_flutter: '5.39.0',+ },+ unsupportedSdks: [],+ check: (s) => isIntroScreenShown(s.appearance),+ },{feature: 'Feedback button surveys',sdkVersions: { 'posthog-js': '1.294.0' },diff --git a/frontend/src/scenes/surveys/utils.test.ts b/frontend/src/scenes/surveys/utils.test.tsindex 4da613eeb711..e9bf23c858a1 100644--- a/frontend/src/scenes/surveys/utils.test.ts+++ b/frontend/src/scenes/surveys/utils.test.ts@@ -530,6 +530,32 @@ describe('survey utils', () => {expect(result?.submitButtonTextColor).toBe('#cccccc')})+ it.each([+ ['introScreenHeader', '<b>Welcome</b><script>alert(1)</script>', '<b>Welcome</b>'],+ ['introScreenDescription', '<p onclick="alert(1)">Takes a minute</p>', '<p>Takes a minute</p>'],+ ['introScreenHeader', undefined, ''],+ ] as const)('sanitizes %s HTML (%s)', (field, value, expected) => {+ const result = sanitizeSurveyAppearance({ [field]: value })++ expect(result?.[field]).toBe(expected)+ })++ it.each([+ ['text', 'a < b && c > d'],+ ['html', 'a < b && c > d'],+ [undefined, 'a < b && c > d'],+ ] as const)(+ 'sanitizes the intro description only as HTML when its content type is %s',+ (contentType, expected) => {+ const result = sanitizeSurveyAppearance({+ introScreenDescription: 'a < b && c > d',+ introScreenDescriptionContentType: contentType,+ })++ expect(result?.introScreenDescription).toBe(expected)+ }+ )+it('removes surveyPopupDelaySeconds for external surveys', () => {const input: SurveyAppearance = {backgroundColor: '#ffffff',diff --git a/frontend/src/scenes/surveys/utils.ts b/frontend/src/scenes/surveys/utils.tsindex 7f51dfe5dec9..06ca52c11da4 100644--- a/frontend/src/scenes/surveys/utils.ts+++ b/frontend/src/scenes/surveys/utils.ts@@ -13,6 +13,7 @@ import {SURVEY_CREATED_SOURCE,SURVEY_RATING_SCALE,} from 'scenes/surveys/constants'+import { getIntroScreenDescriptionContentType } from 'scenes/surveys/surveyIntroScreen'import { SurveyRatingResults } from 'scenes/surveys/surveyLogic'import { urls } from 'scenes/urls'@@ -298,6 +299,11 @@ export function sanitizeSurveyAppearance(submitButtonTextColor: sanitizeColor(appearance.submitButtonTextColor),thankYouMessageHeader: sanitizeHTML(appearance.thankYouMessageHeader ?? ''),thankYouMessageDescription: sanitizeHTML(appearance.thankYouMessageDescription ?? ''),+ introScreenHeader: sanitizeHTML(appearance.introScreenHeader ?? ''),+ introScreenDescription:+ getIntroScreenDescriptionContentType(appearance) === 'text'+ ? (appearance.introScreenDescription ?? '')+ : sanitizeHTML(appearance.introScreenDescription ?? ''),surveyPopupDelaySeconds:surveyType === SurveyType.ExternalSurvey ? undefined : appearance.surveyPopupDelaySeconds,}diff --git a/frontend/src/scenes/team-activity/teamActivityDescriber.tsx b/frontend/src/scenes/team-activity/teamActivityDescriber.tsxindex 820d898d1fae..4677859d7920 100644--- a/frontend/src/scenes/team-activity/teamActivityDescriber.tsx+++ b/frontend/src/scenes/team-activity/teamActivityDescriber.tsx@@ -396,7 +396,15 @@ const TEAM_PROPERTIES_MAPPING: Record<if (before?.appearance?.displayThankYouMessage !== after?.appearance?.displayThankYouMessage) {descriptions.push(- `${preamble} displayThankYouMessage was ${after?.appearance?.whiteLabel ? 'enabled' : 'disabled'}`+ `${preamble} displayThankYouMessage was ${+ after?.appearance?.displayThankYouMessage ? 'enabled' : 'disabled'+ }`+ )+ }++ if (before?.appearance?.displayIntroScreen !== after?.appearance?.displayIntroScreen) {+ descriptions.push(+ `${preamble} Survey intro screen was ${after?.appearance?.displayIntroScreen ? 'enabled' : 'disabled'}`)}@@ -408,6 +416,7 @@ const TEAM_PROPERTIES_MAPPING: Record<propertyChangeDesc('borderColor', (c) => c?.appearance?.borderColor)propertyChangeDesc('placeholder', (c) => c?.appearance?.placeholder)propertyChangeDesc('thankYouMessageHeader', (c) => c?.appearance?.thankYouMessageHeader)+ propertyChangeDesc('intro screen header', (c) => c?.appearance?.introScreenHeader)propertyChangeDesc('position', (c) => c?.appearance?.position)return { description: descriptions }diff --git a/frontend/src/types.ts b/frontend/src/types.tsindex a5205e773368..562031f298b8 100644--- a/frontend/src/types.ts+++ b/frontend/src/types.ts@@ -4249,6 +4249,9 @@ export interface Survey extends WithAccessControl {thankYouMessageHeader?: stringthankYouMessageDescription?: stringthankYouMessageCloseButtonText?: string+ introScreenHeader?: string+ introScreenDescription?: string+ introScreenButtonText?: stringsubmitButtonText?: stringbackButtonText?: string}@@ -4315,6 +4318,12 @@ export interface SurveyAppearance {borderColor?: stringplaceholder?: stringwhiteLabel?: boolean+ // Not a question: dismissing the intro records no response and never counts toward completion metrics.+ displayIntroScreen?: boolean+ introScreenHeader?: string+ introScreenDescription?: string+ introScreenDescriptionContentType?: SurveyQuestionDescriptionContentType+ introScreenButtonText?: stringdisplayThankYouMessage?: booleanthankYouMessageHeader?: stringthankYouMessageDescription?: stringdiff --git a/posthog/schema.py b/posthog/schema.pyindex cea9410d0cd8..33aceef04f9a 100644--- a/posthog/schema.py+++ b/posthog/schema.py@@ -8338,8 +8338,13 @@ class SurveyAppearanceSchema(BaseModel):borderColor: str | None = NonebuttonColor: str | None = NonebuttonTextColor: str | None = None+ displayIntroScreen: bool | None = NoneinputBackground: str | None = NoneinputTextColor: str | None = None+ introScreenButtonText: str | None = None+ introScreenDescription: str | None = None+ introScreenDescriptionContentType: SurveyQuestionDescriptionContentType | None = None+ introScreenHeader: str | None = NonemaxWidth: str | None = Noneplaceholder: str | None = Noneposition: SurveyPosition | None = None