Merge branch 'dev' into analytics

This commit is contained in:
Mike Cao 2025-02-11 21:28:46 -08:00
commit d00d187d27
7 changed files with 23 additions and 22 deletions

View file

@ -14,6 +14,7 @@ export function UpdateNotice({ user, config }) {
const pathname = usePathname();
const [dismissed, setDismissed] = useState(checked);
const allowUpdate =
process.env.NODE_ENV === 'production' &&
user?.isAdmin &&
!config?.updatesDisabled &&
!pathname.includes('/share/') &&

View file

@ -7,7 +7,7 @@ import { badRequest, json, forbidden, serverError } from '@/lib/response';
import { fetchSession, fetchWebsite } from '@/lib/load';
import { getClientInfo, hasBlockedIp } from '@/lib/detect';
import { secret, uuid, visitSalt } from '@/lib/crypto';
import { COLLECTION_TYPE } from '@/lib/constants';
import { COLLECTION_TYPE, DOMAIN_REGEX } from '@/lib/constants';
import { createSession, saveEvent, saveSessionData } from '@/queries';
import { urlOrPathParam } from '@/lib/schema';
@ -16,7 +16,7 @@ const schema = z.object({
payload: z.object({
website: z.string().uuid(),
data: z.object({}).passthrough().optional(),
hostname: z.string().max(100).optional(),
hostname: z.string().regex(DOMAIN_REGEX).max(100).optional(),
language: z.string().max(35).optional(),
referrer: urlOrPathParam.optional(),
screen: z.string().max(11).optional(),

View file

@ -10,7 +10,7 @@ export function useSessionDataProperties(
const params = useFilterParams(websiteId);
return useQuery<any>({
queryKey: ['websites:event-data:properties', { websiteId, ...params }],
queryKey: ['websites:session-data:properties', { websiteId, ...params }],
queryFn: () => get(`/websites/${websiteId}/session-data/properties`, { ...params }),
enabled: !!websiteId,
...options,

View file

@ -12,7 +12,7 @@ export function usePagedQuery<T = any>({
const { query: queryParams } = useNavigation();
const [params, setParams] = useState<PageParams>({
search: '',
page: queryParams.page || '1',
page: +queryParams.page || 1,
});
const { useQuery } = useApi();

View file

@ -241,12 +241,6 @@ export const CHART_COLORS = [
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})$/;
export const SHARE_ID_REGEX = /^[a-zA-Z0-9]{8,16}$/;
export const UUID_REGEX =
/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/;
export const HOSTNAME_REGEX =
/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-_]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-_]*[A-Za-z0-9])$/;
export const IP_REGEX =
/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^(?:(?:[0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:(?:(:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]+|::(ffff(:0{1,4})?:)?((25[0-5]|(2[0-4]|1?[0-9])?[0-9])\.){3}(25[0-5]|(2[0-4]|1?[0-9])?[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1?[0-9])?[0-9])\.){3}(25[0-5]|(2[0-4]|1?[0-9])?[0-9]))$/;
export const DATETIME_REGEX =
/^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]{3}(Z|\+[0-9]{2}:[0-9]{2})?)?$/;

View file

@ -24,7 +24,7 @@ export type ReportType = ObjectValues<typeof REPORT_TYPES>;
export interface PageParams {
search?: string;
page?: string;
page?: string | number;
pageSize?: string;
orderBy?: string;
sortDescending?: boolean;

View file

@ -24,13 +24,16 @@ async function relationalQuery(
return rawQuery(
`
select
data_key as "propertyName",
count(*) as "total"
from session_data
where website_id = {{websiteId::uuid}}
and created_at between {{startDate}} and {{endDate}}
${filterQuery}
group by data_key
data_key as "propertyName",
count(*) as "total"
from website_event e
left join session_data d
on d.session_id = e.session_id
where e.website_id = {{websiteId:uuid}}
and e.created_at between {{startDate}} and {{endDate}}
and d.data_key is not null
${filterQuery}
group by 1
order by 2 desc
limit 500
`,
@ -52,11 +55,14 @@ async function clickhouseQuery(
select
data_key as propertyName,
count(*) as total
from session_data final
where website_id = {websiteId:UUID}
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
from website_event e
left join session_data d
on d.session_id = e.session_id
where e.website_id = {websiteId:UUID}
and e.created_at between {startDate:DateTime64} and {endDate:DateTime64}
and d.data_key != ''
${filterQuery}
group by data_key
group by 1
order by 2 desc
limit 500
`,