🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
More improvements
Edward Cui35a127988b98
diff --git a/server/src/types/import.ts b/server/src/types/import.tsindex babc79e91..531e1a0a0 100644--- a/server/src/types/import.ts+++ b/server/src/types/import.ts@@ -2,15 +2,23 @@ export const importInitiationQueue = "import-initiation";export const processImportChunkQueue = "process-import-chunk";-export interface ImportInitiationJob {- tempFilePath: string;+interface ImportJob {site: string;importId: string;source: "umami";}-export interface ImportMapping<T> {- transform(row: T, headers: string[]): RybbitEvent;+export interface ImportInitiationJob extends ImportJob {+ tempFilePath: string;+}++export interface ProcessImportChunkJob<T> extends ImportJob {+ chunk: T[];+ chunkNumber: number;+}++export interface ImportMapper<T> {+ transform(rows: T, site: string, importId: string): RybbitEvent[];}interface RybbitEvent {diff --git a/server/src/workers/mappings/umami.ts b/server/src/workers/mappings/umami.tsindex f939141d8..dc329b50d 100644--- a/server/src/workers/mappings/umami.ts+++ b/server/src/workers/mappings/umami.ts@@ -1,6 +1,6 @@import { ImportMapper } from "../../types/import.js";-interface UmamiEvent {+export interface UmamiEvent {website_id: string; // Ignoresession_id: string;visit_id: string; // ?@@ -82,57 +82,66 @@ export const umamiHeaders = ["job_id"];-export class UmamiImportMapper implements ImportMapper<UmamiEvent> {- transform(row: UmamiEvent, headers: string[]): any {- const [screenWidth, screenHeight] = row.screen?.split("x") || [null, null];+export class UmamiImportMapper implements ImportMapper<UmamiEvent[]> {+ transform(rows: UmamiEvent[], site: string, importId: string) {+ return rows.map(row => {+ const [screenWidth, screenHeight] = row.screen?.split("x") || [0, 0];- const referrer = row.referrer_domain- ? `${row.referrer_domain}${row.referrer_path || ""}${+ const referrer = row.referrer_domain+ ? `${row.referrer_domain}${row.referrer_path || ""}${row.referrer_query || ""}`- : null;+ : "";- const props: Record<string, any> = {};- if (row.utm_source) props.utm_source = row.utm_source;- if (row.utm_medium) props.utm_medium = row.utm_medium;- if (row.utm_campaign) props.utm_campaign = row.utm_campaign;- if (row.utm_content) props.utm_content = row.utm_content;- if (row.utm_term) props.utm_term = row.utm_term;- if (row.gclid) props.gclid = row.gclid;- if (row.fbclid) props.fbclid = row.fbclid;- if (row.msclkid) props.msclkid = row.msclkid;- if (row.ttclid) props.ttclid = row.ttclid;- if (row.li_fat_id) props.li_fat_id = row.li_fat_id;- if (row.twclid) props.twclid = row.twclid;- if (row.tag) props.tag = row.tag;+ const props: Record<string, any> = {};+ if (row.utm_source) props.utm_source = row.utm_source;+ if (row.utm_medium) props.utm_medium = row.utm_medium;+ if (row.utm_campaign) props.utm_campaign = row.utm_campaign;+ if (row.utm_content) props.utm_content = row.utm_content;+ if (row.utm_term) props.utm_term = row.utm_term;+ if (row.gclid) props.gclid = row.gclid;+ if (row.fbclid) props.fbclid = row.fbclid;+ if (row.msclkid) props.msclkid = row.msclkid;+ if (row.ttclid) props.ttclid = row.ttclid;+ if (row.li_fat_id) props.li_fat_id = row.li_fat_id;+ if (row.twclid) props.twclid = row.twclid;+ if (row.tag) props.tag = row.tag;- // Umami: 1 for pageview, 2 for custom event- const eventType =- row.event_type === "2" || row.event_type === 2- ? "custom_event"- : "pageview";+ // Umami: 1 for pageview, 2 for custom event+ const eventType =+ row.event_type === "2" || row.event_type === 2+ ? "custom_event"+ : "pageview";- return {- timestamp: row.created_at,- session_id: row.session_id,- user_id: row.distinct_id,- hostname: row.hostname,- pathname: row.url_path,- querystring: row.url_query,- page_title: row.page_title,- referrer: referrer,- browser: row.browser,- operating_system: row.os,- language: row.language,- country: row.country,- region: row.region,- city: row.city,- screen_width: screenWidth ? parseInt(screenWidth, 10) : null,- screen_height: screenHeight ? parseInt(screenHeight, 10) : null,- device_type: row.device,- type: eventType,- event_name: row.event_name,- props: JSON.stringify(props),- };+ return {+ site_id: Number(site),+ timestamp: row.created_at,+ session_id: row.session_id,+ user_id: row.distinct_id,+ hostname: row.hostname,+ pathname: row.url_path,+ querystring: row.url_query,+ url_parameters: {placeholder: "a"},+ page_title: row.page_title,+ referrer: referrer,+ channel: "placeholder",+ browser: row.browser,+ browser_version: "placeholder",+ operating_system: row.os,+ operating_system_version: "placeholder",+ language: row.language,+ country: row.country,+ region: row.region,+ city: row.city,+ lat: 0, // placeholder+ lon: 0, // placeholder+ screen_width: screenWidth ? parseInt(screenWidth, 10) : 0,+ screen_height: screenHeight ? parseInt(screenHeight, 10) : 0,+ device_type: row.device,+ type: eventType,+ event_name: row.event_name,+ props: props,+ };+ });}}