🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
more accurate device types
Bill Yang0993f6bd181d
diff --git a/server/src/actions/pageviewQueue.ts b/server/src/actions/pageviewQueue.tsindex 2651e3847..3d4bbd2e6 100644--- a/server/src/actions/pageviewQueue.ts+++ b/server/src/actions/pageviewQueue.ts@@ -65,11 +65,7 @@ class PageviewQueue {language: pv.language || "",screen_width: pv.screenWidth || 0,screen_height: pv.screenHeight || 0,- device_type: getDeviceType(- pv.screenWidth,- pv.screenHeight,- pv.ua.os.name- ),+ device_type: getDeviceType(pv.ua),country: geoData[pv.ipAddress]?.data?.countryIso || "",// countryIso: geoData[pv.ip]?.data?.countryIso || null,}));diff --git a/server/src/actions/trackPageView.ts b/server/src/actions/trackPageView.tsindex 2cb876b28..2d63ff74e 100644--- a/server/src/actions/trackPageView.ts+++ b/server/src/actions/trackPageView.ts@@ -83,11 +83,7 @@ const updateSession = async (pageviews: 1,entry_page: pageview.pathname || "",// exit_page: pageview.pathname,- device_type: getDeviceType(- pageview.screenWidth,- pageview.screenHeight,- pageview.ua.os.name- ),+ device_type: getDeviceType(pageview.ua),screen_width: pageview.screenWidth || 0,screen_height: pageview.screenHeight || 0,browser: pageview.ua.browser.name || "",@@ -117,8 +113,6 @@ export async function trackPageView(userId: userId,sessionId: existingSession?.session_id || crypto.randomUUID(),};- console.info(payload.ua.device);- console.info(payload.ua.os);pageviewQueue.add(payload);// insertPageview(payload);diff --git a/server/src/utils.ts b/server/src/utils.tsindex afbc93099..218b83c92 100644--- a/server/src/utils.ts+++ b/server/src/utils.ts@@ -102,19 +102,33 @@ export const otherOS = new Set(["DragonFly",]);-export function getDeviceType(- screenWidth: number,- screenHeight: number,- os = ""-): string {- if (desktopOS.has(os)) {+export function getDeviceType(ua: UAParser.IResult): string {+ if (ua.device) {+ if (ua.device.type === "mobile") {+ return "Mobile";+ } else if (ua.device.type === "tablet") {+ return "Tablet";+ } else if (ua.device.type === "console") {+ return "Console";+ } else if (ua.device.type === "smarttv") {+ return "TV";+ } else if (ua.device.type === "wearable") {+ return "Wearable";+ } else if (ua.device.type === "embedded") {+ return "Embedded";+ } else if (ua.device.type === "xr") {+ return "XR";+ }+ }++ if (ua.os.name && desktopOS.has(ua.os.name)) {return "Desktop";- } else if (mobileOS.has(os)) {+ } else if (ua.os.name && mobileOS.has(ua.os.name)) {return "Mobile";- } else if (tvOS.has(os)) {+ } else if (ua.os.name && tvOS.has(ua.os.name)) {return "TV";- } else if (gamingOS.has(os)) {- return "Gaming";+ } else if (ua.os.name && gamingOS.has(ua.os.name)) {+ return "Console";} else {return "Other";}