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

feat(experiments): explore results in an insight #21235

Merged
merged 13 commits into from
Apr 11, 2024
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions frontend/src/lib/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1729,3 +1729,12 @@ export function hasFormErrors(object: any): boolean {
}
return !!object
}

export function stringToBoolean(value: unknown): boolean {
const stringValue = String(value).toLowerCase()
const isStrictlyTrue = ['y', 'yes', 't', 'true', 'on', '1'].includes(stringValue)
if (isStrictlyTrue) {
return true
}
return false
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Sentry from '@sentry/react'
import { objectCleanWithEmpty } from 'lib/utils'
import { objectCleanWithEmpty, stringToBoolean } from 'lib/utils'
import { transformLegacyHiddenLegendKeys } from 'scenes/funnels/funnelUtils'
import { MathAvailability } from 'scenes/insights/filters/ActionFilter/ActionFilterRow/ActionFilterRow'
import {
Expand Down Expand Up @@ -226,6 +226,8 @@ export const filtersToQueryNode = (filters: Partial<FilterType>): InsightQueryNo
kind: reverseInsightMap[filters.insight],
properties: cleanGlobalProperties(filters.properties),
filterTestAccounts: filters.filter_test_accounts,

explicitDate: stringToBoolean(filters.explicit_date),
}
if (filters.sampling_factor) {
query.samplingFactor = filters.sampling_factor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { objectClean } from 'lib/utils'
import { objectClean, stringToBoolean } from 'lib/utils'
import { isFunnelsFilter, isLifecycleFilter, isStickinessFilter, isTrendsFilter } from 'scenes/insights/sharedUtils'

import {
Expand Down Expand Up @@ -125,6 +125,7 @@ export const queryNodeToFilter = (query: InsightQueryNode): Partial<FilterType>
date_from: query.dateRange?.date_from,
entity_type: 'events',
sampling_factor: query.samplingFactor,
explicit_date: stringToBoolean(query.explicitDate),
})

if (!isRetentionQuery(query) && !isPathsQuery(query)) {
Expand Down
21 changes: 21 additions & 0 deletions frontend/src/queries/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,9 @@
"$ref": "#/definitions/DateRange",
"description": "Date range for the query"
},
"explicitDate": {
"type": "boolean"
},
"filterTestAccounts": {
"description": "Exclude internal and test users by applying the respective filters",
"type": "boolean"
Expand Down Expand Up @@ -3003,6 +3006,9 @@
"$ref": "#/definitions/DateRange",
"description": "Date range for the query"
},
"explicitDate": {
"type": "boolean"
},
"filterTestAccounts": {
"description": "Exclude internal and test users by applying the respective filters",
"type": "boolean"
Expand Down Expand Up @@ -3074,6 +3080,9 @@
"$ref": "#/definitions/DateRange",
"description": "Date range for the query"
},
"explicitDate": {
"type": "boolean"
},
"filterTestAccounts": {
"description": "Exclude internal and test users by applying the respective filters",
"type": "boolean"
Expand Down Expand Up @@ -3379,6 +3388,9 @@
"$ref": "#/definitions/DateRange",
"description": "Date range for the query"
},
"explicitDate": {
"type": "boolean"
},
"filterTestAccounts": {
"description": "Exclude internal and test users by applying the respective filters",
"type": "boolean"
Expand Down Expand Up @@ -4631,6 +4643,9 @@
"$ref": "#/definitions/DateRange",
"description": "Date range for the query"
},
"explicitDate": {
"type": "boolean"
},
"filterTestAccounts": {
"description": "Exclude internal and test users by applying the respective filters",
"type": "boolean"
Expand Down Expand Up @@ -5010,6 +5025,9 @@
"$ref": "#/definitions/DateRange",
"description": "Date range for the query"
},
"explicitDate": {
"type": "boolean"
},
"filterTestAccounts": {
"description": "Exclude internal and test users by applying the respective filters",
"type": "boolean"
Expand Down Expand Up @@ -5329,6 +5347,9 @@
"$ref": "#/definitions/DateRange",
"description": "Date range for the query"
},
"explicitDate": {
"type": "boolean"
},
"filterTestAccounts": {
"description": "Exclude internal and test users by applying the respective filters",
"type": "boolean"
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/queries/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,8 @@ export interface InsightsQueryBase extends Node {
aggregation_group_type_index?: integer
/** Sampling rate */
samplingFactor?: number | null

explicitDate?: boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

Fly-by comment (off for easter, will have a deeper look next Tuesday) - I don't think we handle this setting in the new insights at all. Seems it gets passed in via the date range filter. I'll look into adding it and would appreciate any context :) After a first look I'd think this should belong into the dateRange object?

Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't see the DateRange component before, but agree should go there!

For context, we need this setting whenever we don't want to round date ranges to start and end of day. This is particularly important for experiments because we want to discard all testing data that came before the exact moment the experiment began.

Copy link
Contributor

Choose a reason for hiding this comment

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

We'll need this setting as well to move both trends & funnel experiments backend off of filters and onto query 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

For more context, the appropriate setting in filters is: https://github.com/PostHog/posthog/blob/master/posthog/schema.py#L2549

}

/** `TrendsFilterType` minus everything inherited from `FilterType` and
Expand Down
43 changes: 40 additions & 3 deletions frontend/src/scenes/experiments/ExperimentView/Results.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import '../Experiment.scss'

import { LemonButton } from '@posthog/lemon-ui'
import { useValues } from 'kea'
import { IconAreaChart } from 'lib/lemon-ui/icons'
import { urls } from 'scenes/urls'

import { filtersToQueryNode } from '~/queries/nodes/InsightQuery/utils/filtersToQueryNode'
import { Query } from '~/queries/Query/Query'
Expand All @@ -17,9 +20,43 @@ export function Results(): JSX.Element {

return (
<div>
<div className="inline-flex items-center space-x-2 mb-2">
<h2 className="m-0 font-semibold text-lg">Results</h2>
<ResultsTag />
<div className="flex">
<div className="w-1/2">
<div className="inline-flex items-center space-x-2 mb-2">
<h2 className="m-0 font-semibold text-lg">Results</h2>
<ResultsTag />
</div>
</div>

<div className="w-1/2 flex flex-col justify-end">
<div className="ml-auto">
<LemonButton
className="ml-auto -translate-y-2"
size="small"
type="secondary"
icon={<IconAreaChart />}
to={urls.insightNew(
undefined,
undefined,
JSON.stringify({
kind: NodeKind.InsightVizNode,
source: filtersToQueryNode(
transformResultFilters(
experimentResults?.filters
? { ...experimentResults.filters, explicit_date: true }
: {}
)
),
showTable: true,
showLastComputation: true,
showLastComputationRefresh: false,
})
)}
>
Explore
</LemonButton>
</div>
</div>
</div>
<SummaryTable />
<Query
Expand Down
7 changes: 7 additions & 0 deletions posthog/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2415,6 +2415,7 @@ class RetentionQuery(BaseModel):
)
aggregation_group_type_index: Optional[int] = Field(default=None, description="Groups aggregation")
dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query")
explicitDate: Optional[bool] = None
filterTestAccounts: Optional[bool] = Field(
default=None, description="Exclude internal and test users by applying the respective filters"
)
Expand Down Expand Up @@ -2449,6 +2450,7 @@ class StickinessQuery(BaseModel):
extra="forbid",
)
dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query")
explicitDate: Optional[bool] = None
filterTestAccounts: Optional[bool] = Field(
default=None, description="Exclude internal and test users by applying the respective filters"
)
Expand Down Expand Up @@ -2492,6 +2494,7 @@ class TrendsQuery(BaseModel):
aggregation_group_type_index: Optional[int] = Field(default=None, description="Groups aggregation")
breakdownFilter: Optional[BreakdownFilter] = Field(default=None, description="Breakdown of the events and actions")
dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query")
explicitDate: Optional[bool] = None
filterTestAccounts: Optional[bool] = Field(
default=None, description="Exclude internal and test users by applying the respective filters"
)
Expand Down Expand Up @@ -2585,6 +2588,7 @@ class FunnelsQuery(BaseModel):
aggregation_group_type_index: Optional[int] = Field(default=None, description="Groups aggregation")
breakdownFilter: Optional[BreakdownFilter] = Field(default=None, description="Breakdown of the events and actions")
dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query")
explicitDate: Optional[bool] = None
filterTestAccounts: Optional[bool] = Field(
default=None, description="Exclude internal and test users by applying the respective filters"
)
Expand Down Expand Up @@ -2627,6 +2631,7 @@ class InsightsQueryBase(BaseModel):
)
aggregation_group_type_index: Optional[int] = Field(default=None, description="Groups aggregation")
dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query")
explicitDate: Optional[bool] = None
filterTestAccounts: Optional[bool] = Field(
default=None, description="Exclude internal and test users by applying the respective filters"
)
Expand Down Expand Up @@ -2659,6 +2664,7 @@ class LifecycleQuery(BaseModel):
extra="forbid",
)
dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query")
explicitDate: Optional[bool] = None
filterTestAccounts: Optional[bool] = Field(
default=None, description="Exclude internal and test users by applying the respective filters"
)
Expand Down Expand Up @@ -2709,6 +2715,7 @@ class PathsQuery(BaseModel):
)
aggregation_group_type_index: Optional[int] = Field(default=None, description="Groups aggregation")
dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query")
explicitDate: Optional[bool] = None
filterTestAccounts: Optional[bool] = Field(
default=None, description="Exclude internal and test users by applying the respective filters"
)
Expand Down
Loading