mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-05 17:05:46 +01:00
commit
5d37810686
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "umami",
|
||||
"version": "2.13.0",
|
||||
"version": "2.13.1",
|
||||
"description": "A simple, fast, privacy-focused alternative to Google Analytics.",
|
||||
"author": "Umami Software, Inc. <hello@umami.is>",
|
||||
"license": "MIT",
|
||||
|
@ -476,7 +476,7 @@
|
||||
"label.first-seen": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "First seen"
|
||||
"value": "Vist per primer cop"
|
||||
}
|
||||
],
|
||||
"label.funnel": [
|
||||
@ -656,7 +656,7 @@
|
||||
"label.last-seen": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Last seen"
|
||||
"value": "Vist per últim cop"
|
||||
}
|
||||
],
|
||||
"label.leave": [
|
||||
@ -876,13 +876,13 @@
|
||||
"label.path": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Path"
|
||||
"value": "Camí"
|
||||
}
|
||||
],
|
||||
"label.paths": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Paths"
|
||||
"value": "Camins"
|
||||
}
|
||||
],
|
||||
"label.powered-by": [
|
||||
@ -922,7 +922,7 @@
|
||||
"label.properties": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Properties"
|
||||
"value": "Propietats"
|
||||
}
|
||||
],
|
||||
"label.property": [
|
||||
@ -1042,19 +1042,19 @@
|
||||
"label.revenue": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Revenue"
|
||||
"value": "Ingressos"
|
||||
}
|
||||
],
|
||||
"label.revenue-description": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Look into your revenue across time."
|
||||
"value": "Observi els seus ingressos al llarg del temps."
|
||||
}
|
||||
],
|
||||
"label.revenue-property": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Revenue Property"
|
||||
"value": "Propietat d'Ingressos"
|
||||
}
|
||||
],
|
||||
"label.role": [
|
||||
@ -1114,7 +1114,7 @@
|
||||
"label.session": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Session"
|
||||
"value": "Sessió"
|
||||
}
|
||||
],
|
||||
"label.sessions": [
|
||||
@ -1180,7 +1180,7 @@
|
||||
"label.team-manager": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Team manager"
|
||||
"value": "Responsable d'Equip"
|
||||
}
|
||||
],
|
||||
"label.team-member": [
|
||||
@ -1288,7 +1288,7 @@
|
||||
"label.transactions": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Transactions"
|
||||
"value": "Transaccions"
|
||||
}
|
||||
],
|
||||
"label.transfer": [
|
||||
@ -1330,7 +1330,7 @@
|
||||
"label.uniqueCustomers": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "Unique Customers"
|
||||
"value": "Clients Únics"
|
||||
}
|
||||
],
|
||||
"label.unknown": [
|
||||
@ -1372,7 +1372,7 @@
|
||||
"label.user-property": [
|
||||
{
|
||||
"type": 0,
|
||||
"value": "User Property"
|
||||
"value": "Propietat d'Usuari"
|
||||
}
|
||||
],
|
||||
"label.username": [
|
||||
|
@ -1,13 +1,15 @@
|
||||
import { useTimezone } from 'components/hooks';
|
||||
import { REALTIME_INTERVAL } from 'lib/constants';
|
||||
import { RealtimeData } from 'lib/types';
|
||||
import { useApi } from './useApi';
|
||||
import { REALTIME_INTERVAL } from 'lib/constants';
|
||||
|
||||
export function useRealtime(websiteId: string) {
|
||||
const { get, useQuery } = useApi();
|
||||
const { timezone } = useTimezone();
|
||||
const { data, isLoading, error } = useQuery<RealtimeData>({
|
||||
queryKey: ['realtime', websiteId],
|
||||
queryKey: ['realtime', { websiteId, timezone }],
|
||||
queryFn: async () => {
|
||||
return get(`/realtime/${websiteId}`);
|
||||
return get(`/realtime/${websiteId}`, { timezone });
|
||||
},
|
||||
enabled: !!websiteId,
|
||||
refetchInterval: REALTIME_INTERVAL,
|
||||
|
@ -78,7 +78,7 @@
|
||||
"label.filter-combined": "Combinat",
|
||||
"label.filter-raw": "En cru",
|
||||
"label.filters": "Filtres",
|
||||
"label.first-seen": "First seen",
|
||||
"label.first-seen": "Vist per primer cop",
|
||||
"label.funnel": "Embut",
|
||||
"label.funnel-description": "Entengui la taxa de conversió i abandonament dels usuaris.",
|
||||
"label.goal": "Meta",
|
||||
@ -104,7 +104,7 @@
|
||||
"label.last-days": "Últims {x} dies",
|
||||
"label.last-hours": "Últimes {x} hores",
|
||||
"label.last-months": "Últims {x} mesos",
|
||||
"label.last-seen": "Last seen",
|
||||
"label.last-seen": "Vist per últim cop",
|
||||
"label.leave": "Abandonar",
|
||||
"label.leave-team": "Abandonar equip",
|
||||
"label.less-than": "Menor que",
|
||||
@ -134,14 +134,14 @@
|
||||
"label.pageTitle": "Títol de la pàgina",
|
||||
"label.pages": "Pàgines",
|
||||
"label.password": "Contrasenya",
|
||||
"label.path": "Path",
|
||||
"label.paths": "Paths",
|
||||
"label.path": "Camí",
|
||||
"label.paths": "Camins",
|
||||
"label.powered-by": "Funciona amb {name}",
|
||||
"label.previous": "Anterior",
|
||||
"label.previous-period": "Període anterior",
|
||||
"label.previous-year": "Any anterior",
|
||||
"label.profile": "Perfil",
|
||||
"label.properties": "Properties",
|
||||
"label.properties": "Propietats",
|
||||
"label.property": "Propietat",
|
||||
"label.queries": "Consultes",
|
||||
"label.query": "Consulta",
|
||||
@ -161,9 +161,9 @@
|
||||
"label.reset-website": "Restableix estadístiques",
|
||||
"label.retention": "Retenció",
|
||||
"label.retention-description": "Mesuri la retenció del seu lloc web fent un seguiment de la freqüència amb què tornen els usuaris.",
|
||||
"label.revenue": "Revenue",
|
||||
"label.revenue-description": "Look into your revenue across time.",
|
||||
"label.revenue-property": "Revenue Property",
|
||||
"label.revenue": "Ingressos",
|
||||
"label.revenue-description": "Observi els seus ingressos al llarg del temps.",
|
||||
"label.revenue-property": "Propietat d'Ingressos",
|
||||
"label.role": "Rol",
|
||||
"label.run-query": "Executar consulta",
|
||||
"label.save": "Desa",
|
||||
@ -173,7 +173,7 @@
|
||||
"label.select-date": "Seleccionar data",
|
||||
"label.select-role": "Seleccionar rol",
|
||||
"label.select-website": "Seleccionar lloc web",
|
||||
"label.session": "Session",
|
||||
"label.session": "Sessió",
|
||||
"label.sessions": "Sessions",
|
||||
"label.settings": "Configuració",
|
||||
"label.share-url": "Enllaç per compartir",
|
||||
@ -184,7 +184,7 @@
|
||||
"label.tablet": "Tauleta",
|
||||
"label.team": "Equip",
|
||||
"label.team-id": "ID del equip",
|
||||
"label.team-manager": "Team manager",
|
||||
"label.team-manager": "Responsable d'Equip",
|
||||
"label.team-member": "Membre de l'equip",
|
||||
"label.team-name": "Nom de l'equip",
|
||||
"label.team-owner": "Propietari de l'equip",
|
||||
@ -202,21 +202,21 @@
|
||||
"label.total": "Total",
|
||||
"label.total-records": "Total de registres",
|
||||
"label.tracking-code": "Codi de seguiment",
|
||||
"label.transactions": "Transactions",
|
||||
"label.transactions": "Transaccions",
|
||||
"label.transfer": "Transferir",
|
||||
"label.transfer-website": "Transferir lloc web",
|
||||
"label.true": "Cert",
|
||||
"label.type": "Tipus",
|
||||
"label.unique": "Únic",
|
||||
"label.unique-visitors": "Visitants únics",
|
||||
"label.uniqueCustomers": "Unique Customers",
|
||||
"label.uniqueCustomers": "Clients Únics",
|
||||
"label.unknown": "Desconegut",
|
||||
"label.untitled": "Sense títol",
|
||||
"label.update": "Actualitzar",
|
||||
"label.url": "URL",
|
||||
"label.urls": "URLs",
|
||||
"label.user": "Usuari",
|
||||
"label.user-property": "User Property",
|
||||
"label.user-property": "Propietat d'Usuari",
|
||||
"label.username": "Nom d'usuari",
|
||||
"label.users": "Usuaris",
|
||||
"label.utm": "UTM",
|
||||
|
@ -12,11 +12,19 @@ import { filtersToArray } from './params';
|
||||
const log = debug('umami:prisma');
|
||||
|
||||
const MYSQL_DATE_FORMATS = {
|
||||
minute: '%Y-%m-%dT%H:%i:00Z',
|
||||
hour: '%Y-%m-%dT%H:00:00Z',
|
||||
day: '%Y-%m-%dT00:00:00Z',
|
||||
month: '%Y-%m-01T00:00:00Z',
|
||||
year: '%Y-01-01T00:00:00Z',
|
||||
minute: '%Y-%m-%dT%H:%i:00',
|
||||
hour: '%Y-%m-%d %H:00:00',
|
||||
day: '%Y-%m-%d',
|
||||
month: '%Y-%m-01',
|
||||
year: '%Y-01-01',
|
||||
};
|
||||
|
||||
const POSTGRESQL_DATE_FORMATS = {
|
||||
minute: 'YYYY-MM-DD HH24:MI:00',
|
||||
hour: 'YYYY-MM-DD HH24:00:00',
|
||||
day: 'YYYY-MM-DD',
|
||||
month: 'YYYY-MM-01',
|
||||
year: 'YYYY-01-01',
|
||||
};
|
||||
|
||||
function getAddIntervalQuery(field: string, interval: string): string {
|
||||
@ -60,31 +68,30 @@ function getDateSQL(field: string, unit: string, timezone?: string): string {
|
||||
|
||||
if (db === POSTGRESQL) {
|
||||
if (timezone) {
|
||||
return `date_trunc('${unit}', ${field} at time zone '${timezone}')`;
|
||||
return `to_char(date_trunc('${unit}', ${field} at time zone '${timezone}'), '${POSTGRESQL_DATE_FORMATS[unit]}')`;
|
||||
}
|
||||
return `date_trunc('${unit}', ${field})`;
|
||||
return `to_char(date_trunc('${unit}', ${field}), '${POSTGRESQL_DATE_FORMATS[unit]}')`;
|
||||
}
|
||||
|
||||
if (db === MYSQL) {
|
||||
if (timezone) {
|
||||
const tz = moment.tz(timezone).format('Z');
|
||||
|
||||
return `date_format(convert_tz(${field},'+00:00','${tz}'), '${MYSQL_DATE_FORMATS[unit]}')`;
|
||||
}
|
||||
|
||||
return `date_format(${field}, '${MYSQL_DATE_FORMATS[unit]}')`;
|
||||
}
|
||||
}
|
||||
|
||||
function getDateWeeklySQL(field: string) {
|
||||
function getDateWeeklySQL(field: string, timezone?: string) {
|
||||
const db = getDatabaseType();
|
||||
|
||||
if (db === POSTGRESQL) {
|
||||
return `concat(extract(dow from ${field}), ':', to_char(${field}, 'HH24'))`;
|
||||
return `concat(extract(dow from (${field} at time zone '${timezone}')), ':', to_char((${field} at time zone '${timezone}'), 'HH24'))`;
|
||||
}
|
||||
|
||||
if (db === MYSQL) {
|
||||
return `date_format(${field}, '%w:%H')`;
|
||||
const tz = moment.tz(timezone).format('Z');
|
||||
return `date_format(convert_tz(${field},'+00:00','${tz}'), '%w:%H')`;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,14 +7,17 @@ import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { getRealtimeData } from 'queries';
|
||||
import * as yup from 'yup';
|
||||
import { REALTIME_RANGE } from 'lib/constants';
|
||||
import { TimezoneTest } from 'lib/yup';
|
||||
|
||||
export interface RealtimeRequestQuery {
|
||||
websiteId: string;
|
||||
timezone?: string;
|
||||
}
|
||||
|
||||
const schema = {
|
||||
GET: yup.object().shape({
|
||||
websiteId: yup.string().uuid().required(),
|
||||
timezone: TimezoneTest,
|
||||
}),
|
||||
};
|
||||
|
||||
@ -23,7 +26,7 @@ export default async (req: NextApiRequestQueryBody<RealtimeRequestQuery>, res: N
|
||||
await useValidate(schema, req, res);
|
||||
|
||||
if (req.method === 'GET') {
|
||||
const { websiteId } = req.query;
|
||||
const { websiteId, timezone } = req.query;
|
||||
|
||||
if (!(await canViewWebsite(req.auth, websiteId))) {
|
||||
return unauthorized(res);
|
||||
@ -31,7 +34,7 @@ export default async (req: NextApiRequestQueryBody<RealtimeRequestQuery>, res: N
|
||||
|
||||
const startDate = subMinutes(startOfMinute(new Date()), REALTIME_RANGE);
|
||||
|
||||
const data = await getRealtimeData(websiteId, { startDate });
|
||||
const data = await getRealtimeData(websiteId, { startDate, timezone });
|
||||
|
||||
return ok(res, data);
|
||||
}
|
||||
|
@ -6,9 +6,11 @@ import { NextApiResponse } from 'next';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { pageInfo } from 'lib/schema';
|
||||
import { getWebsiteSessionsWeekly } from 'queries';
|
||||
import { TimezoneTest } from 'lib/yup';
|
||||
|
||||
export interface ReportsRequestQuery extends PageParams {
|
||||
websiteId: string;
|
||||
timezone?: string;
|
||||
}
|
||||
|
||||
const schema = {
|
||||
@ -16,6 +18,7 @@ const schema = {
|
||||
websiteId: yup.string().uuid().required(),
|
||||
startAt: yup.number().integer().required(),
|
||||
endAt: yup.number().integer().min(yup.ref('startAt')).required(),
|
||||
timezone: TimezoneTest,
|
||||
...pageInfo,
|
||||
}),
|
||||
};
|
||||
@ -28,7 +31,7 @@ export default async (
|
||||
await useAuth(req, res);
|
||||
await useValidate(schema, req, res);
|
||||
|
||||
const { websiteId, startAt, endAt } = req.query;
|
||||
const { websiteId, startAt, endAt, timezone } = req.query;
|
||||
|
||||
if (req.method === 'GET') {
|
||||
if (!(await canViewWebsite(req.auth, websiteId))) {
|
||||
@ -38,7 +41,7 @@ export default async (
|
||||
const startDate = new Date(+startAt);
|
||||
const endDate = new Date(+endAt);
|
||||
|
||||
const data = await getWebsiteSessionsWeekly(websiteId, { startDate, endDate });
|
||||
const data = await getWebsiteSessionsWeekly(websiteId, { startDate, endDate, timezone });
|
||||
|
||||
return ok(res, data);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { getRealtimeActivity, getPageviewStats, getSessionStats } from 'queries/index';
|
||||
import { getPageviewStats, getRealtimeActivity, getSessionStats } from 'queries/index';
|
||||
|
||||
function increment(data: object, key: string) {
|
||||
if (key) {
|
||||
@ -10,9 +10,12 @@ function increment(data: object, key: string) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getRealtimeData(websiteId: string, criteria: { startDate: Date }) {
|
||||
const { startDate } = criteria;
|
||||
const filters = { startDate, endDate: new Date(), unit: 'minute' };
|
||||
export async function getRealtimeData(
|
||||
websiteId: string,
|
||||
criteria: { startDate: Date; timezone: string },
|
||||
) {
|
||||
const { startDate, timezone } = criteria;
|
||||
const filters = { startDate, endDate: new Date(), unit: 'minute', timezone };
|
||||
const [activity, pageviews, sessions] = await Promise.all([
|
||||
getRealtimeActivity(websiteId, filters),
|
||||
getPageviewStats(websiteId, filters),
|
||||
|
@ -31,6 +31,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
||||
and event_type = {{eventType}}
|
||||
${filterQuery}
|
||||
group by 1
|
||||
order by 1
|
||||
`,
|
||||
params,
|
||||
);
|
||||
|
@ -24,6 +24,7 @@ async function relationalQuery(
|
||||
createdAt: { gte: startDate, lte: endDate },
|
||||
},
|
||||
take: 500,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
||||
and event_type = {{eventType}}
|
||||
${filterQuery}
|
||||
group by 1
|
||||
order by 1
|
||||
`,
|
||||
params,
|
||||
);
|
||||
|
@ -13,13 +13,14 @@ export async function getWebsiteSessionsWeekly(
|
||||
}
|
||||
|
||||
async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
||||
const { timezone = 'utc' } = filters;
|
||||
const { rawQuery, getDateWeeklySQL, parseFilters } = prisma;
|
||||
const { params } = await parseFilters(websiteId, filters);
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
select
|
||||
${getDateWeeklySQL('created_at')} as time,
|
||||
${getDateWeeklySQL('created_at', timezone)} as time,
|
||||
count(distinct session_id) as value
|
||||
from website_event
|
||||
where website_id = {{websiteId::uuid}}
|
||||
@ -32,13 +33,14 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
|
||||
}
|
||||
|
||||
async function clickhouseQuery(websiteId: string, filters: QueryFilters) {
|
||||
const { timezone = 'utc' } = filters;
|
||||
const { rawQuery } = clickhouse;
|
||||
const { startDate, endDate } = filters;
|
||||
|
||||
return rawQuery(
|
||||
`
|
||||
select
|
||||
formatDateTime(created_at, '%w:%H') as time,
|
||||
formatDateTime(toDateTime(created_at, '${timezone}'), '%w:%H') as time,
|
||||
count(distinct session_id) as value
|
||||
from website_event_stats_hourly
|
||||
where website_id = {websiteId:UUID}
|
||||
|
Loading…
Reference in New Issue
Block a user