Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

clean up unused code

Carl-Gerhard Lindesvärd8ff317b32d9e
diff --git a/apps/api/src/utils/parseReferrer.ts b/apps/api/src/utils/parseReferrer.ts
deleted file mode 100644
index adec1df98..000000000
--- a/apps/api/src/utils/parseReferrer.ts
+++ /dev/null
@@ -1,58 +0,0 @@
-import { stripTrailingSlash } from '@openpanel/common';
-
-import referrers from '../referrers';
-
-function getHostname(url: string | undefined) {
- if (!url) {
- return '';
- }
-
- try {
- return new URL(url).hostname;
- } catch (e) {
- return '';
- }
-}
-
-export function parseReferrer(url: string | undefined) {
- const hostname = getHostname(url);
- const match = referrers[hostname] ?? referrers[hostname.replace('www.', '')];
-
- return {
- name: match?.name ?? '',
- type: match?.type ?? 'unknown',
- url: stripTrailingSlash(url ?? ''),
- };
-}
-
-export function getReferrerWithQuery(
- query: Record<string, string> | undefined
-) {
- if (!query) {
- return null;
- }
-
- 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()
- );
-
- if (match) {
- return {
- name: match.name,
- type: match.type,
- url: '',
- };
- }
-
- return {
- name: source,
- type: 'unknown',
- url: '',
- };
-}
diff --git a/apps/api/src/utils/url.ts b/apps/api/src/utils/url.ts
deleted file mode 100644
index c6d3723db..000000000
--- a/apps/api/src/utils/url.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-export function parseSearchParams(
- params: URLSearchParams
-): Record<string, string> | undefined {
- const result: Record<string, string> = {};
- for (const [key, value] of params.entries()) {
- result[key] = value;
- }
- return Object.keys(result).length ? result : undefined;
-}
-
-export function parsePath(path?: string): {
- query?: Record<string, string>;
- path: string;
- hash?: string;
-} {
- if (!path) {
- return {
- path: '',
- };
- }
-
- try {
- const url = new URL(path);
- return {
- query: parseSearchParams(url.searchParams),
- path: url.pathname,
- hash: url.hash || undefined,
- };
- } catch (error) {
- return {
- path,
- };
- }
-}
-
-export function isSameDomain(
- url1: string | undefined,
- url2: string | undefined
-) {
- if (!url1 || !url2) {
- return false;
- }
- try {
- return new URL(url1).hostname === new URL(url2).hostname;
- } catch (e) {
- return false;
- }
-}