Skip to content

Commit

Permalink
Merge pull request #2903 from umami-software/dev
Browse files Browse the repository at this point in the history
v2.13.1
  • Loading branch information
mikecao authored Aug 24, 2024
2 parents 47a6170 + bba584a commit 5d37810
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 52 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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. <[email protected]>",
"license": "MIT",
Expand Down
26 changes: 13 additions & 13 deletions public/intl/messages/ca-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@
"label.first-seen": [
{
"type": 0,
"value": "First seen"
"value": "Vist per primer cop"
}
],
"label.funnel": [
Expand Down Expand Up @@ -656,7 +656,7 @@
"label.last-seen": [
{
"type": 0,
"value": "Last seen"
"value": "Vist per últim cop"
}
],
"label.leave": [
Expand Down Expand Up @@ -876,13 +876,13 @@
"label.path": [
{
"type": 0,
"value": "Path"
"value": "Camí"
}
],
"label.paths": [
{
"type": 0,
"value": "Paths"
"value": "Camins"
}
],
"label.powered-by": [
Expand Down Expand Up @@ -922,7 +922,7 @@
"label.properties": [
{
"type": 0,
"value": "Properties"
"value": "Propietats"
}
],
"label.property": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -1114,7 +1114,7 @@
"label.session": [
{
"type": 0,
"value": "Session"
"value": "Sessió"
}
],
"label.sessions": [
Expand Down Expand Up @@ -1180,7 +1180,7 @@
"label.team-manager": [
{
"type": 0,
"value": "Team manager"
"value": "Responsable d'Equip"
}
],
"label.team-member": [
Expand Down Expand Up @@ -1288,7 +1288,7 @@
"label.transactions": [
{
"type": 0,
"value": "Transactions"
"value": "Transaccions"
}
],
"label.transfer": [
Expand Down Expand Up @@ -1330,7 +1330,7 @@
"label.uniqueCustomers": [
{
"type": 0,
"value": "Unique Customers"
"value": "Clients Únics"
}
],
"label.unknown": [
Expand Down Expand Up @@ -1372,7 +1372,7 @@
"label.user-property": [
{
"type": 0,
"value": "User Property"
"value": "Propietat d'Usuari"
}
],
"label.username": [
Expand Down
8 changes: 5 additions & 3 deletions src/components/hooks/queries/useRealtime.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
26 changes: 13 additions & 13 deletions src/lang/ca-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
31 changes: 19 additions & 12 deletions src/lib/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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')`;
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/pages/api/realtime/[websiteId].ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
};

Expand All @@ -23,15 +26,15 @@ 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);
}

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);
}
Expand Down
7 changes: 5 additions & 2 deletions src/pages/api/websites/[websiteId]/sessions/weekly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ 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 = {
GET: yup.object().shape({
websiteId: yup.string().uuid().required(),
startAt: yup.number().integer().required(),
endAt: yup.number().integer().min(yup.ref('startAt')).required(),
timezone: TimezoneTest,
...pageInfo,
}),
};
Expand All @@ -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))) {
Expand All @@ -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);
}
Expand Down
11 changes: 7 additions & 4 deletions src/queries/analytics/getRealtimeData.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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),
Expand Down
1 change: 1 addition & 0 deletions src/queries/analytics/pageviews/getPageviewStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ async function relationalQuery(websiteId: string, filters: QueryFilters) {
and event_type = {{eventType}}
${filterQuery}
group by 1
order by 1
`,
params,
);
Expand Down
Loading

0 comments on commit 5d37810

Please sign in to comment.