: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(experiments): Track settings tab views and setting changes (#118460)
Juraj Majerikfc21aa8daa4e
diff --git a/frontend/src/lib/utils/eventUsageLogic.ts b/frontend/src/lib/utils/eventUsageLogic.tsindex aa10fc53ee7c..2eb8f47adb06 100644--- a/frontend/src/lib/utils/eventUsageLogic.ts+++ b/frontend/src/lib/utils/eventUsageLogic.ts@@ -1245,6 +1245,16 @@ export interface eventUsageLogicActions {page: numberstatusFilter: string}+ reportExperimentsSettingChanged: (+ setting: string,+ value: unknown+ ) => {+ setting: string+ value: unknown+ }+ reportExperimentsSettingsViewed: () => {+ value: true+ }reportFeatureFlagBulkCopy: (flagCount: number,projectCount: number,@@ -1887,6 +1897,8 @@ export const eventUsageLogic = kea<eventUsageLogicType>([hasSearch: booleanarchived: boolean}) => listView,+ reportExperimentsSettingsViewed: true,+ reportExperimentsSettingChanged: (setting: string, value: unknown) => ({ setting, value }),reportExperimentViewed: (experiment: Experiment, duration: number | null) => ({ experiment, duration }),reportExperimentMetricBreakdownAdded: (experiment: Experiment,@@ -2499,6 +2511,12 @@ export const eventUsageLogic = kea<eventUsageLogicType>([archived,})},+ reportExperimentsSettingsViewed: () => {+ posthog.capture('experiments settings viewed')+ },+ reportExperimentsSettingChanged: ({ setting, value }) => {+ posthog.capture('experiments setting changed', { setting, value })+ },reportExperimentViewed: ({ experiment, duration }) => {posthog.capture('experiment viewed', {...getEventPropertiesForExperiment(experiment),diff --git a/frontend/src/scenes/settings/environment/experimentsConfigLogic.ts b/frontend/src/scenes/settings/environment/experimentsConfigLogic.tsindex 4bbf687e5fe2..4d8198bfc712 100644--- a/frontend/src/scenes/settings/environment/experimentsConfigLogic.ts+++ b/frontend/src/scenes/settings/environment/experimentsConfigLogic.ts@@ -3,6 +3,7 @@ import { loaders } from 'kea-loaders'import api from 'lib/api'import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'+import { eventUsageLogic } from 'lib/utils/eventUsageLogic'import { teamLogic } from '~/scenes/teamLogic'@@ -21,6 +22,10 @@ export interface ExperimentsConfig {flag_cleanup_repository: string | null}+// Repository names identify the customer's codebase, so only report whether one is set.+const redactSettingValue = (setting: string, value: unknown): unknown =>+ setting === 'flag_cleanup_repository' ? value !== null : value+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface experimentsConfigLogicValues {currentTeamId: number | null // teamLogic@@ -32,6 +37,13 @@ export interface experimentsConfigLogicValues {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface experimentsConfigLogicActions {+ reportExperimentsSettingChanged: (+ setting: string,+ value: unknown+ ) => {+ setting: string+ value: unknown+ } // eventUsageLogicloadExperimentsConfig: () => anyloadExperimentsConfigFailure: (error: string,@@ -68,7 +80,10 @@ export type experimentsConfigLogicType = MakeLogicType<export const experimentsConfigLogic = kea<experimentsConfigLogicType>([path(['scenes', 'settings', 'environment', 'experimentsConfigLogic']),- connect({ values: [teamLogic, ['currentTeamId']] }),+ connect(() => ({+ values: [teamLogic, ['currentTeamId']],+ actions: [eventUsageLogic, ['reportExperimentsSettingChanged']],+ })),actions({updateExperimentsConfig: (payload: Partial<ExperimentsConfig>) => ({ payload }),}),@@ -107,6 +122,9 @@ export const experimentsConfigLogic = kea<experimentsConfigLogicType>([try {// nosemgrep: prefer-codegen-api -- Legacy raw API call with a hand-written URL and an unchecked response type. organizationsProjectsExperimentsConfigPartialUpdate() from '~/generated/core/api' serves this route, but its generated types do not describe this call yet, so fix the endpoint's OpenAPI schema first.await api.update(`api/projects/${values.currentTeamId}/experiments_config/`, payload)+ for (const [setting, value] of Object.entries(payload)) {+ actions.reportExperimentsSettingChanged(setting, redactSettingValue(setting, value))+ }} catch (error: any) {lemonToast.error(error.data?.detail || 'Failed to update experiment settings. Please try again.')} finally {diff --git a/products/experiments/frontend/scenes/experimentsLogic.ts b/products/experiments/frontend/scenes/experimentsLogic.tsindex 545070bcd7ea..95cdfc284599 100644--- a/products/experiments/frontend/scenes/experimentsLogic.ts+++ b/products/experiments/frontend/scenes/experimentsLogic.ts@@ -208,6 +208,9 @@ export interface experimentsLogicActions {page: numberstatusFilter: string} // eventUsageLogic+ reportExperimentsSettingsViewed: () => {+ value: true+ } // eventUsageLogicloadCurrentTeamSuccess: (currentTeam: TeamPublicType | null,payload?: any@@ -554,7 +557,7 @@ export const experimentsLogic = kea<experimentsLogicType>([teamLogic,['loadCurrentTeamSuccess', 'updateCurrentTeamSuccess'],eventUsageLogic,- ['reportExperimentsListViewed'],+ ['reportExperimentsListViewed', 'reportExperimentsSettingsViewed'],],})),actions({@@ -605,6 +608,11 @@ export const experimentsLogic = kea<experimentsLogicType>([],}),listeners(({ actions, values }) => ({+ setExperimentsTab: ({ tabKey }) => {+ if (tabKey === ExperimentsTabs.Settings) {+ actions.reportExperimentsSettingsViewed()+ }+ },setExperimentsFilters: async (_, breakpoint) => {// Only debounce after the first load — the debounce is for search input,// but the initial load from urlToAction should fire immediately.