Skip to content

Commit

Permalink
chore(experiments): add usage events (#25619)
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajmajerik authored Oct 16, 2024
1 parent 861adc6 commit 024bddb
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 3 deletions.
25 changes: 25 additions & 0 deletions frontend/src/lib/utils/eventUsageLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,11 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
}),
reportExperimentInsightLoadFailed: true,
reportExperimentVariantShipped: (experiment: Experiment) => ({ experiment }),
reportExperimentVariantScreenshotUploaded: (experimentId: number | 'new') => ({ experimentId }),
reportExperimentResultsLoadingTimeout: (experimentId: number | 'new') => ({ experimentId }),
reportExperimentReleaseConditionsViewed: (experimentId: number | 'new') => ({ experimentId }),
reportExperimentReleaseConditionsUpdated: (experimentId: number | 'new') => ({ experimentId }),

// Definition Popover
reportDataManagementDefinitionHovered: (type: TaxonomicFilterGroupType) => ({ type }),
reportDataManagementDefinitionClickView: (type: TaxonomicFilterGroupType) => ({ type }),
Expand Down Expand Up @@ -1051,6 +1056,26 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
secondary_metrics_count: experiment.secondary_metrics.length,
})
},
reportExperimentVariantScreenshotUploaded: ({ experimentId }) => {
posthog.capture('experiment variant screenshot uploaded', {
experiment_id: experimentId,
})
},
reportExperimentResultsLoadingTimeout: ({ experimentId }) => {
posthog.capture('experiment results loading timeout', {
experiment_id: experimentId,
})
},
reportExperimentReleaseConditionsViewed: ({ experimentId }) => {
posthog.capture('experiment release conditions viewed', {
experiment_id: experimentId,
})
},
reportExperimentReleaseConditionsUpdated: ({ experimentId }) => {
posthog.capture('experiment release conditions updated', {
experiment_id: experimentId,
})
},
reportPropertyGroupFilterAdded: () => {
posthog.capture('property group filter added')
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { VariantScreenshot } from './VariantScreenshot'

export function DistributionTable(): JSX.Element {
const { experimentId, experiment, experimentResults } = useValues(experimentLogic)
const { reportExperimentReleaseConditionsViewed } = useActions(experimentLogic)
const { openSidePanel } = useActions(sidePanelStateLogic)

const columns: LemonTableColumns<MultivariateFlagVariant> = [
Expand Down Expand Up @@ -60,7 +61,10 @@ export function DistributionTable(): JSX.Element {
<div className="ml-auto mb-2">
<LemonButton
icon={<IconFlag />}
onClick={() => openSidePanel(SidePanelTab.ExperimentFeatureFlag)}
onClick={() => {
openSidePanel(SidePanelTab.ExperimentFeatureFlag)
reportExperimentReleaseConditionsViewed(experiment.id)
}}
type="secondary"
size="xsmall"
className="font-semibold"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { experimentLogic } from '../experimentLogic'

export function ReleaseConditionsTable(): JSX.Element {
const { experiment } = useValues(experimentLogic)
const { reportExperimentReleaseConditionsViewed } = useActions(experimentLogic)
const { aggregationLabel } = useValues(groupsModel)
const { openSidePanel } = useActions(sidePanelStateLogic)

Expand Down Expand Up @@ -65,7 +66,10 @@ export function ReleaseConditionsTable(): JSX.Element {
<div className="ml-auto mb-2">
<LemonButton
icon={<IconFlag />}
onClick={() => openSidePanel(SidePanelTab.ExperimentFeatureFlag)}
onClick={() => {
openSidePanel(SidePanelTab.ExperimentFeatureFlag)
reportExperimentReleaseConditionsViewed(experiment.id)
}}
type="secondary"
size="xsmall"
className="font-semibold"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function VariantScreenshot({
rolloutPercentage: number
}): JSX.Element {
const { experiment } = useValues(experimentLogic)
const { updateExperimentVariantImages } = useActions(experimentLogic)
const { updateExperimentVariantImages, reportExperimentVariantScreenshotUploaded } = useActions(experimentLogic)

const [mediaId, setMediaId] = useState(experiment.parameters?.variant_screenshot_media_ids?.[variantKey] || null)
const [isLoadingImage, setIsLoadingImage] = useState(true)
Expand All @@ -30,6 +30,7 @@ export function VariantScreenshot({
[variantKey]: id,
}
updateExperimentVariantImages(updatedVariantImages)
reportExperimentVariantScreenshotUploaded(experiment.id)
}
},
onError: (detail) => {
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/scenes/experiments/experimentLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ export const experimentLogic = kea<experimentLogicType>([
'reportExperimentReset',
'reportExperimentExposureCohortCreated',
'reportExperimentVariantShipped',
'reportExperimentVariantScreenshotUploaded',
'reportExperimentResultsLoadingTimeout',
'reportExperimentReleaseConditionsViewed',
],
insightDataLogic({ dashboardItemId: EXPERIMENT_INSIGHT_ID }),
['setQuery'],
Expand Down Expand Up @@ -775,6 +778,9 @@ export const experimentLogic = kea<experimentLogicType>([
}
} catch (error: any) {
actions.setExperimentResultCalculationError({ detail: error.detail, statusCode: error.status })
if (error.status === 504) {
actions.reportExperimentResultsLoadingTimeout(values.experimentId)
}
return null
}
},
Expand Down
1 change: 1 addition & 0 deletions frontend/src/scenes/feature-flags/featureFlagLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ export const featureFlagLogic = kea<featureFlagLogicType>([
const experimentId = currentPath.split('/').pop()

if (experimentId) {
eventUsageLogic.actions.reportExperimentReleaseConditionsUpdated(parseInt(experimentId))
experimentLogic({ experimentId: parseInt(experimentId) }).actions.loadExperiment()
}
},
Expand Down

0 comments on commit 024bddb

Please sign in to comment.