Skip to content

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

Enhance analytics API and documentation for improved data handling and user clarity

Bill Yang17268113985d
diff --git a/client/src/api/admin/sites.ts b/client/src/api/admin/sites.ts
index 14330294e..40547a50b 100644
--- a/client/src/api/admin/sites.ts
+++ b/client/src/api/admin/sites.ts
@@ -105,6 +105,7 @@ export function useSiteHasData(siteId: string) {
.then((res) => res.json())
.then((data) => data.hasData as Boolean);
},
+ refetchInterval: 5000,
staleTime: Infinity,
});
}
diff --git a/client/src/app/[site]/components/shared/Map.tsx b/client/src/app/[site]/components/shared/Map.tsx
index 553e8a3a4..19b0c9367 100644
--- a/client/src/app/[site]/components/shared/Map.tsx
+++ b/client/src/app/[site]/components/shared/Map.tsx
@@ -12,6 +12,7 @@ import { useCountries, useSubdivisions } from "../../../../lib/geo";
import { addFilter, FilterParameter } from "../../../../lib/store";
import { CountryFlag } from "./icons/CountryFlag";
import { getCountryPopulation } from "../../../../lib/countryPopulation";
+import { round } from "lodash";
interface TooltipContent {
name: string;
@@ -347,7 +348,7 @@ export function MapComponent({
{mode === "perCapita" && mapView === "countries" && (
<div className="text-sm text-neutral-300">
<span className="font-bold text-accent-400">
- {tooltipContent.perCapita?.toFixed(2)}
+ {round(tooltipContent.perCapita ?? 0, 2)}
</span>{" "}
per million people
</div>
diff --git a/docs/src/app/page.jsx b/docs/src/app/page.jsx
index 1505b58e8..61a6f61d6 100644
--- a/docs/src/app/page.jsx
+++ b/docs/src/app/page.jsx
@@ -152,7 +152,7 @@ export default function IndexPage() {
Is Rybbit GDPR and CCPA compliant?
</AccordionTrigger>
<AccordionContent className="px-6 pb-4 text-neutral-300">
- Yes, Rybbit is fully compliant with GDPR, CCPA, and other privacy regulations. We don't use cookies or collect any personal data that could identify your users. We prioritize privacy by design while still giving you all the analytics you need.
+ Yes, Rybbit is fully compliant with GDPR, CCPA, and other privacy regulations. We don't use cookies or collect any personal data that could identify your users. We salt user IDs daily to ensure users are not fingerprinted. You will not need to display a cookie consent banner to your users.
</AccordionContent>
</AccordionItem>
@@ -161,7 +161,28 @@ export default function IndexPage() {
How does Rybbit compare to Google Analytics?
</AccordionTrigger>
<AccordionContent className="px-6 pb-4 text-neutral-300">
- Unlike Google Analytics, Rybbit provides a clean, intuitive interface that's easy to use. We focus on the metrics that matter most, without overwhelming you with too many options. Plus, we respect user privacy, don't slow down your site, and offer first-party data collection.
+ <p>
+ Rybbit is much less bloated than Google Analytics, both in terms of our tracking script and the UX of the dashboard. We show you exactly what you need to see.
+ </p>
+ <br/>
+ <p>
+ You can see for yourself by checking out our <Link href="https://tracking.tomato.gg/1" className="text-emerald-400 hover:text-emerald-300">demo site</Link>. The difference in usability is night and day.
+ </p>
+ </AccordionContent>
+ </AccordionItem>
+
+ <AccordionItem value="item-7" className="border-b border-neutral-700/50">
+ <AccordionTrigger className="px-6 py-4 text-base md:text-lg font-medium hover:text-emerald-400 transition-colors">
+ How does Rybbit compare to Plausible/Umami/Matomo/Simple Analytics?
+ </AccordionTrigger>
+ <AccordionContent className="px-6 pb-4 text-neutral-300">
+ <p>
+ Rybbit is similiar to these other analytics platforms, but we are raising the bar when it comes to UX and the quality and scope of our feature set.
+ </p>
+ <br/>
+ <p>
+ We don't want to just be a simple analytics tool, but we carefully craft every feature to be understandable without having to read pages of documentation.
+ </p>
</AccordionContent>
</AccordionItem>
@@ -170,7 +191,7 @@ export default function IndexPage() {
Can I self-host Rybbit?
</AccordionTrigger>
<AccordionContent className="px-6 pb-4 text-neutral-300">
- Absolutely! Rybbit is available as a self-hosted option. You can install it on your own server and have complete control over your data. We also offer a cloud version if you prefer a managed solution.
+ Absolutely! Rybbit is available as a self-hosted option. You can install it on your own server and have complete control over your data. <Link href="/docs/self-hosting" className="text-emerald-400 hover:text-emerald-300">Learn more here</Link>. We also offer a cloud version if you prefer a managed solution.
</AccordionContent>
</AccordionItem>
@@ -179,7 +200,7 @@ export default function IndexPage() {
How easy is it to set up Rybbit?
</AccordionTrigger>
<AccordionContent className="px-6 pb-4 text-neutral-300">
- Setting up Rybbit is incredibly simple. Just add a small script to your website, and you're good to go. Most users are up and running in less than 5 minutes. We also provide comprehensive documentation and support if you need any help.
+ <Link href="/docs/tracker" className="text-emerald-400 hover:text-emerald-300">Setting up Rybbit</Link> is incredibly simple. Just add a small script to your website or install @rybbit/js from npm, and you're good to go. Most users are up and running in less than 5 minutes. We also provide comprehensive documentation and support if you need any help.
</AccordionContent>
</AccordionItem>
@@ -188,7 +209,15 @@ export default function IndexPage() {
What platforms does Rybbit support?
</AccordionTrigger>
<AccordionContent className="px-6 pb-4 text-neutral-300">
- Rybbit works with virtually any website platform. Whether you're using WordPress, Shopify, Next.js, React, Vue, or any other framework, our simple tracking snippet integrates seamlessly. We also offer specialized plugins for popular platforms to make integration even easier.
+ Rybbit works with virtually any website platform. Whether you're using WordPress, Shopify, Next.js, React, Vue, or any other framework, our simple tracking snippet integrates seamlessly. You can also use @rybbit/js, our web SDK you can install from npm.
+ </AccordionContent>
+ </AccordionItem>
+ <AccordionItem value="item-6">
+ <AccordionTrigger className="px-6 py-4 text-base md:text-lg font-medium hover:text-emerald-400 transition-colors">
+ Is Rybbit truly open source?
+ </AccordionTrigger>
+ <AccordionContent className="px-6 pb-4 text-neutral-300">
+ Yes, Rybbit is 100% open source. Every single line of code, including for our cloud/enterprise offerings, is available on GitHub under the AGPL 3.0 license.
</AccordionContent>
</AccordionItem>
</Accordion>
diff --git a/server/src/api/analytics/deleteReport.ts b/server/src/api/analytics/deleteReport.ts
index 90d22f7d4..70c3bb484 100644
--- a/server/src/api/analytics/deleteReport.ts
+++ b/server/src/api/analytics/deleteReport.ts
@@ -1,11 +1,8 @@
-import { FastifyRequest, FastifyReply } from "fastify";
+import { eq } from "drizzle-orm";
+import { FastifyReply, FastifyRequest } from "fastify";
import { db } from "../../db/postgres/postgres.js";
import { reports } from "../../db/postgres/schema.js";
-import { eq } from "drizzle-orm";
-import {
- getUserHasAccessToSite,
- getUserHasAccessToSitePublic,
-} from "../../lib/auth-utils.js";
+import { getUserHasAccessToSite } from "../../lib/auth-utils.js";
export async function deleteReport(
request: FastifyRequest<{
@@ -16,7 +13,6 @@ export async function deleteReport(
reply: FastifyReply
) {
const { reportId } = request.params;
- const userId = request.user?.id;
try {
// First get the report to check ownership
diff --git a/server/src/api/analytics/getJourneys.ts b/server/src/api/analytics/getJourneys.ts
index 27abf06bf..552adde9d 100644
--- a/server/src/api/analytics/getJourneys.ts
+++ b/server/src/api/analytics/getJourneys.ts
@@ -55,7 +55,7 @@ export const getJourneys = async (
timestamp
FROM events
WHERE
- site_id = ${site}
+ site_id = {siteId:Int32}
${timeStatement || ""}
AND type = 'pageview'
ORDER BY session_id, timestamp
@@ -66,7 +66,7 @@ export const getJourneys = async (
journey_segments AS (
SELECT
- arraySlice(path_sequence, 1, ${maxSteps}) AS journey,
+ arraySlice(path_sequence, 1, {maxSteps:Int32}) AS journey,
count() AS sessions_count
FROM user_paths
GROUP BY journey
@@ -80,13 +80,15 @@ export const getJourneys = async (
sessions_count * 100 / (
SELECT count(DISTINCT session_id)
FROM events
- WHERE site_id = ${site} ${timeStatement || ""}
+ WHERE site_id = {siteId:Int32}
+ ${timeStatement || ""}
) AS percentage
FROM journey_segments
`,
- // query_params: {
- // site: parseInt(site, 10),
- // },
+ query_params: {
+ siteId: parseInt(site, 10),
+ maxSteps: parseInt(steps, 10),
+ },
});
const data = await result.json();
diff --git a/server/src/api/analytics/getOverview.ts b/server/src/api/analytics/getOverview.ts
index f1aacd941..58fa112a4 100644
--- a/server/src/api/analytics/getOverview.ts
+++ b/server/src/api/analytics/getOverview.ts
@@ -59,7 +59,7 @@ const getQuery = ({
COUNT(CASE WHEN type = 'pageview' THEN 1 END) AS pages_in_session
FROM events
WHERE
- site_id = ${site}
+ site_id = {siteId:Int32}
${filterStatement}
${getTimeStatement(
pastMinutes
@@ -79,7 +79,7 @@ const getQuery = ({
COUNT(DISTINCT user_id) AS users
FROM events
WHERE
- site_id = ${site}
+ site_id = {siteId:Int32}
${filterStatement}
${getTimeStatement(
pastMinutes
@@ -131,6 +131,9 @@ export async function getOverview(
const result = await clickhouse.query({
query,
format: "JSONEachRow",
+ query_params: {
+ siteId: Number(site),
+ },
});
const data = await processResults<GetOverviewResponse>(result);
diff --git a/server/src/api/analytics/getOverviewBucketed.ts b/server/src/api/analytics/getOverviewBucketed.ts
index db27ad9a1..9470c87da 100644
--- a/server/src/api/analytics/getOverviewBucketed.ts
+++ b/server/src/api/analytics/getOverviewBucketed.ts
@@ -112,7 +112,7 @@ FROM
COUNT(*) AS pages_in_session
FROM events
WHERE
- site_id = ${site}
+ site_id = {siteId:Int32}
${filterStatement}
${getTimeStatement(
pastMinutes
@@ -145,7 +145,7 @@ FULL JOIN
COUNT(DISTINCT user_id) AS users
FROM events
WHERE
- site_id = ${site}
+ site_id = {siteId:Int32}
${filterStatement}
${getTimeStatement(
pastMinutes
@@ -215,6 +215,9 @@ export async function getOverviewBucketed(
const result = await clickhouse.query({
query,
format: "JSONEachRow",
+ query_params: {
+ siteId: Number(site),
+ },
});
const data = await processResults<getOverviewBucketed[number]>(result);
diff --git a/server/src/api/analytics/getSession.ts b/server/src/api/analytics/getSession.ts
index 8e72d9217..f158e4be9 100644
--- a/server/src/api/analytics/getSession.ts
+++ b/server/src/api/analytics/getSession.ts
@@ -97,8 +97,8 @@ SELECT
exit_page
FROM sessions
WHERE
- site_id = ${site}
- AND session_id = '${sessionId}'
+ site_id = {siteId:Int32}
+ AND session_id = {sessionId:String}
LIMIT 1
`;
@@ -108,8 +108,8 @@ SELECT
COUNT(*) as total
FROM events
WHERE
- site_id = ${site}
- AND session_id = '${sessionId}'
+ site_id = {siteId:Int32}
+ AND session_id = {sessionId:String}
`;
// 3. Query to get paginated pageviews
@@ -126,11 +126,11 @@ SELECT
properties
FROM events
WHERE
- site_id = ${site}
- AND session_id = '${sessionId}'
+ site_id = {siteId:Int32}
+ AND session_id = {sessionId:String}
ORDER BY timestamp ASC
-LIMIT ${limit}
-OFFSET ${offset}
+LIMIT {limit:Int32}
+OFFSET {offset:Int32}
`;
// Execute queries in parallel
@@ -139,14 +139,28 @@ OFFSET ${offset}
clickhouse.query({
query: sessionQuery,
format: "JSONEachRow",
+ query_params: {
+ siteId: Number(site),
+ sessionId,
+ },
}),
clickhouse.query({
query: countQuery,
format: "JSONEachRow",
+ query_params: {
+ siteId: Number(site),
+ sessionId,
+ },
}),
clickhouse.query({
query: pageviewsQuery,
format: "JSONEachRow",
+ query_params: {
+ siteId: Number(site),
+ sessionId,
+ limit,
+ offset,
+ },
}),
]);
diff --git a/server/src/api/analytics/getSessions.ts b/server/src/api/analytics/getSessions.ts
index e3514b29d..4e9ca207d 100644
--- a/server/src/api/analytics/getSessions.ts
+++ b/server/src/api/analytics/getSessions.ts
@@ -83,8 +83,8 @@ export async function getSessions(
countIf(type = 'custom_event') AS events
FROM events
WHERE
- site_id = ${site}
- ${userId ? ` AND user_id = '${userId}'` : ""}
+ site_id = {siteId:Int32}
+ ${userId ? ` AND user_id = {userId:String}` : ""}
${timeStatement}
GROUP BY
session_id,
@@ -94,13 +94,19 @@ export async function getSessions(
FROM AggregatedSessions
WHERE 1 = 1 ${filterStatement}
ORDER BY session_end DESC
- LIMIT 100 OFFSET ${(page - 1) * 100}
+ LIMIT {limit:Int32} OFFSET {offset:Int32}
`;
try {
const result = await clickhouse.query({
query,
format: "JSONEachRow",
+ query_params: {
+ siteId: Number(site),
+ userId,
+ limit: 100,
+ offset: (page - 1) * 100,
+ },
});
const data = await processResults<GetSessionsResponse[number]>(result);
diff --git a/server/src/api/analytics/getSingleCol.ts b/server/src/api/analytics/getSingleCol.ts
index 1f29f1b81..0327e4797 100644
--- a/server/src/api/analytics/getSingleCol.ts
+++ b/server/src/api/analytics/getSingleCol.ts
@@ -62,7 +62,7 @@ const getQuery = (request: FastifyRequest<GenericRequest>) => {
${percentageStatement}
FROM events
WHERE
- site_id = ${site}
+ site_id = {siteId:Int32}
AND event_name IS NOT NULL
AND event_name <> ''
${filterStatement}
@@ -88,7 +88,7 @@ const getQuery = (request: FastifyRequest<GenericRequest>) => {
SELECT *
FROM events
WHERE
- site_id = ${site}
+ site_id = {siteId:Int32}
AND type = 'pageview'
${filterStatement}
${timeStatement}
@@ -158,7 +158,7 @@ const getQuery = (request: FastifyRequest<GenericRequest>) => {
leadInFrame(timestamp) OVER (PARTITION BY session_id ORDER BY timestamp ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) as next_timestamp
FROM events
WHERE
- site_id = ${site}
+ site_id = {siteId:Int32}
AND type = 'pageview'
${filterStatement}
${timeStatement}
@@ -202,7 +202,7 @@ const getQuery = (request: FastifyRequest<GenericRequest>) => {
COUNT() as pageviews
FROM events
WHERE
- site_id = ${site}
+ site_id = {siteId:Int32}
AND ${geSqlParam(parameter)} IS NOT NULL
AND ${geSqlParam(parameter)} <> ''
${filterStatement}
@@ -240,6 +240,9 @@ export async function getSingleCol(
const result = await clickhouse.query({
query,
format: "JSONEachRow",
+ query_params: {
+ siteId: Number(site),
+ },
});
const data = await processResults<GetSingleColResponse[number]>(result);
diff --git a/server/src/api/analytics/getUserSessionCount.ts b/server/src/api/analytics/getUserSessionCount.ts
index ffcc45484..90ed6f655 100644
--- a/server/src/api/analytics/getUserSessionCount.ts
+++ b/server/src/api/analytics/getUserSessionCount.ts
@@ -40,8 +40,8 @@ export async function getUserSessionCount(
count() as sessions
FROM sessions
WHERE
- site_id = ${site}
- AND user_id = '${userId}'
+ site_id = {siteId:Int32}
+ AND user_id = {userId:String}
GROUP BY date
ORDER BY date ASC
`;
@@ -50,6 +50,10 @@ export async function getUserSessionCount(
const result = await clickhouse.query({
query,
format: "JSONEachRow",
+ query_params: {
+ siteId: Number(site),
+ userId,
+ },
});
const data = await processResults<GetUserSessionCountResponse[number]>(
diff --git a/server/src/api/analytics/getUserSessions.ts b/server/src/api/analytics/getUserSessions.ts
index e74a3495a..5b1fdc4d0 100644
--- a/server/src/api/analytics/getUserSessions.ts
+++ b/server/src/api/analytics/getUserSessions.ts
@@ -82,8 +82,8 @@ SELECT
region
FROM events
WHERE
- site_id = ${site}
- AND user_id = '${userId}'
+ site_id = {siteId:Int32}
+ AND user_id = {userId:String}
${filterStatement}
${getTimeStatement({
date: { startDate, endDate, timezone },
@@ -95,6 +95,10 @@ ORDER BY timestamp ASC
const result = await clickhouse.query({
query,
format: "JSONEachRow",
+ query_params: {
+ siteId: Number(site),
+ userId,
+ },
});
const pageviews = await processResults<Pageview>(result);
diff --git a/server/src/api/analytics/getUsers.ts b/server/src/api/analytics/getUsers.ts
index 6bbe65c58..0328a1777 100644
--- a/server/src/api/analytics/getUsers.ts
+++ b/server/src/api/analytics/getUsers.ts
@@ -102,7 +102,7 @@ WITH AggregatedUsers AS (
min(timestamp) AS first_seen
FROM events
WHERE
- site_id = ${site}
+ site_id = {siteId:Int32}
${timeStatement}
GROUP BY
user_id
@@ -110,8 +110,8 @@ WITH AggregatedUsers AS (
SELECT *
FROM AggregatedUsers
WHERE 1 = 1 ${filterStatement}
-ORDER BY ${actualSortBy} ${actualSortOrder}
-LIMIT ${pageSizeNum} OFFSET ${offset}
+ORDER BY {sortBy:String} ${actualSortOrder}
+LIMIT {limit:Int32} OFFSET {offset:Int32}
`;
// Query to get total count
@@ -120,7 +120,7 @@ SELECT
count(DISTINCT user_id) AS total_count
FROM events
WHERE
- site_id = ${site}
+ site_id = {siteId:Int32}
${filterStatement}
${getTimeStatement({
date: { startDate, endDate, timezone },
@@ -133,10 +133,20 @@ WHERE
clickhouse.query({
query,
format: "JSONEachRow",
+ query_params: {
+ siteId: Number(site),
+ limit: pageSizeNum,
+ offset,
+ sortBy: actualSortBy,
+ sortOrder: actualSortOrder,
+ },
}),
clickhouse.query({
query: countQuery,
format: "JSONEachRow",
+ query_params: {
+ siteId: Number(site),
+ },
}),
]);
diff --git a/server/src/api/analytics/sql-sanitziation.ts b/server/src/api/analytics/sql-sanitziation.ts
new file mode 100644
index 000000000..e69de29bb
diff --git a/server/src/api/sites/getSiteHasData.ts b/server/src/api/sites/getSiteHasData.ts
index 452ffd8ab..23f630631 100644
--- a/server/src/api/sites/getSiteHasData.ts
+++ b/server/src/api/sites/getSiteHasData.ts
@@ -11,8 +11,11 @@ export async function getSiteHasData(
// Check if site has data using original method
const pageviewsData: { count: number }[] = await clickhouse
.query({
- query: `SELECT count(*) as count FROM events WHERE site_id = ${site}`,
+ query: `SELECT count(*) as count FROM events WHERE site_id = {siteId:Int32}`,
format: "JSONEachRow",
+ query_params: {
+ siteId: Number(site),
+ },
})
.then((res) => res.json());