Skip to content

Commit 12085d2

Browse files
committed
fix: longer event id for events with long paths
1 parent 7cdbadb commit 12085d2

File tree

3 files changed

+59
-57
lines changed

3 files changed

+59
-57
lines changed

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

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,7 @@ export const GeoBuilders: Record<string, SimpleQueryConfig> = {
7070
customizable: true
7171
},
7272

73-
countries: {
74-
table: 'analytics.events',
75-
fields: [
76-
'country as name',
77-
'COUNT(*) as pageviews',
78-
'COUNT(DISTINCT anonymous_id) as visitors',
79-
'ROUND((COUNT(*) / SUM(COUNT(*)) OVER()) * 100, 2) as percentage'
80-
],
81-
where: ['country != \'\'', 'event_name = \'screen_view\''],
82-
groupBy: ['country'],
83-
orderBy: 'pageviews DESC',
84-
limit: 25,
85-
timeField: 'time',
86-
allowedFilters: ['country', 'path', 'device_type', 'browser_name'],
87-
customizable: true,
88-
plugins: { normalizeGeo: true, deduplicateGeo: true }
89-
},
90-
91-
cities: {
73+
city: {
9274
table: 'analytics.events',
9375
fields: [
9476
'city as name',
@@ -99,42 +81,9 @@ export const GeoBuilders: Record<string, SimpleQueryConfig> = {
9981
where: ['city != \'\'', 'event_name = \'screen_view\''],
10082
groupBy: ['city'],
10183
orderBy: 'pageviews DESC',
102-
limit: 25,
103-
timeField: 'time',
104-
allowedFilters: ['city', 'country', 'path', 'device_type'],
105-
customizable: true
106-
},
107-
108-
regions: {
109-
table: 'analytics.events',
110-
fields: [
111-
'region as name',
112-
'COUNT(*) as pageviews',
113-
'COUNT(DISTINCT anonymous_id) as visitors',
114-
'ROUND((COUNT(*) / SUM(COUNT(*)) OVER()) * 100, 2) as percentage'
115-
],
116-
where: ['region != \'\'', 'event_name = \'screen_view\''],
117-
groupBy: ['region'],
118-
orderBy: 'pageviews DESC',
119-
limit: 25,
120-
timeField: 'time',
121-
allowedFilters: ['region', 'country', 'path', 'device_type'],
122-
customizable: true
123-
},
124-
125-
geo_time_series: {
126-
table: 'analytics.events',
127-
fields: [
128-
'toDate(time) as date',
129-
'country',
130-
'COUNT(*) as pageviews',
131-
'COUNT(DISTINCT anonymous_id) as visitors'
132-
],
133-
where: ['country != \'\'', 'event_name = \'screen_view\''],
134-
groupBy: ['toDate(time)', 'country'],
135-
orderBy: 'date ASC, pageviews DESC',
84+
limit: 100,
13685
timeField: 'time',
137-
allowedFilters: ['country', 'city', 'region', 'path'],
86+
allowedFilters: ['country', 'path', 'device_type'],
13887
customizable: true
13988
}
14089
};

apps/basket/src/utils/event-schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const MAX_FUTURE_MS = 60 * 60 * 1000; // 1 hour
3535
const MIN_TIMESTAMP = 946684800000; // year 2000
3636

3737
export const analyticsEventSchema = z.object({
38-
eventId: z.string().max(128),
38+
eventId: z.string().max(512),
3939
name: z.string().min(1).max(128),
4040
anonymousId: z.string().nullable().optional(),
4141
sessionId: z.string().nullable().optional(),

apps/dashboard/app/(main)/websites/[id]/_components/tabs/audience-tab.tsx

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ interface ProcessedData {
8484
geographic: {
8585
countries: GeographicEntry[];
8686
regions: GeographicEntry[];
87+
cities: GeographicEntry[];
8788
timezones: GeographicEntry[];
8889
languages: GeographicEntry[];
8990
};
@@ -167,7 +168,7 @@ export function WebsiteAudienceTab({
167168
() => [
168169
{
169170
id: "geographic-data",
170-
parameters: ["country", "region", "timezone", "language"],
171+
parameters: ["country", "region", "city", "timezone", "language"],
171172
limit: 100,
172173
},
173174
{
@@ -227,7 +228,7 @@ export function WebsiteAudienceTab({
227228
const processedData = useMemo((): ProcessedData => {
228229
if (!batchResults?.length) {
229230
return {
230-
geographic: { countries: [], regions: [], timezones: [], languages: [] },
231+
geographic: { countries: [], regions: [], cities: [], timezones: [], languages: [] },
231232
device: {
232233
device_type: [],
233234
browser_name: [],
@@ -247,6 +248,7 @@ export function WebsiteAudienceTab({
247248
geographic: {
248249
countries: normalizeData(geographicResult?.data?.country || []),
249250
regions: normalizeData(geographicResult?.data?.region || []),
251+
cities: normalizeData(geographicResult?.data?.city || []),
250252
timezones: normalizeData(geographicResult?.data?.timezone || []),
251253
languages: normalizeData(geographicResult?.data?.language || []),
252254
},
@@ -644,6 +646,46 @@ export function WebsiteAudienceTab({
644646
[]
645647
);
646648

649+
// City specific columns with icon
650+
const cityColumns = useMemo(
651+
(): ColumnDef<GeographicEntry>[] => [
652+
{
653+
id: "name",
654+
accessorKey: "name",
655+
header: "City",
656+
cell: (info: CellContext<GeographicEntry, any>) => {
657+
const name = info.getValue() as string;
658+
return (
659+
<div className="flex items-center gap-2">
660+
<MapPin className="h-4 w-4 text-primary" />
661+
<span className="font-medium">{name}</span>
662+
</div>
663+
);
664+
},
665+
},
666+
{
667+
id: "visitors",
668+
accessorKey: "visitors",
669+
header: "Visitors",
670+
},
671+
{
672+
id: "pageviews",
673+
accessorKey: "pageviews",
674+
header: "Pageviews",
675+
},
676+
{
677+
id: "percentage",
678+
accessorKey: "percentage",
679+
header: "Share",
680+
cell: (info: CellContext<GeographicEntry, any>) => {
681+
const percentage = info.getValue() as number;
682+
return <PercentageBadge percentage={percentage} />;
683+
},
684+
},
685+
],
686+
[]
687+
);
688+
647689
// Prepare tabs for enhanced geographic data with unique keys
648690
const geographicTabs = useMemo(
649691
() => [
@@ -683,16 +725,27 @@ export function WebsiteAudienceTab({
683725
})),
684726
columns: languageColumns,
685727
},
728+
{
729+
id: "cities",
730+
label: "Cities",
731+
data: processedData.geographic.cities.map((item, index) => ({
732+
...item,
733+
_uniqueKey: `city-${item.name}-${index}`,
734+
})),
735+
columns: cityColumns,
736+
},
686737
],
687738
[
688739
processedData.geographic.countries,
689740
processedData.geographic.regions,
690741
processedData.geographic.timezones,
691742
processedData.geographic.languages,
743+
processedData.geographic.cities,
692744
countryColumns,
693745
geographicColumns,
694746
timezoneColumns,
695747
languageColumns,
748+
cityColumns,
696749
]
697750
);
698751

0 commit comments

Comments
 (0)