: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
import { MakeLogicType, afterMount, connect, kea, key, path, props } from 'kea'
import { loaders } from 'kea-loaders'
import api from 'lib/api'
import { teamLogic } from 'scenes/teamLogic'
import type { Experiment } from '~/types'
export interface ExperimentTabLogicProps {
featureFlagId: number
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface experimentTabLogicValues {
currentProjectId: number | string // teamLogic
relatedExperiments: Experiment[]
relatedExperimentsLoading: boolean
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface experimentTabLogicActions {
loadRelatedExperiments: () => any
loadRelatedExperimentsFailure: (
error: string,
errorObject?: any
) => {
error: string
errorObject?: any
}
loadRelatedExperimentsSuccess: (
relatedExperiments: Experiment[],
payload?: any
) => {
relatedExperiments: Experiment[]
payload?: any
}
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface experimentTabLogicMeta {
key: number
}
export type experimentTabLogicType = MakeLogicType<
experimentTabLogicValues,
experimentTabLogicActions,
ExperimentTabLogicProps,
experimentTabLogicMeta
>
export const experimentTabLogic = kea<experimentTabLogicType>([
path(['scenes', 'experiments', 'experimentTabLogic']),
props({} as ExperimentTabLogicProps),
key((props) => props.featureFlagId),
connect(() => ({ values: [teamLogic, ['currentProjectId']] })),
loaders(({ props, values }) => ({
relatedExperiments: [
[] as Experiment[],
{
loadRelatedExperiments: async () => {
// nosemgrep: prefer-codegen-api -- Legacy raw API call with a hand-written URL and an unchecked response type. Use experimentsList() from 'products/experiments/frontend/generated/api' instead.
const response = await api.get(
`api/projects/${values.currentProjectId}/experiments/?feature_flag_id=${props.featureFlagId}`
)
return response.results || []
},
},
],
})),
afterMount(({ actions }) => {
actions.loadRelatedExperiments()
}),
])