From 949722900acf02faab54020c80de643442e12d21 Mon Sep 17 00:00:00 2001 From: Phani Raj Date: Mon, 17 Jun 2024 13:40:06 -0500 Subject: [PATCH] feat(surveys): Make Event based Surveys a paid feature (#23024) This commit makes the event based surveys a paid feature of the product. Billing related changes merged in PostHog/billing#706 We also added relevant details about events, iterations & shuffling to survey creation event logging. --- frontend/src/lib/utils/eventUsageLogic.ts | 21 ++++++++++++++++++++ frontend/src/scenes/surveys/SurveyEdit.tsx | 5 +++-- frontend/src/scenes/surveys/surveysLogic.tsx | 4 ++++ frontend/src/types.ts | 1 + 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/utils/eventUsageLogic.ts b/frontend/src/lib/utils/eventUsageLogic.ts index b005053a507c2..b915a56757129 100644 --- a/frontend/src/lib/utils/eventUsageLogic.ts +++ b/frontend/src/lib/utils/eventUsageLogic.ts @@ -36,6 +36,7 @@ import { InsightShortId, InsightType, ItemMode, + MultipleSurveyQuestion, PersonType, PropertyFilterType, PropertyFilterValue, @@ -1210,6 +1211,10 @@ export const eventUsageLogic = kea([ }) }, reportSurveyCreated: ({ survey, isDuplicate }) => { + const questionsWithShuffledOptions = survey.questions.filter((question) => { + return question.hasOwnProperty('shuffleOptions') && (question as MultipleSurveyQuestion).shuffleOptions + }) + posthog.capture('survey created', { name: survey.name, id: survey.id, @@ -1217,6 +1222,12 @@ export const eventUsageLogic = kea([ questions_length: survey.questions.length, question_types: survey.questions.map((question) => question.type), is_duplicate: isDuplicate ?? false, + events_count: survey.conditions?.events?.values.length, + recurring_survey_iteration_count: survey.iteration_count == undefined ? 0 : survey.iteration_count, + recurring_survey_iteration_interval: + survey.iteration_frequency_days == undefined ? 0 : survey.iteration_frequency_days, + shuffle_questions_enabled: !!survey.appearance.shuffleQuestions, + shuffle_question_options_enabled_count: questionsWithShuffledOptions.length, }) }, reportSurveyLaunched: ({ survey }) => { @@ -1265,11 +1276,21 @@ export const eventUsageLogic = kea([ }) }, reportSurveyEdited: ({ survey }) => { + const questionsWithShuffledOptions = survey.questions.filter((question) => { + return question.hasOwnProperty('shuffleOptions') && (question as MultipleSurveyQuestion).shuffleOptions + }) + posthog.capture('survey edited', { name: survey.name, id: survey.id, created_at: survey.created_at, start_date: survey.start_date, + events_count: survey.conditions?.events?.values.length, + recurring_survey_iteration_count: survey.iteration_count == undefined ? 0 : survey.iteration_count, + recurring_survey_iteration_interval: + survey.iteration_frequency_days == undefined ? 0 : survey.iteration_frequency_days, + shuffle_questions_enabled: !!survey.appearance.shuffleQuestions, + shuffle_question_options_enabled_count: questionsWithShuffledOptions.length, }) }, reportSurveyTemplateClicked: ({ template }) => { diff --git a/frontend/src/scenes/surveys/SurveyEdit.tsx b/frontend/src/scenes/surveys/SurveyEdit.tsx index 58a483ac79a81..61c9f63e44617 100644 --- a/frontend/src/scenes/surveys/SurveyEdit.tsx +++ b/frontend/src/scenes/surveys/SurveyEdit.tsx @@ -59,7 +59,8 @@ export default function SurveyEdit(): JSX.Element { setFlagPropertyErrors, setSchedule, } = useActions(surveyLogic) - const { surveysMultipleQuestionsAvailable, surveysRecurringScheduleAvailable } = useValues(surveysLogic) + const { surveysMultipleQuestionsAvailable, surveysRecurringScheduleAvailable, surveysEventsAvailable } = + useValues(surveysLogic) const { featureFlags } = useValues(enabledFeaturesLogic) const sortedItemIds = survey.questions.map((_, idx) => idx.toString()) const { thankYouMessageDescriptionContentType } = survey.appearance @@ -618,7 +619,7 @@ export default function SurveyEdit(): JSX.Element { )} - {featureFlags[FEATURE_FLAGS.SURVEYS_EVENTS] && ( + {featureFlags[FEATURE_FLAGS.SURVEYS_EVENTS] && surveysEventsAvailable && ( { diff --git a/frontend/src/scenes/surveys/surveysLogic.tsx b/frontend/src/scenes/surveys/surveysLogic.tsx index 377502ac84806..dc79e3dea4388 100644 --- a/frontend/src/scenes/surveys/surveysLogic.tsx +++ b/frontend/src/scenes/surveys/surveysLogic.tsx @@ -158,6 +158,10 @@ export const surveysLogic = kea([ (s) => [s.hasAvailableFeature], (hasAvailableFeature) => hasAvailableFeature(AvailableFeature.SURVEYS_RECURRING), ], + surveysEventsAvailable: [ + (s) => [s.hasAvailableFeature], + (hasAvailableFeature) => hasAvailableFeature(AvailableFeature.SURVEYS_EVENTS), + ], showSurveysDisabledBanner: [ (s) => [s.currentTeam, s.currentTeamLoading, s.surveys], (currentTeam, currentTeamLoading, surveys) => { diff --git a/frontend/src/types.ts b/frontend/src/types.ts index c8222367389cc..23e84132c413d 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -89,6 +89,7 @@ export enum AvailableFeature { SURVEYS_SLACK_NOTIFICATIONS = 'surveys_slack_notifications', SURVEYS_WAIT_PERIODS = 'surveys_wait_periods', SURVEYS_RECURRING = 'surveys_recurring', + SURVEYS_EVENTS = 'survey_events', TRACKED_USERS = 'tracked_users', TEAM_MEMBERS = 'team_members', API_ACCESS = 'api_access',