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!

Fixes & improvements

Blue Mouse80412209d90f
diff --git a/backend/apps/cloud/src/alert/alert.controller.ts b/backend/apps/cloud/src/alert/alert.controller.ts
index 47de6a7a8..a41334175 100644
--- a/backend/apps/cloud/src/alert/alert.controller.ts
+++ b/backend/apps/cloud/src/alert/alert.controller.ts
@@ -171,6 +171,13 @@ export class AlertController {
where: { project: { id: In(pids) } },
})
+ if (user.planCode === PlanCode.none) {
+ throw new HttpException(
+ 'You cannot create new alerts due to no active subscription. Please upgrade your account plan to continue.',
+ HttpStatus.PAYMENT_REQUIRED,
+ )
+ }
+
if (user.isAccountBillingSuspended) {
throw new HttpException(
'The account that owns this site is currently suspended, this is because of a billing issue. Please resolve the issue to continue.',
diff --git a/backend/apps/cloud/src/common/templates/en/trial-ending-cancelled.html b/backend/apps/cloud/src/common/templates/en/trial-ending-cancelled.html
index e1bbd8ae1..3fcffb694 100644
--- a/backend/apps/cloud/src/common/templates/en/trial-ending-cancelled.html
+++ b/backend/apps/cloud/src/common/templates/en/trial-ending-cancelled.html
@@ -13,4 +13,5 @@ the trial ends to keep everything running.<br /><br />
Got questions? Just reply to this email — we're happy to help.<br /><br />
-Andrii Romasiun Founder, Swetrix
+Andrii Romasiun<br />
+Founder, Swetrix
diff --git a/backend/apps/cloud/src/experiment/experiment.controller.ts b/backend/apps/cloud/src/experiment/experiment.controller.ts
index 6fc8cbed2..52f230267 100644
--- a/backend/apps/cloud/src/experiment/experiment.controller.ts
+++ b/backend/apps/cloud/src/experiment/experiment.controller.ts
@@ -34,6 +34,7 @@ import { DataSource } from 'typeorm'
import { UserService } from '../user/user.service'
import { ProjectService } from '../project/project.service'
import { AppLoggerService } from '../logger/logger.service'
+import { PlanCode } from '../user/entities/user.entity'
import {
AnalyticsService,
getLowestPossibleTimeBucket,
@@ -215,6 +216,13 @@ export class ExperimentController {
where: { project: { id: experimentDto.pid } },
})
+ if (user.planCode === PlanCode.none) {
+ throw new HttpException(
+ 'You cannot create new experiments due to no active subscription. Please upgrade your account plan to continue.',
+ HttpStatus.PAYMENT_REQUIRED,
+ )
+ }
+
if (user.isAccountBillingSuspended) {
throw new HttpException(
'The account that owns this site is currently suspended, this is because of a billing issue. Please resolve the issue to continue.',
diff --git a/backend/apps/cloud/src/feature-flag/feature-flag.controller.ts b/backend/apps/cloud/src/feature-flag/feature-flag.controller.ts
index 1626e2ab1..c1c42b5c1 100644
--- a/backend/apps/cloud/src/feature-flag/feature-flag.controller.ts
+++ b/backend/apps/cloud/src/feature-flag/feature-flag.controller.ts
@@ -31,6 +31,7 @@ import _round from 'lodash/round'
import { UserService } from '../user/user.service'
import { ProjectService } from '../project/project.service'
import { AppLoggerService } from '../logger/logger.service'
+import { PlanCode } from '../user/entities/user.entity'
import {
AnalyticsService,
getLowestPossibleTimeBucket,
@@ -190,6 +191,13 @@ export class FeatureFlagController {
where: { project: { id: flagDto.pid } },
})
+ if (user.planCode === PlanCode.none) {
+ throw new HttpException(
+ 'You cannot create new feature flags due to no active subscription. Please upgrade your account plan to continue.',
+ HttpStatus.PAYMENT_REQUIRED,
+ )
+ }
+
if (user.isAccountBillingSuspended) {
throw new HttpException(
'The account that owns this site is currently suspended, this is because of a billing issue. Please resolve the issue to continue.',
diff --git a/backend/apps/cloud/src/goal/goal.controller.ts b/backend/apps/cloud/src/goal/goal.controller.ts
index 5b9b2dd8e..657554968 100644
--- a/backend/apps/cloud/src/goal/goal.controller.ts
+++ b/backend/apps/cloud/src/goal/goal.controller.ts
@@ -27,6 +27,7 @@ import dayjs from 'dayjs'
import { UserService } from '../user/user.service'
import { ProjectService } from '../project/project.service'
import { AppLoggerService } from '../logger/logger.service'
+import { PlanCode } from '../user/entities/user.entity'
import {
AnalyticsService,
getLowestPossibleTimeBucket,
@@ -200,6 +201,13 @@ export class GoalController {
where: { project: { id: goalDto.pid } },
})
+ if (user.planCode === PlanCode.none) {
+ throw new HttpException(
+ 'You cannot create new goals due to no active subscription. Please upgrade your account plan to continue.',
+ HttpStatus.PAYMENT_REQUIRED,
+ )
+ }
+
if (user.isAccountBillingSuspended) {
throw new HttpException(
'The account that owns this site is currently suspended, this is because of a billing issue. Please resolve the issue to continue.',
diff --git a/backend/apps/cloud/src/user/user.controller.ts b/backend/apps/cloud/src/user/user.controller.ts
index f5230861d..1a1edb006 100644
--- a/backend/apps/cloud/src/user/user.controller.ts
+++ b/backend/apps/cloud/src/user/user.controller.ts
@@ -9,7 +9,6 @@ import {
Delete,
HttpCode,
BadRequestException,
- ForbiddenException,
UseGuards,
ConflictException,
Headers,
@@ -757,7 +756,11 @@ export class UserController {
throw new BadRequestException('No paid subscription to cancel')
}
- await this.userService.cancelSubscription(id)
+ if (!user.subID) {
+ throw new BadRequestException('No active subscription found')
+ }
+
+ await this.userService.cancelSubscription(user.subID)
if (body.feedback) {
try {
diff --git a/backend/apps/cloud/src/user/user.service.ts b/backend/apps/cloud/src/user/user.service.ts
index 707d63011..52e020c09 100644
--- a/backend/apps/cloud/src/user/user.service.ts
+++ b/backend/apps/cloud/src/user/user.service.ts
@@ -438,7 +438,7 @@ export class UserService {
return false
}
- return ![(PlanCode.none, PlanCode.free, PlanCode.trial)].includes(
+ return ![PlanCode.none, PlanCode.free, PlanCode.trial].includes(
user.planCode,
)
}
@@ -455,20 +455,14 @@ export class UserService {
})
}
- async cancelSubscription(id: string) {
- const user = await this.findOne({ where: { id } })
-
- if (!user?.subID) {
- throw new BadRequestException('No active subscription found')
- }
-
+ async cancelSubscription(subID: string) {
const url = 'https://vendors.paddle.com/api/2.0/subscription/users/cancel'
try {
const result = await axios.post(url, {
vendor_id: Number(PADDLE_VENDOR_ID),
vendor_auth_code: PADDLE_API_KEY,
- subscription_id: Number(user.subID),
+ subscription_id: Number(subID),
})
if (!result.data?.success) {
diff --git a/web/app/pages/Onboarding/Onboarding.tsx b/web/app/pages/Onboarding/Onboarding.tsx
index fd2b4d673..61765ced5 100644
--- a/web/app/pages/Onboarding/Onboarding.tsx
+++ b/web/app/pages/Onboarding/Onboarding.tsx
@@ -60,7 +60,6 @@ import {
siSolid,
siSquarespace,
siSvelte,
- siVite,
siVitepress,
siVuedotjs,
siWebflow,
diff --git a/web/app/pages/Subscribe/Subscribe.tsx b/web/app/pages/Subscribe/Subscribe.tsx
index 6fd99be4e..0f6b0567f 100644
--- a/web/app/pages/Subscribe/Subscribe.tsx
+++ b/web/app/pages/Subscribe/Subscribe.tsx
@@ -5,7 +5,7 @@ import {
ShieldCheckIcon,
CheckIcon,
} from '@phosphor-icons/react'
-import { useCallback, useEffect, useState } from 'react'
+import { useCallback, useEffect, useRef, useState } from 'react'
import { Trans, useTranslation } from 'react-i18next'
import { useNavigate, useLoaderData } from 'react-router'
import { toast } from 'sonner'
@@ -35,7 +35,7 @@ const formatEventsLong = (value: number, locale = 'en-US') =>
const Subscribe = () => {
const { t, i18n } = useTranslation('common')
const { theme } = useTheme()
- const { user } = useAuth()
+ const { user, loadUser } = useAuth()
const navigate = useNavigate()
const { metainfo } = useLoaderData<SubscribeLoaderData>()
@@ -73,14 +73,39 @@ const Subscribe = () => {
const displayPrice =
selectedBillingFrequency === 'yearly' ? yearlyPrice : monthlyPrice
+ const pollRef = useRef<ReturnType<typeof setInterval> | null>(null)
+
useEffect(() => {
- if (hasCompletedCheckout) {
- const timer = setTimeout(() => {
+ if (!hasCompletedCheckout) return
+
+ let attempts = 0
+ const MAX_POLL_ATTEMPTS = 30
+
+ pollRef.current = setInterval(async () => {
+ attempts += 1
+
+ try {
+ const freshUser = await loadUser()
+
+ if (freshUser?.planCode && freshUser.planCode !== 'none') {
+ if (pollRef.current) clearInterval(pollRef.current)
+ navigate(routes.dashboard)
+ return
+ }
+ } catch {
+ // ignore, keep polling
+ }
+
+ if (attempts >= MAX_POLL_ATTEMPTS) {
+ if (pollRef.current) clearInterval(pollRef.current)
navigate(routes.dashboard)
- }, 2000)
- return () => clearTimeout(timer)
+ }
+ }, 2000)
+
+ return () => {
+ if (pollRef.current) clearInterval(pollRef.current)
}
- }, [hasCompletedCheckout, navigate])
+ }, [hasCompletedCheckout, navigate, loadUser])
const handleStartCheckout = () => {
if (paddleLoadError) {
diff --git a/web/app/routes/onboarding.tsx b/web/app/routes/onboarding.tsx
index 319222a82..f5660d7ec 100644
--- a/web/app/routes/onboarding.tsx
+++ b/web/app/routes/onboarding.tsx
@@ -8,7 +8,6 @@ import { data, redirect } from 'react-router'
import { SitemapFunction } from 'remix-sitemap'
import { getAuthenticatedUser, serverFetch } from '~/api/api.server'
-import { isSelfhosted } from '~/lib/constants'
import { DEFAULT_METAINFO, Metainfo } from '~/lib/models/Metainfo'
import { Project } from '~/lib/models/Project'
import { User } from '~/lib/models/User'
diff --git a/web/app/routes/subscribe.tsx b/web/app/routes/subscribe.tsx
index 1b9ac5364..179119288 100644
--- a/web/app/routes/subscribe.tsx
+++ b/web/app/routes/subscribe.tsx
@@ -22,7 +22,7 @@ export const meta: MetaFunction = () => {
const { t } = useTranslation('common')
return [
- ...getTitle(t('titles.checkout')),
+ ...getTitle(t('titles.subscribe')),
...getDescription(t('description.checkout')),
...getPreviewImage(),
]
@@ -53,8 +53,8 @@ export async function loader({ request }: LoaderFunctionArgs) {
return redirect('/onboarding')
}
- // If the user already has a paid subscription, skip checkout
- if (user?.planCode && user.planCode !== 'trial' && user.planCode !== 'none') {
+ // If the user already has an active subscription or legacy trial, skip checkout
+ if (user?.planCode && user.planCode !== 'none') {
if (cookies.length > 0) {
return redirect('/dashboard', {
headers: createHeadersWithCookies(cookies),
diff --git a/web/public/locales/en.json b/web/public/locales/en.json
index 1ef4728e2..6433e122f 100644
--- a/web/public/locales/en.json
+++ b/web/public/locales/en.json
@@ -2272,7 +2272,7 @@
"termsAndConditions": "Terms and Conditions",
"gaAlternative": "Cookieless Google Analytics alternative",
"projectWithPassword": "Website analytics - password required",
- "checkout": "Checkout"
+ "subscribe": "Start your free trial"
},
"description": {
"default": "Swetrix is a privacy-first, cookieless Google Analytics alternative with real-time analytics, no sampling, and built-in performance & error monitoring.",