π 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
Make users start a paid trial after onboarding
Blue Mouse9a85c8bd1897
diff --git a/admin/src/entities/user.entity.ts b/admin/src/entities/user.entity.tsindex 78cf5ccfc..ad1419a2f 100644--- a/admin/src/entities/user.entity.ts+++ b/admin/src/entities/user.entity.ts@@ -41,7 +41,7 @@ export class User {@Column({type: 'enum',enum: PlanCode,- default: PlanCode.trial,+ default: PlanCode.none,})planCode: PlanCodediff --git a/backend/apps/cloud/src/common/templates/en/customer_sign-up.html b/backend/apps/cloud/src/common/templates/en/customer_sign-up.htmlindex 12366812a..88e2ea45a 100644--- a/backend/apps/cloud/src/common/templates/en/customer_sign-up.html+++ b/backend/apps/cloud/src/common/templates/en/customer_sign-up.html@@ -1,29 +1,47 @@Welcome to Swetrix! We're thrilled to have you on board.<br /><br />-Swetrix is an ethical, cookieless web analytics platform. We help you understand your website traffic, track errors, and make data-driven decisions without invading your users' privacy.<br /><br />+Swetrix is an ethical, cookieless web analytics platform. We help you understand+your website traffic, track errors, and make data-driven decisions without+invading your users' privacy.<br /><br />-<b>Your 14-day free trial has started.</b> You have full access to all features during your trial. Here's what happens next:<br />+<b>Your 14-day free trial has started.</b> You have full access to all features+during your trial. Here's what happens next:<br /><ul><li><b>Today</b> β Explore all features with no limits</li><li><b>Day 12</b> β We'll send you a reminder before your trial ends</li>- <li><b>Day 14</b> β Your subscription begins automatically, unless you cancel</li>+ <li>+ <b>Day 14</b> β Your subscription begins automatically, unless you cancel+ </li></ul>-You can manage your subscription or cancel anytime from your <a href="https://swetrix.com/billing" target="_blank">Billing page</a>.<br /><br />+You can manage your subscription or cancel anytime from your+<a href="https://swetrix.com/billing" target="_blank">Billing page</a+>.<br /><br /><b>Get started:</b><br /><ul>- <li><a href="https://swetrix.com/dashboard" target="_blank">Go to your Dashboard</a></li>- <li><a href="https://swetrix.com/docs" target="_blank">Read the Setup Guide</a></li>- <li><a href="https://swetrix.com/docs/integrations" target="_blank">Browse Integrations</a></li>+ <li>+ <a href="https://swetrix.com/dashboard" target="_blank"+ >Go to your Dashboard</a+ >+ </li>+ <li>+ <a href="https://swetrix.com/docs" target="_blank">Read the Setup Guide</a>+ </li>+ <li>+ <a href="https://swetrix.com/docs/integrations" target="_blank"+ >Browse Integrations</a+ >+ </li></ul>-To verify your email address, please <a href="{{url}}">click here</a>.<br /><br />+To verify your email address, please+<a href="{{url}}">click here</a>.<br /><br />-If you're having trouble with the link above, copy and paste this URL into your browser:<br />+If you're having trouble with the link above, copy and paste this URL into your+browser:<br />{{url}}<br /><br />Questions? Just reply to this email - we're happy to help.<br /><br />-Andrii Romasiun,-Swetrix+Andrii Romasiun, Swetrixdiff --git a/backend/apps/cloud/src/common/templates/en/trial-ends-tomorrow.html b/backend/apps/cloud/src/common/templates/en/trial-ends-tomorrow.htmlindex 3413a893f..f99ba1c2e 100644--- a/backend/apps/cloud/src/common/templates/en/trial-ends-tomorrow.html+++ b/backend/apps/cloud/src/common/templates/en/trial-ends-tomorrow.html@@ -2,13 +2,19 @@ Hey there,<br /><br />Just a heads up - your free Swetrix trial ends in about 48 hours.<br /><br />-Most companies don't email you before your trial expires because they hope you'll forget and get charged anyway. We're doing the opposite β we don't want your money if you don't want to give it to us.<br /><br />+Most companies don't email you before your trial expires because they hope+you'll forget and get charged anyway. We're doing the opposite β we don't want+your money if you don't want to give it to us.<br /><br />-If you're loving Swetrix, you don't need to do anything. Your subscription will begin automatically and you'll keep getting privacy-first analytics without interruption.<br /><br />+If you're loving Swetrix, you don't need to do anything. Your subscription will+begin automatically and you'll keep getting privacy-first analytics without+interruption.<br /><br />-If it's not the right fit, no hard feelings. You can <a href="{{url}}" target="_blank">cancel from your billing page</a> before the trial ends and you won't be charged.<br /><br />+If it's not the right fit, no hard feelings. You can+<a href="{{url}}" target="_blank">cancel from your billing page</a> before the+trial ends and you won't be charged.<br /><br />-Got questions about your plan, features, or anything else? Just reply to this email β we're here to help.<br /><br />+Got questions about your plan, features, or anything else? Just reply to this+email β we're here to help.<br /><br />-Andrii Romasiun,-Swetrix+Andrii Romasiun, Swetrixdiff --git a/backend/apps/cloud/src/user/entities/user.entity.ts b/backend/apps/cloud/src/user/entities/user.entity.tsindex acd86b5b1..dc7c7e7f7 100644--- a/backend/apps/cloud/src/user/entities/user.entity.ts+++ b/backend/apps/cloud/src/user/entities/user.entity.ts@@ -231,7 +231,7 @@ export class User {@Column({type: 'enum',enum: PlanCode,- default: PlanCode.trial,+ default: PlanCode.none,})planCode: PlanCodediff --git a/backend/apps/cloud/src/user/user.service.ts b/backend/apps/cloud/src/user/user.service.tsindex 4d1d6abfb..729f5c7e6 100644--- a/backend/apps/cloud/src/user/user.service.ts+++ b/backend/apps/cloud/src/user/user.service.ts@@ -461,8 +461,7 @@ export class UserService {throw new BadRequestException('No active subscription found')}- const url =- 'https://vendors.paddle.com/api/2.0/subscription/users/cancel'+ const url = 'https://vendors.paddle.com/api/2.0/subscription/users/cancel'try {const result = await axios.post(url, {diff --git a/web/app/components/Header/index.tsx b/web/app/components/Header/index.tsxindex 350d50bdc..283db84aa 100644--- a/web/app/components/Header/index.tsx+++ b/web/app/components/Header/index.tsx@@ -72,11 +72,11 @@ import Modal from '~/ui/Modal'import routes from '~/utils/routes'import { cn } from '~/utils/generic'+const CONTACT_US_URL = `https://swetrix.com${routes.contact}`+dayjs.extend(utc)dayjs.extend(duration)-const CONTACT_US_URL = `https://swetrix.com${routes.contact}`-const TRIAL_STATUS_MAPPING = {ENDED: 1,ENDS_TODAY: 2,@@ -648,10 +648,7 @@ const BannerManager = () => {const trialBannerHidden = useMemo(() => {return (- !status ||- isSelfhosted ||- !isAuthenticated ||- !['none', 'trial'].includes(user?.planCode || '')+ !status || isSelfhosted || !isAuthenticated || user?.planCode !== 'trial')}, [status, isAuthenticated, user?.planCode])diff --git a/web/app/pages/Checkout/Checkout.tsx b/web/app/pages/Checkout/Checkout.tsxindex 3af31341d..1e8830d53 100644--- a/web/app/pages/Checkout/Checkout.tsx+++ b/web/app/pages/Checkout/Checkout.tsx@@ -12,6 +12,7 @@ import { toast } from 'sonner'import {BillingFrequency,+ CURRENCIES,PADDLE_JS_URL,PADDLE_VENDOR_ID,paddleLanguageMapping,@@ -43,7 +44,9 @@ const Checkout = () => {if (typeof document === 'undefined') return '100k'return getCookie('swetrix_selected_plan') || '100k'})- const [selectedBillingFrequency, setSelectedBillingFrequency] = useState<'monthly' | 'yearly'>(() => {+ const [selectedBillingFrequency, setSelectedBillingFrequency] = useState<+ 'monthly' | 'yearly'+ >(() => {if (typeof document === 'undefined') return 'monthly'return getCookie('swetrix_selected_billing') === 'yearly'? 'yearly'@@ -55,13 +58,15 @@ const Checkout = () => {const [hasCompletedCheckout, setHasCompletedCheckout] = useState(false)const [isCheckoutOpen, setIsCheckoutOpen] = useState(false)+ const currencyCode = user?.tierCurrency || metainfo.code+ const currency = CURRENCIES[currencyCode] || CURRENCIES.USDconst tier = PLAN_LIMITS[selectedPlan as keyof typeof PLAN_LIMITS]- const monthlyPrice = tier?.price?.USD?.monthly- const yearlyPrice = tier?.price?.USD?.yearly+ const monthlyPrice =+ tier?.price?.[currencyCode]?.monthly ?? tier?.price?.USD?.monthly+ const yearlyPrice =+ tier?.price?.[currencyCode]?.yearly ?? tier?.price?.USD?.yearlyconst displayPrice =- selectedBillingFrequency === 'yearly'- ? Math.round((yearlyPrice || 0) / 12)- : monthlyPrice+ selectedBillingFrequency === 'yearly' ? yearlyPrice : monthlyPriceuseEffect(() => {document.cookie = `swetrix_selected_plan=${selectedPlan}; path=/; max-age=86400`@@ -100,9 +105,7 @@ const Checkout = () => {const handleStartCheckout = () => {if (!isPaddleLoaded || !(window as any).Paddle) {- toast.error(- 'Payment script is still loading. Please try again.',- )+ toast.error('Payment script is still loading. Please try again.')return}@@ -138,35 +141,40 @@ const Checkout = () => {const today = new Date()const trialEndDate = new Date()trialEndDate.setDate(today.getDate() + TRIAL_DAYS)-+const dateFormatter = new Intl.DateTimeFormat(i18n.language, {month: 'long',day: 'numeric',year: 'numeric',})-+const formattedEndDate = dateFormatter.format(trialEndDate)return (- <div className='flex min-h-screen flex-col items-center justify-center bg-gray-50 p-4 dark:bg-slate-950 lg:p-8'>- <div className='w-full max-w-5xl grid grid-cols-1 lg:grid-cols-[1fr_400px] gap-12 lg:gap-16 items-start'>-+ <div className='flex min-h-screen flex-col items-center bg-gray-50 p-4 lg:p-8 dark:bg-slate-950'>+ <div className='grid w-full max-w-5xl grid-cols-1 items-start gap-12 lg:grid-cols-[1fr_400px] lg:gap-16'>{/* Left Column */}<div className='flex flex-col gap-8'><div>- <Text as='h1' size='3xl' weight='bold' tracking='tight'>+ <Text as='h1' size='4xl' weight='bold' tracking='tight'>{t('checkout.title')}</Text>-+<div className='mt-6 flex flex-col gap-3'><div className='flex items-center gap-3'>- <CheckIcon className='size-5 shrink-0 text-emerald-500' weight='bold' />+ <CheckIcon+ className='size-5 shrink-0 text-emerald-500'+ weight='bold'+ /><Text as='p' size='base'>{t('checkout.freeTrialAnytime', { days: TRIAL_DAYS })}</Text></div><div className='flex items-center gap-3'>- <CheckIcon className='size-5 shrink-0 text-emerald-500' weight='bold' />+ <CheckIcon+ className='size-5 shrink-0 text-emerald-500'+ weight='bold'+ /><Text as='p' size='base'>{t('checkout.willRemind')}</Text>@@ -177,7 +185,7 @@ const Checkout = () => {<div><div className='mb-3 flex items-center justify-between'><Text as='p' size='sm' colour='secondary'>- Select your plan+ {t('checkout.selectPlan')}</Text><buttontype='button'@@ -206,13 +214,16 @@ const Checkout = () => {0,showAllPlans ? undefined : INITIAL_VISIBLE_PLANS,).map((planCode) => {- const planTier = PLAN_LIMITS[planCode as keyof typeof PLAN_LIMITS]+ const planTier =+ PLAN_LIMITS[planCode as keyof typeof PLAN_LIMITS]if (!planTier) return nullconst isSelected = selectedPlan === planCodeconst price =selectedBillingFrequency === 'monthly'- ? planTier.price?.USD?.monthly- : planTier.price?.USD?.yearly+ ? (planTier.price?.[currencyCode]?.monthly ??+ planTier.price?.USD?.monthly)+ : (planTier.price?.[currencyCode]?.yearly ??+ planTier.price?.USD?.yearly)const priceLabel =selectedBillingFrequency === 'monthly'? t('pricing.perMonth')@@ -224,14 +235,15 @@ const Checkout = () => {type='button'onClick={() => setSelectedPlan(planCode)}className={cn(- 'flex w-full items-center justify-between rounded-xl px-4 py-3 text-left ring-1 transition-all duration-150',+ 'flex w-full items-center justify-between rounded-lg px-4 py-3 text-left ring-1 transition-all duration-150 ring-inset',isSelected- ? 'ring-2 ring-indigo-500 bg-white shadow-sm dark:bg-slate-900 dark:ring-slate-200'- : 'ring-gray-200 bg-white hover:ring-gray-300 dark:bg-slate-900 dark:ring-slate-700 dark:hover:ring-slate-600',+ ? 'bg-white shadow-sm ring-2 ring-indigo-500 dark:bg-slate-900 dark:ring-slate-200'+ : 'bg-white ring-gray-200 hover:ring-gray-300 dark:bg-slate-900 dark:ring-slate-700 dark:hover:ring-slate-600',)}><Text as='span' size='base' weight='semibold'>- ${price}+ {currency.symbol}+ {price}<Text as='span' size='sm' colour='muted' weight='medium'>/{priceLabel}</Text>@@ -267,15 +279,21 @@ const Checkout = () => {{t('checkout.dueEnd', { date: formattedEndDate })}</Text><Text as='p' size='base' weight='semibold'>- ${displayPrice}+ {currency.symbol}+ {displayPrice}</Text></div><div className='flex items-center justify-between'><Text as='p' size='base' weight='bold'>{t('checkout.dueToday', { days: TRIAL_DAYS })}</Text>- <Text as='p' size='base' weight='bold' className='text-emerald-600 dark:text-emerald-500'>- {t('checkout.free')}+ <Text+ as='p'+ size='base'+ weight='bold'+ className='text-emerald-600 dark:text-emerald-500'+ >+ {currency.symbol}0</Text></div></div>@@ -309,9 +327,14 @@ const Checkout = () => {)}<div id='checkout-container' className='min-h-0 w-full' />-+{!isCheckoutOpen && (- <Text as='p' size='xs' colour='muted' className='mt-4 text-center'>+ <Text+ as='p'+ size='xs'+ colour='muted'+ className='mt-4 text-center'+ ><Transt={t}i18nKey='checkout.termsDesc'@@ -335,7 +358,7 @@ const Checkout = () => {{/* Right Column (Timeline) */}<div className='hidden lg:block lg:pt-16'>- <div className='rounded-2xl bg-white p-6 shadow-xs ring-1 ring-gray-200 dark:bg-slate-900 dark:ring-slate-700/80'>+ <div className='rounded-lg bg-white p-6 shadow-xs ring-1 ring-gray-200 dark:bg-slate-900 dark:ring-slate-700/80'><div className='flex items-start gap-5'><div className='relative flex flex-col items-center'><div className='flex size-10 items-center justify-center rounded-full bg-emerald-100 dark:bg-emerald-900/30'>@@ -391,7 +414,6 @@ const Checkout = () => {</div></div></div>-</div></div>)diff --git a/web/app/pages/UserSettings/UserSettings.tsx b/web/app/pages/UserSettings/UserSettings.tsxindex 1b177fc78..23a1b0af7 100644--- a/web/app/pages/UserSettings/UserSettings.tsx+++ b/web/app/pages/UserSettings/UserSettings.tsx@@ -244,7 +244,13 @@ interface Form extends Partial<User> {}const UserSettings = () => {- const { user, logout, mergeUser, loadUser, isLoading: authLoading } = useAuth()+ const {+ user,+ logout,+ mergeUser,+ loadUser,+ isLoading: authLoading,+ } = useAuth()const loaderData = useLoaderData<UserSettingsLoaderData>()const { theme } = useTheme()@@ -260,7 +266,8 @@ const UserSettings = () => {const [isCancelSubModalOpened, setIsCancelSubModalOpened] = useState(false)const [cancellationFeedback, setCancellationFeedback] = useState('')- const [isCancellingSubscription, setIsCancellingSubscription] = useState(false)+ const [isCancellingSubscription, setIsCancellingSubscription] =+ useState(false)const [lastEvent, setLastEvent] = useState<{ event: string } | null>(null)const metainfo = useMemo(() => {@@ -522,7 +529,7 @@ const UserSettings = () => {}toast.error(fetcher.data.error)}- }, [fetcher.data, fetcher.state, mergeUser, t, logout, navigate])+ }, [fetcher.data, fetcher.state, mergeUser, t, logout, navigate, loadUser])const errors = useMemo(() => {const allErrors: Record<string, string> = {}@@ -1270,8 +1277,7 @@ const UserSettings = () => {title={t('profileSettings.trialActive')}className='mb-6'>- {trialEndsOnMessage}{' '}- {t('billing.trialChargeWarning')}+ {trialEndsOnMessage} {t('billing.trialChargeWarning')}</Alert>) : null}diff --git a/web/app/routes/checkout.tsx b/web/app/routes/checkout.tsxindex 9969b2d10..1b0b0409c 100644--- a/web/app/routes/checkout.tsx+++ b/web/app/routes/checkout.tsx@@ -54,11 +54,7 @@ export async function loader({ request }: LoaderFunctionArgs) {}// If the user already has a paid subscription, skip checkout- if (- user?.planCode &&- user.planCode !== 'trial' &&- user.planCode !== 'none'- ) {+ if (user?.planCode && user.planCode !== 'trial' && user.planCode !== 'none') {if (cookies.length > 0) {return redirect('/dashboard', {headers: createHeadersWithCookies(cookies),@@ -67,11 +63,9 @@ export async function loader({ request }: LoaderFunctionArgs) {return redirect('/dashboard')}- const metainfoResult = await serverFetch<Metainfo>(- request,- 'user/metainfo',- { skipAuth: true },- )+ const metainfoResult = await serverFetch<Metainfo>(request, 'user/metainfo', {+ skipAuth: true,+ })const metainfo = metainfoResult.data ?? DEFAULT_METAINFOconst allCookies = [...cookies, ...metainfoResult.cookies]diff --git a/web/app/routes/dashboard.tsx b/web/app/routes/dashboard.tsxindex c32c87b41..20f6332bc 100644--- a/web/app/routes/dashboard.tsx+++ b/web/app/routes/dashboard.tsx@@ -208,11 +208,7 @@ export async function loader({ request }: LoaderFunctionArgs) {return redirect('/onboarding')}- if (- !isSelfhosted &&- user &&- (!user.planCode || user.planCode === 'trial' || user.planCode === 'none')- ) {+ if (!isSelfhosted && user && (!user.planCode || user.planCode === 'none')) {if (authCookies.length > 0) {return redirect('/checkout', {headers: createHeadersWithCookies(authCookies),diff --git a/web/app/routes/login.tsx b/web/app/routes/login.tsxindex 6eb2caf48..c4fc7d343 100644--- a/web/app/routes/login.tsx+++ b/web/app/routes/login.tsx@@ -40,10 +40,7 @@ export async function loader({ request }: LoaderFunctionArgs) {if (!user.hasCompletedOnboarding) {return redirect('/onboarding')- } else if (- !isSelfhosted &&- (!user.planCode || user.planCode === 'trial' || user.planCode === 'none')- ) {+ } else if (!isSelfhosted && (!user.planCode || user.planCode === 'none')) {return redirect('/checkout')}return redirect('/dashboard')@@ -118,7 +115,9 @@ export async function action({ request }: ActionFunctionArgs) {redirectTo = '/onboarding'} else if (!isSelfhosted &&- (!user.planCode || user.planCode === 'trial' || user.planCode === 'none')+ (!user.planCode ||+ user.planCode === 'trial' ||+ user.planCode === 'none')) {redirectTo = '/checkout'}@@ -171,7 +170,9 @@ export async function action({ request }: ActionFunctionArgs) {redirectTo = '/onboarding'} else if (!isSelfhosted &&- (!loggedInUser.planCode || loggedInUser.planCode === 'trial' || loggedInUser.planCode === 'none')+ (!loggedInUser.planCode ||+ loggedInUser.planCode === 'trial' ||+ loggedInUser.planCode === 'none')) {redirectTo = '/checkout'}diff --git a/web/app/routes/onboarding.tsx b/web/app/routes/onboarding.tsxindex 10e6bf8e4..33dbc6caf 100644--- a/web/app/routes/onboarding.tsx+++ b/web/app/routes/onboarding.tsx@@ -76,10 +76,7 @@ export async function loader({ request }: LoaderFunctionArgs) {if (user?.user?.hasCompletedOnboarding) {// Redirect to checkout if user hasn't subscribed yetconst userPlanCode = user.user.planCode- if (- !isSelfhosted &&- (!userPlanCode || userPlanCode === 'trial' || userPlanCode === 'none')- ) {+ if (!isSelfhosted && (!userPlanCode || userPlanCode === 'none')) {if (allCookies.length > 0) {return redirect('/checkout', {headers: createHeadersWithCookies(allCookies),diff --git a/web/public/locales/en.json b/web/public/locales/en.jsonindex 070501203..0bd09c042 100644--- a/web/public/locales/en.json+++ b/web/public/locales/en.json@@ -2143,7 +2143,8 @@"dueEnd": "Due {{date}}","dueToday": "Due today ({{days}} days free)","free": "$0",- "next": "Next",+ "next": "Start free trial",+ "selectPlan": "Select your plan","termsDesc": "By continuing, you agree to the Terms of Use applicable to Swetrix and confirm you have read our <privacy>Privacy Policy</privacy>."},"onboarding": {