Skip to content

Commit ce9ab00

Browse files
committed
cleanup data & processing in audience tab
1 parent 209c62e commit ce9ab00

File tree

21 files changed

+163
-175
lines changed

21 files changed

+163
-175
lines changed

apps/api/src/query/builders/devices.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ export const DevicesBuilders: Record<string, SimpleQueryConfig> = {
134134
label: 'Visitors',
135135
description: 'Unique visitors with this resolution',
136136
},
137+
{
138+
name: 'percentage',
139+
type: 'number',
140+
label: 'Traffic %',
141+
description: 'Percentage of total traffic',
142+
unit: '%',
143+
},
137144
],
138145
default_visualization: 'table',
139146
supports_granularity: ['hour', 'day'],
@@ -144,6 +151,7 @@ export const DevicesBuilders: Record<string, SimpleQueryConfig> = {
144151
'screen_resolution as name',
145152
'COUNT(*) as pageviews',
146153
'COUNT(DISTINCT anonymous_id) as visitors',
154+
'ROUND((COUNT(*) / SUM(COUNT(*)) OVER()) * 100, 2) as percentage',
147155
],
148156
where: ["screen_resolution != ''", "event_name = 'screen_view'"],
149157
groupBy: ['screen_resolution'],
@@ -349,9 +357,11 @@ export const DevicesBuilders: Record<string, SimpleQueryConfig> = {
349357
browser_versions: {
350358
table: Analytics.events,
351359
fields: [
352-
"CONCAT(browser_name, ' ', browser_version) as name",
360+
'browser_name',
361+
'browser_version',
353362
'COUNT(*) as pageviews',
354363
'COUNT(DISTINCT anonymous_id) as visitors',
364+
'ROUND((COUNT(*) / SUM(COUNT(*)) OVER()) * 100, 2) as percentage',
355365
],
356366
where: [
357367
"browser_name != ''",

apps/api/src/query/builders/geo.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,18 @@ export const GeoBuilders: Record<string, SimpleQueryConfig> = {
9797
table: Analytics.events,
9898
fields: [
9999
'region as name',
100+
'country',
100101
'COUNT(*) as pageviews',
101102
'COUNT(DISTINCT anonymous_id) as visitors',
102103
'ROUND((COUNT(*) / SUM(COUNT(*)) OVER()) * 100, 2) as percentage',
103104
],
104105
where: ["region != ''", "event_name = 'screen_view'"],
105-
groupBy: ['region'],
106+
groupBy: ['region', 'country'],
106107
orderBy: 'pageviews DESC',
107108
limit: 100,
108109
timeField: 'time',
109110
customizable: true,
111+
plugins: { normalizeGeo: true, deduplicateGeo: true },
110112
},
111113

112114
timezone: {
@@ -182,15 +184,17 @@ export const GeoBuilders: Record<string, SimpleQueryConfig> = {
182184
table: Analytics.events,
183185
fields: [
184186
'city as name',
187+
'country',
185188
'COUNT(*) as pageviews',
186189
'COUNT(DISTINCT anonymous_id) as visitors',
187190
'ROUND((COUNT(*) / SUM(COUNT(*)) OVER()) * 100, 2) as percentage',
188191
],
189192
where: ["city != ''", "event_name = 'screen_view'"],
190-
groupBy: ['city'],
193+
groupBy: ['city', 'country'],
191194
orderBy: 'pageviews DESC',
192195
limit: 100,
193196
timeField: 'time',
194197
customizable: true,
198+
plugins: { normalizeGeo: true, deduplicateGeo: true },
195199
},
196200
};

apps/api/src/query/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ function applyReferrerParsing(
190190

191191
function applyGeoNormalization(data: DataRow[]): DataRow[] {
192192
return data.map((row) => {
193-
const currentName = getString(row.name) || getString(row.country);
193+
const currentName = getString(row.country) || getString(row.name);
194194
if (!currentName) {
195195
return row;
196196
}

apps/dashboard/app/(main)/observability/database/[id]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '@phosphor-icons/react';
1111
import type { ColumnDef } from '@tanstack/react-table';
1212
import { use } from 'react';
13-
import { DataTable } from '@/components/analytics/data-table';
13+
import { DataTable } from '@/components/table/data-table';
1414
import { Badge } from '@/components/ui/badge';
1515
import { Card } from '@/components/ui/card';
1616
import { useDbConnection } from '@/hooks/use-db-connections';

apps/dashboard/app/(main)/observability/database/[id]/performance/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
WarningIcon,
1212
} from '@phosphor-icons/react';
1313
import { use, useCallback, useMemo, useState } from 'react';
14-
import { DataTable, StatCard } from '@/components/analytics';
14+
import { StatCard } from '@/components/analytics';
15+
import { DataTable } from '@/components/table/data-table';
1516
import { Alert, AlertDescription } from '@/components/ui/alert';
1617
import { Button } from '@/components/ui/button';
1718
import {

0 commit comments

Comments
 (0)