📈 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
billing: update pricing FAQs with usage info
Blue Mouse898cfea1b83d
diff --git a/backend/apps/cloud/src/project/project.service.ts b/backend/apps/cloud/src/project/project.service.tsindex b37f9920e..7ae04cb80 100644--- a/backend/apps/cloud/src/project/project.service.ts+++ b/backend/apps/cloud/src/project/project.service.ts@@ -104,6 +104,8 @@ const DEFAULT_USAGE_INFO = {const CAPTCHA_PASS_CONDITION ="type = 'captcha' AND if(indexOf(`meta.key`, 'captcha_event') = 0, 'pass', arrayElement(`meta.value`, indexOf(`meta.key`, 'captcha_event'))) = 'pass'"+type UsageInfoPeriod = 'month' | 'last30Days'+export const deleteProjectRedis = async (id: string) => {const key = getRedisProjectKey(id)@@ -912,16 +914,26 @@ export class ProjectService {return count as number}- async getRedisUsageInfo(uid: string): Promise<IUsageInfoRedis | null> {- const key = getRedisUserUsageInfoKey(uid)+ async getRedisUsageInfo(+ uid: string,+ period: UsageInfoPeriod = 'month',+ ): Promise<IUsageInfoRedis | null> {+ const key =+ period === 'last30Days'+ ? `${getRedisUserUsageInfoKey(uid)}_last30d`+ : getRedisUserUsageInfoKey(uid)let info: string | IUsageInfoRedis = await redis.get(key)if (_isEmpty(info)) {- const monthStart = dayjs- .utc()- .startOf('month')- .format('YYYY-MM-DD HH:mm:ss')- const monthEnd = dayjs.utc().endOf('month').format('YYYY-MM-DD HH:mm:ss')+ const now = dayjs.utc()+ const periodStart =+ period === 'last30Days'+ ? now.subtract(30, 'day').format('YYYY-MM-DD HH:mm:ss')+ : now.startOf('month').format('YYYY-MM-DD HH:mm:ss')+ const periodEnd =+ period === 'last30Days'+ ? now.format('YYYY-MM-DD HH:mm:ss')+ : now.endOf('month').format('YYYY-MM-DD HH:mm:ss')const projects = await this.find({where: {@@ -946,8 +958,8 @@ export class ProjectService {const pidChunk = pids.slice(i, i + CHUNK_SIZE)const params = {pids: pidChunk,- monthStart,- monthEnd,+ periodStart,+ periodEnd,}const query = `@@ -958,7 +970,7 @@ export class ProjectService {countIf(type = 'error') AS errorsFROM eventsWHERE pid IN ({pids:Array(FixedString(12))})- AND created BETWEEN {monthStart:String} AND {monthEnd:String}+ AND created BETWEEN {periodStart:String} AND {periodEnd:String}AND type IN ('pageview', 'custom_event', 'captcha', 'error')`diff --git a/backend/apps/cloud/src/user/interfaces/usage-info.ts b/backend/apps/cloud/src/user/interfaces/usage-info.tsindex f34a209db..b7446ae85 100644--- a/backend/apps/cloud/src/user/interfaces/usage-info.ts+++ b/backend/apps/cloud/src/user/interfaces/usage-info.ts@@ -6,10 +6,14 @@ export interface IUsageInfoRedis {errors: number}-export interface IUsageInfo extends IUsageInfoRedis {- projects: number+export interface IUsageInfoBreakdown extends IUsageInfoRedis {trafficPerc: numbercustomEventsPerc: numbercaptchaPerc: numbererrorsPerc: number}++export interface IUsageInfo extends IUsageInfoBreakdown {+ projects: number+ last30Days: IUsageInfoBreakdown+}diff --git a/backend/apps/cloud/src/user/user.controller.ts b/backend/apps/cloud/src/user/user.controller.tsindex baba0aa5a..41a7f9c07 100644--- a/backend/apps/cloud/src/user/user.controller.ts+++ b/backend/apps/cloud/src/user/user.controller.ts@@ -67,7 +67,12 @@ import { CancelSubscriptionDTO } from './dto/cancel-subscription.dto'import { CreateFeedbackDTO } from './dto/create-feedback.dto'import { UpdateWebsiteAddonDTO } from './dto/update-website-addon.dto'import { checkRateLimit, getIPDetails, getIPFromHeaders } from '../common/utils'-import { IUsageInfo, IMetaInfo } from './interfaces'+import {+ IUsageInfo,+ IUsageInfoBreakdown,+ IUsageInfoRedis,+ IMetaInfo,+} from './interfaces'import { ReportFrequency } from '../project/enums'import { OrganisationService } from '../organisation/organisation.service'import { trackCustom } from '../common/analytics'@@ -78,6 +83,33 @@ const UNPAID_PLANS = [PlanCode.free, PlanCode.trial, PlanCode.none]const ORGANISATION_INVITE_EXPIRE_HOURS = 7 * 24 // 7 daysconst FEEDBACK_ATTACHMENTS_LIMIT = 7const FEEDBACK_ATTACHMENT_MAX_SIZE = 5 * 1024 * 1024+const EMPTY_USAGE_INFO: IUsageInfoRedis = {+ total: 0,+ traffic: 0,+ customEvents: 0,+ captcha: 0,+ errors: 0,+}++const formatUsageInfo = (+ rawInfo?: IUsageInfoRedis | null,+): IUsageInfoBreakdown => {+ const usage = rawInfo || EMPTY_USAGE_INFO++ return {+ ...usage,+ trafficPerc: usage.total+ ? _round((usage.traffic / usage.total) * 100, 2)+ : 0,+ customEventsPerc: usage.total+ ? _round((usage.customEvents / usage.total) * 100, 2)+ : 0,+ captchaPerc: usage.total+ ? _round((usage.captcha / usage.total) * 100, 2)+ : 0,+ errorsPerc: usage.total ? _round((usage.errors / usage.total) * 100, 2) : 0,+ }+}@ApiTags('User')@Controller('user')@@ -805,36 +837,17 @@ export class UserController {@Get('usageinfo')async getUsageInfo(@CurrentUserId() uid: string): Promise<IUsageInfo> {- const [rawInfo, projects] = await Promise.all([+ const [rawInfo, rawLast30DaysInfo, projects] = await Promise.all([this.projectService.getRedisUsageInfo(uid),+ this.projectService.getRedisUsageInfo(uid, 'last30Days'),this.projectService.countByAdminId(uid),])- const usage = rawInfo || {- total: 0,- traffic: 0,- customEvents: 0,- captcha: 0,- errors: 0,- }- const info: IUsageInfo = {- ...usage,+ return {+ ...formatUsageInfo(rawInfo),projects,- trafficPerc: usage.total- ? _round((usage.traffic / usage.total) * 100, 2)- : 0,- customEventsPerc: usage.total- ? _round((usage.customEvents / usage.total) * 100, 2)- : 0,- captchaPerc: usage.total- ? _round((usage.captcha / usage.total) * 100, 2)- : 0,- errorsPerc: usage.total- ? _round((usage.errors / usage.total) * 100, 2)- : 0,- }-- return info+ last30Days: formatUsageInfo(rawLast30DaysInfo),+ }}@ApiBearerAuth()diff --git a/web/app/components/pricing/BillingPricing.tsx b/web/app/components/pricing/BillingPricing.tsxindex 63cdd35d0..707f7e6c8 100644--- a/web/app/components/pricing/BillingPricing.tsx+++ b/web/app/components/pricing/BillingPricing.tsx@@ -17,6 +17,7 @@ import {PLAN_LIMITS,} from '~/lib/constants'import { Metainfo, DEFAULT_METAINFO } from '~/lib/models/Metainfo'+import type { UsageInfo } from '~/lib/models/Usageinfo'import {EVENT_TIERS,PLAN_TYPES,@@ -31,6 +32,7 @@ import { useTheme } from '~/providers/ThemeProvider'import type { UserSettingsActionData } from '~/routes/user-settings'import Button from '~/ui/Button'import { FAQ } from '~/ui/FAQ'+import { Link } from '~/ui/Link'import Loader from '~/ui/Loader'import Modal from '~/ui/Modal'import { Text } from '~/ui/Text'@@ -39,6 +41,7 @@ import routes from '~/utils/routes'interface BillingPricingProps {lastEvent?: { event: string } | nullmetainfo?: Metainfo+ usageInfo?: UsageInfo | nullopenCheckout: (options: Record<string, any>) => boolean}@@ -64,6 +67,7 @@ const getSelectionRank = (planType: PlanTypeCode, eventTier: EventTierCode) =>const BillingPricing = ({lastEvent,metainfo = DEFAULT_METAINFO,+ usageInfo,openCheckout,}: BillingPricingProps) => {const {@@ -378,7 +382,7 @@ const BillingPricing = ({EVENT_TIERS['500k'].monthlyEvents.toLocaleString('en-US'),}- return [0, 1, 4].map((idx) => ({+ const sharedItems = [0, 1, 4].map((idx) => ({question: (<Trans t={t} i18nKey={`main.faq.items.${idx}.q`} values={faqValues} />),@@ -386,7 +390,32 @@ const BillingPricing = ({<Trans t={t} i18nKey={`main.faq.items.${idx}.a`} values={faqValues} />),}))- }, [t])++ const currentUsageItem = {+ question: t('billing.currentUsageFaqQuestion'),+ answer: (+ <p>+ <Trans+ t={t}+ i18nKey='billing.currentUsageFaqAnswer'+ values={{+ events: formatEventsLong(usageInfo?.last30Days?.total || 0),+ }}+ components={{+ subscriptionLink: (+ <Link+ to={`${routes.user_settings}?tab=billing`}+ className='font-medium underline decoration-dashed hover:decoration-solid'+ />+ ),+ }}+ />+ </p>+ ),+ }++ return [sharedItems[0]!, currentUsageItem, ...sharedItems.slice(1)]+ }, [t, usageInfo?.last30Days?.total])return (<>@@ -441,7 +470,7 @@ const BillingPricing = ({<Text as='h2' size='2xl' weight='bold'>{t('billing.planFaqTitle')}</Text>- <FAQ items={faqItems} className='mt-3' />+ <FAQ items={faqItems} className='mt-3' defaultOpenFirst /></div></main>diff --git a/web/app/lib/models/Usageinfo.ts b/web/app/lib/models/Usageinfo.tsindex 592c54a76..f7ad6dbaa 100644--- a/web/app/lib/models/Usageinfo.ts+++ b/web/app/lib/models/Usageinfo.ts@@ -1,12 +1,16 @@-export interface UsageInfo {+export interface UsageInfoBreakdown {total: numbertraffic: numbercustomEvents: numbercaptcha: numbererrors: number- projects: numbertrafficPerc: numbercustomEventsPerc: numbercaptchaPerc: numbererrorsPerc: number}++export interface UsageInfo extends UsageInfoBreakdown {+ projects: number+ last30Days: UsageInfoBreakdown+}diff --git a/web/app/pages/Subscribe/Subscribe.tsx b/web/app/pages/Subscribe/Subscribe.tsxindex bdf07d1f4..7aa5a8035 100644--- a/web/app/pages/Subscribe/Subscribe.tsx+++ b/web/app/pages/Subscribe/Subscribe.tsx@@ -533,7 +533,7 @@ const Subscribe = () => {)}</div>- <FAQ items={faqItems} />+ <FAQ items={faqItems} defaultOpenFirst /></div><div className='hidden lg:block lg:pt-16'>diff --git a/web/app/pages/UserSettings/UserSettings.tsx b/web/app/pages/UserSettings/UserSettings.tsxindex 486dcd667..23460a3a5 100644--- a/web/app/pages/UserSettings/UserSettings.tsx+++ b/web/app/pages/UserSettings/UserSettings.tsx@@ -195,6 +195,17 @@ const DEFAULT_USAGE_INFO: UsageInfo = {errorsPerc: 0,customEventsPerc: 0,captchaPerc: 0,+ last30Days: {+ total: 0,+ traffic: 0,+ errors: 0,+ customEvents: 0,+ captcha: 0,+ trafficPerc: 0,+ errorsPerc: 0,+ customEventsPerc: 0,+ captchaPerc: 0,+ },}const WEBSITE_ADDON_QUANTITY_OPTIONS = Array.from(diff --git a/web/app/routes/user-settings_.choose-plan.tsx b/web/app/routes/user-settings_.choose-plan.tsxindex 511cc8c0d..559f18cb5 100644--- a/web/app/routes/user-settings_.choose-plan.tsx+++ b/web/app/routes/user-settings_.choose-plan.tsx@@ -9,6 +9,7 @@ import BillingPricing from '~/components/pricing/BillingPricing'import { usePaddle } from '~/hooks/usePaddle'import { getOgImageUrl, isSelfhosted } from '~/lib/constants'import { DEFAULT_METAINFO, Metainfo } from '~/lib/models/Metainfo'+import type { UsageInfo } from '~/lib/models/Usageinfo'import { getDescription, getPreviewImage, getTitle } from '~/utils/seo'import {createHeadersWithCookies,@@ -34,6 +35,7 @@ export const meta: MetaFunction = () => {export interface BillingChoosePlanLoaderData {metainfo: Metainfo+ usageInfo: UsageInfo | null}export async function loader({ request }: LoaderFunctionArgs) {@@ -43,18 +45,23 @@ export async function loader({ request }: LoaderFunctionArgs) {redirectIfNotAuthenticated(request)- const metainfoResult = await serverFetch<Metainfo>(request, 'user/metainfo')+ const [metainfoResult, usageInfoResult] = await Promise.all([+ serverFetch<Metainfo>(request, 'user/metainfo'),+ serverFetch<UsageInfo>(request, 'user/usageinfo'),+ ])const loaderData: BillingChoosePlanLoaderData = {metainfo: metainfoResult.data ?? DEFAULT_METAINFO,+ usageInfo: usageInfoResult.data,}+ const cookies = [...metainfoResult.cookies, ...usageInfoResult.cookies]return data(loaderData, {- headers: createHeadersWithCookies(metainfoResult.cookies),+ headers: createHeadersWithCookies(cookies),})}export default function BillingChoosePlanRoute() {- const { metainfo } = useLoaderData<BillingChoosePlanLoaderData>()+ const { metainfo, usageInfo } = useLoaderData<BillingChoosePlanLoaderData>()const [lastEvent, setLastEvent] = useState<{ event: string } | null>(null)const { openCheckout } = usePaddle({ onEvent: setLastEvent })@@ -62,6 +69,7 @@ export default function BillingChoosePlanRoute() {<BillingPricinglastEvent={lastEvent}metainfo={metainfo}+ usageInfo={usageInfo}openCheckout={openCheckout}/>)diff --git a/web/app/ui/FAQ.tsx b/web/app/ui/FAQ.tsxindex d5f5b2a7a..2ea3928e4 100644--- a/web/app/ui/FAQ.tsx+++ b/web/app/ui/FAQ.tsx@@ -21,6 +21,7 @@ interface FAQProps {* Whether to add horizontal padding to the items.*/withPadding?: boolean+ defaultOpenFirst?: boolean}export function FAQ({@@ -28,15 +29,19 @@ export function FAQ({className,withStructuredData = false,withPadding = false,+ defaultOpenFirst = false,}: FAQProps) {return (<div className={cn('flex flex-col', className)}>{_map(items, (item, idx) => {const showTopBorder = idx !== 0+ const defaultOpenProps =+ defaultOpenFirst && idx === 0 ? { open: true } : {}return (<detailskey={idx}+ {...defaultOpenProps}className={cn('group w-full text-left',showTopBorder && 'border-t border-gray-200 dark:border-white/10',diff --git a/web/public/locales/en.json b/web/public/locales/en.jsonindex ca343e1c5..6dda32333 100644--- a/web/public/locales/en.json+++ b/web/public/locales/en.json@@ -590,7 +590,7 @@"items": [{"q": "What plan should I choose?",- "a": "You can start with the {{lowestPlanEventsAmount}} events per month plan. If you already have some traffic, you can start with the {{moderatePlanEventsAmount}} events per month plan.\n\n In any case, you can upgrade or downgrade your plan anytime, and we will pro-rate your subscription if you change your plan so it would be fair for you."+ "a": "Standard plans are best if you need privacy-first analytics, funnels, error tracking, bot filtering, email reports and API access. Plus plans include everything in Standard and add session replays, feature flags, A/B testing, higher API rate limits, more websites, more team members and priority support.\n\nOnce you've picked a plan type, choose the event volume based on your traffic. You can start with the {{lowestPlanEventsAmount}} events per month plan. If you already have some traffic, you can start with the {{moderatePlanEventsAmount}} events per month plan.\n\nIn any case, you can upgrade or downgrade your plan anytime, and we will pro-rate your subscription if you change your plan so it would be fair for you."},{"q": "What happens if I exceed my plan's limit?",@@ -2862,6 +2862,8 @@"choosePlanPageDesc": "Pick your monthly event volume, plan type, and billing period. You'll see the exact price before checkout.","choosePlanCurrentPlanDesc": "Pick your monthly event volume, plan type, and billing period. Your current plan is {{plan}} with {{events}} events per month, and changes are prorated automatically.","planFaqTitle": "Plan questions",+ "currentUsageFaqQuestion": "What's my current usage?",+ "currentUsageFaqAnswer": "You have used {{events}} billable events in the last 30 days. Please see your full usage report, including websites and team members, under the <subscriptionLink>Subscription section</subscriptionLink> in your account settings.","membersNotification": "Invited project members do not need their own subscription; their usage counts toward the account owner's plan limit.","trialDescription": "Your free trial includes all features and unlimited data collection. When it ends, choose a paid plan that matches your usage to keep using Swetrix.","trialChargeWarning": "You will be charged automatically when the trial ends unless you cancel first. You can cancel anytime from this page.",