Skip to content

Commit ffa8d8d

Browse files
committed
Merge remote-tracking branch 'origin/dev' into dev
2 parents e8a933f + f659450 commit ffa8d8d

19 files changed

Lines changed: 11252 additions & 89 deletions

File tree

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
-- drop projections
2+
ALTER TABLE umami.website_event DROP PROJECTION website_event_url_path_projection;
3+
ALTER TABLE umami.website_event DROP PROJECTION website_event_referrer_domain_projection;
4+
5+
--drop view
6+
DROP TABLE umami.website_event_stats_hourly_mv;
7+
8+
-- rename columns
9+
ALTER TABLE umami.website_event RENAME COLUMN "subdivision1" TO "region";
10+
ALTER TABLE umami.website_event_stats_hourly RENAME COLUMN "subdivision1" TO "region";
11+
12+
-- drop columns
13+
ALTER TABLE umami.website_event DROP COLUMN "subdivision2";
14+
15+
-- recreate projections
16+
ALTER TABLE umami.website_event
17+
ADD PROJECTION website_event_url_path_projection (
18+
SELECT * ORDER BY toStartOfDay(created_at), website_id, url_path, created_at
19+
);
20+
21+
ALTER TABLE umami.website_event MATERIALIZE PROJECTION website_event_url_path_projection;
22+
23+
ALTER TABLE umami.website_event
24+
ADD PROJECTION website_event_referrer_domain_projection (
25+
SELECT * ORDER BY toStartOfDay(created_at), website_id, referrer_domain, created_at
26+
);
27+
28+
ALTER TABLE umami.website_event MATERIALIZE PROJECTION website_event_referrer_domain_projection;
29+
30+
-- recreate view
31+
CREATE MATERIALIZED VIEW umami.website_event_stats_hourly_mv
32+
TO umami.website_event_stats_hourly
33+
AS
34+
SELECT
35+
website_id,
36+
session_id,
37+
visit_id,
38+
hostname,
39+
browser,
40+
os,
41+
device,
42+
screen,
43+
language,
44+
country,
45+
region,
46+
city,
47+
entry_url,
48+
exit_url,
49+
url_paths as url_path,
50+
url_query,
51+
utm_source,
52+
utm_medium,
53+
utm_campaign,
54+
utm_content,
55+
utm_term,
56+
referrer_domain,
57+
page_title,
58+
gclid,
59+
fbclid,
60+
msclkid,
61+
ttclid,
62+
li_fat_id,
63+
twclid,
64+
event_type,
65+
event_name,
66+
views,
67+
min_time,
68+
max_time,
69+
tag,
70+
timestamp as created_at
71+
FROM (SELECT
72+
website_id,
73+
session_id,
74+
visit_id,
75+
hostname,
76+
browser,
77+
os,
78+
device,
79+
screen,
80+
language,
81+
country,
82+
region,
83+
city,
84+
argMinState(url_path, created_at) entry_url,
85+
argMaxState(url_path, created_at) exit_url,
86+
arrayFilter(x -> x != '', groupArray(url_path)) as url_paths,
87+
arrayFilter(x -> x != '', groupArray(url_query)) url_query,
88+
arrayFilter(x -> x != '', groupArray(utm_source)) utm_source,
89+
arrayFilter(x -> x != '', groupArray(utm_medium)) utm_medium,
90+
arrayFilter(x -> x != '', groupArray(utm_campaign)) utm_campaign,
91+
arrayFilter(x -> x != '', groupArray(utm_content)) utm_content,
92+
arrayFilter(x -> x != '', groupArray(utm_term)) utm_term,
93+
arrayFilter(x -> x != '', groupArray(referrer_domain)) referrer_domain,
94+
arrayFilter(x -> x != '', groupArray(page_title)) page_title,
95+
arrayFilter(x -> x != '', groupArray(gclid)) gclid,
96+
arrayFilter(x -> x != '', groupArray(fbclid)) fbclid,
97+
arrayFilter(x -> x != '', groupArray(msclkid)) msclkid,
98+
arrayFilter(x -> x != '', groupArray(ttclid)) ttclid,
99+
arrayFilter(x -> x != '', groupArray(li_fat_id)) li_fat_id,
100+
arrayFilter(x -> x != '', groupArray(twclid)) twclid,
101+
event_type,
102+
if(event_type = 2, groupArray(event_name), []) event_name,
103+
sumIf(1, event_type = 1) views,
104+
min(created_at) min_time,
105+
max(created_at) max_time,
106+
arrayFilter(x -> x != '', groupArray(tag)) tag,
107+
toStartOfHour(created_at) timestamp
108+
FROM umami.website_event
109+
GROUP BY website_id,
110+
session_id,
111+
visit_id,
112+
hostname,
113+
browser,
114+
os,
115+
device,
116+
screen,
117+
language,
118+
country,
119+
region,
120+
city,
121+
event_type,
122+
timestamp);

