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(web-analytics): Allow customers to compare against a different period #26820

Merged
merged 13 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
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
105 changes: 25 additions & 80 deletions frontend/src/queries/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -546,22 +546,6 @@
},
"type": "object"
},
"AssistantCompareFilter": {
"additionalProperties": false,
"properties": {
"compare": {
"default": false,
"description": "Whether to compare the current date range to a previous date range.",
"type": "boolean"
},
"compare_to": {
"default": "-7d",
"description": "The date range to compare to. The value is a relative date. Examples of relative dates are: `-1y` for 1 year ago, `-14m` for 14 months ago, `-100w` for 100 weeks ago, `-14d` for 14 days ago, `-30h` for 30 hours ago.",
"type": "string"
}
},
"type": "object"
},
"AssistantDateTimePropertyFilter": {
"additionalProperties": false,
"properties": {
Expand Down Expand Up @@ -742,7 +726,7 @@
"description": "Breakdown the chart by a property"
},
"dateRange": {
"$ref": "#/definitions/AssistantInsightDateRange",
"$ref": "#/definitions/DateRange",
"description": "Date range for the query"
},
"filterTestAccounts": {
Expand Down Expand Up @@ -1043,27 +1027,11 @@
}
]
},
"AssistantInsightDateRange": {
"additionalProperties": false,
"properties": {
"date_from": {
"default": "-7d",
"description": "Start date. The value can be:\n- a relative date. Examples of relative dates are: `-1y` for 1 year ago, `-14m` for 14 months ago, `-1w` for 1 week ago, `-14d` for 14 days ago, `-30h` for 30 hours ago.\n- an absolute ISO 8601 date string. a constant `yStart` for the current year start. a constant `mStart` for the current month start. a constant `dStart` for the current day start. Prefer using relative dates.",
"type": ["string", "null"]
},
"date_to": {
"default": null,
"description": "Right boundary of the date range. Use `null` for the current date. You can not use relative dates here.",
"type": ["string", "null"]
}
},
"type": "object"
},
"AssistantInsightsQueryBase": {
"additionalProperties": false,
"properties": {
"dateRange": {
"$ref": "#/definitions/AssistantInsightDateRange",
"$ref": "#/definitions/DateRange",
"description": "Date range for the query"
},
"filterTestAccounts": {
Expand Down Expand Up @@ -1365,7 +1333,7 @@
"description": "Compare to date range"
},
"dateRange": {
"$ref": "#/definitions/AssistantInsightDateRange",
"$ref": "#/definitions/DateRange",
"description": "Date range for the query"
},
"filterTestAccounts": {
Expand Down Expand Up @@ -3803,9 +3771,12 @@
"additionalProperties": false,
"properties": {
"compare": {
"default": false,
"description": "Whether to compare the current date range to a previous date range.",
"type": "boolean"
},
"compare_to": {
"description": "The date range to compare to. The value is a relative date. Examples of relative dates are: `-1y` for 1 year ago, `-14m` for 14 months ago, `-100w` for 100 weeks ago, `-14d` for 14 days ago, `-30h` for 30 hours ago.",
"type": "string"
}
},
Expand Down Expand Up @@ -6873,7 +6844,7 @@
"description": "Breakdown of the events and actions"
},
"dateRange": {
"$ref": "#/definitions/InsightDateRange",
"$ref": "#/definitions/DateRange",
"description": "Date range for the query"
},
"filterTestAccounts": {
Expand Down Expand Up @@ -7786,24 +7757,6 @@
},
"type": "object"
},
"InsightDateRange": {
"additionalProperties": false,
"properties": {
"date_from": {
"default": "-7d",
"type": ["string", "null"]
},
"date_to": {
"type": ["string", "null"]
},
"explicitDate": {
"default": false,
"description": "Whether the date_from and date_to should be used verbatim. Disables rounding to the start and end of period.",
"type": ["boolean", "null"]
}
},
"type": "object"
},
"InsightFilter": {
"anyOf": [
{
Expand Down Expand Up @@ -7966,7 +7919,7 @@
"description": "Groups aggregation"
},
"dateRange": {
"$ref": "#/definitions/InsightDateRange",
"$ref": "#/definitions/DateRange",
"description": "Date range for the query"
},
"filterTestAccounts": {
Expand Down Expand Up @@ -8023,7 +7976,7 @@
"description": "Groups aggregation"
},
"dateRange": {
"$ref": "#/definitions/InsightDateRange",
"$ref": "#/definitions/DateRange",
"description": "Date range for the query"
},
"filterTestAccounts": {
Expand Down Expand Up @@ -8080,7 +8033,7 @@
"description": "Groups aggregation"
},
"dateRange": {
"$ref": "#/definitions/InsightDateRange",
"$ref": "#/definitions/DateRange",
"description": "Date range for the query"
},
"filterTestAccounts": {
Expand Down Expand Up @@ -8137,7 +8090,7 @@
"description": "Groups aggregation"
},
"dateRange": {
"$ref": "#/definitions/InsightDateRange",
"$ref": "#/definitions/DateRange",
"description": "Date range for the query"
},
"filterTestAccounts": {
Expand Down Expand Up @@ -8194,7 +8147,7 @@
"description": "Groups aggregation"
},
"dateRange": {
"$ref": "#/definitions/InsightDateRange",
"$ref": "#/definitions/DateRange",
"description": "Date range for the query"
},
"filterTestAccounts": {
Expand Down Expand Up @@ -8304,7 +8257,7 @@
"description": "Groups aggregation"
},
"dateRange": {
"$ref": "#/definitions/InsightDateRange",
"$ref": "#/definitions/DateRange",
"description": "Date range for the query"
},
"filterTestAccounts": {
Expand Down Expand Up @@ -8713,7 +8666,7 @@
"description": "Groups aggregation"
},
"dateRange": {
"$ref": "#/definitions/InsightDateRange",
"$ref": "#/definitions/DateRange",
"description": "Date range for the query"
},
"filterTestAccounts": {
Expand Down Expand Up @@ -11481,7 +11434,7 @@
"description": "Groups aggregation"
},
"dateRange": {
"$ref": "#/definitions/InsightDateRange",
"$ref": "#/definitions/DateRange",
"description": "Date range for the query"
},
"filterTestAccounts": {
Expand Down Expand Up @@ -12153,7 +12106,7 @@
"description": "Compare to date range"
},
"dateRange": {
"$ref": "#/definitions/InsightDateRange",
"$ref": "#/definitions/DateRange",
"description": "Date range for the query"
},
"filterTestAccounts": {
Expand Down Expand Up @@ -12704,7 +12657,7 @@
"description": "Whether we should be comparing against a specific conversion goal"
},
"dateRange": {
"$ref": "#/definitions/InsightDateRange",
"$ref": "#/definitions/DateRange",
"description": "Date range for the query"
},
"filterTestAccounts": {
Expand Down Expand Up @@ -12895,6 +12848,9 @@
"WebExternalClicksTableQuery": {
"additionalProperties": false,
"properties": {
"compareFilter": {
"$ref": "#/definitions/CompareFilter"
},
"conversionGoal": {
"anyOf": [
{
Expand Down Expand Up @@ -13008,6 +12964,9 @@
"WebGoalsQuery": {
"additionalProperties": false,
"properties": {
"compareFilter": {
"$ref": "#/definitions/CompareFilter"
},
"conversionGoal": {
"anyOf": [
{
Expand Down Expand Up @@ -13148,14 +13107,7 @@
"additionalProperties": false,
"properties": {
"compareFilter": {
"anyOf": [
{
"$ref": "#/definitions/CompareFilter"
},
{
"type": "null"
}
]
"$ref": "#/definitions/CompareFilter"
},
"conversionGoal": {
"anyOf": [
Expand Down Expand Up @@ -13287,14 +13239,7 @@
"$ref": "#/definitions/WebStatsBreakdown"
},
"compareFilter": {
"anyOf": [
{
"$ref": "#/definitions/CompareFilter"
},
{
"type": "null"
}
]
"$ref": "#/definitions/CompareFilter"
},
"conversionGoal": {
"anyOf": [
Expand Down
46 changes: 4 additions & 42 deletions frontend/src/queries/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ interface InsightVizNodeViewProps {
/** Base class for insight query nodes. Should not be used directly. */
export interface InsightsQueryBase<R extends AnalyticsQueryResponseBase<any>> extends Node<R> {
/** Date range for the query */
dateRange?: InsightDateRange
dateRange?: DateRange
/**
* Exclude internal and test users by applying the respective filters
*
Expand Down Expand Up @@ -1004,31 +1004,11 @@ export type AssistantGroupPropertyFilter = AssistantBasePropertyFilter & {

export type AssistantPropertyFilter = AssistantGenericPropertyFilter | AssistantGroupPropertyFilter

export interface AssistantInsightDateRange {
/**
* Start date. The value can be:
* - a relative date. Examples of relative dates are: `-1y` for 1 year ago, `-14m` for 14 months ago, `-1w` for 1 week ago, `-14d` for 14 days ago, `-30h` for 30 hours ago.
* - an absolute ISO 8601 date string.
* a constant `yStart` for the current year start.
* a constant `mStart` for the current month start.
* a constant `dStart` for the current day start.
* Prefer using relative dates.
* @default -7d
*/
date_from?: string | null

/**
* Right boundary of the date range. Use `null` for the current date. You can not use relative dates here.
* @default null
*/
date_to?: string | null
}

export interface AssistantInsightsQueryBase {
/**
* Date range for the query
*/
dateRange?: AssistantInsightDateRange
dateRange?: DateRange

/**
* Exclude internal and test users by applying the respective filters
Expand Down Expand Up @@ -1171,7 +1151,7 @@ export interface AssistantTrendsFilter {
yAxisScaleType?: TrendsFilterLegacy['y_axis_scale_type']
}

export interface AssistantCompareFilter {
export interface CompareFilter {
/**
* Whether to compare the current date range to a previous date range.
* @default false
Expand All @@ -1180,7 +1160,6 @@ export interface AssistantCompareFilter {

/**
* The date range to compare to. The value is a relative date. Examples of relative dates are: `-1y` for 1 year ago, `-14m` for 14 months ago, `-100w` for 100 weeks ago, `-14d` for 14 days ago, `-30h` for 30 hours ago.
* @default -7d
*/
compare_to?: string
}
Expand Down Expand Up @@ -1789,6 +1768,7 @@ interface WebAnalyticsQueryBase<R extends Record<string, any>> extends DataNode<
dateRange?: DateRange
properties: WebAnalyticsPropertyFilters
conversionGoal?: WebAnalyticsConversionGoal | null
compareFilter?: CompareFilter
sampling?: {
enabled?: boolean
forceSamplingRate?: SamplingRate
Expand All @@ -1800,7 +1780,6 @@ interface WebAnalyticsQueryBase<R extends Record<string, any>> extends DataNode<

export interface WebOverviewQuery extends WebAnalyticsQueryBase<WebOverviewQueryResponse> {
kind: NodeKind.WebOverviewQuery
compareFilter?: CompareFilter | null
includeLCPScore?: boolean
}

Expand Down Expand Up @@ -1852,7 +1831,6 @@ export enum WebStatsBreakdown {
export interface WebStatsTableQuery extends WebAnalyticsQueryBase<WebStatsTableQueryResponse> {
kind: NodeKind.WebStatsTableQuery
breakdownBy: WebStatsBreakdown
compareFilter?: CompareFilter | null
includeScrollDepth?: boolean // automatically sets includeBounceRate to true
includeBounceRate?: boolean
doPathCleaning?: boolean
Expand Down Expand Up @@ -2321,17 +2299,6 @@ export interface DateRange {
explicitDate?: boolean | null
}

export interface InsightDateRange {
/** @default -7d */
date_from?: string | null
date_to?: string | null
/** Whether the date_from and date_to should be used verbatim. Disables
* rounding to the start and end of period.
* @default false
* */
explicitDate?: boolean | null
}

export type MultipleBreakdownType = Extract<BreakdownType, 'person' | 'event' | 'group' | 'session' | 'hogql'>

export interface Breakdown {
Expand All @@ -2358,11 +2325,6 @@ export interface BreakdownFilter {
breakdown_hide_other_aggregation?: boolean | null // hides the "other" field for trends
}

export interface CompareFilter {
compare?: boolean
compare_to?: string
}

// TODO: Rename to `DashboardFilters` for consistency with `HogQLFilters`
export interface DashboardFilter {
date_from?: string | null
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ const VariationCell = (
{ isPercentage, reverseColors }: VariationCellProps = { isPercentage: false, reverseColors: false }
): QueryContextColumnComponent => {
const formatNumber = (value: number): string =>
isPercentage ? `${(value * 100).toFixed(1)}%` : value.toLocaleString()
isPercentage ? `${(value * 100).toFixed(1)}%` : value?.toLocaleString() ?? '(empty)'

return function Cell({ value }) {
const { compareFilter } = useValues(webAnalyticsLogic)

if (!value) {
return null
}
Expand All @@ -57,10 +59,11 @@ const VariationCell = (
}

const [current, previous] = value as [number, number]

const pctChangeFromPrevious =
previous === 0 && current === 0 // Special case, render as flatline
? 0
: current === null
: current === null || !compareFilter || compareFilter.compare === false
? null
: previous === null || previous === 0
? Infinity
Expand Down
Loading
Loading