Skip to content

Commit 45c6355

Browse files
committed
Add IP address support to user info and display on user page
- Updated UserInfo type to include an optional IP address field. - Enhanced UserPage component to conditionally display the user's IP address using a Badge component. - Modified getUserInfo API to retrieve and return the user's IP address, ensuring comprehensive analytics data is available.
1 parent f3ba8e7 commit 45c6355

3 files changed

Lines changed: 21 additions & 8 deletions

File tree

client/src/api/analytics/userInfo.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export type UserInfo = {
1919
first_seen: string;
2020
pageviews: number;
2121
events: number;
22+
ip?: string;
2223
};
2324

2425
export function useUserInfo(siteId: number, userId: string) {

client/src/app/[site]/user/[userId]/page.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { OperatingSystem } from "../../components/shared/icons/OperatingSystem";
2929
import { VisitCalendar } from "./components/Calendar";
3030
import { Avatar } from "../../../../components/Avatar";
3131
import { MobileSidebar } from "../../components/Sidebar/MobileSidebar";
32+
import { Badge } from "../../../../components/ui/badge";
3233

3334
export default function UserPage() {
3435
useSetPageTitle("Rybbit · User");
@@ -54,12 +55,20 @@ export default function UserPage() {
5455
Back to Users
5556
</Button>
5657
<div className="mb-4">
57-
<h1 className="text-2xl font-bold mb-4 flex items-center gap-2">
58-
<div>
59-
<MobileSidebar />
58+
<h1 className="mb-4 flex items-center gap-2 justify-between">
59+
<div className="text-2xl font-bold flex items-center gap-2">
60+
<div>
61+
<MobileSidebar />
62+
</div>
63+
64+
<Avatar size={40} name={userId as string} />
65+
{userId?.slice(0, 10)}
6066
</div>
61-
<Avatar size={40} name={userId as string} />
62-
{userId?.slice(0, 10)}
67+
{data?.ip && (
68+
<Badge variant="outline" className="flex gap-1 text-neutral-300">
69+
IP: <span className="text-neutral-100">{data?.ip}</span>
70+
</Badge>
71+
)}
6372
</h1>
6473
<div className="bg-neutral-900 p-3 rounded-lg flex flex-col gap-1 border border-neutral-750 text-sm mb-3">
6574
{isLoading ? (
@@ -124,7 +133,7 @@ export default function UserPage() {
124133
{data?.operating_system}
125134
{data?.operating_system_version && <span className="ml-1">v{data?.operating_system_version}</span>}
126135
</div>
127-
<span className="text-neutral-100">Screen Size:</span>
136+
<span className="text-neutral-100">Screen:</span>
128137
<div className="flex gap-1 text-neutral-300">
129138
{data?.screen_width} x {data?.screen_height}
130139
</div>

server/src/api/analytics/getUserInfo.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ interface UserPageviewData {
2020
first_seen: string;
2121
pageviews: number;
2222
events: number;
23+
ip: string;
2324
}
2425

2526
export async function getUserInfo(
@@ -58,7 +59,8 @@ export async function getUserInfo(
5859
argMinIf(pathname, timestamp, type = 'pageview') AS entry_page,
5960
argMaxIf(pathname, timestamp, type = 'pageview') AS exit_page,
6061
countIf(type = 'pageview') AS pageviews,
61-
countIf(type = 'custom_event') AS events
62+
countIf(type = 'custom_event') AS events,
63+
argMax(ip, timestamp) AS ip
6264
FROM
6365
events
6466
WHERE
@@ -87,7 +89,8 @@ export async function getUserInfo(
8789
MAX(session_end) AS last_seen,
8890
MIN(session_start) AS first_seen,
8991
SUM(pageviews) AS pageviews,
90-
SUM(events) AS events
92+
SUM(events) AS events,
93+
any(ip) AS ip
9194
FROM
9295
sessions
9396
`,

0 commit comments

Comments
 (0)