db/clickhouse/schema.sql

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ CREATE TABLE umami.website_event
1313
screen LowCardinality(String),
1414
language LowCardinality(String),
1515
country LowCardinality(String),
16-
subdivision1 LowCardinality(String),
17-
subdivision2 LowCardinality(String),
16+
region LowCardinality(String),
1817
city String,
1918
--pageviews
2019
url_path String,
@@ -96,7 +95,7 @@ CREATE TABLE umami.website_event_stats_hourly
9695
screen LowCardinality(String),
9796
language LowCardinality(String),
9897
country LowCardinality(String),
99-
subdivision1 LowCardinality(String),
98+
region LowCardinality(String),
10099
city String,
101100
entry_url AggregateFunction(argMin, String, DateTime('UTC')),
102101
exit_url AggregateFunction(argMax, String, DateTime('UTC')),
@@ -148,7 +147,7 @@ SELECT
148147
screen,
149148
language,
150149
country,
151-
subdivision1,
150+
region,
152151
city,
153152
entry_url,
154153
exit_url,
@@ -185,7 +184,7 @@ FROM (SELECT
185184
screen,
186185
language,
187186
country,
188-
subdivision1,
187+
region,
189188
city,
190189
argMinState(url_path, created_at) entry_url,
191190
argMaxState(url_path, created_at) exit_url,
@@ -222,7 +221,7 @@ GROUP BY website_id,
222221
screen,
223222
language,
224223
country,
225-
subdivision1,
224+
region,
226225
city,
227226
event_type,
228227
timestamp);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-- AlterTable
2+
ALTER TABLE `website_event` ADD COLUMN `hostname` VARCHAR(100) NULL;
3+
4+
-- DataMigration
5+
UPDATE `website_event` w
6+
JOIN `session` s
7+
ON s.website_id = w.website_id
8+
and s.session_id = w.session_id
9+
SET w.hostname = s.hostname;
10+
11+
-- DropIndex
12+
DROP INDEX `session_website_id_created_at_hostname_idx` ON `session`;
13+
DROP INDEX `session_website_id_created_at_subdivision1_idx` ON `session`;
14+
15+
-- AlterTable
16+
ALTER TABLE `session` RENAME COLUMN `subdivision1` TO `region`;
17+
ALTER TABLE `session` DROP COLUMN `subdivision2`;
18+
ALTER TABLE `session` DROP COLUMN `hostname`;
19+
20+
-- CreateIndex
21+
CREATE INDEX `website_event_website_id_created_at_hostname_idx` ON `website_event`(`website_id`, `created_at`, `hostname`);
22+
CREATE INDEX `session_website_id_created_at_region_idx` ON `session`(`website_id`, `created_at`, `region`);

