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!

fix: tighten profile session details handling

Blue Mouse9b8e012799dd
diff --git a/backend/apps/cloud/src/analytics/analytics.service.ts b/backend/apps/cloud/src/analytics/analytics.service.ts
index 7cfecb6d9..c6284f7b5 100644
--- a/backend/apps/cloud/src/analytics/analytics.service.ts
+++ b/backend/apps/cloud/src/analytics/analytics.service.ts
@@ -6299,6 +6299,9 @@ export class AnalyticsService {
pid: string,
psids: string[],
safeTimezone: string,
+ profileId: string,
+ groupFrom: string,
+ groupTo: string,
): Promise<Map<string, any[]>> {
if (_isEmpty(psids)) {
return new Map()
@@ -6343,8 +6346,10 @@ export class AnalyticsService {
WHERE
pid = {pid:FixedString(12)}
AND type IN ('pageview', 'custom_event', 'error')
+ AND profileId = {profileId:String}
AND psid IS NOT NULL
AND toString(psid) IN {psids:Array(String)}
+ AND created BETWEEN {groupFrom:DateTime} AND {groupTo:DateTime}
)
UNION ALL
@@ -6376,8 +6381,10 @@ export class AnalyticsService {
FROM revenue
WHERE
pid = {pid:FixedString(12)}
+ AND profile_id = {profileId:String}
AND session_id IS NOT NULL
AND toString(session_id) IN {psids:Array(String)}
+ AND revenue.created BETWEEN {groupFrom:DateTime} AND {groupTo:DateTime}
AND revenue.type IN ('sale', 'refund')
GROUP BY session_id, transaction_id
)
@@ -6396,7 +6403,14 @@ export class AnalyticsService {
const { data } = await clickhouse
.query({
query,
- query_params: { pid, psids, timezone: safeTimezone },
+ query_params: {
+ pid,
+ psids,
+ timezone: safeTimezone,
+ profileId,
+ groupFrom,
+ groupTo,
+ },
})
.then((resultSet) => resultSet.json<IPageflow>())
@@ -6539,6 +6553,9 @@ export class AnalyticsService {
pid,
sessions.map((session) => String(session.psid)).filter(Boolean),
safeTimezone,
+ profileId,
+ paramsData.params.groupFrom,
+ paramsData.params.groupTo,
)
return sessions.map((session) => ({
diff --git a/backend/apps/cloud/src/analytics/dto/get-profile.dto.ts b/backend/apps/cloud/src/analytics/dto/get-profile.dto.ts
index 064a897f6..6962d2bac 100644
--- a/backend/apps/cloud/src/analytics/dto/get-profile.dto.ts
+++ b/backend/apps/cloud/src/analytics/dto/get-profile.dto.ts
@@ -12,7 +12,6 @@ import {
} from 'class-validator'
import { DEFAULT_TIMEZONE } from '../../user/entities/user.entity'
import { PID_REGEX } from '../../common/constants'
-import { ValidatePeriod } from '../decorators/validate-period.decorator'
import { GetDataDto } from './getData.dto'
export class GetProfileDto {
@@ -41,19 +40,6 @@ export class GetProfileDto {
})
@IsOptional()
timezone?: string
-
- @ApiProperty({ required: false })
- @IsOptional()
- @ValidatePeriod()
- period?: string
-
- @ApiProperty({ required: false })
- @IsOptional()
- from?: string
-
- @ApiProperty({ required: false })
- @IsOptional()
- to?: string
}
export class GetProfileSessionsDto extends PickType(GetDataDto, [
diff --git a/backend/apps/community/src/analytics/analytics.service.ts b/backend/apps/community/src/analytics/analytics.service.ts
index 87bc2a261..09d1e952d 100644
--- a/backend/apps/community/src/analytics/analytics.service.ts
+++ b/backend/apps/community/src/analytics/analytics.service.ts
@@ -6662,6 +6662,9 @@ export class AnalyticsService {
pid: string,
psids: string[],
safeTimezone: string,
+ profileId: string,
+ groupFrom: string,
+ groupTo: string,
): Promise<Map<string, any[]>> {
if (_isEmpty(psids)) {
return new Map()
@@ -6707,8 +6710,10 @@ export class AnalyticsService {
WHERE
pid = {pid:FixedString(12)}
AND type IN ('pageview', 'custom_event', 'error')
+ AND profileId = {profileId:String}
AND psid IS NOT NULL
AND toString(psid) IN {psids:Array(String)}
+ AND created BETWEEN {groupFrom:DateTime} AND {groupTo:DateTime}
)
)
@@ -6726,7 +6731,14 @@ export class AnalyticsService {
const { data } = await clickhouse
.query({
query,
- query_params: { pid, psids, timezone: safeTimezone },
+ query_params: {
+ pid,
+ psids,
+ timezone: safeTimezone,
+ profileId,
+ groupFrom,
+ groupTo,
+ },
})
.then((resultSet) => resultSet.json<IPageflow>())
@@ -6869,6 +6881,9 @@ export class AnalyticsService {
pid,
sessions.map((session) => String(session.psid)).filter(Boolean),
safeTimezone,
+ profileId,
+ paramsData.params.groupFrom,
+ paramsData.params.groupTo,
)
return sessions.map((session) => ({
diff --git a/backend/apps/community/src/analytics/dto/get-profile.dto.ts b/backend/apps/community/src/analytics/dto/get-profile.dto.ts
index 064a897f6..6962d2bac 100644
--- a/backend/apps/community/src/analytics/dto/get-profile.dto.ts
+++ b/backend/apps/community/src/analytics/dto/get-profile.dto.ts
@@ -12,7 +12,6 @@ import {
} from 'class-validator'
import { DEFAULT_TIMEZONE } from '../../user/entities/user.entity'
import { PID_REGEX } from '../../common/constants'
-import { ValidatePeriod } from '../decorators/validate-period.decorator'
import { GetDataDto } from './getData.dto'
export class GetProfileDto {
@@ -41,19 +40,6 @@ export class GetProfileDto {
})
@IsOptional()
timezone?: string
-
- @ApiProperty({ required: false })
- @IsOptional()
- @ValidatePeriod()
- period?: string
-
- @ApiProperty({ required: false })
- @IsOptional()
- from?: string
-
- @ApiProperty({ required: false })
- @IsOptional()
- to?: string
}
export class GetProfileSessionsDto extends PickType(GetDataDto, [
diff --git a/docs/content/docs/analytics-dashboard/profiles-and-sessions.mdx b/docs/content/docs/analytics-dashboard/profiles-and-sessions.mdx
index 3156e5a3e..159bbadab 100644
--- a/docs/content/docs/analytics-dashboard/profiles-and-sessions.mdx
+++ b/docs/content/docs/analytics-dashboard/profiles-and-sessions.mdx
@@ -42,6 +42,7 @@ This is particularly useful for finding users who experienced specific bugs (e.g
## Profile Details
Clicking on any profile in the list opens the **Profile Details** view. This view provides a comprehensive history of that specific user's interaction with your site.
+Its core stats and session history are shown across all time, independent of the dashboard date range that was used to find the profile.
### Overview & Activity Calendar
diff --git a/docs/content/docs/api/stats.mdx b/docs/content/docs/api/stats.mdx
index 3de58b653..c8d539ce4 100644
--- a/docs/content/docs/api/stats.mdx
+++ b/docs/content/docs/api/stats.mdx
@@ -1389,12 +1389,6 @@ Timezone for the data.
<hr />
-**period**, **from**, **to**
-
-Time range parameters.
-
-<hr />
-
### GET /v1/log/profile/sessions
Returns a list of sessions for a specific user profile.
diff --git a/web/app/api/api.server.ts b/web/app/api/api.server.ts
index ba70e9979..b415d6ca3 100644
--- a/web/app/api/api.server.ts
+++ b/web/app/api/api.server.ts
@@ -1917,18 +1917,12 @@ export async function getProfileServer(
request: Request,
pid: string,
profileId: string,
- period = 'all',
- from = '',
- to = '',
timezone = '',
password?: string,
): Promise<ServerFetchResult<ProfileDetailsResponse>> {
const params = new URLSearchParams()
params.append('pid', pid)
params.append('profileId', profileId)
- params.append('period', period)
- if (from) params.append('from', from)
- if (to) params.append('to', to)
if (timezone) params.append('timezone', timezone)
const headers: Record<string, string> = {}
diff --git a/web/app/pages/Project/tabs/Profiles/ProfileDetails.tsx b/web/app/pages/Project/tabs/Profiles/ProfileDetails.tsx
index 1ed2cc3bd..84e4740d3 100644
--- a/web/app/pages/Project/tabs/Profiles/ProfileDetails.tsx
+++ b/web/app/pages/Project/tabs/Profiles/ProfileDetails.tsx
@@ -1,5 +1,6 @@
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
+import utc from 'dayjs/plugin/utc'
import _capitalize from 'lodash/capitalize'
import _isEmpty from 'lodash/isEmpty'
import {
@@ -43,9 +44,11 @@ import countries from '~/utils/isoCountries'
import { getProfileDisplayName, ProfileAvatar } from '~/utils/profileAvatars'
import { BrowserIcon, OSIcon } from '../SharedIcons'
+import { InfoRow, PanelSection } from '../components/DetailPanels'
import { Pageflow } from '../Sessions/Pageflow'
dayjs.extend(relativeTime)
+dayjs.extend(utc)
const ONLINE_THRESHOLD_MINUTES = 5
const RECENTLY_ACTIVE_THRESHOLD_MINUTES = 30
@@ -131,7 +134,7 @@ const formatDateTime = (
) => {
if (!value) return null
- const date = dayjs(value)
+ const date = dayjs.utc(value)
if (!date.isValid()) return null
return date.toDate().toLocaleDateString(language, {
@@ -160,8 +163,8 @@ const getSessionDuration = (session: ProfileSession) => {
return 0
}
- const first = dayjs(pages[0].created)
- const last = dayjs(pages[pages.length - 1].created)
+ const first = dayjs.utc(pages[0].created)
+ const last = dayjs.utc(pages[pages.length - 1].created)
if (!first.isValid() || !last.isValid()) {
return 0
}
@@ -172,56 +175,6 @@ const getSessionDuration = (session: ProfileSession) => {
const isSessionLive = (value: ProfileSession['isLive']) =>
value === true || value === 1
-const InfoRow = ({
- label,
- value,
- valueClassName,
-}: {
- label: string
- value: ReactNode
- valueClassName?: string
-}) => (
- <div className='grid grid-cols-[minmax(0,1fr)_minmax(0,1.35fr)] items-center gap-3 border-b border-gray-100 py-1.5 last:border-0 dark:border-slate-800/80'>
- <Text size='sm' colour='secondary' className='min-w-0'>
- {label}
- </Text>
- <Text
- as='div'
- size='sm'
- weight='medium'
- colour='primary'
- className={cn(
- 'flex min-w-0 items-center justify-end gap-1 text-right wrap-break-word',
- valueClassName,
- )}
- >
- {value}
- </Text>
- </div>
-)
-
-const PanelSection = ({
- title,
- children,
-}: {
- title: ReactNode
- children: ReactNode
-}) => (
- <section className='border-t border-gray-100 pt-3 first:border-t-0 first:pt-0 dark:border-slate-800/80'>
- <Text
- as='h3'
- size='xs'
- weight='semibold'
- colour='primary'
- className='mb-1.5 uppercase'
- tracking='wide'
- >
- {title}
- </Text>
- {children}
- </section>
-)
-
const ActivityCalendar = ({
data,
}: {
@@ -1014,7 +967,7 @@ export const ProfileDetails = ({
value={
<>
<CurrencyDollarIcon className='h-4 w-4 text-emerald-500' />
- {new Intl.NumberFormat('en-US', {
+ {new Intl.NumberFormat(language || 'en-US', {
style: 'currency',
currency: revenueCurrency,
minimumFractionDigits: 2,
diff --git a/web/app/pages/Project/tabs/Profiles/ProfilesView.tsx b/web/app/pages/Project/tabs/Profiles/ProfilesView.tsx
index bfa06bb44..a0be14f31 100644
--- a/web/app/pages/Project/tabs/Profiles/ProfilesView.tsx
+++ b/web/app/pages/Project/tabs/Profiles/ProfilesView.tsx
@@ -185,7 +185,6 @@ const ProfilesView = ({ tnMapping }: ProfilesViewProps) => {
try {
const data = await profileProxy.fetchProfile(id, profileId, {
- period: 'all',
timezone,
})
diff --git a/web/app/pages/Project/tabs/Sessions/SessionDetailView.tsx b/web/app/pages/Project/tabs/Sessions/SessionDetailView.tsx
index 78a1a82ce..61dc3ac16 100644
--- a/web/app/pages/Project/tabs/Sessions/SessionDetailView.tsx
+++ b/web/app/pages/Project/tabs/Sessions/SessionDetailView.tsx
@@ -15,6 +15,7 @@ import { useTranslation } from 'react-i18next'
import { Link } from '~/ui/Link'
import { BrowserIcon, OSIcon } from '../SharedIcons'
+import { InfoRow, PanelSection } from '../components/DetailPanels'
import { PROJECT_TABS } from '~/lib/constants'
import { SessionDetails as SessionDetailsType } from '~/lib/models/Project'
import { BackButton } from '~/pages/Project/View/components/BackButton'
@@ -29,7 +30,6 @@ import {
getLocaleDisplayName,
getStringFromTime,
getTimeFromSeconds,
- cn,
} from '~/utils/generic'
import Flag from '~/ui/Flag'
@@ -84,61 +84,6 @@ interface PlatformPart {
const RECENTLY_ACTIVE_THRESHOLD_MINUTES = 30
const RECENTLY_ACTIVE_THRESHOLD_SECONDS = RECENTLY_ACTIVE_THRESHOLD_MINUTES * 60
-const InfoRow = ({
- label,
- value,
- valueClassName,
-}: {
- label: string
- value: React.ReactNode
- valueClassName?: string
-}) => (
- <div className='grid grid-cols-[minmax(0,1fr)_minmax(0,1.35fr)] items-center gap-3 border-b border-gray-100 py-1.5 last:border-0 dark:border-slate-800/80'>
- <Text size='sm' colour='secondary' className='min-w-0'>
- {label}
- </Text>
- <Text
- as='div'
- size='sm'
- weight='medium'
- colour='primary'
- className={cn(
- 'flex min-w-0 items-center justify-end gap-1 text-right wrap-break-word',
- valueClassName,
- )}
- >
- {value}
- </Text>
- </div>
-)
-
-const PanelSection = ({
- title,
- action,
- children,
-}: {
- title: React.ReactNode
- action?: React.ReactNode
- children: React.ReactNode
-}) => (
- <section className='border-t border-gray-100 pt-3 first:border-t-0 first:pt-0 dark:border-slate-800/80'>
- <div className='mb-1.5 flex items-center justify-between gap-3'>
- <Text
- as='h3'
- size='xs'
- weight='semibold'
- colour='primary'
- className='uppercase'
- tracking='wide'
- >
- {title}
- </Text>
- {action}
- </div>
- {children}
- </section>
-)
-
const formatCompactElapsed = (seconds: number) => {
const safeSeconds = Math.max(0, seconds)
const minute = 60
@@ -361,8 +306,8 @@ export const SessionDetailView = ({
: formatDateTime(lastActivityAt, language, timeFormat, timezone)
const lastSeenLabel = lastSeenTime
? lastSeenTime === 'now'
- ? 'seen now'
- : `seen ${lastSeenTime} ago`
+ ? t('project.online')
+ : t('project.lastSeenAgo', { time: `${lastSeenTime} ago` })
: t('project.endOfSession')
const isRecentlyActive =
!details.isLive &&
diff --git a/web/app/pages/Project/tabs/components/DetailPanels.tsx b/web/app/pages/Project/tabs/components/DetailPanels.tsx
new file mode 100644
index 000000000..3238bf040
--- /dev/null
+++ b/web/app/pages/Project/tabs/components/DetailPanels.tsx
@@ -0,0 +1,59 @@
+import type { ReactNode } from 'react'
+
+import { Text } from '~/ui/Text'
+import { cn } from '~/utils/generic'
+
+export const InfoRow = ({
+ label,
+ value,
+ valueClassName,
+}: {
+ label: string
+ value: ReactNode
+ valueClassName?: string
+}) => (
+ <div className='grid grid-cols-[minmax(0,1fr)_minmax(0,1.35fr)] items-center gap-3 border-b border-gray-100 py-1.5 last:border-0 dark:border-slate-800/80'>
+ <Text size='sm' colour='secondary' className='min-w-0'>
+ {label}
+ </Text>
+ <Text
+ as='div'
+ size='sm'
+ weight='medium'
+ colour='primary'
+ className={cn(
+ 'flex min-w-0 items-center justify-end gap-1 text-right wrap-break-word',
+ valueClassName,
+ )}
+ >
+ {value}
+ </Text>
+ </div>
+)
+
+export const PanelSection = ({
+ title,
+ action,
+ children,
+}: {
+ title: ReactNode
+ action?: ReactNode
+ children: ReactNode
+}) => (
+ <section className='border-t border-gray-100 pt-3 first:border-t-0 first:pt-0 dark:border-slate-800/80'>
+ <div className='mb-1.5 flex items-center justify-between gap-3'>
+ <Text
+ as='h3'
+ size='xs'
+ weight='semibold'
+ colour='primary'
+ className='uppercase'
+ tracking='wide'
+ >
+ {title}
+ </Text>
+ {action}
+ </div>
+ {children}
+ </section>
+)
diff --git a/web/app/routes/api.analytics.ts b/web/app/routes/api.analytics.ts
index d1e1250fd..60a95dd2d 100644
--- a/web/app/routes/api.analytics.ts
+++ b/web/app/routes/api.analytics.ts
@@ -540,9 +540,6 @@ export async function action({ request }: ActionFunctionArgs) {
request,
projectId,
body.profileId,
- params.period || 'all',
- formatDateForBackend(params.from) || '',
- formatDateForBackend(params.to) || '',
params.timezone || '',
password || undefined,
)