Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(experiments): add usage events #25619

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ export function ResultsHeader(): JSX.Element {
export function NoResultsEmptyState(): JSX.Element {
type ErrorCode = 'no-events' | 'no-flag-info' | 'no-control-variant' | 'no-test-variant'

const { experimentResultsLoading, experimentResultCalculationError } = useValues(experimentLogic)
const { experiment, experimentResultsLoading, experimentResultCalculationError } = useValues(experimentLogic)
const { reportExperimentResultsLoadingTimeout } = useActions(experimentLogic)

function ChecklistItem({ errorCode, value }: { errorCode: ErrorCode; value: boolean }): JSX.Element {
const failureText = {
Expand Down Expand Up @@ -275,6 +276,7 @@ export function NoResultsEmptyState(): JSX.Element {
}

if (experimentResultCalculationError?.statusCode === 504) {
reportExperimentResultsLoadingTimeout(experiment.id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's a good idea to call actions directly from the body of a React component. It will probably work (and perhaps trigger more often than expected), but I'd either move this to the logic somehow, or wrap it with an useEffect (and move higher up before all the returns).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Moved it to the logic.

return (
<div>
<div className="border rounded bg-bg-light py-10">
Expand Down
3 changes: 3 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
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
Loading