db/mysql/schema.prisma

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@ model User {
3131
model Session {
3232
id String @id @unique @map("session_id") @db.VarChar(36)
3333
websiteId String @map("website_id") @db.VarChar(36)
34-
hostname String? @db.VarChar(100)
3534
browser String? @db.VarChar(20)
3635
os String? @db.VarChar(20)
3736
device String? @db.VarChar(20)
3837
screen String? @db.VarChar(11)
3938
language String? @db.VarChar(35)
4039
country String? @db.Char(2)
41-
subdivision1 String? @db.Char(20)
42-
subdivision2 String? @db.VarChar(50)
40+
region String? @db.Char(20)
4341
city String? @db.VarChar(50)
4442
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamp(0)
4543
@@ -49,14 +47,13 @@ model Session {
4947
@@index([createdAt])
5048
@@index([websiteId])
5149
@@index([websiteId, createdAt])
52-
@@index([websiteId, createdAt, hostname])
5350
@@index([websiteId, createdAt, browser])
5451
@@index([websiteId, createdAt, os])
5552
@@index([websiteId, createdAt, device])
5653
@@index([websiteId, createdAt, screen])
5754
@@index([websiteId, createdAt, language])
5855
@@index([websiteId, createdAt, country])
59-
@@index([websiteId, createdAt, subdivision1])
56+
@@index([websiteId, createdAt, region])
6057
@@index([websiteId, createdAt, city])
6158
@@map("session")
6259
}
@@ -115,6 +112,7 @@ model WebsiteEvent {
115112
eventType Int @default(1) @map("event_type") @db.UnsignedInt
116113
eventName String? @map("event_name") @db.VarChar(50)
117114
tag String? @db.VarChar(50)
115+
hostname String? @db.VarChar(100)
118116
119117
eventData EventData[]
120118
session Session @relation(fields: [sessionId], references: [id])
@@ -132,6 +130,7 @@ model WebsiteEvent {
132130
@@index([websiteId, createdAt, tag])
133131
@@index([websiteId, sessionId, createdAt])
134132
@@index([websiteId, visitId, createdAt])
133+
@@index([websiteId, createdAt, hostname])
135134
@@map("website_event")
136135
}
137136

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-- AlterTable
2+
ALTER TABLE "website_event" ADD COLUMN "hostname" VARCHAR(100);
3+
4+
-- DataMigration
5+
UPDATE "website_event" w
6+
SET hostname = s.hostname
7+
FROM "session" s
8+
WHERE s.website_id = w.website_id
9+
and s.session_id = w.session_id;
10+
11+
-- DropIndex
12+
DROP INDEX IF EXISTS "session_website_id_created_at_hostname_idx";
13+
DROP INDEX IF EXISTS "session_website_id_created_at_subdivision1_idx";
14+
15+
-- AlterTable
16+
ALTER TABLE "session" RENAME COLUMN "subdivision1" TO "region";
17+
ALTER TABLE "session" DROP COLUMN "subdivision2";
18+
ALTER TABLE "session" DROP COLUMN "hostname";
19+
20+
-- CreateIndex
21+
CREATE INDEX "website_event_website_id_created_at_hostname_idx" ON "website_event"("website_id", "created_at", "hostname");
22+
CREATE INDEX "session_website_id_created_at_region_idx" ON "session"("website_id", "created_at", "region");
23+
24+
25+

db/postgresql/schema.prisma

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@ model User {
3131
model Session {
3232
id String @id @unique @map("session_id") @db.Uuid
3333
websiteId String @map("website_id") @db.Uuid
34-
hostname String? @db.VarChar(100)
3534
browser String? @db.VarChar(20)
3635
os String? @db.VarChar(20)
3736
device String? @db.VarChar(20)
3837
screen String? @db.VarChar(11)
3938
language String? @db.VarChar(35)
4039
country String? @db.Char(2)
41-
subdivision1 String? @db.VarChar(20)
42-
subdivision2 String? @db.VarChar(50)
40+
region String? @db.VarChar(20)
4341
city String? @db.VarChar(50)
4442
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)
4543
@@ -49,14 +47,13 @@ model Session {
4947
@@index([createdAt])
5048
@@index([websiteId])
5149
@@index([websiteId, createdAt])
52-
@@index([websiteId, createdAt, hostname])
5350
@@index([websiteId, createdAt, browser])
5451
@@index([websiteId, createdAt, os])
5552
@@index([websiteId, createdAt, device])
5653
@@index([websiteId, createdAt, screen])
5754
@@index([websiteId, createdAt, language])
5855
@@index([websiteId, createdAt, country])
59-
@@index([websiteId, createdAt, subdivision1])
56+
@@index([websiteId, createdAt, region])
6057
@@index([websiteId, createdAt, city])
6158
@@map("session")
6259
}
@@ -115,6 +112,7 @@ model WebsiteEvent {
115112
eventType Int @default(1) @map("event_type") @db.Integer
116113
eventName String? @map("event_name") @db.VarChar(50)
117114
tag String? @db.VarChar(50)
115+
hostname String? @db.VarChar(100)
118116
119117
eventData EventData[]
120118
session Session @relation(fields: [sessionId], references: [id])
@@ -132,6 +130,7 @@ model WebsiteEvent {
132130
@@index([websiteId, createdAt, tag])
133131
@@index([websiteId, sessionId, createdAt])
134132
@@index([websiteId, visitId, createdAt])
133+
@@index([websiteId, createdAt, hostname])
135134
@@map("website_event")
136135
}
137136

src/app/(main)/websites/[websiteId]/sessions/[sessionId]/SessionInfo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default function SessionInfo({ data }) {
3636
<Icon>
3737
<Icons.Location />
3838
</Icon>
39-
{getRegionName(data?.subdivision1)}
39+
{getRegionName(data?.region)}
4040
</dd>
4141

4242
<dt>{formatMessage(labels.city)}</dt>

src/app/api/send/route.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ export async function POST(request: Request) {
8080
}
8181

8282
// Client info
83-
const { ip, userAgent, device, browser, os, country, subdivision1, subdivision2, city } =
84-
await getClientInfo(request, payload);
83+
const { ip, userAgent, device, browser, os, country, region, city } = await getClientInfo(
84+
request,
85+
payload,
86+
);
8587

8688
// Bot check
8789
if (!process.env.DISABLE_BOT_CHECK && isbot(userAgent)) {
@@ -111,15 +113,13 @@ export async function POST(request: Request) {
111113
await createSession({
112114
id: sessionId,
113115
websiteId,
114-
hostname,
115116
browser,
116117
os,
117118
device,
118119
screen,
119120
language,
120121
country,
121-
subdivision1,
122-
subdivision2,
122+
region,
123123
city,
124124
});
125125
} catch (e: any) {
@@ -212,8 +212,7 @@ export async function POST(request: Request) {
212212
screen,
213213
language,
214214
country,
215-
subdivision1,
216-
subdivision2,
215+
region,
217216
city,
218217
tag,
219218
createdAt,

0 commit comments

Comments
 (0)