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!

Simplify UI

Blue Mouseae2f40ccab04
diff --git a/web/app/pages/Project/Settings/ProjectSettings.tsx b/web/app/pages/Project/Settings/ProjectSettings.tsx
index ec04807ae..ad0961b4c 100644
--- a/web/app/pages/Project/Settings/ProjectSettings.tsx
+++ b/web/app/pages/Project/Settings/ProjectSettings.tsx
@@ -555,6 +555,45 @@ const ProjectSettings = () => {
'manual' | 'auto'
>(() => initialProject.captchaDifficultyMode || 'manual')
const [showRegenerateSecret, setShowRegenerateSecret] = useState(false)
+ const captchaDifficultyItems = useMemo(
+ () => [
+ {
+ value: 'auto' as const,
+ label: t('project.settings.captcha.difficultyLevels.auto'),
+ },
+ {
+ value: 2,
+ label: t('project.settings.captcha.difficultyLevels.veryEasy'),
+ },
+ {
+ value: 3,
+ label: t('project.settings.captcha.difficultyLevels.easy'),
+ },
+ {
+ value: 4,
+ label: t('project.settings.captcha.difficultyLevels.medium'),
+ },
+ {
+ value: 5,
+ label: t('project.settings.captcha.difficultyLevels.hard'),
+ },
+ {
+ value: 6,
+ label: t('project.settings.captcha.difficultyLevels.veryHard'),
+ },
+ ],
+ [t],
+ )
+ const selectedCaptchaDifficultyItem = useMemo(() => {
+ if (captchaDifficultyMode === 'auto') {
+ return captchaDifficultyItems[0]
+ }
+
+ return (
+ captchaDifficultyItems.find((item) => item.value === captchaDifficulty) ||
+ captchaDifficultyItems[3]
+ )
+ }, [captchaDifficulty, captchaDifficultyItems, captchaDifficultyMode])
// for reset data via filters
const [activeFilter, setActiveFilter] = useState<string[]>([])
@@ -1417,9 +1456,10 @@ const ProjectSettings = () => {
label={t('project.settings.captcha.secretKey')}
hint={t('project.settings.captcha.learnMore')}
name='captchaSecretKey'
+ type='password'
className='mt-4 lg:w-1/2'
value={captchaSecretKey}
- disabled
+ readOnly
/>
<div className='mt-4 flex gap-2'>
<Button
@@ -1432,49 +1472,6 @@ const ProjectSettings = () => {
</div>
<div className='mt-6'>
- <Select
- label={t('project.settings.captcha.difficultyMode')}
- hint={t(
- 'project.settings.captcha.difficultyModeHint',
- )}
- className='mb-4 lg:w-1/2'
- hintClassName='lg:w-2/3'
- items={[
- {
- value: 'manual' as const,
- label: t(
- 'project.settings.captcha.difficultyModes.manual',
- ),
- },
- {
- value: 'auto' as const,
- label: t(
- 'project.settings.captcha.difficultyModes.auto',
- ),
- },
- ]}
- keyExtractor={(item) => item.value}
- labelExtractor={(item) => item.label}
- selectedItem={{
- value: captchaDifficultyMode,
- label: '',
- }}
- onSelect={(item: {
- value: 'manual' | 'auto'
- label: string
- }) => {
- setCaptchaDifficultyMode(item.value)
- }}
- title={
- captchaDifficultyMode === 'auto'
- ? t(
- 'project.settings.captcha.difficultyModes.auto',
- )
- : t(
- 'project.settings.captcha.difficultyModes.manual',
- )
- }
- />
<Select
label={t('project.settings.captcha.difficulty')}
hint={
@@ -1484,68 +1481,23 @@ const ProjectSettings = () => {
}
className='lg:w-1/2'
hintClassName='lg:w-2/3'
- items={[
- {
- value: 2,
- label: t(
- 'project.settings.captcha.difficultyLevels.veryEasy',
- ),
- },
- {
- value: 3,
- label: t(
- 'project.settings.captcha.difficultyLevels.easy',
- ),
- },
- {
- value: 4,
- label: t(
- 'project.settings.captcha.difficultyLevels.medium',
- ),
- },
- {
- value: 5,
- label: t(
- 'project.settings.captcha.difficultyLevels.hard',
- ),
- },
- {
- value: 6,
- label: t(
- 'project.settings.captcha.difficultyLevels.veryHard',
- ),
- },
- ]}
+ items={captchaDifficultyItems}
keyExtractor={(item) => String(item.value)}
labelExtractor={(item) => item.label}
- selectedItem={{ value: captchaDifficulty, label: '' }}
+ selectedItem={selectedCaptchaDifficultyItem}
onSelect={(item: {
- value: number
+ value: number | 'auto'
label: string
}) => {
+ if (item.value === 'auto') {
+ setCaptchaDifficultyMode('auto')
+ return
+ }
+
+ setCaptchaDifficultyMode('manual')
setCaptchaDifficulty(item.value)
}}
- title={
- captchaDifficulty === 2
- ? t(
- 'project.settings.captcha.difficultyLevels.veryEasy',
- )
- : captchaDifficulty === 3
- ? t(
- 'project.settings.captcha.difficultyLevels.easy',
- )
- : captchaDifficulty === 4
- ? t(
- 'project.settings.captcha.difficultyLevels.medium',
- )
- : captchaDifficulty === 5
- ? t(
- 'project.settings.captcha.difficultyLevels.hard',
- )
- : t(
- 'project.settings.captcha.difficultyLevels.veryHard',
- )
- }
+ title={selectedCaptchaDifficultyItem.label}
/>
<Button
type='button'
diff --git a/web/app/pages/Project/tabs/Captcha/CaptchaView.tsx b/web/app/pages/Project/tabs/Captcha/CaptchaView.tsx
index 189fac37a..fc8b30761 100644
--- a/web/app/pages/Project/tabs/Captcha/CaptchaView.tsx
+++ b/web/app/pages/Project/tabs/Captcha/CaptchaView.tsx
@@ -1,6 +1,5 @@
import cx from 'clsx'
import _isEmpty from 'lodash/isEmpty'
-import _keys from 'lodash/keys'
import _map from 'lodash/map'
import {
CompassIcon,
@@ -50,14 +49,14 @@ import NoCaptchaEvents from './NoCaptchaEvents'
import WaitingForCaptchaEvent from './WaitingForCaptchaEvent'
const PANELS_ORDER = [
- 'captcha_event',
- 'captcha_difficulty',
- 'captcha_reason',
- 'solve_time',
'cc',
'br',
'os',
'dv',
+ 'captcha_event',
+ 'captcha_difficulty',
+ 'solve_time',
+ 'captcha_reason',
]
const iconClassName = 'w-6 h-6'
@@ -114,6 +113,7 @@ const CaptchaView = ({ projectId }: CaptchaViewProps) => {
replayed?: number[]
} | null>(null)
const [summaryData, setSummaryData] = useState<any | null>(null)
+ const [summaryCompareData, setSummaryCompareData] = useState<any | null>(null)
const [isPanelsDataEmpty, setIsPanelsDataEmpty] = useState(false)
const [analyticsLoading, setAnalyticsLoading] = useState(true)
const [dataLoading, setDataLoading] = useState(false)
@@ -167,13 +167,29 @@ const CaptchaView = ({ projectId }: CaptchaViewProps) => {
to = getFormatDate(dateRange[1])
}
- const data = await captchaProxy.fetchCaptcha(projectId, {
+ const requestParams = {
timeBucket,
period: period === 'custom' && dateRange ? '' : period,
filters,
from: period === 'custom' && dateRange ? from : '',
to: period === 'custom' && dateRange ? to : '',
- })
+ }
+ const compareFrom = searchParams.get('compareFrom') || ''
+ const compareTo = searchParams.get('compareTo') || ''
+ const compareEnabled =
+ searchParams.get('compare') === 'true' && compareFrom && compareTo
+
+ const [data, compareData] = await Promise.all([
+ captchaProxy.fetchCaptcha(projectId, requestParams),
+ compareEnabled
+ ? captchaProxy.fetchCaptcha(projectId, {
+ ...requestParams,
+ period: '',
+ from: compareFrom,
+ to: compareTo,
+ })
+ : Promise.resolve(null),
+ ])
if (!isMountedRef.current) return
@@ -183,6 +199,7 @@ const CaptchaView = ({ projectId }: CaptchaViewProps) => {
setIsPanelsDataEmpty(true)
setChartData(null)
setSummaryData(null)
+ setSummaryCompareData(null)
return
}
@@ -194,17 +211,17 @@ const CaptchaView = ({ projectId }: CaptchaViewProps) => {
setChartData(null)
}
- if (_isEmpty(params)) {
- setIsPanelsDataEmpty(true)
- } else {
- setPanelsData({
- types: _keys(params),
- data: params,
- })
- setIsPanelsDataEmpty(false)
- }
+ const hasData =
+ !_isEmpty(params) || !_isEmpty(chart?.x) || !_isEmpty(summary)
+
+ setPanelsData({
+ types: PANELS_ORDER,
+ data: params || {},
+ })
+ setIsPanelsDataEmpty(!hasData)
setSummaryData(summary || null)
+ setSummaryCompareData(compareData?.summary || null)
setAnalyticsLoading(false)
setDataLoading(false)
} catch (reason) {
@@ -214,6 +231,7 @@ const CaptchaView = ({ projectId }: CaptchaViewProps) => {
setIsPanelsDataEmpty(true)
setChartData(null)
setSummaryData(null)
+ setSummaryCompareData(null)
console.error('[ERROR](loadCaptcha) Loading captcha data failed:', reason)
}
}
@@ -249,29 +267,68 @@ const CaptchaView = ({ projectId }: CaptchaViewProps) => {
// Check if we have existing data
const hasExistingData = chartData !== null || !_isEmpty(panelsData.types)
- const formatPercent = (value?: number) => `${Number(value || 0).toFixed(1)}%`
+ const formatNumber = (value: number, type: 'main' | 'badge') =>
+ `${type === 'badge' && value > 0 ? '+' : ''}${nFormatter(value, 1)}`
+ const formatPercent = (value: number, type: 'main' | 'badge') =>
+ `${type === 'badge' && value > 0 ? '+' : ''}${Number(value || 0).toFixed(1)}%`
const formatSeconds = (value?: number) =>
value ? `${Number(value).toFixed(2)}s` : 'N/A'
+ const formatSecondsChange = (value: number) =>
+ `${value > 0 ? '+' : value < 0 ? '-' : ''}${Math.abs(Number(value || 0)).toFixed(2)}s`
const formatReason = (value?: string | null) =>
value
? t(`project.captchaAnalytics.reasons.${value}`, { defaultValue: value })
: 'N/A'
+ const formatDifficulty = (value?: string | null) => {
+ switch (Number(value)) {
+ case 2:
+ return t('project.settings.captcha.difficultyLevels.veryEasy')
+ case 3:
+ return t('project.settings.captcha.difficultyLevels.easy')
+ case 4:
+ return t('project.settings.captcha.difficultyLevels.medium')
+ case 5:
+ return t('project.settings.captcha.difficultyLevels.hard')
+ case 6:
+ return t('project.settings.captcha.difficultyLevels.veryHard')
+ default:
+ return t('project.captchaAnalytics.difficultyValue', { value })
+ }
+ }
const summaryCards = summaryData
? [
{
label: t('project.captchaAnalytics.generated'),
value: summaryData.generated || 0,
- valueMapper: (value: number) => nFormatter(value, 1),
+ change: summaryCompareData
+ ? (summaryData.generated || 0) - (summaryCompareData.generated || 0)
+ : undefined,
+ goodChangeDirection: 'down' as const,
+ valueMapper: formatNumber,
},
{
label: t('project.captchaAnalytics.passRate'),
- value: formatPercent(summaryData.passRate),
- valueMapper: (value: string) => value,
+ value: summaryData.passRate || 0,
+ change: summaryCompareData
+ ? (summaryData.passRate || 0) - (summaryCompareData.passRate || 0)
+ : undefined,
+ goodChangeDirection: 'down' as const,
+ valueMapper: formatPercent,
},
{
label: t('project.captchaAnalytics.medianSolve'),
- value: formatSeconds(summaryData.solveP50),
- valueMapper: (value: string) => value,
+ value: summaryData.solveP50 || 0,
+ change:
+ summaryCompareData &&
+ summaryData.solveP50 > 0 &&
+ summaryCompareData.solveP50 > 0
+ ? summaryData.solveP50 - summaryCompareData.solveP50
+ : undefined,
+ goodChangeDirection: 'up' as const,
+ valueMapper: (value: number, type: 'main' | 'badge') =>
+ type === 'badge'
+ ? formatSecondsChange(value)
+ : formatSeconds(value),
},
]
: []
@@ -333,6 +390,8 @@ const CaptchaView = ({ projectId }: CaptchaViewProps) => {
key={card.label}
label={card.label}
value={card.value}
+ change={card.change}
+ goodChangeDirection={card.goodChangeDirection}
valueMapper={card.valueMapper}
/>
))}
@@ -341,14 +400,11 @@ const CaptchaView = ({ projectId }: CaptchaViewProps) => {
</CaptchaChart>
) : null}
<div className='mt-3 grid grid-cols-1 gap-3 sm:grid-cols-2'>
- {!_isEmpty(panelsData.types)
+ {panelsData.types
? _map(PANELS_ORDER, (type: keyof typeof tnMapping) => {
- if (_isEmpty(panelsData.data[type])) {
- return null
- }
-
const panelName = tnMapping[type]
const panelIcon = panelIconMapping[type]
+ const panelData = panelsData.data?.[type] || []
if (type === 'cc') {
const rowMapper = (entry: any) => {
@@ -368,7 +424,7 @@ const CaptchaView = ({ projectId }: CaptchaViewProps) => {
id={type}
getFilterLink={getFilterLink}
name={panelName}
- data={panelsData.data[type]}
+ data={panelData}
rowMapper={rowMapper}
activeTabId={type}
/>
@@ -383,7 +439,7 @@ const CaptchaView = ({ projectId }: CaptchaViewProps) => {
id={type}
getFilterLink={getFilterLink}
name={panelName}
- data={panelsData.data[type]}
+ data={panelData}
rowMapper={(entry: {
name: keyof typeof deviceIconMapping
}) => {
@@ -436,7 +492,7 @@ const CaptchaView = ({ projectId }: CaptchaViewProps) => {
id={type}
getFilterLink={getFilterLink}
name={panelName}
- data={panelsData.data[type]}
+ data={panelData}
rowMapper={rowMapper}
activeTabId={type}
/>
@@ -484,7 +540,7 @@ const CaptchaView = ({ projectId }: CaptchaViewProps) => {
id={type}
getFilterLink={getFilterLink}
name={panelName}
- data={panelsData.data[type]}
+ data={panelData}
rowMapper={rowMapper}
activeTabId={type}
/>
@@ -499,7 +555,7 @@ const CaptchaView = ({ projectId }: CaptchaViewProps) => {
id={type}
getFilterLink={getFilterLink}
name={panelName}
- data={panelsData.data[type]}
+ data={panelData}
rowMapper={(entry: any) =>
t(`project.captchaAnalytics.events.${entry.name}`, {
defaultValue: entry.name,
@@ -518,7 +574,7 @@ const CaptchaView = ({ projectId }: CaptchaViewProps) => {
id={type}
getFilterLink={getFilterLink}
name={panelName}
- data={panelsData.data[type]}
+ data={panelData}
rowMapper={(entry: any) => formatReason(entry.name)}
activeTabId={type}
/>
@@ -533,12 +589,8 @@ const CaptchaView = ({ projectId }: CaptchaViewProps) => {
id={type}
getFilterLink={getFilterLink}
name={panelName}
- data={panelsData.data[type]}
- rowMapper={(entry: any) =>
- t('project.captchaAnalytics.difficultyValue', {
- value: entry.name,
- })
- }
+ data={panelData}
+ rowMapper={(entry: any) => formatDifficulty(entry.name)}
activeTabId={type}
/>
)
@@ -551,7 +603,7 @@ const CaptchaView = ({ projectId }: CaptchaViewProps) => {
id={type}
getFilterLink={getFilterLink}
name={panelName}
- data={panelsData.data[type]}
+ data={panelData}
activeTabId={type}
/>
)
diff --git a/web/app/pages/UserSettings/UserSettings.tsx b/web/app/pages/UserSettings/UserSettings.tsx
index 0d5072025..d00a013bb 100644
--- a/web/app/pages/UserSettings/UserSettings.tsx
+++ b/web/app/pages/UserSettings/UserSettings.tsx
@@ -858,8 +858,9 @@ const UserSettings = () => {
<Input
label={t('profileSettings.apiKey')}
name='apiKey'
+ type='password'
value={user.apiKey}
- disabled
+ readOnly
/>
</div>
<Button
diff --git a/web/app/ui/Input.tsx b/web/app/ui/Input.tsx
index 0d0993809..315eaf139 100644
--- a/web/app/ui/Input.tsx
+++ b/web/app/ui/Input.tsx
@@ -99,14 +99,14 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
<button
type='button'
onClick={() => {
- if (disabled || readOnly) return
+ if (disabled) return
setShowPassword(!showPassword)
}}
aria-label={showPassword ? 'Hide password' : 'Show password'}
aria-pressed={showPassword}
- disabled={disabled || readOnly}
- aria-disabled={disabled || readOnly || undefined}
- tabIndex={disabled || readOnly ? -1 : 0}
+ disabled={disabled}
+ aria-disabled={disabled || undefined}
+ tabIndex={disabled ? -1 : 0}
className='absolute inset-y-0 right-0 my-1 mr-1 flex items-center rounded-md px-2 text-gray-400 transition-colors hover:text-gray-700 focus-visible:ring-2 focus-visible:ring-slate-900 focus-visible:outline-hidden disabled:cursor-not-allowed disabled:opacity-60 disabled:hover:text-gray-400 dark:text-gray-500 dark:hover:text-gray-200 dark:focus-visible:ring-slate-300 dark:disabled:hover:text-gray-500'
>
{showPassword ? (
diff --git a/web/public/locales/en.json b/web/public/locales/en.json
index 16ab16c30..d822a3ee9 100644
--- a/web/public/locales/en.json
+++ b/web/public/locales/en.json
@@ -1967,7 +1967,7 @@
"ctp": "Connection type",
"searchEngine": "Search engine",
"aiReferral": "AI referral",
- "captcha_event": "CAPTCHA events",
+ "captcha_event": "Challenge status",
"captcha_difficulty": "Difficulty",
"captcha_reason": "Auto difficulty reasons",
"solve_time": "Solve time"
@@ -2297,16 +2297,11 @@
"regenerateKeyWarning": "Are you sure you want to regenerate the secret key? This will invalidate the current key and all applications using it will need to be updated.",
"noKeyGenerated": "No secret key has been generated yet. Generate one to enable CAPTCHA for this project.",
"learnMore": "Use this secret key in your backend to verify CAPTCHA tokens. Learn more in our documentation.",
- "difficultyMode": "Difficulty mode",
- "difficultyModeHint": "Manual always uses the selected difficulty. Auto starts from the selected fallback and raises difficulty when risk signals increase.",
- "difficultyModes": {
- "manual": "Manual",
- "auto": "Auto"
- },
"difficulty": "CAPTCHA difficulty",
"difficultyHint": "Higher difficulty levels provide better bot protection but may be more challenging for users to solve.",
- "difficultyAutoHint": "Auto uses this as the fallback difficulty, then raises it for traffic spikes, replay attempts, hosting IPs, and other risk signals.",
+ "difficultyAutoHint": "Auto picks the challenge difficulty dynamically based on traffic spikes, replay attempts, hosting IPs, and other risk signals.",
"difficultyLevels": {
+ "auto": "Auto",
"veryEasy": "Very easy",
"easy": "Easy",
"medium": "Medium",