Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

801 B
Raw Blame
export interface AnalyticsParameters {
  websiteId: string;
  startDate?: Date | string;
  endDate?: Date | string;
  startAt?: number;
  endAt?: number;
  unit?: string;
  timezone?: string;
}

/** Encode structured GET criteria once, before URLSearchParams escapes them. */
export function serializeAnalyticsQuery(params: Record<string, any>) {
  const { websiteId: _websiteId, id: _id, startDate, endDate, ...query } = params;
  if (startDate != null) query.startAt = +new Date(startDate);
  if (endDate != null) query.endAt = +new Date(endDate);
  return Object.fromEntries(
    Object.entries(query)
      .filter(([, value]) => value !== undefined)
      .map(([key, value]) => [
        key,
        typeof value === 'object' && value !== null ? JSON.stringify(value) : value,
      ]),
  );
}