Skip to content

Commit

Permalink
feat(surveys): Make Event based Surveys a paid feature (#23024)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Phanatic authored Jun 17, 2024
1 parent ebe4e70 commit 9497229
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
21 changes: 21 additions & 0 deletions frontend/src/lib/utils/eventUsageLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
InsightShortId,
InsightType,
ItemMode,
MultipleSurveyQuestion,
PersonType,
PropertyFilterType,
PropertyFilterValue,
Expand Down Expand Up @@ -1210,13 +1211,23 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
})
},
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,
survey_type: survey.type,
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 }) => {
Expand Down Expand Up @@ -1265,11 +1276,21 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
})
},
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 }) => {
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/scenes/surveys/SurveyEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -618,7 +619,7 @@ export default function SurveyEdit(): JSX.Element {
)}
</BindLogic>
</LemonField.Pure>
{featureFlags[FEATURE_FLAGS.SURVEYS_EVENTS] && (
{featureFlags[FEATURE_FLAGS.SURVEYS_EVENTS] && surveysEventsAvailable && (
<LemonField.Pure label="User sends events">
<EventSelect
onChange={(includedEvents) => {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/scenes/surveys/surveysLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ export const surveysLogic = kea<surveysLogicType>([
(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) => {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 9497229

Please sign in to comment.