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 9 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
43 changes: 11 additions & 32 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 @@ -3803,9 +3787,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 @@ -12895,6 +12882,9 @@
"WebExternalClicksTableQuery": {
"additionalProperties": false,
"properties": {
"compareFilter": {
"$ref": "#/definitions/CompareFilter"
},
"conversionGoal": {
"anyOf": [
{
Expand Down Expand Up @@ -13008,6 +12998,9 @@
"WebGoalsQuery": {
"additionalProperties": false,
"properties": {
"compareFilter": {
"$ref": "#/definitions/CompareFilter"
},
"conversionGoal": {
"anyOf": [
{
Expand Down Expand Up @@ -13148,14 +13141,7 @@
"additionalProperties": false,
"properties": {
"compareFilter": {
"anyOf": [
{
"$ref": "#/definitions/CompareFilter"
},
{
"type": "null"
}
]
"$ref": "#/definitions/CompareFilter"
},
"conversionGoal": {
"anyOf": [
Expand Down Expand Up @@ -13287,14 +13273,7 @@
"$ref": "#/definitions/WebStatsBreakdown"
},
"compareFilter": {
"anyOf": [
{
"$ref": "#/definitions/CompareFilter"
},
{
"type": "null"
}
]
"$ref": "#/definitions/CompareFilter"
},
"conversionGoal": {
"anyOf": [
Expand Down
11 changes: 2 additions & 9 deletions frontend/src/queries/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,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 +1180,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 +1788,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 +1800,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 +1851,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 @@ -2358,11 +2356,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
5 changes: 4 additions & 1 deletion frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const VariationCell = (
isPercentage ? `${(value * 100).toFixed(1)}%` : value.toLocaleString()

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
10 changes: 6 additions & 4 deletions frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([
return { tileId, tabId }
},
setConversionGoalWarning: (warning: ConversionGoalWarning | null) => ({ warning }),
setCompareFilter: (compareFilter: CompareFilter | null) => ({ compareFilter }),
setCompareFilter: (compareFilter: CompareFilter) => ({ compareFilter }),
}),
reducers({
webAnalyticsFilters: [
Expand Down Expand Up @@ -475,7 +475,7 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([
},
],
compareFilter: [
{ compare: true } as CompareFilter | null,
{ compare: true } as CompareFilter,
persistConfig,
{
setCompareFilter: (_, { compareFilter }) => compareFilter,
Expand Down Expand Up @@ -621,7 +621,7 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([
display: ChartDisplayType.ActionsLineGraph,
...trendsFilter,
},
compareFilter: compareFilter || { compare: false },
compareFilter,
filterTestAccounts,
conversionGoal: featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_CONVERSION_GOAL_FILTERS]
? conversionGoal
Expand Down Expand Up @@ -882,6 +882,7 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([
kind: NodeKind.WebExternalClicksTableQuery,
properties: webAnalyticsFilters,
dateRange,
compareFilter,
sampling,
limit: 10,
filterTestAccounts,
Expand Down Expand Up @@ -1290,6 +1291,7 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([
kind: NodeKind.WebGoalsQuery,
properties: webAnalyticsFilters,
dateRange,
compareFilter,
sampling,
limit: 10,
filterTestAccounts,
Expand Down Expand Up @@ -1321,7 +1323,7 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([
},
}
: null,
featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_REPLAY]
!conversionGoal && featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_REPLAY]
? {
kind: 'replay',
tileId: TileId.REPLAY,
Expand Down
Loading
Loading