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.

stashed some changes + added console log to middleware

Steven Tey8b50dd0899a9
diff --git a/components/home/link-card.tsx b/components/home/link-card.tsx
index 22e7cade56..d30cb38fb0 100644
--- a/components/home/link-card.tsx
+++ b/components/home/link-card.tsx
@@ -8,6 +8,7 @@ import { fetcher, nFormatter, linkConstructor } from "@/lib/utils";
import Link from "next/link";
import { useStatsContext } from "@/components/stats/context";
import { motion } from "framer-motion";
+import { FRAMER_MOTION_LIST_ITEM_VARIANTS } from "@/lib/constants";
export default function LinkCard({
_key: key,
@@ -48,10 +49,7 @@ export default function LinkCard({
return (
<motion.li
- variants={{
- hidden: { scale: 0.8, opacity: 0 },
- show: { scale: 1, opacity: 1, transition: { type: "spring" } },
- }}
+ variants={FRAMER_MOTION_LIST_ITEM_VARIANTS}
className="flex items-center border border-gray-200 dark:border-gray-600 hover:border-black dark:hover:border-white p-3 rounded-md transition-all"
>
<BlurImage
diff --git a/components/home/placeholder-card.tsx b/components/home/placeholder-card.tsx
index 54f8f30dd1..edbb9bebf8 100644
--- a/components/home/placeholder-card.tsx
+++ b/components/home/placeholder-card.tsx
@@ -1,12 +1,10 @@
import { motion } from "framer-motion";
+import { FRAMER_MOTION_LIST_ITEM_VARIANTS } from "@/lib/constants";
export default function PlaceholderCard() {
return (
<motion.li
- variants={{
- hidden: { scale: 0.8, opacity: 0 },
- show: { scale: 1, opacity: 1, transition: { type: "spring" } },
- }}
+ variants={FRAMER_MOTION_LIST_ITEM_VARIANTS}
className="flex items-center border border-gray-200 dark:border-gray-600 hover:border-black dark:hover:border-white p-3 rounded-md transition-all"
>
<div className="w-10 h-10 rounded-full mr-2 bg-gray-200 dark:bg-gray-600 animate-pulse" />
diff --git a/lib/constants.ts b/lib/constants.ts
index 54c5e7a7c5..b2899cb15b 100644
--- a/lib/constants.ts
+++ b/lib/constants.ts
@@ -8,6 +8,11 @@ export const LOCALHOST_GEO_DATA = {
export const INTERVALS = ["1h", "24h", "7d", "30d"];
+export const FRAMER_MOTION_LIST_ITEM_VARIANTS = {
+ hidden: { scale: 0.8, opacity: 0 },
+ show: { scale: 1, opacity: 1, transition: { type: "spring" } },
+};
+
export const COUNTRIES: { [key: string]: string } = {
AF: "Afghanistan",
AL: "Albania",
diff --git a/lib/stats.ts b/lib/stats.ts
index 70b84ac84e..3fa1697582 100644
--- a/lib/stats.ts
+++ b/lib/stats.ts
@@ -9,6 +9,7 @@ export interface RawStatsProps {
export interface StatsProps {
key: string;
+ interval: IntervalProps;
totalClicks: number;
clicksData: { start: number; end: number; count: number }[];
locationData: {
@@ -17,7 +18,7 @@ export interface StatsProps {
city: string;
region: string;
}[];
- browserData: { browser: string; count: number }[];
+ deviceData: { device: string; browser: string; os: string }[];
}
export type IntervalProps = "1h" | "24h" | "7d" | "30d";
@@ -116,32 +117,22 @@ export function processData(
};
});
- const browserData =
- data.length > 0
- ? data.reduce((acc, d) => {
- const browser = d.ua?.browser?.name;
- // @ts-ignore
- const count = acc[browser] || 0;
- // @ts-ignore
- acc[browser] = count + 1;
- return acc;
- }, {})
- : {};
-
- const browserDataArray = Object.entries(browserData).map(
- ([browser, count]) => ({
- browser,
- count,
- })
- );
+ const deviceData = data.map(({ ua }) => {
+ const { device, browser, os } = ua || {};
+ return {
+ device: device?.type || "Unknown",
+ browser: browser?.name || "Unknown",
+ os: os?.name || "Unknown",
+ };
+ });
return {
key,
+ interval: interval || "7d",
totalClicks: data.length,
clicksData,
locationData,
- // @ts-ignore
- browserData: browserDataArray,
+ deviceData,
};
}
@@ -178,6 +169,33 @@ export const processLocationData = (
.sort((a, b) => b.count - a.count);
};
+export type DeviceType = "size" | "browser" | "os";
+
+// export const processDeviceData = (
+// data: StatsProps["deviceData"],
+// type: LocationType
+// ): LocationStatsProps[] => {
+// const countryCodeMap: { [key: string]: string } = {};
+
+// const results =
+// data && data.length > 0
+// ? data.reduce<Record<string, number>>((acc, d) => {
+// const count = acc[d[type]] || 0;
+// acc[d[type]] = count + 1;
+// countryCodeMap[d[type]] = d.countryCode;
+// return acc;
+// }, {})
+// : {};
+
+// return Object.entries(results)
+// .map(([item, count]) => ({
+// display: item,
+// code: countryCodeMap[item],
+// count,
+// }))
+// .sort((a, b) => b.count - a.count);
+// };
+
export const dummyData: StatsProps = {
key: "test",
totalClicks: 100,
diff --git a/middleware.ts b/middleware.ts
index 5b06feb2ca..158f09271f 100644
--- a/middleware.ts
+++ b/middleware.ts
@@ -15,6 +15,8 @@ export default async function middleware(req: NextRequest, ev: NextFetchEvent) {
let hostname = req.headers.get("host");
if (hostname === "localhost:3000") hostname = "dub.sh";
+ console.log(userAgent(req));
+
const path = req.nextUrl.pathname;
const key = path.split("/")[1];
if (