Skip to content

Commit e7ce652

Browse files
authored
Fix conversions realtime (#6456)
* realtime -> realtime_30m for conversions * tests + render last 30min pill only for conversions
1 parent 648f16f commit e7ce652

7 files changed

Lines changed: 98 additions & 10 deletions

File tree

assets/js/dashboard/stats/behaviours/conversions.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,29 @@ import {
1010
BreakdownReportKey
1111
} from '../reports/reports-config'
1212
import { QueryApiResponse, QueryResultRow } from '../../api'
13-
import { NonTimeDimension } from '../../stats-query'
13+
import { NonTimeDimension, StatsQuery } from '../../stats-query'
1414
import { FilterInfo } from '../../components/drilldown-link'
1515
import {
1616
BEHAVIOURS_BAR_COLOR,
1717
BEHAVIOURS_METRIC_COLUMN_WIDTH,
1818
BEHAVIOURS_METRICS_HIDDEN_ON_MOBILE
1919
} from '.'
2020
import { useSiteContext } from '../../site-context'
21+
import {
22+
defaultGetStatsQuery,
23+
StatsReportQueryKey
24+
} from '../../hooks/use-query-api'
25+
import { DashboardPeriod } from '../../dashboard-time-periods'
26+
27+
export function getConversionsStatsQuery(
28+
queryKey: StatsReportQueryKey
29+
): StatsQuery {
30+
const statsQuery = defaultGetStatsQuery(queryKey)
31+
if (statsQuery.date_range === DashboardPeriod.realtime) {
32+
return { ...statsQuery, date_range: DashboardPeriod.realtime_30m }
33+
}
34+
return statsQuery
35+
}
2136

2237
type ConversionsProps = {
2338
onDataReady?: (data: QueryApiResponse) => void
@@ -63,6 +78,7 @@ export default function Conversions({
6378
hideMetricsIfAllNull={['total_revenue', 'average_revenue']}
6479
hideMetricsOnMobile={BEHAVIOURS_METRICS_HIDDEN_ON_MOBILE}
6580
metricColumnWidth={BEHAVIOURS_METRIC_COLUMN_WIDTH}
81+
getStatsQuery={getConversionsStatsQuery}
6682
/>
6783
)
6884
}

assets/js/dashboard/stats/behaviours/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,9 @@ function Behaviours({
619619
</TabButton>
620620
)}
621621
</TabWrapper>
622-
{isRealtime() && <Pill className="-mt-1">last 30min</Pill>}
622+
{isRealtime() && mode === Mode.CONVERSIONS && (
623+
<Pill className="-mt-1">last 30min</Pill>
624+
)}
623625
{[Mode.CONVERSIONS, Mode.PROPS].includes(mode) ? (
624626
<ImportedWarningBubble
625627
queryApiResponse={currentQueryApiResponse}

assets/js/dashboard/stats/breakdowns.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ import {
1616
import { Filter } from '../dashboard-state'
1717
import classNames from 'classnames'
1818
import { DIRECT_NONE } from './sources'
19+
import { StatsReportQueryKey } from '../hooks/use-query-api'
1920

2021
export type SharedBreakdownReportProps = {
2122
dimensionLabel: string
2223
dimensions: NonTimeDimension[]
2324
metrics: Metric[]
2425
alwaysOnFilters?: ApiFilter[]
26+
getStatsQuery?: (queryKey: StatsReportQueryKey) => StatsQuery
2527
/**
2628
* When true, `percentage` is shown inline inside the Visitors
2729
* cell rather than as its own column. Set to false for reports that want

assets/js/dashboard/stats/modals/conversions.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import {
1010
BREAKDOWN_REPORTS,
1111
BreakdownReportKey
1212
} from '../reports/reports-config'
13-
import { getGoalsFilterInfo } from '../behaviours/conversions'
13+
import {
14+
getConversionsStatsQuery,
15+
getGoalsFilterInfo
16+
} from '../behaviours/conversions'
1417
import { useSiteContext } from '../../site-context'
1518

1619
function ConversionsModal() {
@@ -34,6 +37,7 @@ function ConversionsModal() {
3437
defaultOrderBy={[['visitors', 'desc']]}
3538
DimensionElement={GoalsDimensionCell}
3639
hideMetricsIfAllNull={['total_revenue', 'average_revenue']}
40+
getStatsQuery={getConversionsStatsQuery}
3741
/>
3842
</Modal>
3943
)

assets/js/dashboard/stats/modals/details-breakdown.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ export function DetailsBreakdown({
9494
searchEnabled = true,
9595
onDataReady,
9696
bundlePercentageWithVisitors = true,
97-
hideMetricsIfAllNull
97+
hideMetricsIfAllNull,
98+
getStatsQuery
9899
}: DetailsBreakdownProps) {
99100
const site = useSiteContext()
100101
const { dashboardState } = useDashboardStateContext()
@@ -135,7 +136,9 @@ export function DetailsBreakdown({
135136
}
136137
]
137138

138-
const apiState = useSearchAndPaginateQueryAPI(site, statsReportQueryKey)
139+
const apiState = useSearchAndPaginateQueryAPI(site, statsReportQueryKey, {
140+
getStatsQuery
141+
})
139142

140143
useEffect(() => {
141144
const pages = apiState.data?.pages

assets/js/dashboard/stats/reports/index-breakdown.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export function IndexBreakdown({
6868
metricColumnWidth = DEFAULT_METRIC_COLUMN_WIDTH,
6969
bundlePercentageWithVisitors = true,
7070
hideMetricsIfAllNull,
71-
hideMetricsOnMobile
71+
hideMetricsOnMobile,
72+
getStatsQuery
7273
}: IndexBreakdownProps) {
7374
const site = useSiteContext()
7475
const { dashboardState } = useDashboardStateContext()
@@ -91,7 +92,7 @@ export function IndexBreakdown({
9192
const { apiState, isRealtimeSilentUpdate } = useQueryApi(
9293
site,
9394
statsReportQueryKey,
94-
{ enabled: visible }
95+
{ enabled: visible, getStatsQuery }
9596
)
9697

9798
useEffect(() => {

e2e/tests/dashboard/behaviours.spec.ts

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
} from '../test-utils'
2626

2727
const getReport = (page: Page) => page.getByTestId('report-behaviours')
28+
const LAST_30MIN_PILL = 'last 30min'
2829

2930
test('special goals', async ({ page, request }, testInfo) => {
3031
test.slow(
@@ -564,8 +565,8 @@ test('goals breakdown', async ({ page, request }) => {
564565
revenue_reporting_currency: 'EUR',
565566
timestamp: { minutesAgo: 59 }
566567
},
567-
{ user_id: 124, name: 'add_site', timestamp: { minutesAgo: 50 } },
568-
{ user_id: 125, name: 'add_site', timestamp: { minutesAgo: 50 } }
568+
{ user_id: 124, name: 'add_site', timestamp: { minutesAgo: 15 } },
569+
{ user_id: 125, name: 'add_site', timestamp: { minutesAgo: 2 } }
569570
]
570571
})
571572

@@ -709,6 +710,32 @@ test('goals breakdown', async ({ page, request }) => {
709710

710711
await closeModalButton(page).click()
711712
})
713+
714+
await test.step('realtime goal index breakdown displays stats from last 30min', async () => {
715+
await page.goto('/' + domain + '?period=realtime', { waitUntil: 'commit' })
716+
await report.getByTestId('report-end').scrollIntoViewIfNeeded()
717+
718+
await expect(goalsTabButton).toHaveAttribute('data-active', 'true')
719+
await expect(report.getByText(LAST_30MIN_PILL)).toBeVisible()
720+
721+
await expectHeaders(report, ['Goal', 'Uniques', 'Total', 'CR'])
722+
723+
await expectRows(report, ['Add a site'])
724+
await expectMetricValues(report, 'Add a site', ['2', '2', '100%'])
725+
})
726+
727+
await test.step('realtime goals modal displays stats from last 30min', async () => {
728+
await detailsLink(report).click()
729+
730+
await expect(
731+
modal(page).getByRole('heading', { name: 'Goal conversions' })
732+
).toBeVisible()
733+
734+
await expectRows(modal(page), ['Add a site'])
735+
await expectMetricValues(modal(page), 'Add a site', ['2', '2', '100%'])
736+
737+
await closeModalButton(page).click()
738+
})
712739
})
713740

714741
test('props breakdown', async ({ page, request }) => {
@@ -722,6 +749,7 @@ test('props breakdown', async ({ page, request }) => {
722749
{
723750
name: 'pageview',
724751
pathname: '/page',
752+
timestamp: { minutesAgo: 15 },
725753
'meta.key': [
726754
'logged_in',
727755
'browser_language',
@@ -752,12 +780,14 @@ test('props breakdown', async ({ page, request }) => {
752780
{
753781
name: 'pageview',
754782
pathname: '/page',
783+
timestamp: { minutesAgo: 1 },
755784
'meta.key': ['logged_in', 'browser_language'],
756785
'meta.value': ['false', 'en_US']
757786
},
758787
{
759788
name: 'pageview',
760789
pathname: '/page',
790+
timestamp: { minutesAgo: 2 },
761791
'meta.key': ['logged_in', 'browser_language'],
762792
'meta.value': ['true', 'es']
763793
}
@@ -768,7 +798,7 @@ test('props breakdown', async ({ page, request }) => {
768798

769799
await addAllCustomProps({ page, domain })
770800

771-
await page.goto('/' + domain, { waitUntil: 'commit' })
801+
await page.goto(`/${domain}?period=all`, { waitUntil: 'commit' })
772802

773803
const propsTabButton = tabButtonWithDropdown(report, 'Properties')
774804

@@ -854,6 +884,36 @@ test('props breakdown', async ({ page, request }) => {
854884
await expectMetricValues(report, 'en_US', ['2', '2', '66.7%'])
855885
await expectMetricValues(report, 'es', ['1', '1', '33.3%'])
856886
})
887+
888+
await page.goto('/' + domain + '?period=realtime', { waitUntil: 'commit' })
889+
await report.getByTestId('report-end').scrollIntoViewIfNeeded()
890+
891+
await test.step('realtime props index breakdown displays stats from last 5min', async () => {
892+
await propsTabButton.click()
893+
await dropdown(report)
894+
.getByRole('button', { name: 'browser_language' })
895+
.click()
896+
897+
await expect(report.getByText(LAST_30MIN_PILL)).toBeHidden()
898+
899+
await expectHeaders(report, ['browser_language', 'Visitors', 'Events', '%'])
900+
901+
await expectRows(report, ['en_US', 'es'])
902+
await expectMetricValues(report, 'en_US', ['1', '1', '50%'])
903+
})
904+
905+
await test.step('realtime props details modal displays stats from last 5min', async () => {
906+
await detailsLink(report).click()
907+
908+
await expect(
909+
modal(page).getByRole('heading', { name: 'Custom property breakdown' })
910+
).toBeVisible()
911+
912+
await expectRows(modal(page), ['en_US', 'es'])
913+
await expectMetricValues(modal(page), 'en_US', ['1', '1', '50%'])
914+
915+
await closeModalButton(page).click()
916+
})
857917
})
858918

859919
test('funnels', async ({ page, request }) => {

0 commit comments

Comments
 (0)