Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

clean-up session replay settings options

Francis Caoe9ac09ec5de4
diff --git a/src/app/(main)/websites/[websiteId]/settings/WebsiteReplaySettings.tsx b/src/app/(main)/websites/[websiteId]/settings/WebsiteReplaySettings.tsx
index 8a65e5d13..bc57e0da7 100644
--- a/src/app/(main)/websites/[websiteId]/settings/WebsiteReplaySettings.tsx
+++ b/src/app/(main)/websites/[websiteId]/settings/WebsiteReplaySettings.tsx
@@ -1,10 +1,11 @@
import {
+ Button,
Column,
- Form,
- FormButtons,
- FormField,
- FormSubmitButton,
Label,
+ ListItem,
+ Row,
+ Select,
+ Slider,
Switch,
TextField,
} from '@umami/react-zen';
@@ -16,27 +17,30 @@ interface ReplayConfig {
maskLevel?: string;
maxDuration?: number;
blockSelector?: string;
- retentionDays?: number;
}
export function WebsiteReplaySettings({ websiteId }: { websiteId: string }) {
const website = useWebsite();
const { t, labels, messages } = useMessages();
- const { mutateAsync, touch, toast } = useUpdateQuery(`/websites/${websiteId}`);
+ const { mutateAsync, touch, toast, isPending } = useUpdateQuery(`/websites/${websiteId}`);
const [enabled, setEnabled] = useState(website?.replayEnabled ?? false);
const config = (website?.replayConfig as ReplayConfig) || {};
- const handleSubmit = async (data: any) => {
+ const [sampleRate, setSampleRate] = useState(config.sampleRate ?? 0.15);
+ const [maskLevel, setMaskLevel] = useState(config.maskLevel ?? 'strict');
+ const [maxDuration, setMaxDuration] = useState(String(config.maxDuration ?? 300000));
+ const [blockSelector, setBlockSelector] = useState(config.blockSelector ?? '');
+
+ const handleSave = async () => {
await mutateAsync(
{
replayEnabled: enabled,
replayConfig: {
- sampleRate: parseFloat(data.sampleRate) || 1,
- maskLevel: data.maskLevel || 'moderate',
- maxDuration: parseInt(data.maxDuration, 10) || 600000,
- blockSelector: data.blockSelector || '',
- retentionDays: parseInt(data.retentionDays, 10) || 30,
+ sampleRate,
+ maskLevel,
+ maxDuration: parseInt(maxDuration, 10) || 300000,
+ ...(blockSelector && { blockSelector }),
},
},
{
@@ -50,47 +54,51 @@ export function WebsiteReplaySettings({ websiteId }: { websiteId: string }) {
};
return (
- <Form
- onSubmit={handleSubmit}
- values={{
- sampleRate: String(config.sampleRate ?? 1),
- maskLevel: config.maskLevel ?? 'moderate',
- maxDuration: String(config.maxDuration ?? 600000),
- blockSelector: config.blockSelector ?? '',
- retentionDays: String(config.retentionDays ?? 30),
- }}
- >
- <Column gap="4">
- <Label>{t(labels.replays)}</Label>
- <Switch isSelected={enabled} onChange={setEnabled}>
- {t(labels.replayEnabled)}
- </Switch>
- {enabled && (
- <>
- <FormField name="sampleRate" label={t(labels.sampleRate)}>
- <TextField />
- </FormField>
- <FormField
- name="maskLevel"
- label={`${t(labels.maskLevel)} (strict / moderate / relaxed)`}
- >
- <TextField />
- </FormField>
- <FormField name="maxDuration" label={`${t(labels.maxDuration)} (ms)`}>
- <TextField />
- </FormField>
- <FormField name="blockSelector" label={t(labels.blockSelector)}>
- <TextField />
- </FormField>
- <FormField name="retentionDays" label={t(labels.retentionDays)}>
- <TextField />
- </FormField>
- </>
- )}
- </Column>
- <FormButtons>
- <FormSubmitButton variant="primary">{t(labels.save)}</FormSubmitButton>
- </FormButtons>
- </Form>
+ <Column gap="4">
+ <Label>{t(labels.replays)}</Label>
+ <Switch isSelected={enabled} onChange={setEnabled}>
+ {t(labels.replayEnabled)}
+ </Switch>
+ {enabled && (
+ <>
+ <Slider
+ label={t(labels.sampleRate)}
+ minValue={0.05}
+ maxValue={1}
+ step={0.05}
+ value={sampleRate}
+ onChange={v => setSampleRate(Array.isArray(v) ? v[0] : v)}
+ showValue
+ formatOptions={{ style: 'percent', maximumFractionDigits: 0 }}
+ style={{ maxWidth: '360px' }}
+ />
+ <Column gap="1">
+ <Label>{t(labels.maskLevel)}</Label>
+ <Select value={maskLevel} onChange={setMaskLevel} style={{ maxWidth: '360px' }}>
+ <ListItem id="strict">strict</ListItem>
+ <ListItem id="moderate">moderate</ListItem>
+ </Select>
+ </Column>
+ <Column gap="1">
+ <Label>{t(labels.maxDuration)}</Label>
+ <Select value={maxDuration} onChange={setMaxDuration} style={{ maxWidth: '360px' }}>
+ <ListItem id="300000">5 minutes</ListItem>
+ <ListItem id="600000">10 minutes</ListItem>
+ <ListItem id="900000">15 minutes</ListItem>
+ <ListItem id="1200000">20 minutes</ListItem>
+ </Select>
+ </Column>
+ <Column gap="1">
+ <Label>{t(labels.blockSelector)}</Label>
+ <TextField value={blockSelector} onChange={setBlockSelector} />
+ </Column>
+ </>
+ )}
+ <Row>
+ <Button variant="primary" onPress={handleSave} isDisabled={isPending}>
+ {t(labels.save)}
+ </Button>
+ </Row>
+ </Column>
);
}
diff --git a/src/app/(main)/websites/[websiteId]/settings/WebsiteTrackingCode.tsx b/src/app/(main)/websites/[websiteId]/settings/WebsiteTrackingCode.tsx
index 85152e22c..a5f202faa 100644
--- a/src/app/(main)/websites/[websiteId]/settings/WebsiteTrackingCode.tsx
+++ b/src/app/(main)/websites/[websiteId]/settings/WebsiteTrackingCode.tsx
@@ -34,7 +34,16 @@ export function WebsiteTrackingCode({
if (website?.replayEnabled) {
const recorderUrl = getUrl(RECORDER_NAME);
- code += `\n<script defer src="${recorderUrl}" data-website-id="${websiteId}"></script>`;
+ const replayConfig = (website.replayConfig as any) || {};
+ let recorderAttrs = `data-website-id="${websiteId}"`;
+ if (replayConfig.sampleRate !== undefined)
+ recorderAttrs += ` data-sample-rate="${replayConfig.sampleRate}"`;
+ if (replayConfig.maskLevel) recorderAttrs += ` data-mask-level="${replayConfig.maskLevel}"`;
+ if (replayConfig.maxDuration !== undefined)
+ recorderAttrs += ` data-max-duration="${replayConfig.maxDuration}"`;
+ if (replayConfig.blockSelector)
+ recorderAttrs += ` data-block-selector="${replayConfig.blockSelector}"`;
+ code += `\n<script defer src="${recorderUrl}" ${recorderAttrs}></script>`;
}
return (
diff --git a/src/app/api/websites/[websiteId]/route.ts b/src/app/api/websites/[websiteId]/route.ts
index 80850f443..c74d018a3 100644
--- a/src/app/api/websites/[websiteId]/route.ts
+++ b/src/app/api/websites/[websiteId]/route.ts
@@ -46,10 +46,9 @@ export async function POST(
replayConfig: z
.object({
sampleRate: z.number().min(0).max(1).optional(),
- maskLevel: z.enum(['strict', 'moderate', 'relaxed']).optional(),
+ maskLevel: z.enum(['strict', 'moderate']).optional(),
maxDuration: z.number().int().positive().optional(),
blockSelector: z.string().optional(),
- retentionDays: z.number().int().positive().optional(),
})
.nullable()
.optional(),
diff --git a/src/recorder/index.js b/src/recorder/index.js
index 7e7db03cc..3d47af472 100644
--- a/src/recorder/index.js
+++ b/src/recorder/index.js
@@ -10,9 +10,9 @@ import { record } from 'rrweb';
const website = attr(`${_data}website-id`);
const hostUrl = attr(`${_data}host-url`);
- const sampleRate = parseFloat(attr(`${_data}sample-rate`) || '1');
- const maskLevel = attr(`${_data}mask-level`) || 'moderate';
- const maxDuration = parseInt(attr(`${_data}max-duration`) || '600000', 10);
+ const sampleRate = parseFloat(attr(`${_data}sample-rate`) || '0.15');
+ const maskLevel = attr(`${_data}mask-level`) || 'strict';
+ const maxDuration = parseInt(attr(`${_data}max-duration`) || '300000', 10);
const blockSelector = attr(`${_data}block-selector`) || '';
if (!website) return;
@@ -85,20 +85,11 @@ import { record } from 'rrweb';
case 'strict':
return {
maskAllInputs: true,
- maskTextContent: true,
- maskAllText: true,
+ maskTextSelector: '*',
};
- case 'relaxed':
+ default: // moderate
return {
maskAllInputs: true,
- maskTextContent: false,
- maskAllText: false,
- };
- default:
- return {
- maskAllInputs: true,
- maskTextContent: false,
- maskAllText: false,
};
}
};