🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
refactor: centralize time zone constants and unify naming convention
Andrii Andrushchyshyndee6525f74cd
diff --git a/client/src/api/analytics/useGetEvents.ts b/client/src/api/analytics/useGetEvents.tsindex 04afeaff0..ff94b7fbb 100644--- a/client/src/api/analytics/useGetEvents.ts+++ b/client/src/api/analytics/useGetEvents.ts@@ -3,6 +3,7 @@ import { Time } from "../../components/DateSelector/types";import { BACKEND_URL } from "../../lib/const";import { useStore } from "../../lib/store";import { authedFetchWithError, buildUrl, getStartAndEndDate } from "../utils";+import { timeZone } from "../../lib/dateTimeUtils";export type Event = {timestamp: string;@@ -57,7 +58,6 @@ export function useGetEventsInfinite(options: GetEventsOptions = {}) {const { startDate, endDate } = options.time? getStartAndEndDate(options.time): getStartAndEndDate(time);- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;const pageSize = options.pageSize || 20;return useInfiniteQuery<EventsResponse, Error>({@@ -66,7 +66,7 @@ export function useGetEventsInfinite(options: GetEventsOptions = {}) {site,startDate,endDate,- timezone,+ timeZone,filters,pageSize,options.isRealtime,@@ -76,7 +76,7 @@ export function useGetEventsInfinite(options: GetEventsOptions = {}) {const params: Record<string, any> = {startDate,endDate,- timezone,+ timeZone,page: pageParam,pageSize,};diff --git a/client/src/api/analytics/useGetFunnel.ts b/client/src/api/analytics/useGetFunnel.tsindex deff39dfe..e42cf675f 100644--- a/client/src/api/analytics/useGetFunnel.ts+++ b/client/src/api/analytics/useGetFunnel.ts@@ -2,6 +2,7 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";import { BACKEND_URL } from "../../lib/const";import { authedFetch, authedFetchWithError } from "../utils";import { useStore, Filter } from "../../lib/store";+import { timeZone } from "../../lib/dateTimeUtils";import { useDebounce } from "@uidotdev/usehooks";export type FunnelStep = {@@ -62,11 +63,10 @@ export function useGetFunnel(config?: FunnelRequest, debounce?: boolean) {throw new Error("Funnel configuration is required");}- // Add timezone to the request- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;+ // Add time zone to the requestconst fullConfig = {...configToUse,- timezone,+ timeZone,};try {const response = await authedFetchWithError<{ data: FunnelResponse[] }>(@@ -102,11 +102,10 @@ export function useSaveFunnel() {SaveFunnelRequest>({mutationFn: async (funnelConfig) => {- // Add timezone to the request- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;+ // Add time zone to the requestconst fullConfig = {...funnelConfig,- timezone,+ timeZone,};try {diff --git a/client/src/api/analytics/useGetGoal.ts b/client/src/api/analytics/useGetGoal.tsindex 95f5f718c..7170005ed 100644--- a/client/src/api/analytics/useGetGoal.ts+++ b/client/src/api/analytics/useGetGoal.ts@@ -1,5 +1,6 @@import { useQuery } from "@tanstack/react-query";import { BACKEND_URL } from "../../lib/const";+import { timeZone } from "../../lib/dateTimeUtils";import { authedFetch } from "../utils";import { useStore, Filter } from "../../lib/store";import { Goal } from "./useGetGoals";@@ -22,15 +23,14 @@ export function useGetGoal({enabled?: boolean;}) {const { site } = useStore();- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;return useQuery({- queryKey: ["goal", site, goalId, startDate, endDate, timezone, filters],+ queryKey: ["goal", site, goalId, startDate, endDate, timeZone, filters],queryFn: async () => {return authedFetch(`${BACKEND_URL}/goal/${goalId}/${site}`, {startDate,endDate,- timezone,+ timeZone,filters,}).then((res) => res.json());},diff --git a/client/src/api/analytics/useGetGoals.ts b/client/src/api/analytics/useGetGoals.tsindex 851b68870..461e97142 100644--- a/client/src/api/analytics/useGetGoals.ts+++ b/client/src/api/analytics/useGetGoals.ts@@ -1,5 +1,6 @@import { useQuery } from "@tanstack/react-query";import { BACKEND_URL } from "../../lib/const";+import { timeZone } from "../../lib/dateTimeUtils";import {getFilteredFilters,GOALS_PAGE_FILTERS,@@ -56,7 +57,6 @@ export function useGetGoals({minutes?: number;}) {const { site, time } = useStore();- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;const filteredFilters = getFilteredFilters(GOALS_PAGE_FILTERS);// If startDate and endDate are not provided, use time from store@@ -64,7 +64,7 @@ export function useGetGoals({if (minutes) {// If minutes is explicitly provided, use it- timeParams = { minutes: minutes.toString(), timezone };+ timeParams = { minutes: minutes.toString(), timeZone };} else if (!startDate || !endDate) {// Otherwise get time parameters from the store's time// This will handle last-24-hours mode automatically@@ -72,7 +72,7 @@ export function useGetGoals({timeParams = Object.fromEntries(new URLSearchParams(queryParams));} else {// Use explicitly provided dates if available- timeParams = { startDate, endDate, timezone };+ timeParams = { startDate, endDate, timeZone };}return useQuery({diff --git a/client/src/api/analytics/useGetOverview.ts b/client/src/api/analytics/useGetOverview.tsindex a0cf681c0..6c6d85236 100644--- a/client/src/api/analytics/useGetOverview.ts+++ b/client/src/api/analytics/useGetOverview.ts@@ -2,6 +2,7 @@ import { useQuery } from "@tanstack/react-query";import { useStore } from "../../lib/store";import { authedFetch, getStartAndEndDate } from "../utils";import { BACKEND_URL } from "../../lib/const";+import { timeZone } from "../../lib/dateTimeUtils";export type GetOverviewResponse = {sessions: number;@@ -28,11 +29,10 @@ export function useGetOverview({return useQuery({queryKey: ["overview", timeToUse, site, filters],queryFn: () => {- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;return authedFetch(`${BACKEND_URL}/overview/${site}`, {startDate,endDate,- timezone,+ timeZone,filters,}).then((res) => res.json());},@@ -60,10 +60,9 @@ export function useGetOverviewPastMinutes({return useQuery({queryKey: ["overview-past-minutes", pastMinutes, site],queryFn: () => {- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;return authedFetch(`${BACKEND_URL}/overview/${site}`, {pastMinutes,- timezone,+ timeZone,}).then((res) => res.json());},staleTime: Infinity,diff --git a/client/src/api/analytics/useGetOverviewBucketed.ts b/client/src/api/analytics/useGetOverviewBucketed.tsindex cd322c50e..aef585219 100644--- a/client/src/api/analytics/useGetOverviewBucketed.ts+++ b/client/src/api/analytics/useGetOverviewBucketed.ts@@ -5,6 +5,7 @@ import {} from "@tanstack/react-query";import { BACKEND_URL } from "../../lib/const";import { TimeBucket, useStore } from "../../lib/store";+import { timeZone } from "../../lib/dateTimeUtils";import { APIResponse } from "../types";import { authedFetch, getStartAndEndDate } from "../utils";@@ -40,11 +41,10 @@ export function useGetOverviewBucketed({return useQuery({queryKey: ["overview-bucketed", timeToUse, bucket, site, filters],queryFn: () => {- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;return authedFetch(`${BACKEND_URL}/overview-bucketed/${site}`, {startDate,endDate,- timezone,+ timeZone,bucket,filters,}).then((res) => res.json());@@ -99,19 +99,18 @@ export function useGetOverviewBucketedPastMinutes({]: ["overview-bucketed-past-minutes", pastMinutes, site, bucket, filters],queryFn: () => {- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;return authedFetch(`${BACKEND_URL}/overview-bucketed/${site}`,useRange? {- timezone,+ timeZone,bucket,pastMinutesStart,pastMinutesEnd,filters,}: {- timezone,+ timeZone,bucket,pastMinutes,filters,@@ -167,9 +166,8 @@ export function useGetOverviewBucketedPreviousPastMinutes({filters,],queryFn: () => {- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;return authedFetch(`${BACKEND_URL}/overview-bucketed/${site}`, {- timezone,+ timeZone,bucket,pastMinutesStart,pastMinutesEnd,diff --git a/client/src/api/analytics/useGetOverviewBucketedWithInView.ts b/client/src/api/analytics/useGetOverviewBucketedWithInView.tsindex 79a41a580..87aa4eb17 100644--- a/client/src/api/analytics/useGetOverviewBucketedWithInView.ts+++ b/client/src/api/analytics/useGetOverviewBucketedWithInView.ts@@ -1,6 +1,7 @@import { useQuery } from "@tanstack/react-query";import { TimeBucket } from "../../lib/store";import { BACKEND_URL } from "../../lib/const";+import { timeZone } from "../../lib/dateTimeUtils";import { authedFetch } from "../utils";import { APIResponse } from "../types";import { GetOverviewBucketedResponse } from "./useGetOverviewBucketed";@@ -25,9 +26,8 @@ export function useGetOverviewBucketedWithInView({return useQuery<APIResponse<GetOverviewBucketedResponse>>({queryKey: ["overview-bucketed-past-minutes", pastMinutes, site, bucket],queryFn: () => {- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;return authedFetch(`${BACKEND_URL}/overview-bucketed/${site}`, {- timezone,+ timeZone,bucket,pastMinutes,}).then((res) => res.json());diff --git a/client/src/api/analytics/useGetOverviewWithInView.ts b/client/src/api/analytics/useGetOverviewWithInView.tsindex 99ed2736e..80999ea2e 100644--- a/client/src/api/analytics/useGetOverviewWithInView.ts+++ b/client/src/api/analytics/useGetOverviewWithInView.ts@@ -1,6 +1,7 @@import { useGetOverviewPastMinutes } from "./useGetOverview";import { useQuery } from "@tanstack/react-query";import { BACKEND_URL } from "../../lib/const";+import { timeZone } from "../../lib/dateTimeUtils";import { authedFetch } from "../utils";/**@@ -20,10 +21,9 @@ export function useGetOverviewWithInView({return useQuery({queryKey: ["overview-past-minutes", pastMinutes, site],queryFn: () => {- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;return authedFetch(`${BACKEND_URL}/overview/${site}`, {pastMinutes,- timezone,+ timeZone,}).then((res) => res.json());},enabled: isInView, // Only fetch when in viewdiff --git a/client/src/api/analytics/useJourneys.ts b/client/src/api/analytics/useJourneys.tsindex f3db401ca..cd027b3a5 100644--- a/client/src/api/analytics/useJourneys.ts+++ b/client/src/api/analytics/useJourneys.ts@@ -6,7 +6,7 @@ import { Time } from "../../components/DateSelector/types";export interface JourneyParams {siteId?: number;steps?: number;- timezone?: string;+ timeZone?: string;time: Time;limit?: number;}@@ -24,14 +24,14 @@ export interface JourneysResponse {export const useJourneys = ({siteId,steps = 3,- timezone = "UTC",+ timeZone = "UTC",time,limit = 100,}: JourneyParams) => {const { startDate, endDate } = getStartAndEndDate(time);return useQuery<JourneysResponse>({- queryKey: ["journeys", siteId, steps, startDate, endDate, timezone, limit],+ queryKey: ["journeys", siteId, steps, startDate, endDate, timeZone, limit],queryFn: async () => {let url = `${BACKEND_URL}/journeys/${siteId}`;const params = new URLSearchParams();@@ -39,7 +39,7 @@ export const useJourneys = ({if (steps) params.append("steps", steps.toString());if (startDate) params.append("startDate", startDate);if (endDate) params.append("endDate", endDate);- if (timezone) params.append("timezone", timezone);+ if (timeZone) params.append("timeZone", timeZone);if (limit) params.append("limit", limit.toString());const queryString = params.toString();diff --git a/client/src/api/analytics/useSingleCol.ts b/client/src/api/analytics/useSingleCol.tsindex d45bc3665..7b650e6d5 100644--- a/client/src/api/analytics/useSingleCol.ts+++ b/client/src/api/analytics/useSingleCol.ts@@ -1,5 +1,6 @@import { useQuery, UseQueryResult } from "@tanstack/react-query";import { FilterParameter, useStore } from "../../lib/store";+import { timeZone } from "../../lib/dateTimeUtils";import { APIResponse } from "../types";import { BACKEND_URL } from "../../lib/const";import { getStartAndEndDate, authedFetch } from "../utils";@@ -36,7 +37,7 @@ export function useSingleCol({const queryParams = isPast24HoursMode? {// Past minutes approach- timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,+ timeZone: timeZone,parameter,limit,minutes: periodTime === "previous" ? 48 * 60 : 24 * 60,@@ -45,7 +46,7 @@ export function useSingleCol({: {// Regular date-based approach...getStartAndEndDate(timeToUse),- timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,+ timeZone: timeZone,parameter,limit,filters: useFilters ? filters : undefined,@@ -97,9 +98,8 @@ export function useSingleColRealtime({return useQuery({queryKey: [parameter, site, limit, minutes, "realtime"],queryFn: () => {- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;return authedFetch(`${BACKEND_URL}/single-col/${site}`, {- timezone,+ timeZone,parameter,limit,minutes,diff --git a/client/src/api/analytics/userSessions.ts b/client/src/api/analytics/userSessions.tsindex 1eff4efeb..bda4caa6d 100644--- a/client/src/api/analytics/userSessions.ts+++ b/client/src/api/analytics/userSessions.ts@@ -1,5 +1,6 @@import { useInfiniteQuery, useQuery } from "@tanstack/react-query";import { BACKEND_URL } from "../../lib/const";+import { timeZone } from "../../lib/dateTimeUtils";import {getFilteredFilters,SESSION_PAGE_FILTERS,@@ -34,11 +35,10 @@ export function useGetUserSessions(userId: string) {return useQuery({queryKey: ["user-sessions", userId, time, site, filters],queryFn: () => {- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;return authedFetch(`${BACKEND_URL}/user/${userId}/sessions/${site}`, {startDate,endDate,- timezone,+ timeZone,filters,}).then((res) => res.json());},@@ -86,11 +86,9 @@ export function useGetSessionsInfinite(userId?: string) {return useInfiniteQuery<APIResponse<GetSessionsResponse>>({queryKey: ["sessions-infinite", time, site, filteredFilters, userId],queryFn: ({ pageParam = 1 }) => {- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;-// Use an object for request parameters so we can conditionally add fieldsconst requestParams: Record<string, any> = {- timezone,+ timeZone,filters: filteredFilters,page: pageParam,};@@ -219,10 +217,9 @@ export function useGetUserSessionCount(userId: string) {return useQuery<APIResponse<UserSessionCountResponse[]>>({queryKey: ["user-session-count", userId, site],queryFn: () => {- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;return authedFetch(`${BACKEND_URL}/user/session-count/${site}`, {userId,- timezone,+ timeZone,}).then((res) => res.json());},staleTime: Infinity,diff --git a/client/src/api/analytics/users.ts b/client/src/api/analytics/users.tsindex f70e53a8f..59728415f 100644--- a/client/src/api/analytics/users.ts+++ b/client/src/api/analytics/users.ts@@ -1,5 +1,6 @@import { useQuery } from "@tanstack/react-query";import { BACKEND_URL } from "../../lib/const";+import { timeZone } from "../../lib/dateTimeUtils";import {useStore,Filter,@@ -64,11 +65,9 @@ export function useGetUsers(options: GetUsersOptions) {filteredFilters,],queryFn: async () => {- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;-// Build request parametersconst requestParams: Record<string, any> = {- timezone,+ timeZone,filters: filteredFilters,page,pageSize,diff --git a/client/src/api/analytics/utils.ts b/client/src/api/analytics/utils.tsindex 0f5355376..48914b1df 100644--- a/client/src/api/analytics/utils.ts+++ b/client/src/api/analytics/utils.ts@@ -1,5 +1,6 @@import { Time } from "../../components/DateSelector/types";import { getStartAndEndDate } from "../utils";+import { timeZone } from "../../lib/dateTimeUtils";/*** Generates URL query parameters for time filtering@@ -7,14 +8,13 @@ import { getStartAndEndDate } from "../utils";* @returns URL query string with time parameters*/export function getQueryTimeParams(time: Time): string {- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;const params = new URLSearchParams();// Handle last-24-hours mode differentlyif (time.mode === "last-24-hours") {// Use minutes parameter instead of date rangeparams.append("minutes", "1440"); // 24 hours * 60 minutes- params.append("timezone", timezone);+ params.append("timeZone", timeZone);return params.toString();}@@ -23,7 +23,7 @@ export function getQueryTimeParams(time: Time): string {if (startDate) params.append("startDate", startDate);if (endDate) params.append("endDate", endDate);- params.append("timezone", timezone);+ params.append("timeZone", timeZone);return params.toString();}diff --git a/client/src/app/[site]/journeys/page.tsx b/client/src/app/[site]/journeys/page.tsxindex af7cfca8b..046c6a8e0 100644--- a/client/src/app/[site]/journeys/page.tsx+++ b/client/src/app/[site]/journeys/page.tsx@@ -20,6 +20,7 @@ import { DateSelector } from "../../../components/DateSelector/DateSelector";import { DateRangeMode, Time } from "../../../components/DateSelector/types";import { MobileSidebar } from "../../../components/MobileSidebar";import { useSetPageTitle } from "../../../hooks/useSetPageTitle";+import { timeZone } from "../../../lib/dateTimeUtils";const MAX_LINK_HEIGHT = 100;@@ -36,13 +37,13 @@ export default function JourneysPage() {startDate: DateTime.now().minus({ days: 7 }).toISODate(),endDate: DateTime.now().toISODate(),wellKnown: "Last 7 days",- timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,+ timeZone: timeZone,} as DateRangeMode);const { data, isLoading, error } = useJourneys({siteId: siteMetadata?.siteId,steps,- timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,+ timeZone: timeZone,time,limit: maxJourneys,});diff --git a/client/src/lib/dateTimeUtils.ts b/client/src/lib/dateTimeUtils.tsindex 3facb5ac3..a4f0834c6 100644--- a/client/src/lib/dateTimeUtils.ts+++ b/client/src/lib/dateTimeUtils.ts@@ -1,16 +1,17 @@-import { Duration, DurationLikeObject, Settings } from "luxon";-// Detect user locale+// Detect user locale from the browser environment (fallback to 'en-US' on server)export const userLocale = typeof navigator !== "undefined" ? navigator.language : "en-US";-// Detect user 12h/24h preference+// Detect whether the user prefers 12-hour time format (true = 12h, false = 24h)const resolved = new Intl.DateTimeFormat(userLocale, { hour: "numeric" }).resolvedOptions();export const hour12 = resolved.hourCycle === "h12";-// Set default locale globally-Settings.defaultLocale = userLocale;+// Detect user's timezone (not exported but used internally)+export const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;+// Set default locale for Luxon globally+Settings.defaultLocale = userLocale;/*** Returns localized weekday names, starting from Monday.diff --git a/server/src/api/analytics/getEventNames.ts b/server/src/api/analytics/getEventNames.tsindex 1bd55b71c..b2487166a 100644--- a/server/src/api/analytics/getEventNames.ts+++ b/server/src/api/analytics/getEventNames.ts@@ -19,7 +19,7 @@ export interface GetEventNamesRequest {Querystring: {startDate?: string;endDate?: string;- timezone: string;+ timeZone: string;filters?: string;minutes?: string;};@@ -29,7 +29,7 @@ export async function getEventNames(req: FastifyRequest<GetEventNamesRequest>,res: FastifyReply) {- const { startDate, endDate, timezone, filters, minutes } = req.query;+ const { startDate, endDate, timeZone, filters, minutes } = req.query;const site = req.params.site;const userHasAccessToSite = await getUserHasAccessToSitePublic(req, site);if (!userHasAccessToSite) {@@ -39,7 +39,7 @@ export async function getEventNames(const timeStatement = getTimeStatement(minutes? { pastMinutes: Number(minutes) }- : { date: { startDate, endDate, timezone } }+ : { date: { startDate, endDate, timeZone } });const filterStatement = filters ? getFilterStatement(filters) : "";diff --git a/server/src/api/analytics/getEventProperties.ts b/server/src/api/analytics/getEventProperties.tsindex 72f0adeab..c402c049e 100644--- a/server/src/api/analytics/getEventProperties.ts+++ b/server/src/api/analytics/getEventProperties.ts@@ -20,7 +20,7 @@ export interface GetEventPropertiesRequest {Querystring: {startDate?: string;endDate?: string;- timezone: string;+ timeZone: string;eventName: string;filters?: string;minutes?: string;@@ -31,7 +31,7 @@ export async function getEventProperties(req: FastifyRequest<GetEventPropertiesRequest>,res: FastifyReply) {- const { startDate, endDate, timezone, eventName, filters, minutes } =+ const { startDate, endDate, timeZone, eventName, filters, minutes } =req.query;const site = req.params.site;const userHasAccessToSite = await getUserHasAccessToSitePublic(req, site);@@ -46,7 +46,7 @@ export async function getEventProperties(const timeStatement = getTimeStatement(minutes? { pastMinutes: Number(minutes) }- : { date: { startDate, endDate, timezone } }+ : { date: { startDate, endDate, timeZone } });const filterStatement = filters ? getFilterStatement(filters) : "";diff --git a/server/src/api/analytics/getEvents.ts b/server/src/api/analytics/getEvents.tsindex dea4611b0..2cddfe07e 100644--- a/server/src/api/analytics/getEvents.ts+++ b/server/src/api/analytics/getEvents.ts@@ -31,7 +31,7 @@ interface GetEventsRequest {Querystring: {startDate?: string;endDate?: string;- timezone?: string;+ timeZone?: string;filters?: string;page?: string;pageSize?: string;@@ -47,7 +47,7 @@ export async function getEvents(const {startDate,endDate,- timezone,+ timeZone,filters,page = "1",pageSize = "20",@@ -66,7 +66,7 @@ export async function getEvents(// Get time and filter statements if parameters are providedconst timeStatement =startDate || endDate- ? getTimeStatement({ date: { startDate, endDate, timezone } })+ ? getTimeStatement({ date: { startDate, endDate, timeZone } }): "AND timestamp > now() - INTERVAL 30 MINUTE"; // Default to last 30 minutes if no time range specifiedconst filterStatement = filters ? getFilterStatement(filters) : "";diff --git a/server/src/api/analytics/getFunnel.ts b/server/src/api/analytics/getFunnel.tsindex bd8412df5..2496e4839 100644--- a/server/src/api/analytics/getFunnel.ts+++ b/server/src/api/analytics/getFunnel.ts@@ -28,7 +28,7 @@ type Funnel = {steps: FunnelStep[];startDate: string;endDate: string;- timezone: string;+ timeZone: string;filters?: Filter[];};@@ -49,7 +49,7 @@ export async function getFunnel(}>,reply: FastifyReply) {- const { steps, startDate, endDate, timezone, filters } = request.body;+ const { steps, startDate, endDate, timeZone, filters } = request.body;const { site } = request.params;// Validate request@@ -69,7 +69,7 @@ export async function getFunnel(try {// Create the time statement for the date rangeconst timeStatement = getTimeStatement({- date: { startDate, endDate, timezone },+ date: { startDate, endDate, timeZone },});// Get filter conditions using the existing utility functiondiff --git a/server/src/api/analytics/getGoal.ts b/server/src/api/analytics/getGoal.tsindex a490658e0..235dc9251 100644--- a/server/src/api/analytics/getGoal.ts+++ b/server/src/api/analytics/getGoal.ts@@ -21,14 +21,14 @@ export async function getGoal(Querystring: {startDate: string;endDate: string;- timezone: string;+ timeZone: string;filters?: string;};}>,reply: FastifyReply) {const { goalId, site } = request.params;- const { startDate, endDate, timezone, filters } = request.query;+ const { startDate, endDate, timeZone, filters } = request.query;// Check user access to siteconst userHasAccessToSite = await getUserHasAccessToSitePublic(request, site);@@ -56,7 +56,7 @@ export async function getGoal(// Build filter and time clauses for ClickHouse queriesconst filterStatement = filters ? getFilterStatement(filters) : "";const timeStatement = getTimeStatement({- date: { startDate, endDate, timezone },+ date: { startDate, endDate, timeZone },});// First, get the total number of unique sessions (denominator for conversion rate)diff --git a/server/src/api/analytics/getGoals.ts b/server/src/api/analytics/getGoals.tsindex 13323c652..fc20533fa 100644--- a/server/src/api/analytics/getGoals.ts+++ b/server/src/api/analytics/getGoals.ts@@ -42,7 +42,7 @@ export async function getGoals(Querystring: {startDate?: string;endDate?: string;- timezone: string;+ timeZone: string;filters?: string;page?: string;pageSize?: string;@@ -59,7 +59,7 @@ export async function getGoals(const {startDate,endDate,- timezone,+ timeZone,filters,page = "1",pageSize = "10",@@ -168,7 +168,7 @@ export async function getGoals(: minutes? { pastMinutes: Number(minutes) }: startDate || endDate- ? { date: { startDate, endDate, timezone } }+ ? { date: { startDate, endDate, timeZone } }: {};const timeStatement = getTimeStatement(timeParams);diff --git a/server/src/api/analytics/getJourneys.ts b/server/src/api/analytics/getJourneys.tsindex 55b3f76d8..32df4230c 100644--- a/server/src/api/analytics/getJourneys.ts+++ b/server/src/api/analytics/getJourneys.ts@@ -10,7 +10,7 @@ export const getJourneys = async (steps?: string;startDate?: string;endDate?: string;- timezone?: string;+ timeZone?: string;limit?: string;};}>,@@ -22,7 +22,7 @@ export const getJourneys = async (steps = "3",startDate,endDate,- timezone = "UTC",+ timeZone = "UTC",limit = "100",} = request.query;@@ -49,7 +49,7 @@ export const getJourneys = async (startDate:startDate || DateTime.now().minus({ days: 30 }).toISODate(),endDate: endDate || DateTime.now().toISODate(),- timezone,+ timeZone,table: "events",}: undefined,diff --git a/server/src/api/analytics/getOverview.ts b/server/src/api/analytics/getOverview.tsindex 58fa112a4..613091714 100644--- a/server/src/api/analytics/getOverview.ts+++ b/server/src/api/analytics/getOverview.ts@@ -20,14 +20,14 @@ type GetOverviewResponse = {const getQuery = ({startDate,endDate,- timezone,+ timeZone,site,filters,pastMinutes,}: {startDate: string;endDate: string;- timezone: string;+ timeZone: string;site: string;filters: string;pastMinutes: number;@@ -65,7 +65,7 @@ const getQuery = ({pastMinutes? { pastMinutes }: {- date: { startDate, endDate, timezone },+ date: { startDate, endDate, timeZone },})}GROUP BY session_id@@ -85,7 +85,7 @@ const getQuery = ({pastMinutes? { pastMinutes }: {- date: { startDate, endDate, timezone },+ date: { startDate, endDate, timeZone },})}AND type = 'pageview'@@ -99,7 +99,7 @@ export interface GenericRequest {Querystring: {startDate: string;endDate: string;- timezone: string;+ timeZone: string;filters: string;parameter: FilterParameter;pastMinutes?: number;@@ -111,7 +111,7 @@ export async function getOverview(req: FastifyRequest<GenericRequest>,res: FastifyReply) {- const { startDate, endDate, timezone, filters, pastMinutes } = req.query;+ const { startDate, endDate, timeZone, filters, pastMinutes } = req.query;const site = req.params.site;const userHasAccessToSite = await getUserHasAccessToSitePublic(req, site);if (!userHasAccessToSite) {@@ -121,7 +121,7 @@ export async function getOverview(const query = getQuery({startDate,endDate,- timezone,+ timeZone,site,filters,pastMinutes: Number(pastMinutes),diff --git a/server/src/api/analytics/getOverviewBucketed.ts b/server/src/api/analytics/getOverviewBucketed.tsindex f55f739e0..e2eb6c99c 100644--- a/server/src/api/analytics/getOverviewBucketed.ts+++ b/server/src/api/analytics/getOverviewBucketed.ts@@ -39,7 +39,7 @@ function getTimeStatementFill(pastMinutes,pastMinutesRange,}: {- date?: { startDate: string; endDate: string; timezone: string };+ date?: { startDate: string; endDate: string; timeZone: string };pastMinutes?: number;pastMinutesRange?: { start: number; end: number };},@@ -51,25 +51,25 @@ function getTimeStatementFill();if (params.date) {- const { startDate, endDate, timezone } = params.date;+ const { startDate, endDate, timeZone } = params.date;return `WITH FILL FROM toTimeZone(toDateTime(${TimeBucketToFn[validatedBucket]}(toDateTime(${SqlString.escape(startDate)}, ${SqlString.escape(- timezone+ timeZone)}))),'UTC')TO if(toDate(${SqlString.escape(endDate)}) = toDate(now(), ${SqlString.escape(- timezone+ timeZone)}),now(),toTimeZone(toDateTime(${TimeBucketToFn[validatedBucket]}(toDateTime(${SqlString.escape(endDate)}, ${SqlString.escape(- timezone+ timeZone)}))) + INTERVAL 1 DAY,'UTC')@@ -138,7 +138,7 @@ function getTimeStatementFill(const getQuery = ({startDate,endDate,- timezone,+ timeZone,bucket,site,filters,@@ -147,7 +147,7 @@ const getQuery = ({}: {startDate: string;endDate: string;- timezone: string;+ timeZone: string;bucket: TimeBucket;site: string;filters: string;@@ -162,7 +162,7 @@ const getQuery = ({? { pastMinutesRange }: pastMinutes? { pastMinutes }- : { date: { startDate, endDate, timezone } };+ : { date: { startDate, endDate, timeZone } };const query = `SELECT@@ -178,7 +178,7 @@ FROMSELECTtoDateTime(${TimeBucketToFn[bucket]- }(toTimeZone(start_time, ${SqlString.escape(timezone)}))) AS time,+ }(toTimeZone(start_time, ${SqlString.escape(timeZone)}))) AS time,COUNT() AS sessions,AVG(pages_in_session) AS pages_per_session,sumIf(1, pages_in_session = 1) / COUNT() AS bounce_rate,@@ -208,7 +208,7 @@ FULL JOINSELECTtoDateTime(${TimeBucketToFn[bucket]- }(toTimeZone(timestamp, ${SqlString.escape(timezone)}))) AS time,+ }(toTimeZone(timestamp, ${SqlString.escape(timeZone)}))) AS time,COUNT(*) AS pageviews,COUNT(DISTINCT user_id) AS usersFROM events@@ -248,7 +248,7 @@ export async function getOverviewBucketed(Querystring: {startDate: string;endDate: string;- timezone: string;+ timeZone: string;bucket: TimeBucket;filters: string;pastMinutes?: number;@@ -261,7 +261,7 @@ export async function getOverviewBucketed(const {startDate,endDate,- timezone,+ timeZone,bucket,filters,pastMinutes,@@ -284,7 +284,7 @@ export async function getOverviewBucketed(const query = getQuery({startDate,endDate,- timezone,+ timeZone,bucket,site,filters,diff --git a/server/src/api/analytics/getSessions.ts b/server/src/api/analytics/getSessions.tsindex 9cea88781..a2f630a8a 100644--- a/server/src/api/analytics/getSessions.ts+++ b/server/src/api/analytics/getSessions.ts@@ -40,7 +40,7 @@ export interface GetSessionsRequest {Querystring: {startDate?: string;endDate?: string;- timezone: string;+ timeZone: string;filters: string;page: number;userId?: string;@@ -57,7 +57,7 @@ export async function getSessions(const {startDate,endDate,- timezone,+ timeZone,filters,page,userId,@@ -85,7 +85,7 @@ export async function getSessions(: minutes? { pastMinutes: Number(minutes) }: startDate && endDate- ? { date: { startDate, endDate, timezone } }+ ? { date: { startDate, endDate, timeZone } }: {};const timeStatement = getTimeStatement(timeParams);diff --git a/server/src/api/analytics/getSingleCol.ts b/server/src/api/analytics/getSingleCol.tsindex 7ecaefc85..fab110166 100644--- a/server/src/api/analytics/getSingleCol.ts+++ b/server/src/api/analytics/getSingleCol.ts@@ -17,7 +17,7 @@ interface GenericRequest {startDate: string;endDate: string;minutes: number;- timezone: string;+ timeZone: string;filters: string;parameter: FilterParameter;limit?: number;@@ -36,7 +36,7 @@ type GetSingleColResponse = {}[];const getQuery = (request: FastifyRequest<GenericRequest>) => {- const { startDate, endDate, timezone, filters, parameter, limit, minutes } =+ const { startDate, endDate, timeZone, filters, parameter, limit, minutes } =request.query;const filterStatement = getFilterStatement(filters);@@ -44,7 +44,7 @@ const getQuery = (request: FastifyRequest<GenericRequest>) => {minutes? { pastMinutes: Number(minutes) }: {- date: { startDate, endDate, timezone },+ date: { startDate, endDate, timeZone },});diff --git a/server/src/api/analytics/getUserSessionCount.ts b/server/src/api/analytics/getUserSessionCount.tsindex 7bd4a78a7..1c77fb767 100644--- a/server/src/api/analytics/getUserSessionCount.ts+++ b/server/src/api/analytics/getUserSessionCount.ts@@ -10,7 +10,7 @@ export interface GetUserSessionCountRequest {};Querystring: {userId?: string;- timezone?: string;+ timeZone?: string;};}@@ -24,7 +24,7 @@ export async function getUserSessionCount(res: FastifyReply) {const { site } = req.params;- const { userId, timezone = "UTC" } = req.query;+ const { userId, timeZone = "UTC" } = req.query;const userHasAccessToSite = await getUserHasAccessToSitePublic(req, site);if (!userHasAccessToSite) {@@ -37,7 +37,7 @@ export async function getUserSessionCount(const query = `SELECT- toDate(timestamp, ${SqlString.escape(timezone)}) as date,+ toDate(timestamp, ${SqlString.escape(timeZone)}) as date,count(DISTINCT session_id) as sessionsFROM eventsWHEREdiff --git a/server/src/api/analytics/getUserSessions.ts b/server/src/api/analytics/getUserSessions.tsindex bdce66078..18f132682 100644--- a/server/src/api/analytics/getUserSessions.ts+++ b/server/src/api/analytics/getUserSessions.ts@@ -44,7 +44,7 @@ export interface GetUserSessionsRequest {Querystring: {startDate: string;endDate: string;- timezone: string;+ timeZone: string;site: string;filters: string;};@@ -57,7 +57,7 @@ export async function getUserSessions(req: FastifyRequest<GetUserSessionsRequest>,res: FastifyReply) {- const { startDate, endDate, timezone, site, filters } = req.query;+ const { startDate, endDate, timeZone, site, filters } = req.query;const userId = req.params.userId;const userHasAccessToSite = await getUserHasAccessToSitePublic(req, site);@@ -67,7 +67,7 @@ export async function getUserSessions(const filterStatement = getFilterStatement(filters);const timeStatement = getTimeStatement({- date: { startDate, endDate, timezone },+ date: { startDate, endDate, timeZone },});const query = `diff --git a/server/src/api/analytics/getUsers.ts b/server/src/api/analytics/getUsers.tsindex 7766f54b6..cd421ccff 100644--- a/server/src/api/analytics/getUsers.ts+++ b/server/src/api/analytics/getUsers.ts@@ -30,7 +30,7 @@ export interface GetUsersRequest {Querystring: {startDate?: string;endDate?: string;- timezone: string;+ timeZone: string;filters: string;page?: string;pageSize?: string;@@ -49,7 +49,7 @@ export async function getUsers(const {startDate,endDate,- timezone,+ timeZone,filters,page = "1",pageSize = "20",@@ -93,7 +93,7 @@ export async function getUsers(: minutes? { pastMinutes: Number(minutes) }: startDate && endDate- ? { date: { startDate, endDate, timezone } }+ ? { date: { startDate, endDate, timeZone } }: {};// Generate filter statement and time statementdiff --git a/server/src/api/analytics/query-validation.ts b/server/src/api/analytics/query-validation.tsindex 46180347d..5296ebd68 100644--- a/server/src/api/analytics/query-validation.ts+++ b/server/src/api/analytics/query-validation.ts@@ -16,7 +16,7 @@ const tableSchema = z.enum(["events", "sessions"]).optional();const dateRegex = /^\d{4}-\d{2}-\d{2}$/;/**- * Schema for date parameters with timezone+ * Schema for date parameters with time zone*/const dateParamsSchema = z.object({startDate: z@@ -33,20 +33,20 @@ const dateParamsSchema = z.object({.refine((date) => !date || !isNaN(Date.parse(date)), {message: "Invalid date value",}),- timezone: z+ timeZone: z.string()- .min(1, { message: "Timezone cannot be empty" })+ .min(1, { message: "Time zone cannot be empty" }).refine((tz) => {try {- // Test if timezone is valid by attempting to format a date with it+ // Test if time zone is valid by attempting to format a date with itIntl.DateTimeFormat(undefined, { timeZone: tz });return true;} catch (e) {return false;}},- { message: "Invalid timezone" }+ { message: "Invalid time zone" }),table: tableSchema,});@@ -69,20 +69,20 @@ const fillDateParamsSchema = z.object({.refine((date) => !date || !isNaN(Date.parse(date)), {message: "Invalid date value",}),- timezone: z+ timeZone: z.string()- .min(1, { message: "Timezone cannot be empty" })+ .min(1, { message: "Time zone cannot be empty" }).refine((tz) => {try {- // Test if timezone is valid by attempting to format a date with it+ // Test if time zone is valid by attempting to format a date with itIntl.DateTimeFormat(undefined, { timeZone: tz });return true;} catch (e) {return false;}},- { message: "Invalid timezone" }+ { message: "Invalid time zone" }),});diff --git a/server/src/api/analytics/utils.ts b/server/src/api/analytics/utils.tsindex fc8c23ea7..e45930298 100644--- a/server/src/api/analytics/utils.ts+++ b/server/src/api/analytics/utils.ts@@ -16,7 +16,7 @@ export function getTimeStatement({date?: {startDate?: string;endDate?: string;- timezone?: string;+ timeZone?: string;table?: "events" | "sessions";};pastMinutes?: number;@@ -34,27 +34,27 @@ export function getTimeStatement({});if (sanitized.date) {- const { startDate, endDate, timezone } = sanitized.date;+ const { startDate, endDate, timeZone } = sanitized.date;if (!startDate && !endDate) {return "";}- // Use SqlString.escape for date and timezone values+ // Use SqlString.escape for date and timeZone valuesreturn `AND timestamp >= toTimeZone(toStartOfDay(toDateTime(${SqlString.escape(startDate- )}, ${SqlString.escape(timezone)})),+ )}, ${SqlString.escape(timeZone)})),'UTC')AND timestamp < if(toDate(${SqlString.escape(endDate)}) = toDate(now(), ${SqlString.escape(- timezone+ timeZone)}),now(),toTimeZone(toStartOfDay(toDateTime(${SqlString.escape(endDate- )}, ${SqlString.escape(timezone)})) + INTERVAL 1 DAY,+ )}, ${SqlString.escape(timeZone)})) + INTERVAL 1 DAY,'UTC'))`;diff --git a/server/src/db/geolocation/geolocation.ts b/server/src/db/geolocation/geolocation.tsindex 3646a9527..49077b67e 100644--- a/server/src/db/geolocation/geolocation.ts+++ b/server/src/db/geolocation/geolocation.ts@@ -12,7 +12,7 @@ interface LocationResponse {countryIso?: string;latitude?: number;longitude?: number;- timezone?: string;+ timeZone?: string;error?: string;subdivisions?: SubdivisionsRecord[];}@@ -40,7 +40,7 @@ function extractLocationData(response: City): LocationResponse {countryIso: response.country?.isoCode,latitude: response.location?.latitude,longitude: response.location?.longitude,- timezone: response.location?.timeZone,+ timeZone: response.location?.timeZone,subdivisions: response.subdivisions,};}