Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Add a lot more buckets

Bill Yangc0242b5f565a
diff --git a/client/src/app/[site]/main/components/MainSection/BucketSelection.tsx b/client/src/app/[site]/main/components/MainSection/BucketSelection.tsx
index 8414b1569..ac70bc9b6 100644
--- a/client/src/app/[site]/main/components/MainSection/BucketSelection.tsx
+++ b/client/src/app/[site]/main/components/MainSection/BucketSelection.tsx
@@ -14,6 +14,15 @@ const getOptions = (time: Time) => {
if (time.mode === "day") {
return (
<SelectContent>
+ <SelectItem size="sm" value="minute">
+ Minute
+ </SelectItem>
+ <SelectItem size="sm" value="five_minutes">
+ 5 Minutes
+ </SelectItem>
+ <SelectItem size="sm" value="fifteen_minutes">
+ 15 Minutes
+ </SelectItem>
<SelectItem size="sm" value="hour">
Hour
</SelectItem>
diff --git a/client/src/app/[site]/main/components/MainSection/Chart.tsx b/client/src/app/[site]/main/components/MainSection/Chart.tsx
index 76e1cc62f..257b3a2ef 100644
--- a/client/src/app/[site]/main/components/MainSection/Chart.tsx
+++ b/client/src/app/[site]/main/components/MainSection/Chart.tsx
@@ -13,7 +13,18 @@ const getMax = (time: Time, bucket: TimeBucket) => {
if (time.mode === "day") {
const dayDate = DateTime.fromISO(time.day)
.endOf("day")
- .minus({ minutes: 59 });
+ .minus({
+ minutes:
+ bucket === "hour"
+ ? 59
+ : bucket === "fifteen_minutes"
+ ? 14
+ : bucket === "ten_minutes"
+ ? 9
+ : bucket === "five_minutes"
+ ? 4
+ : 0,
+ });
return now < dayDate ? dayDate.toJSDate() : undefined;
} else if (time.mode === "range") {
if (bucket === "hour") {
@@ -214,20 +225,12 @@ export function Chart({
</div>
) : null}
<div className="flex justify-between text-sm w-36">
- <div>
- {bucket === "hour"
- ? currentTime.toFormat("M/d h a")
- : currentTime.toLocaleString()}
- </div>
+ <div>{formatTime(currentTime, bucket)}</div>
<div>{formatTooltipValue(currentY, selectedStat)}</div>
</div>
{previousTime && (
<div className="flex justify-between text-sm text-muted-foreground">
- <div>
- {bucket === "hour"
- ? previousTime.toFormat("M/d h a")
- : previousTime.toLocaleString()}
- </div>
+ <div>{formatTime(previousTime, bucket)}</div>
<div>{formatTooltipValue(previousY, selectedStat)}</div>
</div>
)}
@@ -237,3 +240,18 @@ export function Chart({
/>
);
}
+
+const formatTime = (time: DateTime<boolean>, bucket: TimeBucket) => {
+ if (
+ bucket === "minute" ||
+ bucket === "five_minutes" ||
+ bucket === "ten_minutes" ||
+ bucket === "fifteen_minutes"
+ ) {
+ return time.toFormat("M/d h:mm a");
+ } else if (bucket === "hour") {
+ return time.toFormat("M/d h a");
+ } else {
+ return time.toLocaleString();
+ }
+};
diff --git a/client/src/lib/store.ts b/client/src/lib/store.ts
index d8e64ca5b..a76f4594d 100644
--- a/client/src/lib/store.ts
+++ b/client/src/lib/store.ts
@@ -45,7 +45,16 @@ export type Time =
| YearMode
| AllTimeMode;
-export type TimeBucket = "hour" | "day" | "week" | "month" | "year";
+export type TimeBucket =
+ | "minute"
+ | "five_minutes"
+ | "ten_minutes"
+ | "fifteen_minutes"
+ | "hour"
+ | "day"
+ | "week"
+ | "month"
+ | "year";
export type StatType =
| "pageviews"
diff --git a/server/src/api/getOverviewBucketed.ts b/server/src/api/getOverviewBucketed.ts
index 994b6d21c..d30a08ef5 100644
--- a/server/src/api/getOverviewBucketed.ts
+++ b/server/src/api/getOverviewBucketed.ts
@@ -7,17 +7,27 @@ import {
} from "./utils.js";
const TimeBucketToFn = {
+ minute: "toStartOfMinute",
+ five_minutes: "toStartOfFiveMinutes",
+ ten_minutes: "toStartOfTenMinutes",
+ fifteen_minutes: "toStartOfFifteenMinutes",
hour: "toStartOfHour",
day: "toStartOfDay",
week: "toStartOfWeek",
month: "toStartOfMonth",
+ year: "toStartOfYear",
};
const bucketIntervalMap = {
+ minute: "1 MINUTE",
+ five_minutes: "5 MINUTES",
+ ten_minutes: "10 MINUTES",
+ fifteen_minutes: "15 MINUTES",
hour: "1 HOUR",
day: "1 DAY",
week: "7 DAY",
month: "1 MONTH",
+ year: "1 YEAR",
} as const;
function getTimeStatementFill(