Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Minor fixes

Tim Wilson77f1044bed39
diff --git a/apps/web/lib/analytics/utils.ts b/apps/web/lib/analytics/utils.ts
index 6cc34d47a0..3e645110a9 100644
--- a/apps/web/lib/analytics/utils.ts
+++ b/apps/web/lib/analytics/utils.ts
@@ -4,6 +4,7 @@ import { DubApiError } from "../api/errors";
export const editQueryString = (
queryString: string,
data: Record<string, string>,
+ del?: string | string[],
) => {
const searchParams = new URLSearchParams(queryString);
@@ -11,6 +12,9 @@ export const editQueryString = (
searchParams.set(key, data[key]);
}
+ if (del)
+ (Array.isArray(del) ? del : [del]).forEach((d) => searchParams.delete(d));
+
return searchParams.toString();
};
diff --git a/apps/web/ui/analytics/toggle.tsx b/apps/web/ui/analytics/toggle.tsx
index ee617e347b..b56e594770 100644
--- a/apps/web/ui/analytics/toggle.tsx
+++ b/apps/web/ui/analytics/toggle.tsx
@@ -128,72 +128,81 @@ export default function Toggle() {
key: "country",
icon: Flag,
label: "Country",
- options: countries?.map(({ country, count }) => ({
- value: country,
- label: COUNTRIES[country],
- icon: (
- <img
- alt={country}
- src={`https://flag.vercel.app/m/${country}.svg`}
- className="h-2.5 w-4"
- />
- ),
- right: count,
- })),
+ options:
+ countries?.map(({ country, count }) => ({
+ value: country,
+ label: COUNTRIES[country],
+ icon: (
+ <img
+ alt={country}
+ src={`https://flag.vercel.app/m/${country}.svg`}
+ className="h-2.5 w-4"
+ />
+ ),
+ right: count,
+ })) ?? null,
},
{
key: "city",
icon: Building2,
label: "City",
- options: cities?.map(({ city, country, count }) => ({
- value: city,
- label: city,
- icon: (
- <img
- alt={country}
- src={`https://flag.vercel.app/m/${country}.svg`}
- className="h-2.5 w-4"
- />
- ),
- right: count,
- })),
+ options:
+ cities?.map(({ city, country, count }) => ({
+ value: city,
+ label: city,
+ icon: (
+ <img
+ alt={country}
+ src={`https://flag.vercel.app/m/${country}.svg`}
+ className="h-2.5 w-4"
+ />
+ ),
+ right: count,
+ })) ?? null,
},
{
key: "device",
icon: Smartphone,
label: "Device",
- options: devices?.map(({ device, count }) => ({
- value: device,
- label: device,
- icon: (
- <DeviceIcon display={device} tab="devices" className="h-4 w-4" />
- ),
- right: count,
- })),
+ options:
+ devices?.map(({ device, count }) => ({
+ value: device,
+ label: device,
+ icon: (
+ <DeviceIcon display={device} tab="devices" className="h-4 w-4" />
+ ),
+ right: count,
+ })) ?? null,
},
{
key: "browser",
icon: AppWindow,
label: "Browser",
- options: browsers?.map(({ browser, count }) => ({
- value: browser,
- label: browser,
- icon: (
- <DeviceIcon display={browser} tab="browsers" className="h-4 w-4" />
- ),
- right: count,
- })),
+ options:
+ browsers?.map(({ browser, count }) => ({
+ value: browser,
+ label: browser,
+ icon: (
+ <DeviceIcon
+ display={browser}
+ tab="browsers"
+ className="h-4 w-4"
+ />
+ ),
+ right: count,
+ })) ?? null,
},
{
key: "os",
icon: Box,
label: "OS",
- options: os?.map(({ os, count }) => ({
- value: os,
- label: os,
- icon: <DeviceIcon display={os} tab="os" className="h-4 w-4" />,
- right: count,
- })),
+ options:
+ os?.map(({ os, count }) => ({
+ value: os,
+ label: os,
+ icon: <DeviceIcon display={os} tab="os" className="h-4 w-4" />,
+ right: count,
+ })) ?? null,
},
],
[domains, tags],
diff --git a/apps/web/ui/analytics/utils.ts b/apps/web/ui/analytics/utils.ts
index 7bc58329cb..c335054c5a 100644
--- a/apps/web/ui/analytics/utils.ts
+++ b/apps/web/ui/analytics/utils.ts
@@ -1,3 +1,4 @@
+import { SINGULAR_ANALYTICS_ENDPOINTS } from "@/lib/analytics/constants";
import { AnalyticsGroupByOptions } from "@/lib/analytics/types";
import { editQueryString } from "@/lib/analytics/utils";
import { fetcher } from "@dub/utils";
@@ -7,14 +8,20 @@ import { AnalyticsContext } from ".";
export function useAnalyticsFilterOption(
groupBy: AnalyticsGroupByOptions,
-): ({ count?: number } & Record<string, any>) | null {
+): ({ count?: number } & Record<string, any>)[] | null {
const { baseApiPath, queryString, selectedTab, requiresUpgrade } =
useContext(AnalyticsContext);
+ const singular = SINGULAR_ANALYTICS_ENDPOINTS[groupBy];
+
const { data } = useSWR<Record<string, any>[]>(
- `${baseApiPath}?${editQueryString(queryString, {
- groupBy,
- })}`,
+ `${baseApiPath}?${editQueryString(
+ queryString,
+ {
+ groupBy,
+ },
+ singular ?? undefined,
+ )}`,
fetcher,
{
shouldRetryOnError: !requiresUpgrade,