From c393da527242c8a2142fc44eca8a55881ed5b216 Mon Sep 17 00:00:00 2001 From: Phani Raj Date: Wed, 6 Nov 2024 19:36:32 -0600 Subject: [PATCH] feat(Experiments): Create New web experiment from dotcom UI (#26009) Create Web Experiment from the New Experiment page. Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Juraj Majerik Co-authored-by: Ross --- .../src/scenes/experiments/ExperimentForm.tsx | 47 ++++++++++++++++++- .../scenes/experiments/experimentLogic.tsx | 5 ++ .../scenes/experiments/experimentsLogic.ts | 7 ++- 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/frontend/src/scenes/experiments/ExperimentForm.tsx b/frontend/src/scenes/experiments/ExperimentForm.tsx index bcae52d655911..d34838d40224f 100644 --- a/frontend/src/scenes/experiments/ExperimentForm.tsx +++ b/frontend/src/scenes/experiments/ExperimentForm.tsx @@ -13,6 +13,7 @@ import { LemonRadio } from 'lib/lemon-ui/LemonRadio' import { LemonSelect } from 'lib/lemon-ui/LemonSelect' import { capitalizeFirstLetter } from 'lib/utils' import { useEffect } from 'react' +import { experimentsLogic } from 'scenes/experiments/experimentsLogic' import { insightDataLogic } from 'scenes/insights/insightDataLogic' import { insightLogic } from 'scenes/insights/insightLogic' @@ -25,8 +26,9 @@ import { ExperimentInsightCreator } from './MetricSelector' const StepInfo = (): JSX.Element => { const { experiment, featureFlags } = useValues(experimentLogic) - const { addExperimentGroup, removeExperimentGroup, moveToNextFormStep } = useActions(experimentLogic) - + const { addExperimentGroup, removeExperimentGroup, moveToNextFormStep, setExperimentType } = + useActions(experimentLogic) + const { webExperimentsAvailable } = useValues(experimentsLogic) return (
@@ -48,6 +50,47 @@ const StepInfo = (): JSX.Element => { />
+ {webExperimentsAvailable && ( +
+

Experiment type

+
+ Select your experiment setup, this cannot be changed once saved. +
+ + { + setExperimentType(type) + }} + options={[ + { + value: 'product', + label: ( +
+
Product experiment
+
+ Use custom code to manage how variants modify your product. +
+
+ ), + }, + { + value: 'web', + label: ( +
+
No-code web experiment
+
+ Define variants on your website using the PostHog toolbar, no coding + required. +
+
+ ), + }, + ]} + /> +
+ )}

Variants

Add up to 9 variants to test against your control.
diff --git a/frontend/src/scenes/experiments/experimentLogic.tsx b/frontend/src/scenes/experiments/experimentLogic.tsx index 615e6c5b28c9f..a928b09db82cd 100644 --- a/frontend/src/scenes/experiments/experimentLogic.tsx +++ b/frontend/src/scenes/experiments/experimentLogic.tsx @@ -69,6 +69,7 @@ import { getMinimumDetectableEffect, transformFiltersForWinningVariant } from '. const NEW_EXPERIMENT: Experiment = { id: 'new', name: '', + type: 'product', feature_flag_key: '', filters: {}, metrics: [], @@ -159,6 +160,7 @@ export const experimentLogic = kea([ setExperiment: (experiment: Partial) => ({ experiment }), createExperiment: (draft?: boolean) => ({ draft }), setNewExperimentInsight: (filters?: Partial) => ({ filters }), + setExperimentType: (type?: string) => ({ type }), setExperimentExposureInsight: (filters?: Partial) => ({ filters }), removeExperimentGroup: (idx: number) => ({ idx }), setEditExperiment: (editing: boolean) => ({ editing }), @@ -422,6 +424,9 @@ export const experimentLogic = kea([ }) } }, + setExperimentType: async ({ type }) => { + actions.setExperiment({ type: type }) + }, setNewExperimentInsight: async ({ filters }) => { let newInsightFilters const aggregationGroupTypeIndex = values.experiment.parameters?.aggregation_group_type_index diff --git a/frontend/src/scenes/experiments/experimentsLogic.ts b/frontend/src/scenes/experiments/experimentsLogic.ts index 4548efe5f9941..9f4c5bb1ca706 100644 --- a/frontend/src/scenes/experiments/experimentsLogic.ts +++ b/frontend/src/scenes/experiments/experimentsLogic.ts @@ -3,8 +3,9 @@ import Fuse from 'fuse.js' import { actions, connect, events, kea, path, reducers, selectors } from 'kea' import { loaders } from 'kea-loaders' import api from 'lib/api' +import { FEATURE_FLAGS } from 'lib/constants' import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast' -import { featureFlagLogic } from 'lib/logic/featureFlagLogic' +import { featureFlagLogic, FeatureFlagsSet } from 'lib/logic/featureFlagLogic' import { teamLogic } from 'scenes/teamLogic' import { userLogic } from 'scenes/userLogic' @@ -142,6 +143,10 @@ export const experimentsLogic = kea([ return experiments.length === 0 && !experimentsLoading && !values.searchTerm && !values.searchStatus }, ], + webExperimentsAvailable: [ + () => [featureFlagLogic.selectors.featureFlags], + (featureFlags: FeatureFlagsSet) => featureFlags[FEATURE_FLAGS.WEB_EXPERIMENTS], + ], })), events(({ actions }) => ({ afterMount: () => {