Skip to content

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

fix(tracking): refresh browser, device and channel classification (#1278)

Goldflag90e4f85756fe
diff --git a/client/public/browsers/Debian.svg b/client/public/browsers/Debian.svg
new file mode 100644
index 000000000..96dfb32e2
--- /dev/null
+++ b/client/public/browsers/Debian.svg
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 10.0, SVG Export Plug-In . SVG Version: 3.0.0 Build 77) -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" [
+ <!ENTITY ns_flows "http://ns.adobe.com/Flows/1.0/">
+ <!ENTITY ns_extend "http://ns.adobe.com/Extensibility/1.0/">
+ <!ENTITY ns_ai "http://ns.adobe.com/AdobeIllustrator/10.0/">
+ <!ENTITY ns_graphs "http://ns.adobe.com/Graphs/1.0/">
+ <!ENTITY ns_vars "http://ns.adobe.com/Variables/1.0/">
+ <!ENTITY ns_imrep "http://ns.adobe.com/ImageReplacement/1.0/">
+ <!ENTITY ns_sfw "http://ns.adobe.com/SaveForWeb/1.0/">
+ <!ENTITY ns_custom "http://ns.adobe.com/GenericCustomNamespace/1.0/">
+ <!ENTITY ns_adobe_xpath "http://ns.adobe.com/XPath/1.0/">
+ <!ENTITY ns_svg "http://www.w3.org/2000/svg">
+ <!ENTITY ns_xlink "http://www.w3.org/1999/xlink">
+]>
+<svg
+ xmlns:x="&ns_extend;" xmlns:i="&ns_ai;" xmlns:graph="&ns_graphs;" i:viewOrigin="262 450" i:rulerOrigin="0 0" i:pageBounds="0 792 612 0"
+ xmlns="&ns_svg;" xmlns:xlink="&ns_xlink;" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
+ width="87.041" height="108.445" viewBox="0 0 87.041 108.445" overflow="visible" enable-background="new 0 0 87.041 108.445"
+ xml:space="preserve">
+ <metadata>
+ <variableSets xmlns="&ns_vars;">
+ <variableSet varSetName="binding1" locked="none">
+ <variables></variables>
+ <v:sampleDataSets xmlns="&ns_custom;" xmlns:v="&ns_vars;"></v:sampleDataSets>
+ </variableSet>
+ </variableSets>
+ <sfw xmlns="&ns_sfw;">
+ <slices></slices>
+ <sliceSourceBounds y="341.555" x="262" width="87.041" height="108.445" bottomLeftOrigin="true"></sliceSourceBounds>
+ </sfw>
+ </metadata>
+ <g id="Layer_1" i:layer="yes" i:dimmedPercent="50" i:rgbTrio="#4F008000FFFF">
+ <g>
+ <path i:knockout="Off" fill="#A80030" d="M51.986,57.297c-1.797,0.025,0.34,0.926,2.686,1.287
+ c0.648-0.506,1.236-1.018,1.76-1.516C54.971,57.426,53.484,57.434,51.986,57.297"/>
+ <path i:knockout="Off" fill="#A80030" d="M61.631,54.893c1.07-1.477,1.85-3.094,2.125-4.766c-0.24,1.192-0.887,2.221-1.496,3.307
+ c-3.359,2.115-0.316-1.256-0.002-2.537C58.646,55.443,61.762,53.623,61.631,54.893"/>
+ <path i:knockout="Off" fill="#A80030" d="M65.191,45.629c0.217-3.236-0.637-2.213-0.924-0.978
+ C64.602,44.825,64.867,46.932,65.191,45.629"/>
+ <path i:knockout="Off" fill="#A80030" d="M45.172,1.399c0.959,0.172,2.072,0.304,1.916,0.533
+ C48.137,1.702,48.375,1.49,45.172,1.399"/>
+ <path i:knockout="Off" fill="#A80030" d="M47.088,1.932l-0.678,0.14l0.631-0.056L47.088,1.932"/>
+ <path i:knockout="Off" fill="#A80030" d="M76.992,46.856c0.107,2.906-0.85,4.316-1.713,6.812l-1.553,0.776
+ c-1.271,2.468,0.123,1.567-0.787,3.53c-1.984,1.764-6.021,5.52-7.313,5.863c-0.943-0.021,0.639-1.113,0.846-1.541
+ c-2.656,1.824-2.131,2.738-6.193,3.846l-0.119-0.264c-10.018,4.713-23.934-4.627-23.751-17.371
+ c-0.107,0.809-0.304,0.607-0.526,0.934c-0.517-6.557,3.028-13.143,9.007-15.832c5.848-2.895,12.704-1.707,16.893,2.197
+ c-2.301-3.014-6.881-6.209-12.309-5.91c-5.317,0.084-10.291,3.463-11.951,7.131c-2.724,1.715-3.04,6.611-4.227,7.507
+ C31.699,56.271,36.3,61.342,44.083,67.307c1.225,0.826,0.345,0.951,0.511,1.58c-2.586-1.211-4.954-3.039-6.901-5.277
+ c1.033,1.512,2.148,2.982,3.589,4.137c-2.438-0.826-5.695-5.908-6.646-6.115c4.203,7.525,17.052,13.197,23.78,10.383
+ c-3.113,0.115-7.068,0.064-10.566-1.229c-1.469-0.756-3.467-2.322-3.11-2.615c9.182,3.43,18.667,2.598,26.612-3.771
+ c2.021-1.574,4.229-4.252,4.867-4.289c-0.961,1.445,0.164,0.695-0.574,1.971c2.014-3.248-0.875-1.322,2.082-5.609l1.092,1.504
+ c-0.406-2.696,3.348-5.97,2.967-10.234c0.861-1.304,0.961,1.403,0.047,4.403c1.268-3.328,0.334-3.863,0.66-6.609
+ c0.352,0.923,0.814,1.904,1.051,2.878c-0.826-3.216,0.848-5.416,1.262-7.285c-0.408-0.181-1.275,1.422-1.473-2.377
+ c0.029-1.65,0.459-0.865,0.625-1.271c-0.324-0.186-1.174-1.451-1.691-3.877c0.375-0.57,1.002,1.478,1.512,1.562
+ c-0.328-1.929-0.893-3.4-0.916-4.88c-1.49-3.114-0.527,0.415-1.736-1.337c-1.586-4.947,1.316-1.148,1.512-3.396
+ c2.404,3.483,3.775,8.881,4.404,11.117c-0.48-2.726-1.256-5.367-2.203-7.922c0.73,0.307-1.176-5.609,0.949-1.691
+ c-2.27-8.352-9.715-16.156-16.564-19.818c0.838,0.767,1.896,1.73,1.516,1.881c-3.406-2.028-2.807-2.186-3.295-3.043
+ c-2.775-1.129-2.957,0.091-4.795,0.002c-5.23-2.774-6.238-2.479-11.051-4.217l0.219,1.023c-3.465-1.154-4.037,0.438-7.782,0.004
+ c-0.228-0.178,1.2-0.644,2.375-0.815c-3.35,0.442-3.193-0.66-6.471,0.122c0.808-0.567,1.662-0.942,2.524-1.424
+ c-2.732,0.166-6.522,1.59-5.352,0.295c-4.456,1.988-12.37,4.779-16.811,8.943l-0.14-0.933c-2.035,2.443-8.874,7.296-9.419,10.46
+ l-0.544,0.127c-1.059,1.793-1.744,3.825-2.584,5.67c-1.385,2.36-2.03,0.908-1.833,1.278c-2.724,5.523-4.077,10.164-5.246,13.97
+ c0.833,1.245,0.02,7.495,0.335,12.497c-1.368,24.704,17.338,48.69,37.785,54.228c2.997,1.072,7.454,1.031,11.245,1.141
+ c-4.473-1.279-5.051-0.678-9.408-2.197c-3.143-1.48-3.832-3.17-6.058-5.102l0.881,1.557c-4.366-1.545-2.539-1.912-6.091-3.037
+ l0.941-1.229c-1.415-0.107-3.748-2.385-4.386-3.646l-1.548,0.061c-1.86-2.295-2.851-3.949-2.779-5.23l-0.5,0.891
+ c-0.567-0.973-6.843-8.607-3.587-6.83c-0.605-0.553-1.409-0.9-2.281-2.484l0.663-0.758c-1.567-2.016-2.884-4.6-2.784-5.461
+ c0.836,1.129,1.416,1.34,1.99,1.533c-3.957-9.818-4.179-0.541-7.176-9.994l0.634-0.051c-0.486-0.732-0.781-1.527-1.172-2.307
+ l0.276-2.75C4.667,58.121,6.719,47.409,7.13,41.534c0.285-2.389,2.378-4.932,3.97-8.92l-0.97-0.167
+ c1.854-3.234,10.586-12.988,14.63-12.486c1.959-2.461-0.389-0.009-0.772-0.629c4.303-4.453,5.656-3.146,8.56-3.947
+ c3.132-1.859-2.688,0.725-1.203-0.709c5.414-1.383,3.837-3.144,10.9-3.846c0.745,0.424-1.729,0.655-2.35,1.205
+ c4.511-2.207,14.275-1.705,20.617,1.225c7.359,3.439,15.627,13.605,15.953,23.17l0.371,0.1
+ c-0.188,3.802,0.582,8.199-0.752,12.238L76.992,46.856"/>
+ <path i:knockout="Off" fill="#A80030" d="M32.372,59.764l-0.252,1.26c1.181,1.604,2.118,3.342,3.626,4.596
+ C34.661,63.502,33.855,62.627,32.372,59.764"/>
+ <path i:knockout="Off" fill="#A80030" d="M35.164,59.654c-0.625-0.691-0.995-1.523-1.409-2.352
+ c0.396,1.457,1.207,2.709,1.962,3.982L35.164,59.654"/>
+ <path i:knockout="Off" fill="#A80030" d="M84.568,48.916l-0.264,0.662c-0.484,3.438-1.529,6.84-3.131,9.994
+ C82.943,56.244,84.088,52.604,84.568,48.916"/>
+ <path i:knockout="Off" fill="#A80030" d="M45.527,0.537C46.742,0.092,48.514,0.293,49.803,0c-1.68,0.141-3.352,0.225-5.003,0.438
+ L45.527,0.537"/>
+ <path i:knockout="Off" fill="#A80030" d="M2.872,23.219c0.28,2.592-1.95,3.598,0.494,1.889
+ C4.676,22.157,2.854,24.293,2.872,23.219"/>
+ <path i:knockout="Off" fill="#A80030" d="M0,35.215c0.563-1.728,0.665-2.766,0.88-3.766C-0.676,33.438,0.164,33.862,0,35.215"/>
+ </g>
+ </g>
+</svg>
diff --git a/client/public/browsers/Vivaldi.svg b/client/public/browsers/Vivaldi.svg
new file mode 100644
index 000000000..c6fc6a01e
--- /dev/null
+++ b/client/public/browsers/Vivaldi.svg
@@ -0,0 +1 @@
+<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path fill="#EF3939" d="M12 0C6.75 0 3.817 0 1.912 1.904.007 3.81 0 6.75 0 12s0 8.175 1.912 10.08C3.825 23.985 6.75 24 12 24c5.25 0 8.183 0 10.088-1.904C23.993 20.19 24 17.25 24 12s0-8.175-1.912-10.08C20.175.015 17.25 0 12 0zm-.168 3a9 9 0 016.49 2.648 9 9 0 010 12.704A9 9 0 1111.832 3zM7.568 7.496a1.433 1.433 0 00-.142.004A1.5 1.5 0 006.21 9.75l1.701 3c.93 1.582 1.839 3.202 2.791 4.822a1.417 1.417 0 001.41.75 1.5 1.5 0 001.223-.81l4.447-7.762A1.56 1.56 0 0018 8.768a1.5 1.5 0 10-2.828.914 2.513 2.513 0 01.256 1.119v.246a2.393 2.393 0 01-2.52 2.13 2.348 2.348 0 01-1.965-1.214c-.307-.51-.6-1.035-.9-1.553-.42-.72-.826-1.41-1.246-2.16a1.433 1.433 0 00-1.229-.754Z"/></svg>
\ No newline at end of file
diff --git a/client/src/app/[site]/components/shared/icons/Browser.tsx b/client/src/app/[site]/components/shared/icons/Browser.tsx
index bcb56f8df..371fa766d 100644
--- a/client/src/app/[site]/components/shared/icons/Browser.tsx
+++ b/client/src/app/[site]/components/shared/icons/Browser.tsx
@@ -1,13 +1,17 @@
import { Compass } from "lucide-react";
import Image from "next/image";
-const BROWSER_TO_LOGO: Record<string, string> = {
+export const BROWSER_TO_LOGO: Record<string, string> = {
Chrome: "Chrome.svg",
"Mobile Chrome": "Chrome.svg",
"Chrome WebView": "Chrome.svg",
+ "Chrome Mobile": "Chrome.svg",
+ "Chrome Mobile iOS": "Chrome.svg",
"Chrome Headless": "Chromium.svg",
+ "Headless Chrome": "Chromium.svg",
Chromium: "Chromium.svg",
GSA: "Chromium.svg",
+ "Google Search App": "Chromium.svg",
Firefox: "Firefox.svg",
"Firefox Focus": "Firefox.svg",
"Mobile Firefox": "Firefox.svg",
@@ -15,16 +19,21 @@ const BROWSER_TO_LOGO: Record<string, string> = {
Safari: "Safari.svg",
"Mobile Safari": "Safari.svg",
Edge: "Edge.svg",
+ "Edge WebView": "Edge.svg",
+ "Edge WebView2": "Edge.svg",
+ "Microsoft Edge": "Edge.svg",
Opera: "Opera.svg",
"Opera Touch": "Opera.svg",
"Opera GX": "OperaGX.svg",
"Samsung Internet": "SamsungInternet.svg",
Yandex: "Yandex.svg",
QQBrowser: "QQ.webp",
+ "QQ Browser": "QQ.webp",
Whale: "Whale.svg",
Baidu: "Baidu.svg",
WebKit: "WebKit.svg",
DuckDuckGo: "DuckDuckGo.svg",
+ "DuckDuckGo Privacy Browser": "DuckDuckGo.svg",
Facebook: "Facebook.svg",
"Sogou Explorer": "Sogou.png",
"Avast Secure Browser": "Avast.png",
@@ -49,6 +58,7 @@ const BROWSER_TO_LOGO: Record<string, string> = {
"Coc Coc": "CocCoc.svg",
"Huawei Browser": "Huawei.svg",
IE: "IE.svg",
+ IEMobile: "IE.svg",
Quark: "Quark.svg",
"MIUI Browser": "Miui.png",
Brave: "Brave.svg",
@@ -61,6 +71,7 @@ const BROWSER_TO_LOGO: Record<string, string> = {
Snapchat: "Snapchat.svg",
TikTok: "TikTok.svg",
Twitter: "Twitter.svg",
+ Vivaldi: "Vivaldi.svg",
Waterfox: "Waterfox.svg",
};
diff --git a/client/src/app/[site]/components/shared/icons/Device.tsx b/client/src/app/[site]/components/shared/icons/Device.tsx
index 487313f5b..59d041d35 100644
--- a/client/src/app/[site]/components/shared/icons/Device.tsx
+++ b/client/src/app/[site]/components/shared/icons/Device.tsx
@@ -1,11 +1,18 @@
-import { Laptop, Smartphone } from "lucide-react";
+import { Gamepad2, Glasses, Laptop, Smartphone, Tablet, Tv, Watch } from "lucide-react";
-export function DeviceIcon({ deviceType, size = 16 }: { deviceType?: string; size?: number }) {
+export function getDeviceIconComponent(deviceType?: string) {
const type = deviceType?.toLowerCase() || "";
- if (type.includes("mobile") || type.includes("tablet")) {
- return <Smartphone width={size} height={size} />;
- }
+ if (type.includes("mobile")) return Smartphone;
+ if (type.includes("tablet")) return Tablet;
+ if (type === "tv") return Tv;
+ if (type === "console") return Gamepad2;
+ if (type === "wearable") return Watch;
+ if (type === "xr") return Glasses;
+ return Laptop;
+}
- return <Laptop width={size} height={size} />;
-}
\ No newline at end of file
+export function DeviceIcon({ deviceType, size = 16 }: { deviceType?: string; size?: number }) {
+ const Icon = getDeviceIconComponent(deviceType);
+ return <Icon width={size} height={size} />;
+}
diff --git a/client/src/app/[site]/components/shared/icons/OperatingSystem.tsx b/client/src/app/[site]/components/shared/icons/OperatingSystem.tsx
index d5012188a..4037956ea 100644
--- a/client/src/app/[site]/components/shared/icons/OperatingSystem.tsx
+++ b/client/src/app/[site]/components/shared/icons/OperatingSystem.tsx
@@ -1,21 +1,37 @@
import { Compass } from "lucide-react";
import Image from "next/image";
-const OS_TO_LOGO: Record<string, string> = {
+export const OS_TO_LOGO: Record<string, string> = {
Windows: "Windows.svg",
"Windows Phone": "Windows.svg",
+ "Windows Mobile": "Windows.svg",
+ "Windows RT": "Windows.svg",
Android: "Android.svg",
android: "Android.svg",
+ "Android-x86": "Android.svg",
Linux: "Tux.svg",
+ Arch: "Tux.svg",
+ CentOS: "Tux.svg",
+ Gentoo: "Tux.svg",
+ Kubuntu: "Tux.svg",
+ Manjaro: "Tux.svg",
+ Mint: "Tux.svg",
+ openSUSE: "Tux.svg",
+ RedHat: "Tux.svg",
+ Slackware: "Tux.svg",
+ SUSE: "Tux.svg",
+ Xubuntu: "Tux.svg",
macOS: "macOS.svg",
iOS: "Apple.svg",
"Chrome OS": "Chrome.svg",
+ Chromecast: "Chrome.svg",
+ "Chromecast Android": "Chrome.svg",
"Chromecast Linux": "Chrome.svg",
"Chromecast Fuchsia": "Chrome.svg",
Ubuntu: "Ubuntu.svg",
HarmonyOS: "HarmonyOS.svg",
OpenHarmony: "OpenHarmony.png",
- PlayStation: "PlayStation.svg",
+ PlayStation: "Playstation.svg",
Tizen: "Tizen.png",
Symbian: "Symbian.svg",
Debian: "Debian.svg",
diff --git a/client/src/app/[site]/globe/3d/hooks/timelineLayer/timelineMarkerHelpers.ts b/client/src/app/[site]/globe/3d/hooks/timelineLayer/timelineMarkerHelpers.ts
index a8d410f54..694705fa8 100644
--- a/client/src/app/[site]/globe/3d/hooks/timelineLayer/timelineMarkerHelpers.ts
+++ b/client/src/app/[site]/globe/3d/hooks/timelineLayer/timelineMarkerHelpers.ts
@@ -2,8 +2,10 @@ import { createElement } from "react";
// @ts-ignore - React 19 has built-in types
import { renderToStaticMarkup } from "react-dom/server";
import * as CountryFlags from "country-flag-icons/react/3x2";
-import { Monitor, Smartphone } from "lucide-react";
import { getChannelIconComponent } from "../../../../../../components/Channel";
+import { BROWSER_TO_LOGO } from "../../../../components/shared/icons/Browser";
+import { getDeviceIconComponent } from "../../../../components/shared/icons/Device";
+import { OS_TO_LOGO } from "../../../../components/shared/icons/OperatingSystem";
// Render country flag to static SVG
export function renderCountryFlag(countryCode: string): string {
@@ -16,8 +18,7 @@ export function renderCountryFlag(countryCode: string): string {
// Render device icon based on device type
export function renderDeviceIcon(deviceType: string): string {
- const type = deviceType?.toLowerCase() || "";
- const Icon = type.includes("mobile") || type.includes("tablet") ? Smartphone : Monitor;
+ const Icon = getDeviceIconComponent(deviceType);
const iconElement = createElement(Icon, { size: 14, className: "inline-block" });
return renderToStaticMarkup(iconElement);
}
@@ -32,30 +33,10 @@ export function renderChannelIcon(channel: string): string {
// Get browser icon path
export function getBrowserIconPath(browser: string): string {
- const BROWSER_TO_LOGO: Record<string, string> = {
- Chrome: "Chrome.svg",
- "Mobile Chrome": "Chrome.svg",
- Firefox: "Firefox.svg",
- "Mobile Firefox": "Firefox.svg",
- Safari: "Safari.svg",
- "Mobile Safari": "Safari.svg",
- Edge: "Edge.svg",
- Opera: "Opera.svg",
- Brave: "Brave.svg",
- };
return BROWSER_TO_LOGO[browser] ? `/browsers/${BROWSER_TO_LOGO[browser]}` : "";
}
// Get OS icon path
export function getOSIconPath(os: string): string {
- const OS_TO_LOGO: Record<string, string> = {
- Windows: "Windows.svg",
- Android: "Android.svg",
- android: "Android.svg",
- Linux: "Tux.svg",
- macOS: "macOS.svg",
- iOS: "Apple.svg",
- "Chrome OS": "Chrome.svg",
- };
return OS_TO_LOGO[os] ? `/operating-systems/${OS_TO_LOGO[os]}` : "";
}
diff --git a/client/src/components/Channel.tsx b/client/src/components/Channel.tsx
index b7e601089..a091a0437 100644
--- a/client/src/components/Channel.tsx
+++ b/client/src/components/Channel.tsx
@@ -1,6 +1,9 @@
import {
+ Bell,
Bot,
+ Briefcase,
Calendar,
+ CornerDownRight,
DollarSign,
ExternalLink,
FileQuestion,
@@ -10,7 +13,11 @@ import {
HelpCircle,
Link,
Mail,
+ Megaphone,
+ MessageSquare,
Monitor,
+ Network,
+ Newspaper,
Search,
ShoppingCart,
Users,
@@ -24,6 +31,8 @@ export function getChannelIconComponent(channel: string) {
switch (channel) {
case "Direct":
return Link;
+ case "Internal":
+ return CornerDownRight;
case "Organic Search":
case "Paid Search":
return Search;
@@ -41,17 +50,33 @@ export function getChannelIconComponent(channel: string) {
case "Display":
return Monitor;
case "Organic Video":
+ case "Paid Video":
return Video;
case "Affiliate":
return Handshake;
case "Content":
return FileText;
case "Organic Shopping":
+ case "Paid Shopping":
return ShoppingCart;
case "Event":
return Calendar;
case "Audio":
+ case "Paid Audio":
return Headphones;
+ case "Influencer":
+ case "Paid Influencer":
+ return Megaphone;
+ case "Push":
+ return Bell;
+ case "SMS":
+ return MessageSquare;
+ case "News":
+ return Newspaper;
+ case "Productivity":
+ return Briefcase;
+ case "Cross-Network":
+ return Network;
case "AI":
case "Paid AI":
return Bot;
@@ -116,6 +141,21 @@ export const getDisplayName = (hostname: string): string => {
"claude.ai": "Claude",
"gemini.google.com": "Gemini",
"copilot.microsoft.com": "Copilot",
+ "copilot.cloud.microsoft": "Copilot",
+ "m365.cloud.microsoft": "Copilot",
+ "edgeservices.bing.com": "Copilot",
+ "aistudio.google.com": "Google AI Studio",
+ "notebooklm.google.com": "NotebookLM",
+ "duck.ai": "Duck.ai",
+ "kimi.com": "Kimi",
+ "doubao.com": "Doubao",
+ "manus.im": "Manus",
+ "threads.com": "Threads",
+ "www.threads.com": "Threads",
+ "threads.net": "Threads",
+ "www.threads.net": "Threads",
+ "bsky.app": "Bluesky",
+ "outlook.live.com": "Outlook",
"chat.deepseek.com": "DeepSeek",
"deepseek.com": "DeepSeek",
"chat.mistral.ai": "Mistral",
diff --git a/client/src/components/TooltipIcons/TooltipIcons.tsx b/client/src/components/TooltipIcons/TooltipIcons.tsx
index eb570d5be..8aedb0383 100644
--- a/client/src/components/TooltipIcons/TooltipIcons.tsx
+++ b/client/src/components/TooltipIcons/TooltipIcons.tsx
@@ -1,22 +1,11 @@
-import { Laptop, Smartphone } from "lucide-react";
import { Browser } from "../../app/[site]/components/shared/icons/Browser";
import { CountryFlag } from "../../app/[site]/components/shared/icons/CountryFlag";
+import { DeviceIcon } from "../../app/[site]/components/shared/icons/Device";
import { OperatingSystem } from "../../app/[site]/components/shared/icons/OperatingSystem";
import { getRegionName } from "../../lib/geo";
import { getCountryName } from "../../lib/utils";
import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip";
-// DeviceIcon component for displaying mobile/desktop icons
-function DeviceIcon({ deviceType, size = 16 }: { deviceType: string; size?: number }) {
- const type = deviceType.toLowerCase();
-
- if (type.includes("mobile") || type.includes("tablet")) {
- return <Smartphone width={size} height={size} />;
- }
-
- return <Laptop width={size} height={size} />;
-}
-
export function CountryFlagTooltipIcon({
country,
city,
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index a60e3ca98..fe4d7b440 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -471,8 +471,8 @@ importers:
specifier: 18.1.0
version: 18.1.0(@types/[email protected])
ua-parser-js:
- specifier: 2.0.3
- version: 2.0.3
+ specifier: 2.0.10
+ version: 2.0.10
web-vitals:
specifier: ^5.0.3
version: 5.1.0
@@ -3926,9 +3926,6 @@ packages:
resolution: {integrity: sha512-mUWlSxAmYLfwnRBmgYV86tgYmMIICX4kza8YnE/eIlywGe2XoOxlpVnXWwir92xRLjwyarqwpu2EJKD2pk0IUA==}
- '@types/[email protected]':
- resolution: {integrity: sha512-QGpRVpzSaUs30JBSGPjOg4Uveu384erbHBoT1zeONvyCfwQxIkUshLAOqN/k9EjGviPRmWTTe6aH2qySWKTVSw==}
-
resolution: {integrity: sha512-Dh8vAsV36ig5wa9OX4pXvMc9D3Veibfw2wix0CUwYODLD8nkj9UsLjASr49nPg+2eKzxhBV+v7L8pXvT4e639Q==}
@@ -6559,15 +6556,6 @@ packages:
resolution: {integrity: sha512-T294pDgew/Nec/uXRoAcEbh+HIisrlZ7MeTx02KcLLI4eE89dwmUGSFT6L5kK7YrSSwa1Ovfm7ILpehiYVIrWQ==}
engines: {node: '>=6.0.0'}
- resolution: {integrity: sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==}
- engines: {node: 4.x || >=6.0.0}
- peerDependencies:
- encoding: ^0.1.0
- peerDependenciesMeta:
- encoding:
- optional: true
-
resolution: {integrity: sha512-nmh3lCkYZ3grZvqcCH+fjmQ7X+H0OeZgP40OierEaAptX4XofMh5kwNbWh7lBduUzCcV/8kZ+NDLCwm2iorIlA==}
@@ -7626,9 +7614,6 @@ packages:
resolution: {integrity: sha512-exgYmnmL/sJpR3upZfXG5PoatXQii55xAiXGXzY+sROLZ/Y+SLcp9PgJNI9Vz37HpQ74WvDcLT8eqm+kV3FzrA==}
engines: {node: '>=16'}
- resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==}
-
resolution: {integrity: sha512-hdF5ZgjTqgAntKkklYw0R03MG2x/bSzTtkxmIRw/sTNV8YXsCJ1tfLAX23lhxhHJlEf3CRCOCGGWw3vI3GaSPw==}
engines: {node: '>=18'}
@@ -7697,8 +7682,8 @@ packages:
resolution: {integrity: sha512-RwKDW2p3iyWn4UbaxpP2+VxwqXh0jpvdxsYpZ5j/MLLiQOfbsV5shpgQiw93+KMYQPcteeMQ289MaAFzs3G9pw==}
- resolution: {integrity: sha512-LZyXZdNttONW8LjzEH3Z8+6TE7RfrEiJqDKyh0R11p/kxvrV2o9DrT2FGZO+KVNs3k+drcIQ6C3En6wLnzJGpw==}
+ resolution: {integrity: sha512-t+3Ktbq0Ies2vaSezfOaWiolH4OigQIO1dk+1xDpOydB1COVPocVYOrEV5rqZ0kFY9XYG1v9LutCyMgYBpABcw==}
hasBin: true
@@ -7943,9 +7928,6 @@ packages:
resolution: {integrity: sha512-5LAE43jAVLOhB/QqX4bwSiv0Hg1HBfMmOuwBSXHdvg4GMGu9Y0lIq7p4R/yySu6w74WmaR4GM4H9t2IwLW7hgw==}
- resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}
-
resolution: {integrity: sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==}
engines: {node: '>=12'}
@@ -7975,9 +7957,6 @@ packages:
resolution: {integrity: sha512-1to4zXBxmXHV3IiSSEInrreIlu02vUOvrhxJJH5vcxYTBDAx51cqZiKdyTxlecdKNSjj8EcxGBxNf6Vg+945gw==}
engines: {node: ^20.19.0 || ^22.12.0 || >=24.0.0}
- resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==}
-
resolution: {integrity: sha512-TbX3mj8n0odCBFVlY8AxkqcHASw3L60jIuF8jFP78az3C2YhmGvqbHBpAjTRH2/xqYunrJ9g1jSyjCjpoWzIAA==}
engines: {node: '>= 0.4'}
@@ -11663,11 +11642,6 @@ snapshots:
'@types/[email protected]': {}
- '@types/[email protected]':
- dependencies:
- '@types/node': 24.13.3
- form-data: 4.0.5
-
dependencies:
undici-types: 7.18.0
@@ -14488,10 +14462,6 @@ snapshots:
- dependencies:
- whatwg-url: 5.0.0
-
@@ -15771,8 +15741,6 @@ snapshots:
dependencies:
tldts: 7.4.12
-
dependencies:
punycode: 2.3.1
@@ -15860,15 +15828,11 @@ snapshots:
dependencies:
- '@types/node-fetch': 2.6.13
detect-europe-js: 0.1.2
is-standalone-pwa: 0.1.1
- node-fetch: 2.7.0
ua-is-frozen: 0.1.2
- transitivePeerDependencies:
- - encoding
dependencies:
@@ -16097,8 +16061,6 @@ snapshots:
-
@@ -16124,11 +16086,6 @@ snapshots:
transitivePeerDependencies:
- '@noble/hashes'
- dependencies:
- tr46: 0.0.3
- webidl-conversions: 3.0.1
-
dependencies:
is-bigint: 1.1.0
diff --git a/server/package.json b/server/package.json
index b2ef77990..2934e7c29 100644
--- a/server/package.json
+++ b/server/package.json
@@ -82,7 +82,7 @@
"safe-regex2": "^5.0.0",
"sqlstring": "2.3.3",
"stripe": "18.1.0",
- "ua-parser-js": "2.0.3",
+ "ua-parser-js": "2.0.10",
"web-vitals": "^5.0.3",
"zod": "^3.25.76"
},
diff --git a/server/src/services/tracker/const.ts b/server/src/services/tracker/const.ts
index 47faab4f0..c8889c6d9 100644
--- a/server/src/services/tracker/const.ts
+++ b/server/src/services/tracker/const.ts
@@ -25,7 +25,7 @@ const searchDomains = [
"qwant.com",
"search.",
"ecosia.org",
- "brave.com",
+ "search.brave.com",
"startpage.com",
"searchencrypt.com",
"searx.",
@@ -50,10 +50,12 @@ const searchDomains = [
"sogou.com",
"goo.ne.jp",
"rambler.ru",
+ "sm.cn",
+ "petalsearch.com",
// Other search engines
- "neeva.com",
"kagi.com",
+ "presearch.com",
];
const socialDomains = [
@@ -84,8 +86,6 @@ const socialDomains = [
// Other global social platforms
"snapchat.com",
"snap.com",
- "youtube.com",
- "youtu.be",
"discord.com",
"discord.gg",
"whatsapp.com",
@@ -97,19 +97,26 @@ const socialDomains = [
"tmblr.co",
"quora.com",
"threads.net",
+ "threads.com",
"mastodon.social",
"mastodon.",
+ "mstdn.",
+ "mas.to",
+ "fosstodon.org",
+ "hachyderm.io",
+ "infosec.exchange",
"slack.com",
"nextdoor.com",
"clubhouse.com",
- "twitch.tv",
"news.ycombinator.com",
"hn.algolia.com",
// Newer/emerging platforms
"bluesky.app",
"bsky.app",
- "post.news",
+ "farcaster.xyz",
+ "warpcast.com",
+ "lobste.rs",
"truth.social",
"truthsocial.com",
"gettr.com",
@@ -118,7 +125,6 @@ const socialDomains = [
"minds.com",
"diaspora.",
"lemmy.",
- "kbin.social",
"bereal.com",
"vsco.co",
"flickr.com",
@@ -140,6 +146,11 @@ const socialDomains = [
"qq.com",
"weibo.com",
"weibo.cn",
+ "xiaohongshu.com",
+ "xhslink.com",
+ "douyin.com",
+ "zhihu.com",
+ "tieba.baidu.com",
"line.me",
"kakaotalk.com",
"viber.com",
@@ -163,25 +174,20 @@ const videoDomains = [
"max.com",
"peacocktv.com",
"primevideo.com",
- "amazon.com/prime-video",
"paramountplus.com",
"discoveryplus.com",
"crunchyroll.com",
- "funimation.com",
"curiositystream.com",
"mubi.com",
"appletv.com",
"tv.apple.com",
// Video sharing
- "tiktok.com",
- "vm.tiktok.com",
"vevo.com",
"streamable.com",
"bitchute.com",
"rumble.com",
"odysee.com",
- "lbry.tv",
"reels.instagram.com",
// Educational
@@ -192,27 +198,18 @@ const videoDomains = [
"masterclass.com",
"coursera.org",
"pluralsight.com",
- "lynda.com",
- "linkedin.com/learning",
// Live streaming
- "facebook.com/gaming",
- "youtube.com/live",
"kick.com",
- "caffeine.tv",
- "mixer.com",
// Regional platforms
"bilibili.com",
"niconico.jp",
- "vlive.tv",
"youku.com",
"tudou.com",
"iqiyi.com",
// Short-form video
- "vine.co",
- "byte.co",
"triller.co",
"likee.video",
];
@@ -252,8 +249,6 @@ const shoppingDomains = [
"bestbuy.com",
"newegg.com",
"bhphotovideo.com",
- "apple.com/shop",
- "samsung.com/shop",
"microcenter.com",
"tigerdirect.com",
@@ -301,6 +296,51 @@ const shoppingDomains = [
// dashboard has to spell an operator's name the same way the bot patterns do.
const aiChatDomains = AI_CHAT_DOMAINS;
+// Webmail. More specific than the search entries they sit under ("google.",
+// "yahoo."), so a click from an inbox is Email rather than Organic Search.
+const emailDomains = [
+ "mail.google.com",
+ "inbox.google.com",
+ "com.google.android.gm", // Gmail app, via android-app:// referrers
+ "outlook.live.com",
+ "outlook.office.com",
+ "outlook.office365.com",
+ "outlook.cloud.microsoft",
+ "mail.yahoo.com",
+ "mail.yahoo.co.jp",
+ "mail.aol.com",
+ "mail.proton.me",
+ "mail.protonmail.com",
+ "app.fastmail.com",
+ "app.hey.com",
+ "mail.superhuman.com",
+ "mail.zoho.com",
+ "mail.zoho.eu",
+ "mail.yandex.ru",
+ "mail.yandex.com",
+ "e.mail.ru",
+ "mail.qq.com",
+ "mail.163.com",
+ "mail.126.com",
+ "mail.naver.com",
+ "mail.daum.net",
+ "email.seznam.cz",
+ "webmail.",
+];
+
+// Hosts under a search engine's domain that are products, not search results.
+// Listing them here stops "google." from claiming them as Organic Search.
+const nonSearchDomains = [
+ "accounts.google.com",
+ "docs.google.com",
+ "drive.google.com",
+ "sites.google.com",
+ "calendar.google.com",
+ "classroom.google.com",
+ "meet.google.com",
+ "translate.google.com",
+];
+
// AI chat sources (utm_source values)
const aiChatSources = [
"chatgpt",
@@ -395,7 +435,6 @@ const searchSources = [
"rambler",
// Other search engines
- "neeva",
"kagi",
];
@@ -403,6 +442,7 @@ const socialSources = [
// Major social platforms
"facebook",
"twitter",
+ "x",
"linkedin",
"instagram",
"tiktok",
@@ -411,7 +451,6 @@ const socialSources = [
// Other platforms
"snapchat",
- "youtube",
"discord",
"whatsapp",
"telegram",
@@ -423,7 +462,6 @@ const socialSources = [
"slack",
"nextdoor",
"clubhouse",
- "twitch",
"hacker news",
"hackernews",
"ycombinator",
@@ -434,12 +472,17 @@ const socialSources = [
"pin",
"li",
"tw",
- "yt",
+
+ // Meta ads {{site_source_name}} values (fb and ig are above)
+ "meta",
+ "msg",
+ "an",
// Newer/emerging platforms
"bluesky",
"bsky",
- "post",
+ "farcaster",
+ "lobsters",
"truth social",
"gettr",
"parler",
@@ -467,6 +510,10 @@ const socialSources = [
"vk",
"qq",
"weibo",
+ "xiaohongshu",
+ "rednote",
+ "douyin",
+ "zhihu",
"line",
"kakao",
"kakaotalk",
@@ -478,6 +525,7 @@ const socialSources = [
const videoSources = [
// Major video platforms
"youtube",
+ "yt",
"vimeo",
"twitch",
"dailymotion",
@@ -494,7 +542,6 @@ const videoSources = [
"paramount+",
"discovery+",
"crunchyroll",
- "funimation",
"curiositystream",
"mubi",
"apple tv",
@@ -506,7 +553,6 @@ const videoSources = [
"bitchute",
"rumble",
"odysee",
- "lbry",
"reels",
// Educational
@@ -517,24 +563,18 @@ const videoSources = [
"masterclass",
"coursera",
"pluralsight",
- "lynda",
// Live streaming
"kick",
- "caffeine",
- "mixer",
// Regional platforms
"bilibili",
"niconico",
- "vlive",
"youku",
"tudou",
"iqiyi",
// Short-form video
- "vine",
- "byte",
"triller",
"likee",
];
@@ -1135,16 +1175,74 @@ export function isMobileAppId(source: string): boolean {
return /^[a-z0-9_]+(\.([a-z0-9_]+))+$/.test(source);
}
+// Domain lists by source type. Order breaks ties between equally specific
+// matches (AI before search, so an AI host under a search domain stays AI).
+const domainSourceTypes: [string, string[]][] = [
+ ["ai", aiChatDomains],
+ ["email", emailDomains],
+ ["referral", nonSearchDomains],
+ ["search", searchDomains],
+ ["social", socialDomains],
+ ["video", videoDomains],
+ ["shopping", shoppingDomains],
+];
+
+// How specifically `entry` matches `host`: the entry's length, or 0 for no
+// match. A plain entry matches that domain and its subdomains ("facebook.com"
+// matches "l.facebook.com" but not "notfacebook.com"). An entry ending in "."
+// is a brand across TLDs and matches at a label boundary ("google." matches
+// "google.de" and "www.google.co.uk" but not "googleusercontent.com").
+function domainMatchLength(host: string, entry: string): number {
+ if (entry.endsWith(".")) {
+ return host.startsWith(entry) || host.includes("." + entry) ? entry.length : 0;
+ }
+ return host === entry || host.endsWith("." + entry) ? entry.length : 0;
+}
+
+// The most specific entry wins, so "mail.google.com" (email) beats "google."
+// (search) and "tieba.baidu.com" (social) beats "baidu." (search).
+// UTM sources are sometimes a URL ("https://facebook.com/", "//facebook.com")
+// or a host with a path; referring domains arrive as bare hosts.
+function getSourceHost(source: string): string {
+ if (source.includes("//")) {
+ try {
+ return new URL(source.startsWith("//") ? `https:${source}` : source).hostname;
+ } catch {
+ // Not a URL: match the literal source
+ }
+ }
+ return source.split(/[/?#]/)[0];
+}
+
+function getDomainSourceType(source: string): string | null {
+ const host = getSourceHost(source);
+ // A ".com" entry also covers its ".com.<country>" sites ("shopee.com" matches
+ // "shopee.com.my"). Limited to ".com." so "pi.ai.uk" never becomes "pi.ai".
+ const countrylessHost = /\.com\.[a-z]{2}$/.test(host) ? host.slice(0, -3) : "";
+
+ let bestType: string | null = null;
+ let bestLength = 0;
+ for (const [type, domains] of domainSourceTypes) {
+ for (const domain of domains) {
+ const length = Math.max(
+ domainMatchLength(host, domain),
+ countrylessHost ? domainMatchLength(countrylessHost, domain) : 0,
+ );
+ if (length > bestLength) {
+ bestType = type;
+ bestLength = length;
+ }
+ }
+ }
+ return bestType;
+}
+
// Helper function to categorize traffic source type
export function getSourceType(source: string): string {
const lowerSource = source.toLowerCase();
- // Check domains first (AI before search to avoid misclassification)
- if (aiChatDomains.some(domain => lowerSource.includes(domain))) return "ai";
- if (searchDomains.some(domain => lowerSource.includes(domain))) return "search";
- if (socialDomains.some(domain => lowerSource.includes(domain))) return "social";
- if (videoDomains.some(domain => lowerSource.includes(domain))) return "video";
- if (shoppingDomains.some(domain => lowerSource.includes(domain))) return "shopping";
+ const domainSourceType = getDomainSourceType(lowerSource);
+ if (domainSourceType) return domainSourceType;
// Check source names (AI before search)
if (aiChatSources.includes(lowerSource)) return "ai";
diff --git a/server/src/services/tracker/getChannel.test.ts b/server/src/services/tracker/getChannel.test.ts
index 12e611a19..da707ff54 100644
--- a/server/src/services/tracker/getChannel.test.ts
+++ b/server/src/services/tracker/getChannel.test.ts
@@ -15,8 +15,128 @@ describe("getChannel - UTM parameter fallback", () => {
it("retains Referral classification for external referring domains", () => {
expect(getChannel("https://external-site.com/blog", "")).toBe("Referral");
- expect(
- getChannel("https://example.com/page", "utm_source=custom_source", "example.com"),
- ).not.toBe("Referral");
+ expect(getChannel("https://example.com/page", "utm_source=custom_source", "example.com")).not.toBe("Referral");
+ });
+});
+
+const fromReferrer = (host: string) => getChannel(`https://${host}/some/page`, "", "example.org");
+
+describe("getChannel - referrer domain matching", () => {
+ it("does not match a listed domain inside a longer hostname", () => {
+ // "x.com" and "t.co" used to match any host ending in x.com / t.com
+ for (const host of ["dropbox.com", "wix.com", "firefox.com", "microsoft.com", "producthunt.com", "about.me"]) {
+ expect(fromReferrer(host), host).toBe("Referral");
+ }
+ expect(fromReferrer("netflix.com")).toBe("Organic Video");
+ expect(fromReferrer("walmart.com")).toBe("Organic Shopping");
+ expect(fromReferrer("target.com")).toBe("Organic Shopping");
+ // "you.com" and "pi.ai" are AI; hosts that merely end in those letters are not
+ expect(fromReferrer("bayou.com")).toBe("Referral");
+ expect(fromReferrer("api.ai")).toBe("Referral");
+ });
+
+ it("matches listed domains and their subdomains", () => {
+ expect(fromReferrer("t.co")).toBe("Organic Social");
+ expect(fromReferrer("x.com")).toBe("Organic Social");
+ expect(fromReferrer("l.facebook.com")).toBe("Organic Social");
+ expect(fromReferrer("www.perplexity.ai")).toBe("AI");
+ });
+
+ it("matches brand entries across country TLDs at a label boundary", () => {
+ expect(fromReferrer("www.google.co.uk")).toBe("Organic Search");
+ expect(fromReferrer("google.de")).toBe("Organic Search");
+ expect(fromReferrer("search.yahoo.co.jp")).toBe("Organic Search");
+ expect(fromReferrer("yandex.com.tr")).toBe("Organic Search");
+ expect(fromReferrer("amazon.co.uk")).toBe("Organic Shopping");
+ expect(getChannel("android-app://com.google.android.googlequicksearchbox/", "", "example.org")).toBe(
+ "Organic Search"
+ );
+ expect(fromReferrer("googleusercontent.com")).toBe("Referral");
+ });
+
+ it("lets the most specific entry win over a broader search entry", () => {
+ expect(fromReferrer("mail.google.com")).toBe("Email");
+ expect(getChannel("android-app://com.google.android.gm/", "", "example.org")).toBe("Email");
+ expect(fromReferrer("mail.yahoo.com")).toBe("Email");
+ expect(fromReferrer("outlook.live.com")).toBe("Email");
+ expect(fromReferrer("docs.google.com")).toBe("Referral");
+ expect(fromReferrer("accounts.google.com")).toBe("Referral");
+ expect(fromReferrer("gemini.google.com")).toBe("AI");
+ expect(fromReferrer("aistudio.google.com")).toBe("AI");
+ expect(fromReferrer("edgeservices.bing.com")).toBe("AI");
+ expect(fromReferrer("tieba.baidu.com")).toBe("Organic Social");
+ });
+
+ it("classifies YouTube and Twitch as video, not social", () => {
+ expect(fromReferrer("www.youtube.com")).toBe("Organic Video");
+ expect(fromReferrer("m.youtube.com")).toBe("Organic Video");
+ expect(fromReferrer("youtu.be")).toBe("Organic Video");
+ expect(fromReferrer("www.twitch.tv")).toBe("Organic Video");
+ expect(fromReferrer("www.tiktok.com")).toBe("Organic Social");
+ expect(getChannel("", "utm_source=youtube&utm_medium=paid")).toBe("Paid Video");
+ });
+
+ it("recognises current social and AI sources", () => {
+ for (const host of ["www.threads.com", "threads.net", "www.xiaohongshu.com", "lobste.rs", "fosstodon.org"]) {
+ expect(fromReferrer(host), host).toBe("Organic Social");
+ }
+ for (const host of [
+ "duck.ai",
+ "kimi.com",
+ "www.doubao.com",
+ "manus.im",
+ "copilot.cloud.microsoft",
+ "chat.qwen.ai",
+ ]) {
+ expect(fromReferrer(host), host).toBe("AI");
+ }
+ expect(fromReferrer("duckduckgo.com")).toBe("Organic Search");
+ expect(fromReferrer("search.brave.com")).toBe("Organic Search");
+ });
+
+ it("classifies Meta ads source names as paid social", () => {
+ expect(getChannel("", "utm_source=meta&utm_medium=paid")).toBe("Paid Social");
+ expect(getChannel("", "utm_source=an&utm_medium=paid")).toBe("Paid Social");
+ expect(getChannel("", "utm_source=x&utm_medium=social")).toBe("Organic Social");
+ });
+});
+
+describe("getChannel - country sites and URL-valued sources", () => {
+ it("covers country sites of a listed domain", () => {
+ for (const host of ["shopee.com.my", "lazada.com.ph", "mercadolibre.com.mx", "rakuten.com.tw", "walmart.com.mx"]) {
+ expect(fromReferrer(host), host).toBe("Organic Shopping");
+ }
+ expect(getChannel("", "utm_source=shopee.com.my&utm_medium=paid")).toBe("Paid Shopping");
+ expect(fromReferrer("mail.google.com.br")).toBe("Email");
+ // stripping the country code must not create new substring-style collisions
+ expect(fromReferrer("microsoft.co.il")).toBe("Referral");
+ expect(fromReferrer("pi.ai.uk")).toBe("Referral");
+ expect(fromReferrer("t.co.uk")).toBe("Referral");
+ });
+
+ it("reads the host out of URL-valued UTM sources", () => {
+ expect(getChannel("", "utm_source=https%3A%2F%2Ffacebook.com%2F&utm_medium=cpc")).toBe("Paid Social");
+ expect(getChannel("", "utm_source=https%3A%2F%2Fwww.perplexity.ai%2F&utm_medium=paid")).toBe("Paid AI");
+ expect(getChannel("", "utm_source=chatgpt.com%2Fc%2F123")).toBe("AI");
+ expect(getChannel("", "utm_source=https%3A%2F%2Fuser%40facebook.com%2F&utm_medium=cpc")).toBe("Paid Social");
+ expect(getChannel("", "utm_source=%2F%2Ffacebook.com%2F&utm_medium=cpc")).toBe("Paid Social");
+ expect(getChannel("", "utm_source=android-app%3A%2F%2Fcom.google.android.gm%2F")).toBe("Email");
+ });
+});
+
+describe("getChannel - self-referrals", () => {
+ it("classifies navigation between the site's own hosts as Internal", () => {
+ expect(getChannel("https://www.example.org/a", "", "example.org")).toBe("Internal");
+ expect(getChannel("https://blog.example.org/a", "", "example.org")).toBe("Internal");
+ });
+
+ it("keeps campaign-tagged self-referrals out of Internal", () => {
+ expect(getChannel("https://www.example.org/a", "utm_source=newsletter&utm_medium=email", "example.org")).toBe(
+ "Email"
+ );
+ });
+
+ it("does not treat a sibling subdomain as a self-referral", () => {
+ expect(getChannel("https://blog.example.org/a", "", "app.example.org")).toBe("Referral");
});
});
diff --git a/server/src/services/tracker/getChannel.ts b/server/src/services/tracker/getChannel.ts
index 1e3990e7a..e0a782011 100644
--- a/server/src/services/tracker/getChannel.ts
+++ b/server/src/services/tracker/getChannel.ts
@@ -168,9 +168,11 @@ export function getChannel(referrer: string, querystring: string, hostname?: str
}
}
- // If it's a self-referral and has no UTM parameters, treat it as internal traffic
- if (!referrer && !utmSource && !utmMedium && !utmCampaign && !gclid && !gadSource) {
- return selfReferral ? "Internal" : "Direct";
+ if (!utmSource && !utmMedium && !utmCampaign && !gclid && !gadSource) {
+ if (!referrer) return "Direct";
+ // Navigation between the site's own hosts (www ↔ apex, subdomain → parent)
+ // is internal traffic, not a new acquisition.
+ if (selfReferral) return "Internal";
}
// Use utility functions for better categorization
diff --git a/server/src/services/tracker/pageviewQueue.test.ts b/server/src/services/tracker/pageviewQueue.test.ts
index a6990cf5c..ce4b81806 100644
--- a/server/src/services/tracker/pageviewQueue.test.ts
+++ b/server/src/services/tracker/pageviewQueue.test.ts
@@ -44,7 +44,7 @@ function makePayload(overrides: Partial<TotalTrackingPayload & { sessionId: stri
type: "pageview",
ipAddress: "203.0.113.10",
timestamp: new Date().toISOString(),
- ua: { browser: {}, os: {} } as UAParser.IResult,
+ ua: { browser: {}, os: {}, device: {} } as UAParser.IResult,
userAgent: "Mozilla/5.0",
userId: "fingerprint-abc",
identifiedUserId: "",
diff --git a/server/src/utils.test.ts b/server/src/utils.test.ts
index ebadb1d73..d0a380f4d 100644
--- a/server/src/utils.test.ts
+++ b/server/src/utils.test.ts
@@ -1,6 +1,7 @@
import { describe, it, expect } from "vitest";
import { FastifyRequest } from "fastify";
-import { getIpAddress, normalizeOrigin } from "./utils.js";
+import { UAParser } from "ua-parser-js";
+import { getDeviceType, getIpAddress, normalizeOrigin } from "./utils.js";
function requestWithHeaders(headers: Record<string, string | string[]>, ip = "198.51.100.10"): FastifyRequest {
return { headers, ip } as unknown as FastifyRequest;
@@ -222,3 +223,49 @@ describe("normalizeOrigin", () => {
});
});
});
+
+describe("getDeviceType", () => {
+ const deviceType = (userAgent: string, width: number, height: number) =>
+ getDeviceType(width, height, UAParser(userAgent));
+
+ it("uses ua-parser's device type to tell tablets and TVs from phones", () => {
+ const androidTablet =
+ "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36";
+ const androidPhone =
+ "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Mobile Safari/537.36";
+ const iPadChrome =
+ "Mozilla/5.0 (iPad; CPU OS 18_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/140.0.0.0 Mobile/15E148 Safari/604.1";
+ const tizenTv =
+ "Mozilla/5.0 (SMART-TV; LINUX; Tizen 8.0) AppleWebKit/537.36 (KHTML, like Gecko) 120.0.6099.5/8.0 TV Safari/537.36";
+ const quest =
+ "Mozilla/5.0 (X11; Linux x86_64; Quest 3) AppleWebKit/537.36 (KHTML, like Gecko) OculusBrowser/38.0.0.0 SamsungBrowser/4.0 Chrome/132.0.0.0 VR Safari/537.36";
+
+ expect(deviceType(androidTablet, 800, 1280)).toBe("Tablet");
+ expect(deviceType(androidPhone, 412, 915)).toBe("Mobile");
+ expect(deviceType(iPadChrome, 820, 1180)).toBe("Tablet");
+ expect(deviceType(tizenTv, 1920, 1080)).toBe("TV");
+ expect(deviceType(quest, 1680, 1760)).toBe("XR");
+ });
+
+ it("falls back to the OS when ua-parser has no device type", () => {
+ const windows =
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36";
+ expect(deviceType(windows, 1920, 1080)).toBe("Desktop");
+ });
+
+ it("falls back to screen size when neither the device nor the OS is known", () => {
+ expect(deviceType("", 1920, 1080)).toBe("Desktop");
+ expect(deviceType("", 768, 1024)).toBe("Tablet");
+ expect(deviceType("", 390, 844)).toBe("Mobile");
+ expect(deviceType("", 0, 0)).toBe("Mobile");
+ });
+});
+
+describe("ua-parser-js", () => {
+ it("reports the real iOS version behind Safari 26's frozen user agent", () => {
+ // Since iOS 26, Safari reports the OS as 18_x; ua-parser-js >= 2.0.5 corrects it
+ const ios26Safari =
+ "Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.0 Mobile/15E148 Safari/604.1";
+ expect(UAParser(ios26Safari).os.version).toBe("26.0");
+ });
+});
diff --git a/server/src/utils.ts b/server/src/utils.ts
index 6dc3cc04c..8f7ff27b0 100644
--- a/server/src/utils.ts
+++ b/server/src/utils.ts
@@ -3,8 +3,10 @@ import * as psl from "psl";
const desktopOS = new Set([
"AIX",
+ "Amiga OS",
"macOS",
"Windows",
+ "Windows RT",
"Linux",
"FreeBSD",
"OpenBSD",
@@ -89,13 +91,32 @@ const tvOS = new Set([
"Chromecast Linux",
"Chromecast SmartSpeaker",
"NetTV",
+ "Vega OS",
]);
const gamingOS = new Set(["PlayStation", "Xbox", "Nintendo"]);
const embeddedOS = new Set(["Windows IoT", "Contiki", "Raspbian", "Morph OS", "Pico", "NetRange"]);
+// ua-parser's own device classification. It is the only signal that tells a
+// tablet or TV apart from a phone running the same OS (Android, Tizen), so it
+// is consulted before the OS lists below.
+const uaDeviceTypes: Record<string, string> = {
+ mobile: "Mobile",
+ tablet: "Tablet",
+ smarttv: "TV",
+ console: "Console",
+ wearable: "Wearable",
+ xr: "XR",
+ embedded: "Embedded",
+};
+
export function getDeviceType(screenWidth: number, screenHeight: number, ua: UAParser.IResult): string {
+ const uaDeviceType = ua.device.type ? uaDeviceTypes[ua.device.type] : undefined;
+ if (uaDeviceType) {
+ return uaDeviceType;
+ }
+
if (ua.os.name) {
if (desktopOS.has(ua.os.name)) {
return "Desktop";
@@ -114,7 +135,7 @@ export function getDeviceType(screenWidth: number, screenHeight: number, ua: UAP
const smallerDimension = Math.min(screenWidth, screenHeight);
if (largerDimension > 1024) {
return "Desktop";
- } else if (largerDimension > 768 && smallerDimension > 1024) {
+ } else if (smallerDimension >= 600) {
return "Tablet";
}
return "Mobile";
diff --git a/shared/src/aiOperators.ts b/shared/src/aiOperators.ts
index 141c85806..b017c8c6a 100644
--- a/shared/src/aiOperators.ts
+++ b/shared/src/aiOperators.ts
@@ -20,18 +20,23 @@
export const AI_OPERATOR_REFERRER_DOMAINS: Record<string, string[]> = {
OpenAI: ["chatgpt.com", "chat.openai.com"],
Anthropic: ["claude.ai"],
- Google: ["gemini.google.com"],
- Microsoft: ["copilot.microsoft.com"],
+ Google: ["gemini.google.com", "aistudio.google.com", "notebooklm.google.com"],
+ // edgeservices.bing.com is Copilot in the Edge sidebar; the *.cloud.microsoft
+ // hosts are the Microsoft 365 Copilot web app (m365 → copilot redirect, 2026).
+ Microsoft: ["copilot.microsoft.com", "copilot.cloud.microsoft", "m365.cloud.microsoft", "edgeservices.bing.com"],
Perplexity: ["perplexity.ai"],
Meta: ["meta.ai"],
Mistral: ["chat.mistral.ai", "mistral.ai"],
xAI: ["grok.com"],
"You.com": ["you.com"],
- // DuckDuckGo is deliberately absent: DuckAssistBot crawls, but a referral
- // from duckduckgo.com is organic search, not an AI chat hand-off, and
- // listing it here would reclassify every DuckDuckGo visit as AI traffic.
+ // Only duck.ai, DuckDuckGo's chat: a referral from duckduckgo.com is organic
+ // search, not an AI chat hand-off, and listing it here would reclassify
+ // every DuckDuckGo visit as AI traffic.
+ DuckDuckGo: ["duck.ai"],
Cursor: ["cursor.com"],
Cohere: ["coral.cohere.com"],
+ Manus: ["manus.im"],
+ ByteDance: ["doubao.com"],
};
/**
@@ -64,6 +69,14 @@ export const AI_CHAT_ONLY_DOMAINS: string[] = [
"phind.com",
"andi.com",
"codeium.com",
+ "kimi.com",
+ "kimi.moonshot.cn",
+ "chat.qwen.ai",
+ "chat.z.ai",
+ "chatglm.cn",
+ "yuanbao.tencent.com",
+ "genspark.ai",
+ "t3.chat",
];
/** Every domain that counts as AI chat traffic, for channel classification. */