Files
backend/src/website-analytics/website-analytics.types.ts
T
Alireza HassaniandCursor 0c1c3f7ff9 Add AI English name translation and aggregate website view analytics.
Website views chart uses kind=all across page kinds; home hits also count static-images loads.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-28 20:39:37 +03:30

60 lines
1.7 KiB
TypeScript

export const WEBSITE_PAGE_KINDS = [
'home',
'portfolio_list',
'portfolio_detail',
'product_list',
'product_detail',
'store_item_list',
'store_item_detail',
'blog_list',
'blog_detail',
'video_list',
'video_detail',
] as const;
export type WebsitePageKind = (typeof WEBSITE_PAGE_KINDS)[number];
/** @deprecated Prefer WebsitePageKind — kept for dashboard chart query aliases. */
export type WebsiteViewKind = WebsitePageKind | 'website' | 'product' | 'portfolio' | 'blog';
const DETAIL_KINDS = new Set<WebsitePageKind>([
'portfolio_detail',
'product_detail',
'store_item_detail',
'blog_detail',
'video_detail',
]);
/** Legacy chart / POST aliases → canonical page kinds. */
const KIND_ALIASES: Record<string, WebsitePageKind> = {
website: 'home',
product: 'product_detail',
portfolio: 'portfolio_detail',
blog: 'blog_detail',
};
export function isWebsitePageKind(value: unknown): value is WebsitePageKind {
return (
typeof value === 'string' &&
(WEBSITE_PAGE_KINDS as readonly string[]).includes(value)
);
}
export function normalizeWebsitePageKind(value: string): WebsitePageKind | null {
if (isWebsitePageKind(value)) return value;
const aliased = KIND_ALIASES[value];
return aliased ?? null;
}
export function pageKindRequiresEntity(kind: WebsitePageKind): boolean {
return DETAIL_KINDS.has(kind);
}
/** Maps home dashboard chart ids to analytics page kinds (`all` = every storefront page). */
export const HOME_CHART_VIEW_KIND: Partial<Record<string, WebsitePageKind | 'all'>> = {
website_views_30d: 'all',
product_views_30d: 'product_detail',
portfolio_views_30d: 'portfolio_detail',
blog_views_30d: 'blog_detail',
};