Skip to content

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

add better error handling

Bill Yange065c261868c
diff --git a/client/src/app/components/Header/Header.tsx b/client/src/app/components/Header/Header.tsx
index 1b2623206..e6b375a70 100644
--- a/client/src/app/components/Header/Header.tsx
+++ b/client/src/app/components/Header/Header.tsx
@@ -53,6 +53,10 @@ export function Header() {
<div className="flex items-center justify-between py-2">
<div className="flex gap-3">
<div className="flex items-center gap-2 text-xl font-bold">
+ <img
+ className="w-7 mr-1"
+ src={`https://www.google.com/s2/favicons?domain=${`tomato.gg`}&sz=64`}
+ />
<div>Tomato.gg</div>
</div>
<div className="flex items-center gap-1 text-base text-neutral-600 dark:text-neutral-400">
diff --git a/server/public/analytics.js b/server/public/analytics.js
index 16470587d..92bfd1dc1 100644
--- a/server/public/analytics.js
+++ b/server/public/analytics.js
@@ -58,13 +58,11 @@
const originalReplaceState = history.replaceState;
history.pushState = function (...args) {
- console.info("pushState");
originalPushState.apply(this, args);
debouncedTrackPageview();
};
history.replaceState = function (...args) {
- console.info("replaceState");
originalReplaceState.apply(this, args);
debouncedTrackPageview();
};
diff --git a/server/src/actions/pageviewQueue.ts b/server/src/actions/pageviewQueue.ts
index c283c83fd..f815c9719 100644
--- a/server/src/actions/pageviewQueue.ts
+++ b/server/src/actions/pageviewQueue.ts
@@ -31,46 +31,50 @@ class PageviewQueue {
if (this.processing || this.queue.length === 0) return;
this.processing = true;
- try {
- // Get batch of pageviews
- const batch = this.queue.splice(0, this.batchSize);
- const ips = [...new Set(batch.map((pv) => pv.ipAddress))];
+ // Get batch of pageviews
+ const batch = this.queue.splice(0, this.batchSize);
+ const ips = [...new Set(batch.map((pv) => pv.ipAddress))];
+
+ let geoData: any;
+ try {
// Get geo data for all IPs in batch
const geoResponse = await fetch("https://tracking.tomato.gg/geoip/bulk", {
method: "POST",
+
headers: {
"Content-Type": "application/json",
// "Accept-Encoding": "gzip",
},
body: JSON.stringify({ ips }),
});
+ geoData = await geoResponse.json();
+ } catch (error) {
+ console.error("Error getting geo data:", error);
+ }
- const geoData: any = await geoResponse.json();
-
- // Process each pageview with its geo data
- const processedPageviews = batch.map((pv) => ({
- timestamp: DateTime.fromISO(pv.timestamp).toFormat(
- "yyyy-MM-dd HH:mm:ss"
- ),
- session_id: pv.sessionId,
- user_id: pv.userId,
- hostname: pv.hostname || "",
- pathname: pv.pathname || "",
- querystring: pv.querystring || "",
- page_title: pv.page_title || "",
- referrer: pv.referrer || "",
- browser: pv.ua.browser.name || "",
- operating_system: pv.ua.os.name || "",
- language: pv.language || "",
- screen_width: pv.screenWidth || 0,
- screen_height: pv.screenHeight || 0,
- device_type: getDeviceType(pv.screenWidth, pv.screenHeight, pv.ua),
- country: geoData[pv.ipAddress]?.data?.countryIso || "",
- }));
+ // Process each pageview with its geo data
+ const processedPageviews = batch.map((pv) => ({
+ timestamp: DateTime.fromISO(pv.timestamp).toFormat("yyyy-MM-dd HH:mm:ss"),
+ session_id: pv.sessionId,
+ user_id: pv.userId,
+ hostname: pv.hostname || "",
+ pathname: pv.pathname || "",
+ querystring: pv.querystring || "",
+ page_title: pv.page_title || "",
+ referrer: pv.referrer || "",
+ browser: pv.ua.browser.name || "",
+ operating_system: pv.ua.os.name || "",
+ language: pv.language || "",
+ screen_width: pv.screenWidth || 0,
+ screen_height: pv.screenHeight || 0,
+ device_type: getDeviceType(pv.screenWidth, pv.screenHeight, pv.ua),
+ country: geoData?.[pv.ipAddress]?.data?.countryIso || "",
+ }));
- console.info("bulk insert: ", processedPageviews.length);
- // Bulk insert into database
+ console.info("bulk insert: ", processedPageviews.length);
+ // Bulk insert into database
+ try {
await clickhouse.insert({
table: "pageviews",
values: processedPageviews,
diff --git a/server/src/db/postgres/session-cleanup.ts b/server/src/db/postgres/session-cleanup.ts
index f439cb25b..292b985c5 100644
--- a/server/src/db/postgres/session-cleanup.ts
+++ b/server/src/db/postgres/session-cleanup.ts
@@ -39,7 +39,7 @@ function convertPostgresToClickhouse(postgresTimestamp: string): string {
export async function cleanupOldSessions() {
const deletedSessions = await sql<Session[]>`
DELETE FROM active_sessions
- WHERE last_activity < NOW() - INTERVAL '10 minute'
+ WHERE last_activity < NOW() - INTERVAL '30 minute'
RETURNING *
`;