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

fix(experiments): Set aggregation group type index correctly, use fun… #21220

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Changes from all commits
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
32 changes: 20 additions & 12 deletions frontend/src/scenes/experiments/experimentLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { groupsModel } from '~/models/groupsModel'
import { filtersToQueryNode } from '~/queries/nodes/InsightQuery/utils/filtersToQueryNode'
import { queryNodeToFilter } from '~/queries/nodes/InsightQuery/utils/queryNodeToFilter'
import { FunnelsQuery, InsightVizNode, TrendsQuery } from '~/queries/schema'
import { isFunnelsQuery } from '~/queries/utils'
import {
ActionFilter as ActionFilterType,
Breadcrumb,
Expand Down Expand Up @@ -352,17 +353,7 @@ export const experimentLogic = kea<experimentLogicType>([
setNewExperimentInsight: async ({ filters }) => {
let newInsightFilters
const aggregationGroupTypeIndex = values.experiment.parameters?.aggregation_group_type_index
if (filters?.insight === InsightType.FUNNELS) {
newInsightFilters = cleanFilters({
insight: InsightType.FUNNELS,
funnel_viz_type: FunnelVizType.Steps,
date_from: dayjs().subtract(EXPERIMENT_DEFAULT_DURATION, 'day').format('YYYY-MM-DDTHH:mm'),
date_to: dayjs().endOf('d').format('YYYY-MM-DDTHH:mm'),
layout: FunnelLayout.horizontal,
aggregation_group_type_index: aggregationGroupTypeIndex,
...filters,
})
} else {
if (filters?.insight === InsightType.TRENDS) {
const groupAggregation =
aggregationGroupTypeIndex !== undefined
? { math: 'unique_group', math_group_type_index: aggregationGroupTypeIndex }
Expand All @@ -378,6 +369,16 @@ export const experimentLogic = kea<experimentLogicType>([
...eventAddition,
...filters,
})
} else {
newInsightFilters = cleanFilters({
insight: InsightType.FUNNELS,
funnel_viz_type: FunnelVizType.Steps,
date_from: dayjs().subtract(EXPERIMENT_DEFAULT_DURATION, 'day').format('YYYY-MM-DDTHH:mm'),
date_to: dayjs().endOf('d').format('YYYY-MM-DDTHH:mm'),
layout: FunnelLayout.horizontal,
aggregation_group_type_index: aggregationGroupTypeIndex,
...filters,
})
}

// This allows switching between insight types. It's necessary as `updateQuerySource` merges
Expand All @@ -389,6 +390,13 @@ export const experimentLogic = kea<experimentLogicType>([
} else {
;(newQuery as FunnelsQuery).funnelsFilter = undefined
}

// TRICKY: We always know what the group type index should be for funnel queries, so we don't care
// what the previous value was. Hence, instead of a partial update with `updateQuerySource`, we always
// explicitly set it to what it should be
if (isFunnelsQuery(newQuery)) {
newQuery.aggregation_group_type_index = aggregationGroupTypeIndex
}
actions.updateQuerySource(newQuery)
},
// sync form value `filters` with query
Expand Down Expand Up @@ -670,7 +678,7 @@ export const experimentLogic = kea<experimentLogicType>([
experimentInsightType: [
(s) => [s.experiment],
(experiment): InsightType => {
return experiment?.filters?.insight || InsightType.TRENDS
return experiment?.filters?.insight || InsightType.FUNNELS
},
],
isExperimentRunning: [
Expand Down
Loading