Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

revert: saving more data to non-unique entries for filters to work better

Blue Mouse098ca12abf23
diff --git a/src/analytics/analytics.controller.ts b/src/analytics/analytics.controller.ts
index 539c5b5c6..bc04d8b73 100644
--- a/src/analytics/analytics.controller.ts
+++ b/src/analytics/analytics.controller.ts
@@ -270,17 +270,17 @@ export class AnalyticsController {
const sessionHash = getSessionKey(ip, userAgent, logDTO.pid, salt)
const unique = await this.analyticsService.isUnique(sessionHash)
let dto: Array<string | number>
- const ua = UAParser(userAgent)
- const dv = ua.device.type || 'desktop'
- const br = ua.browser.name
- const os = ua.os.name
- // trying to get country from timezome, otherwise using CloudFlare's IP based country code as a fallback
- const cc = ct.getCountryForTimezone(logDTO.tz)?.id || (headers['cf-ipcountry'] === 'XX' ? 'NULL' : headers['cf-ipcountry'])
if (unique) {
+ const ua = UAParser(userAgent)
+ const dv = ua.device.type || 'desktop'
+ const br = ua.browser.name
+ const os = ua.os.name
+ // trying to get country from timezome, otherwise using CloudFlare's IP based country code as a fallback
+ const cc = ct.getCountryForTimezone(logDTO.tz)?.id || (headers['cf-ipcountry'] === 'XX' ? 'NULL' : headers['cf-ipcountry'])
dto = analyticsDTO(logDTO.pid, logDTO.pg, dv, br, os, logDTO.lc, logDTO.ref, logDTO.so, logDTO.me, logDTO.ca, 'NULL' /* logDTO.lt */, cc, 1)
} else if (!logDTO.unique) {
- dto = analyticsDTO(logDTO.pid, logDTO.pg, dv, br, os, logDTO.lc, 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', cc, 0)
+ dto = analyticsDTO(logDTO.pid, logDTO.pg, 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 0)
} else {
throw new BadRequestException('Event was not saved because it was not unique while unique only param is provided')
}
@@ -321,14 +321,19 @@ export class AnalyticsController {
const sessionHash = getSessionKey(ip, userAgent, logDTO.pid, salt)
const unique = await this.analyticsService.isUnique(sessionHash)
- const ua = UAParser(userAgent)
- const dv = ua.device.type || 'desktop'
- const br = ua.browser.name
- const os = ua.os.name
- // using CloudFlare's IP based country code
- const cc = headers['cf-ipcountry'] === 'XX' ? 'NULL' : headers['cf-ipcountry']
+ let dto: Array<string | number>
- const dto: Array<string | number> = analyticsDTO(logDTO.pid, 'NULL', dv, br, os, 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', cc, unique ? 1 : 0)
+ if (unique) {
+ const ua = UAParser(userAgent)
+ const dv = ua.device.type || 'desktop'
+ const br = ua.browser.name
+ const os = ua.os.name
+ // using CloudFlare's IP based country code
+ const cc = headers['cf-ipcountry'] === 'XX' ? 'NULL' : headers['cf-ipcountry']
+ dto = analyticsDTO(logDTO.pid, 'NULL', dv, br, os, 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', cc, 1)
+ } else {
+ dto = analyticsDTO(logDTO.pid, 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 'NULL', 0)
+ }
// todo: fix: may be vulnerable to sql injection attack
const values = `(${dto.map(getElValue).join(',')})`