Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
Merge branch 'dev' into jajaja
Mike Caoa9a9b57f8029
diff --cc src/app/(main)/websites/[websiteId]/events/EventProperties.module.cssindex 479d09949,a56df28f6..000000000deleted file mode 100644,100644--- a/src/app/(main)/websites/[websiteId]/events/EventProperties.module.css+++ /dev/null@@@ -1,25 -1,27 +1,0 @@@--.container {-- display: grid;-- grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));-- gap: 60px;-- margin-bottom: 40px;--}----.table {-- align-self: flex-start;--}----.link:hover {-- cursor: pointer;- color: var(--primary-color);- color: var(--primary400);-}--.header {- margin-bottom: 40px;--}----.title {- text-align: center;-- font-weight: bold;- margin: 20px 0;--}--- .chart {-.data {-- min-height: 620px;--}diff --cc src/app/(main)/websites/[websiteId]/events/EventProperties.tsxindex e4cc16a32,e3e442ad3..877e75f0b--- a/src/app/(main)/websites/[websiteId]/events/EventProperties.tsx+++ b/src/app/(main)/websites/[websiteId]/events/EventProperties.tsx@@@ -1,34 -1,48 +1,59 @@@- import { DataColumn, DataTable } from '@umami/react-zen';-import { useMemo } from 'react';-import { GridColumn, GridTable, Flexbox, Button, ButtonGroup, Loading } from 'react-basics';-import { useEventDataProperties, useEventDataValues, useMessages } from '@/components/hooks';++import { useMemo, useState } from 'react';++import {++ DataColumn,++ DataTable,++ Row,++ Loading,++ Column,++ ToggleGroup,++ ToggleGroupItem,++ Text,++} from '@umami/react-zen';+import {+ useEventDataPropertiesQuery,+ useEventDataValuesQuery,+ useMessages,+} from '@/components/hooks';import { LoadingPanel } from '@/components/common/LoadingPanel';-import PieChart from '@/components/charts/PieChart';-import ListTable from '@/components/metrics/ListTable';-import { useState } from 'react';+import { PieChart } from '@/components/charts/PieChart';- import { useState } from 'react';import { CHART_COLORS } from '@/lib/constants';--import styles from './EventProperties.module.css';++import { ListTable } from '@/components/metrics/ListTable';export function EventProperties({ websiteId }: { websiteId: string }) {const [propertyName, setPropertyName] = useState('');const [eventName, setEventName] = useState('');+ const [propertyView, setPropertyView] = useState('table');+const { formatMessage, labels } = useMessages();- const { data, isLoading, isFetched, error } = useEventDataPropertiesQuery(websiteId);- const { data, isLoading, isFetched, error } = useEventDataProperties(websiteId);- const { data: values } = useEventDataValues(websiteId, eventName, propertyName);++ const { data, isLoading, isFetching, error } = useEventDataPropertiesQuery(websiteId);+ const { data: values } = useEventDataValuesQuery(websiteId, eventName, propertyName);- const chartData =- propertyName && values- ? {- labels: values.map(({ value }) => value),- datasets: [- {- data: values.map(({ total }) => total),- backgroundColor: CHART_COLORS,- borderWidth: 0,- },- ],- }- : null;++ const propertySum = useMemo(() => {+ return values?.reduce((sum, { total }) => sum + total, 0) ?? 0;+ }, [values]);++ const chartData = useMemo(() => {+ if (!propertyName || !values) return null;+ return {+ labels: values.map(({ value }) => value),+ datasets: [+ {+ data: values.map(({ total }) => total),+ backgroundColor: CHART_COLORS,+ borderWidth: 0,+ },+ ],+ };+ }, [propertyName, values]);++ const tableData = useMemo(() => {+ if (!propertyName || !values || propertySum === 0) return [];+ return values.map(({ value, total }) => ({+ x: value,+ y: total,+ z: 100 * (total / propertySum),+ }));+ }, [propertyName, values, propertySum]);const handleRowClick = row => {setEventName(row.eventName);@@@ -36,32 -50,48 +61,37 @@@};return (-- <LoadingPanel isLoading={isLoading} isFetched={isFetched} data={data} error={error}>-- <div className={styles.container}>- <DataTable data={data} cardMode={false} className={styles.table}>- <DataColumn name="eventName" label={formatMessage(labels.name)}>- <GridTable data={data} cardMode={false} className={styles.table}>- <GridColumn name="eventName" label={formatMessage(labels.name)}>-- {row => (-- <div className={styles.link} onClick={() => handleRowClick(row)}>-- {row.eventName}- </div>- )}- </GridColumn>- <GridColumn name="propertyName" label={formatMessage(labels.property)}>- {row => (- <div className={styles.link} onClick={() => handleRowClick(row)}>- {row.propertyName}-- </div>-- )}- </GridColumn>- <GridColumn name="total" label={formatMessage(labels.count)} alignment="end" />- </GridTable>++ <LoadingPanel isLoading={isLoading} isFetching={isFetching} data={data} error={error}>++ <Column>++ <DataTable data={data}>++ <DataColumn id="eventName" label={formatMessage(labels.name)}>++ {(row: any) => <Row onClick={() => handleRowClick(row)}>{row.eventName}</Row>}+ </DataColumn>- <DataColumn name="propertyName" label={formatMessage(labels.property)}>- {row => (- <div className={styles.link} onClick={() => handleRowClick(row)}>- {row.propertyName}- </div>- )}++ <DataColumn id="propertyName" label={formatMessage(labels.property)}>++ {(row: any) => <Row onClick={() => handleRowClick(row)}>{row.propertyName}</Row>}+ </DataColumn>- <DataColumn name="total" label={formatMessage(labels.count)} alignment="end" />++ <DataColumn id="total" label={formatMessage(labels.count)} align="end" />+ </DataTable>{propertyName && (- <div className={styles.chart}>- <div className={styles.title}>{propertyName}</div>- <PieChart key={propertyName + eventName} type="doughnut" data={chartData} />- </div>- <div className={styles.data}>- <Flexbox className={styles.header} gap={12} justifyContent="space-between">- <div className={styles.title}>{`${eventName}: ${propertyName}`}</div>- <ButtonGroup- selectedKey={propertyView}- onSelect={key => setPropertyView(key as string)}- >- <Button key="table">{formatMessage(labels.table)}</Button>- <Button key="chart">{formatMessage(labels.chart)}</Button>- </ButtonGroup>- </Flexbox>++ <Column>++ <Row gap justifyContent="space-between">++ <Text>{`${eventName}: ${propertyName}`}</Text>++ <ToggleGroup value={[propertyView]} onChange={value => setPropertyView(value[0])}>++ <ToggleGroupItem id="table">{formatMessage(labels.table)}</ToggleGroupItem>++ <ToggleGroupItem id="chart">{formatMessage(labels.chart)}</ToggleGroupItem>++ </ToggleGroup>++ </Row>++ {!values ? (+ <Loading icon="dots" />+ ) : propertyView === 'table' ? (+ <ListTable data={tableData} />+ ) : (- <PieChart key={propertyName + eventName} type="doughnut" data={chartData} />++ <PieChart key={propertyName + eventName} type="doughnut" chartData={chartData} />+ )}- </div>++ </Column>)}-- </div>++ </Column></LoadingPanel>);}diff --cc src/components/messages.tsindex c612bce34,1a7a18580..7f1a3b893--- a/src/components/messages.ts+++ b/src/components/messages.ts@@@ -324,19 -314,8 +323,21 @@@ export const labels = defineMessages(paidVideo: { id: 'label.paid-video', defaultMessage: 'Paid video' },grouped: { id: 'label.grouped', defaultMessage: 'Grouped' },other: { id: 'label.other', defaultMessage: 'Other' },+ boards: { id: 'label.boards', defaultMessage: 'Boards' },+ apply: { id: 'label.apply', defaultMessage: 'Apply' },+ links: { id: 'label.links', defaultMessage: 'Links' },+ pixels: { id: 'label.pixels', defaultMessage: 'Pixels' },+ addBoard: { id: 'label.add-board', defaultMessage: 'Add board' },+ maximize: { id: 'label.maximize', defaultMessage: 'Maximize' },+ remaining: { id: 'label.remaining', defaultMessage: 'Remaining' },+ conversion: { id: 'label.conversion', defaultMessage: 'Conversion' },+ firstClick: { id: 'label.first-click', defaultMessage: 'First click' },+ lastClick: { id: 'label.last-click', defaultMessage: 'Last click' },+ online: { id: 'label.online', defaultMessage: 'Online' },+ preferences: { id: 'label.preferences', defaultMessage: 'Preferences' },+ location: { id: 'label.location', defaultMessage: 'Location' },+ chart: { id: 'label.chart', defaultMessage: 'Chart' },+ table: { id: 'label.table', defaultMessage: 'Table' },});export const messages = defineMessages({diff --cc src/queries/sql/getValues.tsindex 6a602f13e,5322a5319..62f978baf--- a/src/queries/sql/getValues.ts+++ b/src/queries/sql/getValues.ts@@@ -12,12 -11,22 +12,18 @@@ export async function getValues});}-async function relationalQuery(- websiteId: string,- column: string,- startDate: Date,- endDate: Date,- search: string,-) {+async function relationalQuery(websiteId: string, column: string, filters: QueryFilters) {const { rawQuery, getSearchSQL } = prisma;const params = {};+ const { startDate, endDate, search } = filters;+let searchQuery = '';+ let excludeDomain = '';++ if (column === 'referrer_domain') {+ excludeDomain = `and website_event.referrer_domain != website_event.hostname+ and website_event.referrer_domain != ''`;+ }if (search) {if (decodeURIComponent(search).includes(',')) {@@@ -60,12 -70,21 +67,17 @@@);}-async function clickhouseQuery(- websiteId: string,- column: string,- startDate: Date,- endDate: Date,- search: string,-) {+async function clickhouseQuery(websiteId: string, column: string, filters: QueryFilters) {const { rawQuery, getSearchSQL } = clickhouse;const params = {};+ const { startDate, endDate, search } = filters;+let searchQuery = '';+ let excludeDomain = '';++ if (column === 'referrer_domain') {+ excludeDomain = `and referrer_domain != hostname and referrer_domain != ''`;+ }if (search) {searchQuery = `and positionCaseInsensitive(${column}, {search:String}) > 0`;diff --cc src/queries/sql/pageviews/getPageviewMetrics.tsindex 8134f0063,67e18b75d..a73f4e4d0--- a/src/queries/sql/pageviews/getPageviewMetrics.ts+++ b/src/queries/sql/pageviews/getPageviewMetrics.ts@@@ -26,21 -21,20 +26,19 @@@ export async function getPageviewMetricasync function relationalQuery(websiteId: string,- type: string,+ parameters: PageviewMetricsParameters,filters: QueryFilters,- limit: number | string = 500,- offset: number | string = 0,-) {+): Promise<PageviewMetricsData[]> {+ const { type, limit = 500, offset = 0 } = parameters;const column = FILTER_COLUMNS[type] || type;const { rawQuery, parseFilters } = prisma;- const { filterQuery, cohortQuery, joinSession, params } = await parseFilters(- websiteId,+ const { filterQuery, joinSessionQuery, cohortQuery, queryParams } = parseFilters({...filters,+ websiteId,eventType: column === 'event_name' ? EVENT_TYPE.customEvent : EVENT_TYPE.pageView,},- {- joinSession: SESSION_COLUMNS.includes(type) || column === 'referrer_domain',- },+ { joinSession: SESSION_COLUMNS.includes(type) },);let entryExitQuery = '';@@@ -72,10 -66,10 +70,10 @@@return rawQuery(`select ${column} x,- ${column === 'referrer_domain' ? 'count(distinct website_event.session_id)' : 'count(*)'} as y+ count(distinct website_event.session_id) as yfrom website_event+ ${joinSessionQuery}${cohortQuery}- ${joinSession}${entryExitQuery}where website_event.website_id = {{websiteId::uuid}}and website_event.created_at between {{startDate}} and {{endDate}}@@@ -168,10 -162,10 +166,10 @@@ async function clickhouseQuerysql = `select g.t as x,- ${column === 'referrer_domain' ? 'uniq(s)' : 'count(*)'} as y+ uniq(s) as yfrom (select ${columnQuery} as t- from website_event_stats_hourly website_event+ from website_event_stats_hourly as website_event${cohortQuery}where website_id = {websiteId:UUID}and created_at between {startDate:DateTime64} and {endDate:DateTime64}