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!

Merge branch 'main' into feature/goals-funnels-improvements

Blue Mouseffca184ea4ff
diff --cc docs/content/docs/api/stats.mdx
index 28a42bd9d,0c3e5a3d5..3de58b653
--- a/docs/content/docs/api/stats.mdx
+++ b/docs/content/docs/api/stats.mdx
@@@ -1612,10 -1424,54 +1618,58 @@@ curl 'https://api.swetrix.com/goal/GOAL
Time range parameters.
+**filters** (optional)
+
+A stringified JSON array of [filter objects](#filters).
+
+ ### GET /goal/:id/sessions
+
+ Returns paginated sessions that matched a specific goal during the selected time range.
+
+ ```bash
+ curl 'https://api.swetrix.com/goal/GOAL_ID/sessions?period=7d&take=30&skip=0'\
+ -H "X-Api-Key: ${SWETRIX_API_KEY}"
+ ```
+
+ ```json title="Response"
+ {
+ "sessions": [
+ {
+ "psid": "123456789",
+ "cc": "US",
+ "os": "Mac OS",
+ "br": "Chrome",
+ "pageviews": 3,
+ "customEvents": 1,
+ "errors": 0,
+ "sessionStart": "2025-01-15 10:30:00",
+ "lastActivity": "2025-01-15 10:35:00",
+ "isLive": 0,
+ "sdur": 300,
+ "profileId": null,
+ "isIdentified": 0,
+ "isFirstSession": 1
+ }
+ ],
+ "take": 30,
+ "skip": 0
+ }
+ ```
+
+ #### Parameters
+
+ **period**, **from**, **to**, **timezone**
+
+ Time range parameters.
+
+ **take** (optional, default: `30`, max: `150`)
+
+ The number of sessions to return per page.
+
+ **skip** (optional, default: `0`)
+
+ The number of sessions to skip (for pagination).
+
### GET /v1/feature-flag/:id/stats
Returns statistics for a specific feature flag (evaluations, true/false counts).
diff --cc web/app/pages/Project/tabs/Goals/GoalsView.tsx
index 39eda8d38,2f9c65ace..ec2ffb201
--- a/web/app/pages/Project/tabs/Goals/GoalsView.tsx
+++ b/web/app/pages/Project/tabs/Goals/GoalsView.tsx
@@@ -48,10 -45,9 +48,11 @@@ import
tbsFormatMapperTooltip,
tbsFormatMapperTooltip24h,
chartTypes,
+ DEFAULT_TIMEZONE,
} from '~/lib/constants'
import DashboardHeader from '~/pages/Project/View/components/DashboardHeader'
+import Filters from '~/pages/Project/View/components/Filters'
+import ProjectViewHeaderActions from '~/pages/Project/View/components/ProjectViewHeaderActions'
import {
useViewProjectContext,
useRefreshTriggers,
@@@ -266,9 -139,8 +273,11 @@@ const getGoalChartSettings =
timeFormat: string,
chartType: string,
dataNames: Record<string, string>,
+ t: TFunction,
+ language: string,
+ stats: GoalStats | null,
+ onDataPointClick?: ChartDataPointClick,
+ dataPointClickLabel?: string,
): ChartOptions => {
const xAxisSize = _size(chartData.x)
@@@ -360,20 -232,20 +376,25 @@@
timeFormat === TimeFormat['24-hour']
? d3.timeFormat(tbsFormatMapperTooltip24h[timeBucket])(item[0].x)
: d3.timeFormat(tbsFormatMapperTooltip[timeBucket])(item[0].x)
- }</li>
+ }</div>
${_map(item, (el: { id: string; name: string; value: string }) => {
return `
- <li class='flex justify-between items-center py-px leading-snug'>
+ <div class='flex justify-between items-center py-px leading-snug'>
<div class='flex items-center min-w-0 mr-4'>
<div class='w-2.5 h-2.5 rounded-xs mr-1.5 shrink-0' style=background-color:${color(el.id)}></div>
- <span class="truncate">${el.name}</span>
+ <span class='truncate text-gray-900 dark:text-gray-50'>${escapeHtml(el.name)}</span>
</div>
- <span class='font-mono whitespace-nowrap'>${el.value}</span>
- </li>
+ <span class='font-mono whitespace-nowrap text-gray-900 dark:text-gray-50'>${el.value}</span>
+ </div>
`
- }).join(
- '',
- )}${onDataPointClick ? `<li class='pt-1 mt-1 border-t border-gray-200 dark:border-slate-700/80 text-[10px] text-gray-400 dark:text-slate-500'>${dataPointClickLabel}</li>` : ''}</ul>`
+ }).join('')}
+ ${breakdownsHtml}
++ ${
++ onDataPointClick
++ ? `<div class='pt-1 mt-1 border-t border-gray-200 dark:border-slate-700/80 text-[10px] text-gray-400 dark:text-slate-500'>${escapeHtml(dataPointClickLabel || '')}</div>`
++ : ''
++ }
+ </div>`
},
},
point:
@@@ -430,8 -310,9 +459,9 @@@ const GoalRow = (
onDelete,
onEdit,
onToggleExpand,
+ onChartDataPointClick,
}: GoalRowProps) => {
- const { t } = useTranslation()
+ const { t, i18n } = useTranslation()
const [showDeleteModal, setShowDeleteModal] = useState(false)
const patternDisplay = useMemo(() => {
@@@ -463,11 -337,10 +493,22 @@@
conversions: t('goals.conversions'),
sessions: t('project.sessions'),
},
+ t,
+ i18n.language,
+ stats,
+ (d) => onChartDataPointClick(goal.id, d),
+ t('project.exploreSessions'),
)
- }, [chartData, timeBucket, timeFormat, t, i18n.language, stats])
- }, [chartData, timeBucket, timeFormat, goal.id, onChartDataPointClick, t])
++ }, [
++ chartData,
++ timeBucket,
++ timeFormat,
++ t,
++ i18n.language,
++ stats,
++ goal.id,
++ onChartDataPointClick,
++ ])
return (
<>
@@@ -1167,8 -995,18 +1230,19 @@@ const GoalsViewInner = (
onSuccess={handleModalSuccess}
projectId={id}
goalId={editingGoalId}
+ tnMapping={tnMapping}
/>
+ <SessionsDrawer
+ isOpen={!!sessionsDrawer}
+ onClose={() => setSessionsDrawer(null)}
+ from={sessionsDrawer?.from || ''}
+ to={sessionsDrawer?.to || ''}
+ label={sessionsDrawer?.label || ''}
+ projectId={id}
+ timezone={timezone}
+ timeFormat={timeFormat as '12-hour' | '24-hour'}
+ goalId={sessionsDrawer?.goalId}
+ />
</div>
</>
)
diff --cc web/app/pages/Project/tabs/Traffic/SessionsDrawer.tsx
index 7ff05dcf3,880e38cb2..4ec901bda
--- a/web/app/pages/Project/tabs/Traffic/SessionsDrawer.tsx
+++ b/web/app/pages/Project/tabs/Traffic/SessionsDrawer.tsx
@@@ -15,9 -28,14 +28,15 @@@ import
} from '~/ui/Drawer'
import Loader from '~/ui/Loader'
import Spin from '~/ui/icons/Spin'
+import { Switch } from '~/ui/Switch'
+ import { Link } from '~/ui/Link'
+ import { Text } from '~/ui/Text'
+ import Flag from '~/ui/Flag'
+ import { useTheme } from '~/providers/ThemeProvider'
+ import { getRelativeDateIfPossible } from '~/utils/date'
import { Session } from '../Sessions/Sessions'
+ import { BrowserIcon, OSIcon } from '../SharedIcons'
const SESSIONS_TAKE = 30
@@@ -69,9 -195,10 +196,13 @@@ interface SessionsDrawerProps
period?: string
funnelId?: string
funnelStep?: number
+ dropoff?: boolean
+ showDropoffToggle?: boolean
+ onDropoffChange?: (checked: boolean) => void
+ goalId?: string
+ errorId?: string
+ sessionEvent?: SessionEventType
+ title?: string
totalCount?: number
}
@@@ -88,9 -215,10 +219,13 @@@ export const SessionsDrawer = (
period = 'custom',
funnelId,
funnelStep,
+ dropoff,
+ showDropoffToggle,
+ onDropoffChange,
+ goalId,
+ errorId,
+ sessionEvent,
+ title,
totalCount,
}: SessionsDrawerProps) => {
const { t } = useTranslation('common')
@@@ -183,9 -352,13 +361,14 @@@
to,
timezone,
isFunnelMode,
+ isGoalMode,
+ isErrorMode,
funnelId,
funnelStep,
+ dropoff,
+ goalId,
+ errorId,
+ sessionEvent,
stableFilters,
t,
],
@@@ -274,16 -449,8 +459,16 @@@
<DrawerHeader>
<div className='flex items-start justify-between'>
<div className='min-w-0'>
- <DrawerTitle>{t('project.sessions')}</DrawerTitle>
+ <DrawerTitle>{title || t('project.sessions')}</DrawerTitle>
<DrawerDescription>{label}</DrawerDescription>
+ {isFunnelMode && showDropoffToggle ? (
+ <Switch
+ checked={Boolean(dropoff)}
+ onChange={onDropoffChange}
+ label={t('project.dropoffSessionsOnly')}
+ className='mt-3'
+ />
+ ) : null}
</div>
<div className='ml-3 flex shrink-0 items-center gap-2'>
{!initialLoading &&
diff --cc web/app/routes/api.analytics.ts
index 7d16ee1b3,e93cef568..d0195e6a2
--- a/web/app/routes/api.analytics.ts
+++ b/web/app/routes/api.analytics.ts
@@@ -158,7 -161,8 +161,9 @@@ interface ProxyRequest
query?: string
funnelId?: string
step?: number
+ dropoff?: boolean
+ goalId?: string
+ sessionEvent?: 'traffic' | 'performance' | 'error'
}
}