Skip to content

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

Enhance mobile app categorization and improve domain matching in tracking

Bill Yanga2ee489906d4
diff --git a/server/src/tracker/const.ts b/server/src/tracker/const.ts
index ab0dc6cdf..4d55e2492 100644
--- a/server/src/tracker/const.ts
+++ b/server/src/tracker/const.ts
@@ -142,7 +142,6 @@ export const videoDomains = [
"rumble.com",
"odysee.com",
"lbry.tv",
- "tiktok.com",
"reels.instagram.com",
// Educational
@@ -621,3 +620,201 @@ export const audioMediums = [
"jingle",
"commercial",
];
+
+// Mobile App IDs (reverse DNS format)
+export const socialAppIds = [
+ // Facebook family
+ "com.facebook",
+ "com.facebook.katana",
+ "com.facebook.facebook",
+ "com.facebook.messenger",
+ "com.facebook.orca",
+
+ // Instagram
+ "com.instagram",
+ "com.instagram.android",
+ "com.burbn.instagram",
+
+ // Twitter/X
+ "com.twitter",
+ "com.twitter.android",
+ "com.atebits.tweetie2",
+
+ // TikTok
+ "com.zhiliaoapp.musically",
+ "com.tiktok",
+
+ // Snapchat
+ "com.snapchat",
+ "com.snapchat.android",
+ "com.toyopagroup.picaboo",
+
+ // LinkedIn
+ "com.linkedin",
+ "com.linkedin.android",
+ "com.linkedin.LinkedIn",
+
+ // Pinterest
+ "com.pinterest",
+
+ // Reddit
+ "com.reddit",
+ "com.reddit.frontpage",
+ "com.reddit.reddit",
+
+ // Discord
+ "com.discord",
+ "com.hammerandchisel.discord",
+
+ // Telegram
+ "org.telegram",
+ "org.telegram.messenger",
+ "ph.telegra.Telegraph",
+
+ // WhatsApp
+ "com.whatsapp",
+
+ // Thread
+ "com.instagram.barcelona",
+ "com.threads",
+
+ // Bluesky
+ "xyz.blueskyweb.app",
+
+ // Mastodon
+ "org.joinmastodon.android",
+
+ // Other social
+ "com.slack",
+ "im.vector.app",
+];
+
+export const videoAppIds = [
+ // YouTube
+ "com.google.android.youtube",
+ "com.google.ios.youtube",
+ "com.google.ios.youtubekids",
+ "com.google.android.apps.youtube.kids",
+ "com.google.ios.youtubeunplugged",
+ "com.google.android.youtube.tv",
+
+ // Streaming services
+ "com.netflix",
+ "com.disney.disneyplus",
+ "com.hulu",
+ "com.hbo.hbonow",
+ "com.hbo.hbomax",
+ "com.peacocktv",
+ "com.amazon.avod",
+ "com.amazon.amazonvideo",
+ "com.cbs.app",
+ "com.paramountplus",
+
+ // Twitch
+ "tv.twitch",
+ "tv.twitch.android.app",
+
+ // Other video
+ "com.vimeo",
+ "com.dailymotion",
+];
+
+export const searchAppIds = [
+ // Google
+ "com.google.android.googlequicksearchbox",
+ "com.google.android.websearch",
+
+ // Bing
+ "com.microsoft.bing",
+
+ // Yahoo
+ "com.yahoo.mobile.client.android.search",
+ "com.yahoo.search",
+
+ // DuckDuckGo
+ "com.duckduckgo.mobile.android",
+ "com.duckduckgo.mobile.ios",
+
+ // Other search
+ "com.ecosia.android",
+ "com.brave.browser",
+ "org.mozilla.firefox",
+ "com.microsoft.emmx",
+];
+
+export const emailAppIds = [
+ // Gmail
+ "com.google.android.gm",
+ "com.google.android.gm.lite",
+ "com.google.Gmail",
+
+ // Outlook
+ "com.microsoft.office.outlook",
+ "com.microsoft.outlooklite",
+ "com.microsoft.Office.Outlook",
+
+ // Yahoo Mail
+ "com.yahoo.mobile.client.android.mail",
+ "com.yahoo.Aerogram",
+
+ // Apple Mail
+ "com.apple.mobilemail",
+
+ // ProtonMail
+ "ch.protonmail.android",
+ "ch.protonmail.protonmail",
+
+ // Other mail apps
+ "com.superhuman.mail",
+ "com.superhuman.Superhuman",
+ "com.samsung.android.email.provider",
+ "me.bluemail.mail",
+ "com.easilydo.mail",
+ "org.kman.AquaMail",
+ "com.aol.mobile.aolapp",
+ "ru.mail.mailapp",
+ "ru.mail.mail",
+ "ru.yandex.mail",
+ "com.pingapp.app",
+ "com.readdle.smartemail",
+];
+
+export const shoppingAppIds = [
+ // Amazon
+ "com.amazon.mShop",
+ "com.amazon.shopping",
+
+ // eBay
+ "com.ebay.mobile",
+
+ // Walmart
+ "com.walmart.android",
+
+ // Target
+ "com.target.ui",
+
+ // Etsy
+ "com.etsy.android",
+
+ // Shopify
+ "com.shopify.mobile",
+
+ // Wish
+ "com.contextlogic.wish",
+
+ // AliExpress
+ "com.alibaba.aliexpresshd",
+
+ // Other shopping
+ "com.wayfair.wayfair",
+ "com.newegg.app",
+ "com.bestbuy.android",
+ "com.ikea.app",
+ "com.homedepot",
+];
+
+// Categorize mobile apps by their bundle ID/package name - helper function
+export function isMobileAppId(source: string): boolean {
+ // Check for common app identifier patterns (com.company.app, etc.)
+ return /^[a-z0-9_]+(\.([a-z0-9_]+))+$/.test(source);
+}
diff --git a/server/src/tracker/getChannel.ts b/server/src/tracker/getChannel.ts
index a6888b949..72073d8a5 100644
--- a/server/src/tracker/getChannel.ts
+++ b/server/src/tracker/getChannel.ts
@@ -3,22 +3,58 @@ import {
audioMediums,
displayMediums,
emailMediums,
+ emailAppIds,
emailSources,
+ isMobileAppId,
pushMediums,
referralMediums,
+ searchAppIds,
searchDomains,
searchSources,
+ shoppingAppIds,
shoppingDomains,
shoppingSources,
smsSources,
+ socialAppIds,
socialDomains,
socialMediums,
socialSources,
+ videoAppIds,
videoDomains,
videoMediums,
videoSources,
} from "./const.js";
+// Categorize mobile app by its bundle ID/package name
+function getMobileAppCategory(
+ appId: string
+): { type: string; isPaid: boolean } | null {
+ const appIdLower = appId.toLowerCase();
+
+ // Check against our defined app ID lists
+ if (socialAppIds.some((id) => appIdLower.includes(id))) {
+ return { type: "Organic Social", isPaid: false };
+ }
+
+ if (videoAppIds.some((id) => appIdLower.includes(id))) {
+ return { type: "Organic Video", isPaid: false };
+ }
+
+ if (searchAppIds.some((id) => appIdLower.includes(id))) {
+ return { type: "Organic Search", isPaid: false };
+ }
+
+ if (emailAppIds.some((id) => appIdLower.includes(id))) {
+ return { type: "Email", isPaid: false };
+ }
+
+ if (shoppingAppIds.some((id) => appIdLower.includes(id))) {
+ return { type: "Organic Shopping", isPaid: false };
+ }
+
+ return null;
+}
+
// UTM and URL parameter parsing utilities
function getUTMParams(querystring: string): Record<string, string> {
const params: Record<string, string> = {};
@@ -56,7 +92,15 @@ function getDomainFromReferrer(referrer: string): string {
// Checks if the referrer is from the same site as the current hostname
function isSelfReferral(referringDomain: string, hostname: string): boolean {
if (!referringDomain || !hostname) return false;
- return referringDomain === hostname;
+
+ // Handle subdomain variations
+ // Strip 'www.' prefixes for both domains
+ const stripWww = (domain: string) => domain.replace(/^www\./, "");
+ const refDomain = stripWww(referringDomain);
+ const currentDomain = stripWww(hostname);
+
+ // Check if domains match or if referrer is a subdomain of current domain
+ return refDomain === currentDomain || refDomain.endsWith("." + currentDomain);
}
export function getChannel(
@@ -79,16 +123,26 @@ export function getChannel(
const gclid = utmParams["gclid"] || "";
const gadSource = utmParams["gad_source"] || "";
+ // Check for mobile app sources using reverse DNS format (bundle IDs/package names)
+ if (utmSource && isMobileAppId(utmSource)) {
+ const appCategory = getMobileAppCategory(utmSource);
+ if (appCategory) {
+ return appCategory.isPaid
+ ? "Paid " + appCategory.type.split(" ")[1]
+ : appCategory.type;
+ }
+ }
+
// If it's a self-referral and has no UTM parameters, treat it as internal traffic
if (
- (selfReferral || !referrer) &&
+ !referrer &&
!utmSource &&
!utmMedium &&
!utmCampaign &&
!gclid &&
!gadSource
) {
- return "Internal";
+ return selfReferral ? "Internal" : "Direct";
}
// Check if traffic is paid
@@ -101,17 +155,27 @@ export function getChannel(
// Check domain type - improved to handle subdomains better
const isDomainSearch = searchDomains.some(
(domain) =>
- referringDomain.includes(domain) ||
- /^(?:www\.)?google\.[a-z]{2,3}$/.test(referringDomain)
+ referringDomain === domain ||
+ referringDomain.endsWith("." + domain) ||
+ (domain.endsWith(".") && referringDomain.startsWith(domain))
);
- const isDomainSocial = socialDomains.some((domain) =>
- referringDomain.includes(domain)
+ const isDomainSocial = socialDomains.some(
+ (domain) =>
+ referringDomain === domain ||
+ referringDomain.endsWith("." + domain) ||
+ (domain.endsWith(".") && referringDomain.startsWith(domain))
);
- const isDomainVideo = videoDomains.some((domain) =>
- referringDomain.includes(domain)
+ const isDomainVideo = videoDomains.some(
+ (domain) =>
+ referringDomain === domain ||
+ referringDomain.endsWith("." + domain) ||
+ (domain.endsWith(".") && referringDomain.startsWith(domain))
);
- const isDomainShopping = shoppingDomains.some((domain) =>
- referringDomain.includes(domain)
+ const isDomainShopping = shoppingDomains.some(
+ (domain) =>
+ referringDomain === domain ||
+ referringDomain.endsWith("." + domain) ||
+ (domain.endsWith(".") && referringDomain.startsWith(domain))
);
// Check source type