diff --git a/app/components/analytics/GeoAnalytics.tsx b/app/components/analytics/GeoAnalytics.tsx
index 2fedf1d..ae58ab3 100644
--- a/app/components/analytics/GeoAnalytics.tsx
+++ b/app/components/analytics/GeoAnalytics.tsx
@@ -27,7 +27,7 @@ export default function GeoAnalytics({ data }: GeoAnalyticsProps) {
|
- Location
+ IP Address
|
Visits
@@ -41,30 +41,38 @@ export default function GeoAnalytics({ data }: GeoAnalyticsProps) {
|
- {sortedData.map((item, index) => (
-
- |
- {item.location || 'Unknown'}
- |
-
- {formatNumber(item.visits)}
- |
-
- {formatNumber(item.visitors)}
- |
-
-
-
-
+ {sortedData.length > 0 ? (
+ sortedData.map((item, index) => (
+
+ |
+ {item.location || 'Unknown'}
+ |
+
+ {formatNumber(item.visits)}
+ |
+
+ {formatNumber(item.visitors)}
+ |
+
+
+
+ {formatPercent(item.percentage)}%
- {formatPercent(item.percentage)}%
-
+ |
+
+ ))
+ ) : (
+
+ |
+ No IP data available
|
- ))}
+ )}
|
diff --git a/app/page.tsx b/app/page.tsx
index 9d92191..0ced34d 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -763,7 +763,7 @@ export default function HomePage() {
Geographic Distribution
-
+
>
);
diff --git a/lib/analytics.ts b/lib/analytics.ts
index 0cd55af..e451723 100644
--- a/lib/analytics.ts
+++ b/lib/analytics.ts
@@ -215,23 +215,22 @@ export async function getGeoAnalytics(params: {
startTime?: string;
endTime?: string;
linkId?: string;
- groupBy?: 'country' | 'city';
teamIds?: string[];
projectIds?: string[];
tagIds?: string[];
}): Promise {
const filter = buildFilter(params);
- const groupByField = params.groupBy === 'city' ? 'city' : 'country';
+ // Use IP address as the grouping field
const query = `
SELECT
- ${groupByField} as location,
+ ip_address as location,
count() as visits,
uniq(ip_address) as visitors,
count() * 100.0 / sum(count()) OVER () as percentage
FROM events
${filter}
- GROUP BY ${groupByField}
+ GROUP BY location
HAVING location != ''
ORDER BY visits DESC
LIMIT 20