Skip to content

Commit

Permalink
feat(hogql): trends funnel (#20370)
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr committed Feb 20, 2024
1 parent 8e92a4b commit 65e1bb4
Show file tree
Hide file tree
Showing 21 changed files with 2,103 additions and 18 deletions.
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.
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/queries/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,12 @@
"required": ["average_conversion_time", "bins"],
"type": "object"
},
"FunnelTrendsResults": {
"items": {
"type": "object"
},
"type": "array"
},
"FunnelVizType": {
"enum": ["steps", "time_to_convert", "trends"],
"type": "string"
Expand Down Expand Up @@ -1873,6 +1879,9 @@
},
{
"$ref": "#/definitions/FunnelTimeToConvertResults"
},
{
"$ref": "#/definitions/FunnelTrendsResults"
}
]
},
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/queries/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,9 @@ export type FunnelTimeToConvertResults = {
average_conversion_time: number
bins: [BinNumber, BinNumber][]
}
export type FunnelTrendsResults = Record<string, any>[]
export interface FunnelsQueryResponse extends QueryResponse {
results: FunnelStepsResults | FunnelStepsBreakdownResults | FunnelTimeToConvertResults
results: FunnelStepsResults | FunnelStepsBreakdownResults | FunnelTimeToConvertResults | FunnelTrendsResults
}

/** `RetentionFilterType` minus everything inherited from `FilterType` */
Expand Down
1 change: 1 addition & 0 deletions posthog/hogql_queries/insights/funnels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from .funnel_strict import FunnelStrict
from .funnel_unordered import FunnelUnordered
from .funnel_time_to_convert import FunnelTimeToConvert
from .funnel_trends import FunnelTrends
9 changes: 3 additions & 6 deletions posthog/hogql_queries/insights/funnels/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ class FunnelBase(ABC):
_extra_event_fields: List[ColumnName]
_extra_event_properties: List[PropertyName]

def __init__(
self,
context: FunnelQueryContext,
):
def __init__(self, context: FunnelQueryContext):
self.context = context

self._extra_event_fields: List[ColumnName] = []
Expand All @@ -56,10 +53,10 @@ def __init__(
def get_query(self) -> ast.SelectQuery:
raise NotImplementedError()

def get_step_counts_query(self) -> str:
def get_step_counts_query(self) -> ast.SelectQuery:
raise NotImplementedError()

def get_step_counts_without_aggregation_query(self) -> str:
def get_step_counts_without_aggregation_query(self) -> ast.SelectQuery:
raise NotImplementedError()

@cached_property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
FunnelsFilter,
FunnelsQuery,
HogQLQueryModifiers,
IntervalType,
)


Expand All @@ -21,6 +22,8 @@ class FunnelQueryContext(QueryContext):
funnelsFilter: FunnelsFilter
breakdownFilter: BreakdownFilter

interval: IntervalType

breakdown: List[Union[str, int]] | None
breakdownType: BreakdownType
breakdownAttributionType: BreakdownAttributionType
Expand All @@ -42,6 +45,8 @@ def __init__(
self.breakdownFilter = self.query.breakdownFilter or BreakdownFilter()

# defaults
self.interval = self.query.interval or IntervalType.day

self.breakdownType = self.breakdownFilter.breakdown_type or BreakdownType.event
self.breakdownAttributionType = (
self.funnelsFilter.breakdownAttributionType or BreakdownAttributionType.first_touch
Expand Down
Loading

0 comments on commit 65e1bb4

Please sign in to comment.