OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
api: improve ref parser
Carl-Gerhard Lindesvärd73006316306c
diff --git a/apps/api/src/controllers/event.controller.ts b/apps/api/src/controllers/event.controller.tsindex 2f6e12212..6d50f1288 100644--- a/apps/api/src/controllers/event.controller.ts+++ b/apps/api/src/controllers/event.controller.ts@@ -243,8 +243,8 @@ export async function postEvent(duration: 0,path: path,referrer: referrer?.url,- referrerName: referrer?.name ?? utmReferrer?.name ?? '',- referrerType: referrer?.type ?? utmReferrer?.type ?? '',+ referrerName: referrer?.name || utmReferrer?.name || '',+ referrerType: referrer?.type || utmReferrer?.type || '',profile: undefined,meta: undefined,};diff --git a/apps/api/src/utils/parseReferrer.ts b/apps/api/src/utils/parseReferrer.tsindex 973582280..adec1df98 100644--- a/apps/api/src/utils/parseReferrer.ts+++ b/apps/api/src/utils/parseReferrer.ts@@ -34,17 +34,25 @@ export function getReferrerWithQuery(const source = query.utm_source ?? query.ref ?? query.utm_referrer ?? '';+ if (source === '') {+ return null;+ }+const match = Object.values(referrers).find(- (referrer) => referrer.name.toLowerCase() === source?.toLowerCase()+ (referrer) => referrer.name.toLowerCase() === source.toLowerCase());- if (!match) {- return null;+ if (match) {+ return {+ name: match.name,+ type: match.type,+ url: '',+ };}return {- name: match.name,- type: match.type,+ name: source,+ type: 'unknown',url: '',};}