📈 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!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Ask for optional website URL and timezone
Blue Mousef2e7ed3ec1a9
diff --git a/web/app/pages/Onboarding/Onboarding.tsx b/web/app/pages/Onboarding/Onboarding.tsxindex 1c8df2f51..51d0e048f 100644--- a/web/app/pages/Onboarding/Onboarding.tsx+++ b/web/app/pages/Onboarding/Onboarding.tsx@@ -17,6 +17,7 @@ import { toast } from 'sonner'import {BROWSER_LOGO_MAP,INTEGRATIONS_URL,+ DEFAULT_TIMEZONE,isSelfhosted,whitelist,languages,@@ -34,6 +35,7 @@ import type {import Button from '~/ui/Button'import Flag from '~/ui/Flag'import Input from '~/ui/Input'+import TimezonePicker from '~/ui/TimezonePicker'import TrackingSetup from '~/ui/TrackingSetup'import Loader from '~/ui/Loader'import Alert from '~/ui/Alert'@@ -41,6 +43,7 @@ import { Text } from '~/ui/Text'import { trackCustom } from '~/utils/analytics'import { cn } from '~/utils/generic'import routes from '~/utils/routes'+import { isValidHttpUrl } from '~/utils/url'const MAX_PROJECT_NAME_LENGTH = 50const ANIMATION_DURATION = 0.4@@ -450,11 +453,16 @@ const Onboarding = () => {})const [direction, setDirection] = useState(0)const [projectName, setProjectName] = useState('')+ const [projectWebsiteUrl, setProjectWebsiteUrl] = useState('')+ const [projectTimezone, setProjectTimezone] = useState(+ () => user?.timezone || DEFAULT_TIMEZONE,+ )const [project, setProject] = useState<Project | null>(loaderProject)const [selectedLanguage, setSelectedLanguage] = useState(i18n.language)const [newProjectErrors, setNewProjectErrors] = useState<{name?: string+ websiteUrl?: string}>({})const currentStep = STEPS[currentStepIndex]@@ -466,6 +474,12 @@ const Onboarding = () => {const totalSteps = stepsForProgress.lengthconst progressStepIndex = stepsForProgress.indexOf(currentStep)+ useEffect(() => {+ if (user?.timezone) {+ setProjectTimezone(user.timezone)+ }+ }, [user?.timezone])+useEffect(() => {if (!fetcher.data) returnif (lastHandledFetcherDataRef.current === fetcher.data) return@@ -475,6 +489,7 @@ const Onboarding = () => {const { intent, project: newProject } = fetcher.dataif (intent === 'create-project' && newProject) {+ loadUser()setTimeout(() => setProject(newProject), 0)goToStep('setup_tracking', { persist: true })} else if (intent === 'update-step') {@@ -485,11 +500,8 @@ const Onboarding = () => {}} else if (fetcher.data?.error) {toast.error(fetcher.data.error)- } else if (fetcher.data?.fieldErrors?.name) {- setTimeout(- () => setNewProjectErrors({ name: fetcher.data!.fieldErrors!.name }),- 0,- )+ } else if (fetcher.data?.fieldErrors) {+ setTimeout(() => setNewProjectErrors(fetcher.data!.fieldErrors!), 0)}// eslint-disable-next-line react-hooks/exhaustive-deps}, [fetcher.data, fetcher.submit, loadUser, logout, navigate])@@ -561,6 +573,14 @@ const Onboarding = () => {}}+ const clearNewProjectError = (field: keyof typeof newProjectErrors) => {+ setNewProjectErrors((current) => {+ const errors = { ...current }+ delete errors[field]+ return errors+ })+ }+const handleCreateProject = (e?: React.FormEvent<HTMLFormElement>) => {e?.preventDefault()e?.stopPropagation()@@ -568,18 +588,25 @@ const Onboarding = () => {if (fetcher.state !== 'idle') returnconst trimmedName = projectName.trim()+ const trimmedWebsiteUrl = projectWebsiteUrl.trim()+ const errors: typeof newProjectErrors = {}if (!trimmedName) {- setNewProjectErrors({ name: t('project.settings.noNameError') })- return+ errors.name = t('project.settings.noNameError')}if (trimmedName.length > MAX_PROJECT_NAME_LENGTH) {- setNewProjectErrors({- name: t('project.settings.pxCharsError', {- amount: MAX_PROJECT_NAME_LENGTH,- }),+ errors.name = t('project.settings.pxCharsError', {+ amount: MAX_PROJECT_NAME_LENGTH,})+ }++ if (trimmedWebsiteUrl && !isValidHttpUrl(trimmedWebsiteUrl)) {+ errors.websiteUrl = t('project.settings.invalidUrl')+ }++ if (Object.keys(errors).length) {+ setNewProjectErrors(errors)return}@@ -587,6 +614,10 @@ const Onboarding = () => {const formData = new FormData()formData.set('intent', 'create-project')formData.set('name', trimmedName)+ formData.set('timezone', projectTimezone)+ if (trimmedWebsiteUrl) {+ formData.set('websiteUrl', trimmedWebsiteUrl)+ }fetcher.submit(formData, { method: 'post' })}@@ -850,7 +881,7 @@ const Onboarding = () => {<ProjectVisualisation />- <div className='w-full sm:max-w-1/2'>+ <div className='w-full sm:max-w-md'><Inputlabel={t('project.settings.name')}hint={t('project.settings.nameHint')}@@ -861,10 +892,42 @@ const Onboarding = () => {value={projectName}onChange={(e) => {setProjectName(e.target.value)- setNewProjectErrors({})+ clearNewProjectError('name')}}error={newProjectErrors.name}/>+ <Input+ name='websiteUrl'+ label={t('project.settings.websiteUrl')}+ hint={t('project.settings.websiteUrlHint')}+ value={projectWebsiteUrl}+ placeholder={t(+ 'project.settings.websiteUrlPlaceholder',+ )}+ className='mt-4'+ onChange={(e) => {+ setProjectWebsiteUrl(e.target.value)+ clearNewProjectError('websiteUrl')+ }}+ error={newProjectErrors.websiteUrl}+ />+ <div className='mt-4'>+ <Text as='p' size='sm' weight='medium'>+ {t('profileSettings.timezone')}+ </Text>+ <Text+ as='p'+ size='xs'+ colour='secondary'+ className='mt-1 mb-2'+ >+ {t('onboarding.createProject.timezoneDesc')}+ </Text>+ <TimezonePicker+ value={projectTimezone}+ onChange={setProjectTimezone}+ />+ </div></div></form>)}diff --git a/web/app/routes/onboarding.tsx b/web/app/routes/onboarding.tsxindex d44158449..5da3399f5 100644--- a/web/app/routes/onboarding.tsx+++ b/web/app/routes/onboarding.tsx@@ -18,6 +18,10 @@ import {redirectIfNotAuthenticated,createHeadersWithCookies,} from '~/utils/session.server'+import { isValidHttpUrl } from '~/utils/url'++const INVALID_WEBSITE_URL_ERROR =+ 'Please enter a valid URL (e.g., https://example.com)'export const sitemap: SitemapFunction = () => ({exclude: true,@@ -150,6 +154,7 @@ export interface OnboardingActionData {error?: stringfieldErrors?: {name?: string+ websiteUrl?: string}project?: Projectuser?: User@@ -164,27 +169,78 @@ export async function action({ request }: ActionFunctionArgs) {switch (intent) {case 'create-project': {const name = formData.get('name')?.toString() || ''+ const trimmedName = name.trim()+ const websiteUrl = formData.get('websiteUrl')?.toString().trim()+ const timezone = formData.get('timezone')?.toString()+ const fieldErrors: OnboardingActionData['fieldErrors'] = {}- if (!name.trim()) {- return data<OnboardingActionData>(- { intent, fieldErrors: { name: 'Project name is required' } },- { status: 400 },- )+ if (!trimmedName) {+ fieldErrors.name = 'Project name is required'+ }++ if (trimmedName.length > 50) {+ fieldErrors.name = 'Project name must be 50 characters or less'+ }++ if (websiteUrl && !isValidHttpUrl(websiteUrl)) {+ fieldErrors.websiteUrl = INVALID_WEBSITE_URL_ERROR}- if (name.length > 50) {+ if (fieldErrors.name || fieldErrors.websiteUrl) {return data<OnboardingActionData>(- {- intent,- fieldErrors: { name: 'Project name must be 50 characters or less' },- },+ { intent, fieldErrors },{ status: 400 },)}+ const body: {+ name: string+ websiteUrl?: string+ } = {+ name: trimmedName,+ }+ if (websiteUrl) body.websiteUrl = websiteUrl++ let updatedUser: User | undefined+ const responseCookies: string[] = []++ if (timezone) {+ const authResult = await getAuthenticatedUser(request)+ const authenticatedUser = authResult?.user.user++ responseCookies.push(...(authResult?.cookies || []))++ if (!authenticatedUser?.email) {+ return data<OnboardingActionData>(+ { intent, error: 'Unable to update timezone' },+ { status: 400 },+ )+ }++ if (authenticatedUser.timezone !== timezone) {+ const userResult = await serverFetch<User>(request, 'user', {+ method: 'PUT',+ body: {+ email: authenticatedUser.email,+ timezone,+ },+ })++ if (userResult.error) {+ return data<OnboardingActionData>(+ { intent, error: userResult.error as string },+ { status: 400 },+ )+ }++ updatedUser = userResult.data as User+ responseCookies.push(...userResult.cookies)+ }+ }+const result = await serverFetch<Project>(request, 'project', {method: 'POST',- body: { name },+ body,})if (result.error) {@@ -194,9 +250,16 @@ export async function action({ request }: ActionFunctionArgs) {)}+ responseCookies.push(...result.cookies)+return data<OnboardingActionData>(- { intent, success: true, project: result.data as Project },- { headers: createHeadersWithCookies(result.cookies) },+ {+ intent,+ success: true,+ project: result.data as Project,+ user: updatedUser,+ },+ { headers: createHeadersWithCookies(responseCookies) },)}diff --git a/web/public/locales/en.json b/web/public/locales/en.jsonindex 8f902c118..e8fee6487 100644--- a/web/public/locales/en.json+++ b/web/public/locales/en.json@@ -2991,7 +2991,8 @@"navDesc": "Add a website to start tracking analytics.","title": "Let's set up your first project","desc": "Create a project to start tracking your website's analytics. Enter a name for it to continue.",- "placeholder": "My awesome website"+ "placeholder": "My awesome website",+ "timezoneDesc": "Project charts, date ranges, and timestamps will use this timezone. You can update it later."},"installTracking": {"navTitle": "Install tracking script",