Skip to content

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

Refactor channel icon handling and enhance AI categorization

Bill Yangdd583d890cf0
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 578d6f4b7..c37797399 100644
--- a/client/src/app/[site]/globe/3d/hooks/timelineLayer/timelineMarkerHelpers.ts
+++ b/client/src/app/[site]/globe/3d/hooks/timelineLayer/timelineMarkerHelpers.ts
@@ -3,24 +3,9 @@ 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,
- Link,
- Search,
- ExternalLink,
- Users,
- Mail,
- HelpCircle,
- DollarSign,
- Video,
- Handshake,
- FileText,
- ShoppingCart,
- Calendar,
- Headphones,
-} from "lucide-react";
+import { Monitor, Smartphone } from "lucide-react";
import { AVATAR_COLORS } from "../../../../../../components/Avatar";
+import { getChannelIconComponent } from "../../../../../../components/Channel";
// Generate avatar SVG using boring-avatars
export function generateAvatarSVG(userId: string, size: number): string {
@@ -50,46 +35,6 @@ export function renderDeviceIcon(deviceType: string): string {
return renderToStaticMarkup(iconElement);
}
-// Get channel icon component
-function getChannelIconComponent(channel: string) {
- switch (channel) {
- case "Direct":
- return Link;
- case "Organic Search":
- return Search;
- case "Referral":
- return ExternalLink;
- case "Organic Social":
- return Users;
- case "Email":
- return Mail;
- case "Unknown":
- return HelpCircle;
- case "Paid Search":
- return Search;
- case "Paid Unknown":
- return DollarSign;
- case "Paid Social":
- return Users;
- case "Display":
- return Monitor;
- case "Organic Video":
- return Video;
- case "Affiliate":
- return Handshake;
- case "Content":
- return FileText;
- case "Organic Shopping":
- return ShoppingCart;
- case "Event":
- return Calendar;
- case "Audio":
- return Headphones;
- default:
- return null;
- }
-}
-
// Render channel icon
export function renderChannelIcon(channel: string): string {
const IconComponent = getChannelIconComponent(channel);
diff --git a/client/src/components/Channel.tsx b/client/src/components/Channel.tsx
index f34226f43..b7e601089 100644
--- a/client/src/components/Channel.tsx
+++ b/client/src/components/Channel.tsx
@@ -1,4 +1,5 @@
import {
+ Bot,
Calendar,
DollarSign,
ExternalLink,
@@ -19,43 +20,49 @@ import { cn } from "../lib/utils";
import { Favicon } from "./Favicon";
import { Badge } from "./ui/badge";
-export const ChannelIcon = ({ channel, className }: { channel: string; className?: string }) => {
+export function getChannelIconComponent(channel: string) {
switch (channel) {
case "Direct":
- return <Link className={cn("w-4 h-4", className)} />;
+ return Link;
case "Organic Search":
- return <Search className={cn("w-4 h-4", className)} />;
+ case "Paid Search":
+ return Search;
case "Referral":
- return <ExternalLink className={cn("w-4 h-4", className)} />;
+ return ExternalLink;
case "Organic Social":
- return <Users className={cn("w-4 h-4", className)} />;
+ case "Paid Social":
+ return Users;
case "Email":
- return <Mail className={cn("w-4 h-4", className)} />;
+ return Mail;
case "Unknown":
- return <HelpCircle className={cn("w-4 h-4", className)} />;
- case "Paid Search":
- return <Search className={cn("w-4 h-4", className)} />;
+ return HelpCircle;
case "Paid Unknown":
- return <DollarSign className={cn("w-4 h-4", className)} />;
- case "Paid Social":
- return <Users className={cn("w-4 h-4", className)} />;
+ return DollarSign;
case "Display":
- return <Monitor className={cn("w-4 h-4", className)} />;
+ return Monitor;
case "Organic Video":
- return <Video className={cn("w-4 h-4", className)} />;
+ return Video;
case "Affiliate":
- return <Handshake className={cn("w-4 h-4", className)} />;
+ return Handshake;
case "Content":
- return <FileText className={cn("w-4 h-4", className)} />;
+ return FileText;
case "Organic Shopping":
- return <ShoppingCart className={cn("w-4 h-4", className)} />;
+ return ShoppingCart;
case "Event":
- return <Calendar className={cn("w-4 h-4", className)} />;
+ return Calendar;
case "Audio":
- return <Headphones className={cn("w-4 h-4", className)} />;
+ return Headphones;
+ case "AI":
+ case "Paid AI":
+ return Bot;
default:
- return <FileQuestion className={cn("w-4 h-4", className)} />;
+ return FileQuestion;
}
+}
+
+export const ChannelIcon = ({ channel, className }: { channel: string; className?: string }) => {
+ const Icon = getChannelIconComponent(channel);
+ return <Icon className={cn("w-4 h-4", className)} />;
};
export const getDisplayName = (hostname: string): string => {
@@ -105,8 +112,26 @@ export const getDisplayName = (hostname: string): string => {
"pinterest.com": "Pinterest",
"www.pinterest.com": "Pinterest",
"chatgpt.com": "ChatGPT",
+ "chat.openai.com": "ChatGPT",
+ "claude.ai": "Claude",
+ "gemini.google.com": "Gemini",
+ "copilot.microsoft.com": "Copilot",
+ "chat.deepseek.com": "DeepSeek",
+ "deepseek.com": "DeepSeek",
+ "chat.mistral.ai": "Mistral",
+ "mistral.ai": "Mistral",
+ "meta.ai": "Meta AI",
+ "poe.com": "Poe",
+ "grok.com": "Grok",
+ "pi.ai": "Pi",
+ "character.ai": "Character.AI",
"perplexity.ai": "Perplexity",
"www.perplexity.ai": "Perplexity",
+ "phind.com": "Phind",
+ "andi.com": "Andi",
+ "you.com": "You.com",
+ "cursor.com": "Cursor",
+ "jasper.ai": "Jasper",
"news.ycombinator.com": "Hacker News",
"stripe.com": "Stripe",
"checkout.stripe.com": "Stripe",
diff --git a/docs/src/components/SpinningGlobe.tsx b/docs/src/components/SpinningGlobe.tsx
index 237166ccf..6b49fab17 100644
--- a/docs/src/components/SpinningGlobe.tsx
+++ b/docs/src/components/SpinningGlobe.tsx
@@ -9,6 +9,7 @@ import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import * as CountryFlags from "country-flag-icons/react/3x2";
import {
+ Bot,
Monitor,
Smartphone,
Link,
@@ -234,6 +235,9 @@ function getChannelIconComponent(channel: string) {
return Calendar;
case "Audio":
return Headphones;
+ case "AI":
+ case "Paid AI":
+ return Bot;
default:
return null;
}
diff --git a/server/src/services/tracker/const.ts b/server/src/services/tracker/const.ts
index 74d47b001..9d4c7e1d6 100644
--- a/server/src/services/tracker/const.ts
+++ b/server/src/services/tracker/const.ts
@@ -55,11 +55,7 @@ const searchDomains = [
"goo.ne.jp",
"rambler.ru",
- // AI-powered search engines
- "perplexity.ai",
- "you.com",
- "phind.com",
- "andi.com",
+ // Other search engines
"neeva.com",
"kagi.com",
];
@@ -304,6 +300,92 @@ const shoppingDomains = [
"foodpanda.com",
];
+// AI chat domains
+const aiChatDomains = [
+ "chatgpt.com",
+ "chat.openai.com",
+ "claude.ai",
+ "gemini.google.com",
+ "copilot.microsoft.com",
+ "deepseek.com",
+ "chat.deepseek.com",
+ "chat.mistral.ai",
+ "mistral.ai",
+ "meta.ai",
+ "poe.com",
+ "grok.com",
+ "pi.ai",
+ "heypi.com",
+ "coral.cohere.com",
+ "character.ai",
+ "qwen.ai",
+ "jasper.ai",
+ "writesonic.com",
+ "chatsonic.com",
+ "perplexity.ai",
+ "you.com",
+ "phind.com",
+ "andi.com",
+ "cursor.com",
+ "codeium.com",
+];
+
+// AI chat sources (utm_source values)
+const aiChatSources = [
+ "chatgpt",
+ "openai",
+ "claude",
+ "anthropic",
+ "gemini",
+ "copilot",
+ "deepseek",
+ "mistral",
+ "meta ai",
+ "metaai",
+ "poe",
+ "grok",
+ "pi",
+ "huggingchat",
+ "cohere",
+ "character.ai",
+ "qwen",
+ "jasper",
+ "writesonic",
+ "chatsonic",
+ "perplexity",
+ "phind",
+ "andi",
+ "you",
+ "cursor",
+ "codeium",
+ "windsurf",
+ "lechat",
+];
+
+// AI chat mediums (utm_medium values)
+const aiChatMediums = [
+ "ai",
+ "ai-chat",
+ "chatbot",
+ "llm",
+ "ai-assistant",
+ "gen-ai",
+ "ai-search",
+];
+
+// AI chat mobile app IDs
+export const aiChatAppIds = [
+ "com.openai.chatgpt",
+ "com.anthropic.claude",
+ "com.google.android.apps.bard",
+ "com.microsoft.copilot",
+ "ai.perplexity.app.android",
+ "ai.perplexity.app.ios",
+ "com.quora.poe",
+ "ai.character.app",
+ "com.deepseek.chat",
+];
+
// Define sources types
const searchSources = [
// Major search engines
@@ -341,11 +423,7 @@ const searchSources = [
"goo",
"rambler",
- // AI-powered search engines
- "perplexity",
- "you",
- "phind",
- "andi",
+ // Other search engines
"neeva",
"kagi",
];
@@ -1090,13 +1168,15 @@ export function isMobileAppId(source: string): boolean {
export function getSourceType(source: string): string {
const lowerSource = source.toLowerCase();
- // Check domains first
+ // 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";
- // Check source names
+ // Check source names (AI before search)
+ if (aiChatSources.includes(lowerSource)) return "ai";
if (searchSources.includes(lowerSource)) return "search";
if (socialSources.includes(lowerSource)) return "social";
if (videoSources.includes(lowerSource)) return "video";
@@ -1104,8 +1184,9 @@ export function getSourceType(source: string): string {
if (emailSources.includes(lowerSource)) return "email";
if (smsSources.includes(lowerSource)) return "sms";
- // Check mobile app IDs
+ // Check mobile app IDs (AI before search)
if (isMobileAppId(source)) {
+ if (aiChatAppIds.includes(source)) return "ai";
if (socialAppIds.includes(source)) return "social";
if (videoAppIds.includes(source)) return "video";
if (searchAppIds.includes(source)) return "search";
@@ -1123,6 +1204,7 @@ export function getSourceType(source: string): string {
export function getMediumType(medium: string): string {
const lowerMedium = medium.toLowerCase();
+ if (aiChatMediums.includes(lowerMedium)) return "ai";
if (socialMediums.includes(lowerMedium)) return "social";
if (videoMediums.includes(lowerMedium)) return "video";
if (displayMediums.includes(lowerMedium)) return "display";
diff --git a/server/src/services/tracker/getChannel.ts b/server/src/services/tracker/getChannel.ts
index 2aefe1254..46c0bee74 100644
--- a/server/src/services/tracker/getChannel.ts
+++ b/server/src/services/tracker/getChannel.ts
@@ -1,10 +1,10 @@
import {
+ aiChatAppIds,
emailAppIds,
getMediumType,
getSourceType,
isMobileAppId,
isPaidTraffic,
- // New imports for expanded categories
newsAppIds,
productivityAppIds,
searchAppIds,
@@ -27,6 +27,10 @@ function getMobileAppCategory(appId: string): { type: string; isPaid: boolean }
return { type: "Organic Video", isPaid: false };
}
+ if (aiChatAppIds.some(id => appIdLower.includes(id))) {
+ return { type: "AI", isPaid: false };
+ }
+
if (searchAppIds.some(id => appIdLower.includes(id))) {
return { type: "Organic Search", isPaid: false };
}
@@ -191,6 +195,8 @@ export function getChannel(referrer: string, querystring: string, hostname?: str
// Paid channels - use intelligent categorization
if (isPaid) {
switch (sourceType) {
+ case "ai":
+ return "Paid AI";
case "search":
return "Paid Search";
case "social":
@@ -202,6 +208,8 @@ export function getChannel(referrer: string, querystring: string, hostname?: str
default:
// Fall back to medium-based detection for paid traffic
switch (mediumType) {
+ case "ai":
+ return "Paid AI";
case "social":
return "Paid Social";
case "video":
@@ -223,6 +231,8 @@ export function getChannel(referrer: string, querystring: string, hostname?: str
// Organic channels - prioritize source type detection
switch (sourceType) {
+ case "ai":
+ return "AI";
case "search":
return "Organic Search";
case "social":
@@ -243,6 +253,8 @@ export function getChannel(referrer: string, querystring: string, hostname?: str
// Medium-based detection for organic traffic
switch (mediumType) {
+ case "ai":
+ return "AI";
case "social":
return "Organic Social";
case "video":
@@ -268,6 +280,7 @@ export function getChannel(referrer: string, querystring: string, hostname?: str
}
// Campaign-based detection as fallback
+ if (/\bai\b|chatgpt|claude|gemini|copilot|llm/.test(utmCampaign)) return "AI";
if (/video/.test(utmCampaign)) return "Organic Video";
if (/shop|shopping/.test(utmCampaign)) return "Organic Shopping";
if (/influencer|creator|sponsored/.test(utmCampaign)) return "Influencer";