🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Fix Umami channel mapping
Edward Cui3a1a61223242
diff --git a/client/src/lib/import/csvParser.ts b/client/src/lib/import/csvParser.tsindex ae99c2a2a..0b98d3bc8 100644--- a/client/src/lib/import/csvParser.ts+++ b/client/src/lib/import/csvParser.ts@@ -16,7 +16,6 @@ interface UmamiEvent {url_path: string;url_query: string;referrer_path: string;- referrer_query: string;referrer_domain: string;page_title: string;event_type: string;@@ -139,7 +138,6 @@ export class CsvParser {url_path: rawEvent.url_path,url_query: rawEvent.url_query,referrer_path: rawEvent.referrer_path,- referrer_query: rawEvent.referrer_query,referrer_domain: rawEvent.referrer_domain,page_title: rawEvent.page_title,event_type: rawEvent.event_type,diff --git a/server/src/api/sites/batchImportEvents.ts b/server/src/api/sites/batchImportEvents.tsindex 876bf5d91..282b4f27e 100644--- a/server/src/api/sites/batchImportEvents.ts+++ b/server/src/api/sites/batchImportEvents.ts@@ -12,7 +12,7 @@ import { eq } from "drizzle-orm";const batchImportRequestSchema = z.object({params: z.object({- site: z.string().min(1),+ site: z.coerce.number().int(),importId: z.string().uuid(),}),body: z.object({@@ -40,7 +40,6 @@ export async function batchImportEvents(request: FastifyRequest<BatchImportRequeconst { site, importId } = parsed.data.params;const { events, isLastBatch } = parsed.data.body;- const siteId = Number(site);const userHasAccess = await getUserHasAdminAccessToSite(request, site);if (!userHasAccess) {@@ -52,14 +51,14 @@ export async function batchImportEvents(request: FastifyRequest<BatchImportRequereturn reply.status(404).send({ error: "Import not found" });}- if (importRecord.siteId !== siteId) {+ if (importRecord.siteId !== site) {return reply.status(400).send({ error: "Import does not belong to this site" });}const [siteRecord] = await db.select({ organizationId: sites.organizationId }).from(sites)- .where(eq(sites.siteId, siteId))+ .where(eq(sites.siteId, site)).limit(1);if (!siteRecord || !siteRecord.organizationId) {diff --git a/server/src/services/import/mappings/umami.ts b/server/src/services/import/mappings/umami.tsindex 8464335d0..6b60eb851 100644--- a/server/src/services/import/mappings/umami.ts+++ b/server/src/services/import/mappings/umami.ts@@ -28,7 +28,7 @@ export interface UmamiEvent {// utm_content: string; // Ignore, part of url_query// utm_term: string; // Ignore, part of url_queryreferrer_path: string;- referrer_query: string;+ // referrer_query: string; // Ignorereferrer_domain: string;page_title: string;@@ -136,10 +136,6 @@ export class UmamiImportMapper {.max(2048).transform(querystring => (querystring ? `?${querystring}` : "")),referrer_path: z.string().max(2048),- referrer_query: z- .string()- .max(2048)- .transform(querystring => (querystring ? `?${querystring}` : "")),referrer_domain: z.string().max(253)@@ -154,7 +150,7 @@ export class UmamiImportMapper {static readonly umamiEventKeyOnlySchema = deriveKeyOnlySchema(UmamiImportMapper.umamiEventSchema);- static transform(events: UmamiEvent[], site: string, importId: string): RybbitEvent[] {+ static transform(events: UmamiEvent[], site: number, importId: string): RybbitEvent[] {return events.reduce<RybbitEvent[]>((acc, event) => {const parsed = UmamiImportMapper.umamiEventSchema.safeParse(event);if (!parsed.success) {@@ -162,11 +158,11 @@ export class UmamiImportMapper {}const data = parsed.data;- const referrer = data.referrer_domain + data.referrer_path + data.referrer_query;+ const referrer = data.referrer_domain + data.referrer_path;const [screenWidth, screenHeight] = data.screen ? data.screen.split("x") : ["0", "0"];acc.push({- site_id: Number(site),+ site_id: site,timestamp: data.created_at,session_id: data.session_id,user_id: data.distinct_id,@@ -176,7 +172,7 @@ export class UmamiImportMapper {url_parameters: getAllUrlParams(data.url_query),page_title: data.page_title,referrer: clearSelfReferrer(referrer, data.hostname.replace(/^www\./, "")),- channel: getChannel(referrer, data.referrer_query, data.hostname),+ channel: getChannel(referrer, data.url_query, data.hostname),browser: data.browser,browser_version: "",operating_system: data.os,