Skip to content

Commit 8c95f46

Browse files
authored
Add IP geolocation support to analytics collector (#9632)
Signed-off-by: Alexander Platov <[email protected]>
1 parent 6933c99 commit 8c95f46

File tree

10 files changed

+460
-11
lines changed

10 files changed

+460
-11
lines changed

common/config/rush/pnpm-lock.yaml

Lines changed: 40 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/analytics-providers/src/utils.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,30 @@ function getDeviceType (type: string | undefined | null): string {
7979

8080
export function collectEventMetadata (properties: Record<string, any> = {}): Record<string, any> {
8181
const trackingParams = getUrlTrackingParams()
82-
const referrer = document.referrer === '' ? '$direct' : document.referrer
82+
83+
const referrer = (() => {
84+
if (document.referrer === '') return '$direct'
85+
86+
try {
87+
const currentDomain = window.location.hostname
88+
const referrerDomain = new URL(document.referrer).hostname
89+
90+
if (currentDomain === referrerDomain) return '$direct'
91+
92+
return document.referrer
93+
} catch {
94+
return document.referrer
95+
}
96+
})()
8397
const referringDomain = referrer !== '$direct' ? new URL(referrer).hostname : '$direct'
8498

8599
const now = new Date()
86100
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
87101
const timezoneOffset = -now.getTimezoneOffset()
88102

103+
const browserLanguage = navigator.language !== '' ? navigator.language : 'en-US'
104+
const browserLanguagePrefix = browserLanguage.split('-')[0] !== '' ? browserLanguage.split('-')[0] : 'en'
105+
89106
return {
90107
...properties,
91108
$timestamp: new Date().toISOString(),
@@ -110,6 +127,8 @@ export function collectEventMetadata (properties: Record<string, any> = {}): Rec
110127
title: document.title,
111128
$timezone: timezone,
112129
$timezone_offset: timezoneOffset,
130+
$browser_language: browserLanguage,
131+
$browser_language_prefix: browserLanguagePrefix,
113132
...trackingParams
114133
}
115134
}

plugins/workbench-resources/src/connect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ export async function connect (title: string): Promise<Client | undefined> {
427427
}
428428

429429
Analytics.setUser(data.social_id, data)
430-
Analytics.setWorkspace(workspace.name, guestRole)
430+
Analytics.setWorkspace(workspace.url, guestRole)
431431
Analytics.handleEvent(WorkbenchEvents.Connect)
432432
console.log('Logged in with account: ', me)
433433
setCurrentAccount(me)

services/analytics-collector/pod-analytics-collector/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,15 @@ WORKDIR /usr/src/app
33

44
COPY bundle/bundle.js ./
55

6+
# Create geodb directory and optionally copy MaxMind databases
7+
RUN mkdir -p /usr/src/geodb
8+
# Copy entire geodb directory
9+
COPY geodb/ /usr/src/geodb/
10+
11+
# Log what databases are available
12+
RUN echo "GeoIP databases status:" && \
13+
(ls -la /usr/src/geodb/*.mmdb 2>/dev/null && echo "MaxMind databases found") || \
14+
echo "No MaxMind databases found - geolocation will be disabled"
15+
616
EXPOSE 4007
717
CMD [ "node", "bundle.js" ]
Binary file not shown.
Binary file not shown.

services/analytics-collector/pod-analytics-collector/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@tsconfig/node16": "^1.0.4",
3535
"@types/cors": "^2.8.12",
3636
"@types/express": "^4.17.13",
37+
"@types/maxmind": "^2.0.5",
3738
"@types/node": "^22.15.29",
3839
"@typescript-eslint/eslint-plugin": "^6.11.0",
3940
"@typescript-eslint/parser": "^6.11.0",
@@ -63,6 +64,7 @@
6364
"@hcengineering/server-token": "^0.6.11",
6465
"cors": "^2.8.5",
6566
"dotenv": "~16.0.0",
66-
"express": "^4.21.2"
67+
"express": "^4.21.2",
68+
"maxmind": "^4.3.6"
6769
}
6870
}

0 commit comments

Comments
 (0)