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.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
set 6 month retention for hobby users
Francis Cao37b6194c5f6d
diff --git a/src/lib/load.ts b/src/lib/load.tsindex d4d6c3c75..d143344a5 100644--- a/src/lib/load.ts+++ b/src/lib/load.ts@@ -38,3 +38,15 @@ export async function fetchSession(websiteId: string, sessionId: string): Promisreturn session;}++export async function fetchAccount(websiteId: string) {+ let account = null;++ const cache = await redis.client.get(`cache:website:${websiteId}`);++ if (cache) {+ account = await redis.client.get(`account:${cache.account_id}`);+ }++ return account;+}diff --git a/src/lib/request.ts b/src/lib/request.tsindex 42c449048..f5b984810 100644--- a/src/lib/request.ts+++ b/src/lib/request.ts@@ -1,8 +1,9 @@+import { startOfMonth, subMonths } from 'date-fns';import { z } from 'zod';import { checkAuth } from '@/lib/auth';import { DEFAULT_PAGE_SIZE, FILTER_COLUMNS } from '@/lib/constants';import { getAllowedUnits, getMinimumUnit, maxDate, parseDateRange } from '@/lib/date';-import { fetchWebsite } from '@/lib/load';+import { fetchAccount, fetchWebsite } from '@/lib/load';import { filtersArrayToObject } from '@/lib/params';import { badRequest, unauthorized } from '@/lib/response';import type { QueryFilters } from '@/lib/types';@@ -82,6 +83,15 @@ export function getRequestFilters(query: Record<string, any>) {export async function setWebsiteDate(websiteId: string, data: Record<string, any>) {const website = await fetchWebsite(websiteId);+ const cloudMode = !!process.env.CLOUD_MODE;++ if (cloudMode) {+ const account = await fetchAccount(websiteId);++ if (!account?.hasSubscription) {+ data.startDate = maxDate(data.startDate, startOfMonth(subMonths(new Date(), 6)));+ }+ }if (website?.resetAt) {data.startDate = maxDate(data.startDate, new Date(website?.resetAt));