mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
Insights report updates.
This commit is contained in:
parent
ccafb03c47
commit
2e1e5e2616
@ -159,6 +159,7 @@ export const labels = defineMessages({
|
|||||||
value: { id: 'labels.value', defaultMessage: 'Value' },
|
value: { id: 'labels.value', defaultMessage: 'Value' },
|
||||||
overview: { id: 'labels.overview', defaultMessage: 'Overview' },
|
overview: { id: 'labels.overview', defaultMessage: 'Overview' },
|
||||||
totalRecords: { id: 'labels.total-records', defaultMessage: 'Total records' },
|
totalRecords: { id: 'labels.total-records', defaultMessage: 'Total records' },
|
||||||
|
insights: { id: 'label.insights', defaultMessage: 'Insights' },
|
||||||
});
|
});
|
||||||
|
|
||||||
export const messages = defineMessages({
|
export const messages = defineMessages({
|
||||||
|
@ -19,6 +19,10 @@ export default function FieldAggregateForm({ name, type, onSelect }) {
|
|||||||
{ label: formatMessage(labels.total), value: 'total' },
|
{ label: formatMessage(labels.total), value: 'total' },
|
||||||
{ label: formatMessage(labels.unique), value: 'unique' },
|
{ label: formatMessage(labels.unique), value: 'unique' },
|
||||||
],
|
],
|
||||||
|
uuid: [
|
||||||
|
{ label: formatMessage(labels.total), value: 'total' },
|
||||||
|
{ label: formatMessage(labels.unique), value: 'unique' },
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const items = options[type];
|
const items = options[type];
|
||||||
|
@ -9,10 +9,10 @@ export default function FieldSelectForm({ fields, onSelect }) {
|
|||||||
<Form>
|
<Form>
|
||||||
<FormRow label={formatMessage(labels.fields)}>
|
<FormRow label={formatMessage(labels.fields)}>
|
||||||
<Menu className={styles.menu} onSelect={key => onSelect(fields[key])}>
|
<Menu className={styles.menu} onSelect={key => onSelect(fields[key])}>
|
||||||
{fields.map(({ name, type }, index) => {
|
{fields.map(({ label, name, type }, index) => {
|
||||||
return (
|
return (
|
||||||
<Item key={index} className={styles.item}>
|
<Item key={index} className={styles.item}>
|
||||||
<div>{name}</div>
|
<div>{label || name}</div>
|
||||||
<div className={styles.type}>{type}</div>
|
<div className={styles.type}>{type}</div>
|
||||||
</Item>
|
</Item>
|
||||||
);
|
);
|
||||||
|
@ -3,20 +3,10 @@ import { Button, Icons, Text, Icon } from 'react-basics';
|
|||||||
import Page from 'components/layout/Page';
|
import Page from 'components/layout/Page';
|
||||||
import PageHeader from 'components/layout/PageHeader';
|
import PageHeader from 'components/layout/PageHeader';
|
||||||
import Funnel from 'assets/funnel.svg';
|
import Funnel from 'assets/funnel.svg';
|
||||||
import Nodes from 'assets/nodes.svg';
|
|
||||||
import Lightbulb from 'assets/lightbulb.svg';
|
import Lightbulb from 'assets/lightbulb.svg';
|
||||||
import styles from './ReportTemplates.module.css';
|
import styles from './ReportTemplates.module.css';
|
||||||
import { useMessages } from 'hooks';
|
import { useMessages } from 'hooks';
|
||||||
|
|
||||||
const reports = [
|
|
||||||
{
|
|
||||||
title: 'Funnel',
|
|
||||||
description: 'Understand the conversion and drop-off rate of users.',
|
|
||||||
url: '/reports/funnel',
|
|
||||||
icon: <Funnel />,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
function ReportItem({ title, description, url, icon }) {
|
function ReportItem({ title, description, url, icon }) {
|
||||||
return (
|
return (
|
||||||
<div className={styles.report}>
|
<div className={styles.report}>
|
||||||
@ -42,6 +32,21 @@ function ReportItem({ title, description, url, icon }) {
|
|||||||
export function ReportTemplates() {
|
export function ReportTemplates() {
|
||||||
const { formatMessage, labels } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
|
|
||||||
|
const reports = [
|
||||||
|
{
|
||||||
|
title: formatMessage(labels.insights),
|
||||||
|
description: 'Dive deeper into your data by using segments and filters.',
|
||||||
|
url: '/reports/insights',
|
||||||
|
icon: <Lightbulb />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: formatMessage(labels.funnel),
|
||||||
|
description: 'Understand the conversion and drop-off rate of users.',
|
||||||
|
url: '/reports/funnel',
|
||||||
|
icon: <Funnel />,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page>
|
<Page>
|
||||||
<PageHeader title={formatMessage(labels.reports)} />
|
<PageHeader title={formatMessage(labels.reports)} />
|
||||||
|
@ -5,7 +5,7 @@ import { ReportContext } from 'components/pages/reports/Report';
|
|||||||
import Empty from 'components/common/Empty';
|
import Empty from 'components/common/Empty';
|
||||||
import { DATA_TYPES, REPORT_PARAMETERS } from 'lib/constants';
|
import { DATA_TYPES, REPORT_PARAMETERS } from 'lib/constants';
|
||||||
import Icons from 'components/icons';
|
import Icons from 'components/icons';
|
||||||
import FieldAddForm from './FieldAddForm';
|
import FieldAddForm from '../FieldAddForm';
|
||||||
import BaseParameters from '../BaseParameters';
|
import BaseParameters from '../BaseParameters';
|
||||||
import ParameterList from '../ParameterList';
|
import ParameterList from '../ParameterList';
|
||||||
import styles from './EventDataParameters.module.css';
|
import styles from './EventDataParameters.module.css';
|
||||||
@ -54,9 +54,11 @@ export function EventDataParameters() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleAdd = (group, value) => {
|
const handleAdd = (group, value) => {
|
||||||
const data = parameterData[group].filter(({ name }) => name !== value.name);
|
const data = parameterData[group];
|
||||||
|
|
||||||
|
if (!data.find(({ name }) => name === value.name)) {
|
||||||
updateReport({ parameters: { [group]: data.concat(value) } });
|
updateReport({ parameters: { [group]: data.concat(value) } });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRemove = (group, index) => {
|
const handleRemove = (group, index) => {
|
||||||
|
@ -1,42 +1,22 @@
|
|||||||
import { useContext, useRef } from 'react';
|
import { useContext, useRef } from 'react';
|
||||||
import { useApi, useMessages } from 'hooks';
|
import { useMessages } from 'hooks';
|
||||||
import { Form, FormRow, FormButtons, SubmitButton, PopupTrigger, Icon, Popup } from 'react-basics';
|
import { Form, FormRow, FormButtons, SubmitButton, PopupTrigger, Icon, Popup } from 'react-basics';
|
||||||
import { ReportContext } from 'components/pages/reports/Report';
|
import { ReportContext } from 'components/pages/reports/Report';
|
||||||
import Empty from 'components/common/Empty';
|
import { REPORT_PARAMETERS, WEBSITE_EVENT_FIELDS } from 'lib/constants';
|
||||||
import { DATA_TYPES, REPORT_PARAMETERS } from 'lib/constants';
|
|
||||||
import Icons from 'components/icons';
|
import Icons from 'components/icons';
|
||||||
import FieldAddForm from './FieldAddForm';
|
|
||||||
import BaseParameters from '../BaseParameters';
|
import BaseParameters from '../BaseParameters';
|
||||||
|
import FieldAddForm from '../FieldAddForm';
|
||||||
import ParameterList from '../ParameterList';
|
import ParameterList from '../ParameterList';
|
||||||
import styles from './InsightsParameters.module.css';
|
import styles from './InsightsParameters.module.css';
|
||||||
|
|
||||||
function useFields(websiteId, startDate, endDate) {
|
|
||||||
const { get, useQuery } = useApi();
|
|
||||||
const { data, error, isLoading } = useQuery(
|
|
||||||
['fields', websiteId, startDate, endDate],
|
|
||||||
() =>
|
|
||||||
get('/reports/event-data', {
|
|
||||||
websiteId,
|
|
||||||
startAt: +startDate,
|
|
||||||
endAt: +endDate,
|
|
||||||
}),
|
|
||||||
{ enabled: !!(websiteId && startDate && endDate) },
|
|
||||||
);
|
|
||||||
|
|
||||||
return { data, error, isLoading };
|
|
||||||
}
|
|
||||||
|
|
||||||
export function InsightsParameters() {
|
export function InsightsParameters() {
|
||||||
const { report, runReport, updateReport, isRunning } = useContext(ReportContext);
|
const { report, runReport, updateReport, isRunning } = useContext(ReportContext);
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels } = useMessages();
|
||||||
const ref = useRef(null);
|
const ref = useRef(null);
|
||||||
const { parameters } = report || {};
|
const { parameters } = report || {};
|
||||||
const { websiteId, dateRange, fields, filters, groups } = parameters || {};
|
const { websiteId, dateRange, fields, filters, groups } = parameters || {};
|
||||||
const { startDate, endDate } = dateRange || {};
|
|
||||||
const queryEnabled = websiteId && dateRange && fields?.length;
|
const queryEnabled = websiteId && dateRange && fields?.length;
|
||||||
const { data, error } = useFields(websiteId, startDate, endDate);
|
const fieldOptions = Object.keys(WEBSITE_EVENT_FIELDS).map(key => WEBSITE_EVENT_FIELDS[key]);
|
||||||
const parametersSelected = websiteId && startDate && endDate;
|
|
||||||
const hasData = data?.length !== 0;
|
|
||||||
|
|
||||||
const parameterGroups = [
|
const parameterGroups = [
|
||||||
{ label: formatMessage(labels.fields), group: REPORT_PARAMETERS.fields },
|
{ label: formatMessage(labels.fields), group: REPORT_PARAMETERS.fields },
|
||||||
@ -78,10 +58,7 @@ export function InsightsParameters() {
|
|||||||
{(close, element) => {
|
{(close, element) => {
|
||||||
return (
|
return (
|
||||||
<FieldAddForm
|
<FieldAddForm
|
||||||
fields={data.map(({ eventKey, InsightsType }) => ({
|
fields={fieldOptions}
|
||||||
name: eventKey,
|
|
||||||
type: DATA_TYPES[InsightsType],
|
|
||||||
}))}
|
|
||||||
group={group}
|
group={group}
|
||||||
element={element}
|
element={element}
|
||||||
onAdd={handleAdd}
|
onAdd={handleAdd}
|
||||||
@ -95,18 +72,11 @@ export function InsightsParameters() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form ref={ref} values={parameters} error={error} onSubmit={handleSubmit}>
|
<Form ref={ref} values={parameters} onSubmit={handleSubmit}>
|
||||||
<BaseParameters />
|
<BaseParameters />
|
||||||
{!hasData && <Empty message={formatMessage(messages.noInsights)} />}
|
{parameterGroups.map(({ label, group }) => {
|
||||||
{parametersSelected &&
|
|
||||||
hasData &&
|
|
||||||
parameterGroups.map(({ label, group }) => {
|
|
||||||
return (
|
return (
|
||||||
<FormRow
|
<FormRow key={label} label={label} action={<AddButton group={group} onAdd={handleAdd} />}>
|
||||||
key={label}
|
|
||||||
label={label}
|
|
||||||
action={<AddButton group={group} onAdd={handleAdd} />}
|
|
||||||
>
|
|
||||||
<ParameterList
|
<ParameterList
|
||||||
items={parameterData[group]}
|
items={parameterData[group]}
|
||||||
onRemove={index => handleRemove(group, index)}
|
onRemove={index => handleRemove(group, index)}
|
||||||
|
@ -24,6 +24,7 @@ export function useFilters() {
|
|||||||
boolean: ['t', 'f'],
|
boolean: ['t', 'f'],
|
||||||
number: ['eq', 'neq', 'gt', 'lt', 'gte', 'lte'],
|
number: ['eq', 'neq', 'gt', 'lt', 'gte', 'lte'],
|
||||||
date: ['be', 'af'],
|
date: ['be', 'af'],
|
||||||
|
uuid: ['eq'],
|
||||||
};
|
};
|
||||||
|
|
||||||
return { filters, types };
|
return { filters, types };
|
||||||
|
@ -120,6 +120,37 @@ export const ROLE_PERMISSIONS = {
|
|||||||
[ROLES.teamMember]: [],
|
[ROLES.teamMember]: [],
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
export const WEBSITE_EVENT_FIELDS = {
|
||||||
|
eventId: { name: 'event_id', type: 'uuid', label: 'Event ID' },
|
||||||
|
websiteId: { name: 'website_id', type: 'uuid', label: 'Website ID' },
|
||||||
|
sessionId: { name: 'session_id', type: 'uuid', label: 'Session ID' },
|
||||||
|
createdAt: { name: 'created_at', type: 'date', label: 'Created date' },
|
||||||
|
urlPath: { name: 'url_path', type: 'string', label: 'URL path' },
|
||||||
|
urlQuery: { name: 'url_query', type: 'string', label: 'URL query' },
|
||||||
|
referrerPath: { name: 'referrer_path', type: 'string', label: 'Referrer path' },
|
||||||
|
referrerQuery: { name: 'referrer_query', type: 'string', label: 'Referrer query' },
|
||||||
|
referrerDomain: { name: 'referrer_domain', type: 'string', label: 'Referrer domain' },
|
||||||
|
pageTitle: { name: 'page_title', type: 'string', label: 'Page title' },
|
||||||
|
eventType: { name: 'event_type', type: 'string', label: 'Event type' },
|
||||||
|
eventName: { name: 'event_name', type: 'string', label: 'Event name' },
|
||||||
|
};
|
||||||
|
|
||||||
|
export const SESSION_FIELDS = {
|
||||||
|
sessionId: { name: 'session_id', type: 'uuid' },
|
||||||
|
websiteId: { name: 'website_id', type: 'uuid' },
|
||||||
|
hostname: { name: 'hostname', type: 'string' },
|
||||||
|
browser: { name: 'browser', type: 'string' },
|
||||||
|
os: { name: 'os', type: 'string' },
|
||||||
|
device: { name: 'device', type: 'string' },
|
||||||
|
screen: { name: 'screen', type: 'string' },
|
||||||
|
language: { name: 'language', type: 'string' },
|
||||||
|
country: { name: 'country', type: 'string' },
|
||||||
|
subdivision1: { name: 'subdivision1', type: 'string' },
|
||||||
|
subdivision2: { name: 'subdivision2', type: 'string' },
|
||||||
|
city: { name: 'city', type: 'string' },
|
||||||
|
createdAt: { name: 'created_at', type: 'date' },
|
||||||
|
};
|
||||||
|
|
||||||
export const THEME_COLORS = {
|
export const THEME_COLORS = {
|
||||||
light: {
|
light: {
|
||||||
primary: '#2680eb',
|
primary: '#2680eb',
|
||||||
@ -169,7 +200,6 @@ export const EVENT_COLORS = [
|
|||||||
export const DOMAIN_REGEX =
|
export const DOMAIN_REGEX =
|
||||||
/^(localhost(:[1-9]\d{0,4})?|((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9-]+(-[a-z0-9-]+)*\.)+(xn--)?[a-z0-9-]{2,63})$/;
|
/^(localhost(:[1-9]\d{0,4})?|((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9-]+(-[a-z0-9-]+)*\.)+(xn--)?[a-z0-9-]{2,63})$/;
|
||||||
|
|
||||||
|
|
||||||
export const SHARE_ID_REGEX = /^[a-zA-Z0-9]{16}$/;
|
export const SHARE_ID_REGEX = /^[a-zA-Z0-9]{16}$/;
|
||||||
|
|
||||||
export const DESKTOP_SCREEN_WIDTH = 1920;
|
export const DESKTOP_SCREEN_WIDTH = 1920;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user