Skip to content

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

update pv queue

Bill Yange54284d902e9
diff --git a/server/src/index.ts b/server/src/index.ts
index 447b93aa5..7f2884fc5 100644
--- a/server/src/index.ts
+++ b/server/src/index.ts
@@ -89,7 +89,7 @@ server.addHook("onRequest", async (request, reply) => {
if (
url?.startsWith("/health") ||
url?.startsWith("/track/pageview") ||
- url?.startsWith("/analytics") ||
+ url?.startsWith("/script") ||
url?.startsWith("/auth") ||
url?.startsWith("/api/auth")
) {
diff --git a/server/src/tracker/pageviewQueue.ts b/server/src/tracker/pageviewQueue.ts
index ab307c460..b5174b815 100644
--- a/server/src/tracker/pageviewQueue.ts
+++ b/server/src/tracker/pageviewQueue.ts
@@ -54,26 +54,35 @@ class PageviewQueue {
}
// Process each pageview with its geo data
- const processedPageviews = batch.map((pv) => ({
- site_id: pv.site_id,
- 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 || "",
- browser_version: pv.ua.browser.major || "",
- operating_system: pv.ua.os.name || "",
- operating_system_version: pv.ua.os.version || "",
- 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 || "",
- }));
+ const processedPageviews = batch.map((pv) => {
+ const countryCode = geoData?.[pv.ipAddress]?.data?.countryIso || "";
+ const regionCode =
+ geoData?.[pv.ipAddress]?.data?.subdivisions?.[0]?.isoCode || "";
+
+ return {
+ site_id: pv.site_id,
+ 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 || "",
+ browser_version: pv.ua.browser.major || "",
+ operating_system: pv.ua.os.name || "",
+ operating_system_version: pv.ua.os.version || "",
+ language: pv.language || "",
+ screen_width: pv.screenWidth || 0,
+ screen_height: pv.screenHeight || 0,
+ device_type: getDeviceType(pv.screenWidth, pv.screenHeight, pv.ua),
+ country: countryCode,
+ iso_3166_2: countryCode + "-" + regionCode,
+ };
+ });
console.info("bulk insert: ", processedPageviews.length);
// Bulk insert into database