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!

Improve billing settings

Blue Mousee5db660cfcb5
diff --git a/web/app/components/pricing/BillingPricing.tsx b/web/app/components/pricing/BillingPricing.tsx
index f9dc43965..7bc4f5a6f 100644
--- a/web/app/components/pricing/BillingPricing.tsx
+++ b/web/app/components/pricing/BillingPricing.tsx
@@ -1,34 +1,27 @@
import dayjs from 'dayjs'
import _isNil from 'lodash/isNil'
-import _round from 'lodash/round'
-import { ArrowRightIcon, CheckIcon } from '@phosphor-icons/react'
+import { ArrowLeftIcon } from '@phosphor-icons/react'
import type { TFunction } from 'i18next'
import React, { memo, useCallback, useEffect, useMemo, useState } from 'react'
import { Trans, useTranslation } from 'react-i18next'
import { useFetcher } from 'react-router'
import { toast } from 'sonner'
+import MarketingPricing, {
+ type MarketingPricingSelection,
+} from '~/components/pricing/MarketingPricing'
import {
- BillingFrequency,
CONTACT_EMAIL,
- CURRENCIES,
paddleLanguageMapping,
PLAN_LIMITS,
} from '~/lib/constants'
import { Metainfo, DEFAULT_METAINFO } from '~/lib/models/Metainfo'
import {
- ADDONS,
- EVENT_TIER_CODES,
EVENT_TIERS,
- PLAN_ENTITLEMENTS,
PLAN_TYPES,
getEffectivePlanType,
getEventTierByPlanCode,
- getIncludedSessionReplays,
- getPlanMonthlyPrice,
getPlanPrice,
- type BillingInterval,
- type CurrencyCode,
type EventTierCode,
type PlanTypeCode,
} from '~/lib/pricing/catalog'
@@ -36,11 +29,10 @@ import { useAuth } from '~/providers/AuthProvider'
import { useTheme } from '~/providers/ThemeProvider'
import type { UserSettingsActionData } from '~/routes/user-settings'
import Button from '~/ui/Button'
+import { FAQ } from '~/ui/FAQ'
import Loader from '~/ui/Loader'
import Modal from '~/ui/Modal'
-import { Switch } from '~/ui/Switch'
import { Text } from '~/ui/Text'
-import { cn } from '~/utils/generic'
import routes from '~/utils/routes'
interface BillingPricingProps {
@@ -49,40 +41,15 @@ interface BillingPricingProps {
openCheckout: (options: Record<string, any>) => boolean
}
-interface PendingSelection {
- planType: PlanTypeCode
- eventTier: EventTierCode
- billingFrequency: BillingInterval
- currency: CurrencyCode
-}
-
-const planTypeOptions: PlanTypeCode[] = ['standard', 'plus', 'enterprise']
+type PendingSelection = MarketingPricingSelection
const formatEventsLong = (value: number): string =>
value.toLocaleString('en-US')
-const formatPrice = (amount: number | null) => {
- if (amount === null) return null
- return Number.isInteger(amount) ? amount.toFixed(0) : amount.toFixed(2)
-}
-
-const formatReplayQuota = (value: number | string, t: TFunction) => {
- if (value === 0) return t('pricing.sessionReplay.none')
- if (typeof value === 'number') {
- return t('pricing.sessionReplay.included', {
- amount: formatEventsLong(value),
- })
- }
- return t('pricing.sessionReplay.customQuota')
-}
-
const getPlanName = (planType: PlanTypeCode, t: TFunction) =>
t(`pricing.planTypes.${planType}.name`)
-const getCheckoutErrorMessage = (
- error: string | undefined,
- t: TFunction,
-) => {
+const getCheckoutErrorMessage = (error: string | undefined, t: TFunction) => {
if (error?.startsWith('billing.')) {
return t(error)
}
@@ -90,10 +57,8 @@ const getCheckoutErrorMessage = (
return error || t('billing.checkoutPreparationError')
}
-const getSelectionRank = (
- planType: PlanTypeCode,
- eventTier: EventTierCode,
-) => PLAN_TYPES[planType].sortOrder * 100 + EVENT_TIERS[eventTier].sortOrder
+const getSelectionRank = (planType: PlanTypeCode, eventTier: EventTierCode) =>
+ PLAN_TYPES[planType].sortOrder * 100 + EVENT_TIERS[eventTier].sortOrder
const BillingPricing = ({
lastEvent,
@@ -104,7 +69,7 @@ const BillingPricing = ({
t,
i18n: { language },
} = useTranslation('common')
- const { isAuthenticated, user, loadUser } = useAuth()
+ const { user, loadUser } = useAuth()
const { theme } = useTheme()
const previewFetcher = useFetcher<UserSettingsActionData>()
@@ -114,31 +79,20 @@ const BillingPricing = ({
const currentPlanType = getEffectivePlanType(user?.planType, user?.planCode)
const currentEventTier =
getEventTierByPlanCode(user?.planCode)?.code || '100k'
+ const currentPlanLimit = user?.planCode ? PLAN_LIMITS[user.planCode] : null
- const [selectedPlanType, setSelectedPlanType] =
- useState<PlanTypeCode>(currentPlanType)
- const [selectedEventTier, setSelectedEventTier] =
- useState<EventTierCode>(currentEventTier)
- const [selectedBillingFrequency, setSelectedBillingFrequency] =
- useState<BillingInterval>(
- (user?.billingFrequency as BillingInterval) || BillingFrequency.monthly,
- )
- const [selectionLoading, setSelectionLoading] = useState(false)
+ const [activeSelection, setActiveSelection] =
+ useState<PendingSelection | null>(null)
+ const [selectionLoading, setSelectionLoading] =
+ useState<PendingSelection | null>(null)
const [
isNewPlanConfirmationModalOpened,
setIsNewPlanConfirmationModalOpened,
] = useState(false)
const [pendingSelection, setPendingSelection] =
useState<PendingSelection | null>(null)
- const [showDowngradeModal, setShowDowngradeModal] = useState(false)
-
- useEffect(() => {
- setSelectedPlanType(currentPlanType)
- setSelectedEventTier(currentEventTier)
- setSelectedBillingFrequency(
- (user?.billingFrequency as BillingInterval) || BillingFrequency.monthly,
- )
- }, [currentEventTier, currentPlanType, user?.billingFrequency])
+ const [downgradeSelection, setDowngradeSelection] =
+ useState<PendingSelection | null>(null)
const subUpdatePreview = useMemo(() => {
if (
@@ -200,21 +154,26 @@ const BillingPricing = ({
generatePayLinkFetcher.data?.data
) {
const url = (generatePayLinkFetcher.data.data as any).url
+ const checkoutSelection = activeSelection || selectionLoading
const opened = openCheckout({
override: url,
locale: paddleLanguageMapping[language] || language,
- title: t('pricing.selectedPlanWithEvents', {
- plan: getPlanName(selectedPlanType, t),
- events: formatEventsLong(EVENT_TIERS[selectedEventTier].monthlyEvents),
- }),
+ title: checkoutSelection
+ ? t('pricing.selectedPlanWithEvents', {
+ plan: getPlanName(checkoutSelection.planType, t),
+ events: formatEventsLong(
+ EVENT_TIERS[checkoutSelection.eventTier].monthlyEvents,
+ ),
+ })
+ : t('pricing.title'),
displayModeTheme: theme,
country: metainfo.country,
})
if (!opened) {
toast.error(t('billing.paddleStillLoading'))
- setSelectionLoading(false)
+ setSelectionLoading(null)
}
generatePayLinkFetcher.data = undefined
@@ -223,63 +182,20 @@ const BillingPricing = ({
'[ERROR] An error occured while generating pay link:',
generatePayLinkFetcher.data.error,
)
- toast.error(
- getCheckoutErrorMessage(generatePayLinkFetcher.data.error, t),
- )
- setSelectionLoading(false)
+ toast.error(getCheckoutErrorMessage(generatePayLinkFetcher.data.error, t))
+ setSelectionLoading(null)
}
}, [
+ activeSelection,
generatePayLinkFetcher.data,
language,
metainfo.country,
openCheckout,
- selectedEventTier,
- selectedPlanType,
+ selectionLoading,
t,
theme,
])
- const currencyCode = (
- (user?.tierCurrency || metainfo.code) in CURRENCIES
- ? user?.tierCurrency || metainfo.code
- : 'USD'
- ) as CurrencyCode
- const currency = CURRENCIES[currencyCode]
- const selectedPrice = getPlanPrice(
- selectedPlanType,
- selectedEventTier,
- selectedBillingFrequency,
- currencyCode,
- )
- const selectedMonthlyPrice = getPlanMonthlyPrice(
- selectedPlanType,
- selectedEventTier,
- selectedBillingFrequency,
- currencyCode,
- )
- const currentPlanLimit = user?.planCode ? PLAN_LIMITS[user.planCode] : null
- const currentEvents = currentPlanLimit?.monthlyUsageLimit || 0
- const selectedEvents = EVENT_TIERS[selectedEventTier].monthlyEvents
- const selectedReplayQuota = getIncludedSessionReplays(
- selectedPlanType,
- selectedEventTier,
- )
- const isTrialingPaidPlan =
- !!user?.trialEndDate &&
- !['none', 'trial', 'free'].includes(user?.planCode || '') &&
- dayjs(user.trialEndDate).isAfter(dayjs())
- const sameSelection =
- user?.planCode === EVENT_TIERS[selectedEventTier].planCode &&
- currentPlanType === selectedPlanType &&
- user?.billingFrequency === selectedBillingFrequency
- const currentRank = getSelectionRank(currentPlanType, currentEventTier)
- const selectedRank = getSelectionRank(selectedPlanType, selectedEventTier)
- const isDowngrade =
- !user?.cancellationEffectiveDate && selectedRank < currentRank
- const isUnpaid = ['free', 'trial', 'none'].includes(user?.planCode || '')
- const cannotSelfServe =
- selectedPlanType === 'enterprise' || !selectedPrice?.paddlePlanId
-
useEffect(() => {
if (!lastEvent) return
@@ -290,14 +206,53 @@ const BillingPricing = ({
await loadUser()
toast.success(t('apiNotifications.subscriptionUpdated'))
}, 3000)
- setSelectionLoading(false)
+ setSelectionLoading(null)
+ setActiveSelection(null)
} else if (eventData.event === 'Checkout.Close') {
- setSelectionLoading(false)
+ setSelectionLoading(null)
}
}
lastEventHandler(lastEvent)
}, [lastEvent, t, loadUser])
+ const isTrialingPaidPlan =
+ !!user?.trialEndDate &&
+ !['none', 'trial', 'free'].includes(user?.planCode || '') &&
+ dayjs(user.trialEndDate).isAfter(dayjs())
+
+ const hasActiveSubscription =
+ !!user?.subID &&
+ !user.cancellationEffectiveDate &&
+ !['none', 'trial', 'free'].includes(user.planCode || '')
+
+ const getSelectionMeta = (selection: PendingSelection) => {
+ const selectedPrice = getPlanPrice(
+ selection.planType,
+ selection.eventTier,
+ selection.billingFrequency,
+ selection.currency,
+ )
+ const sameSelection =
+ user?.planCode === EVENT_TIERS[selection.eventTier].planCode &&
+ currentPlanType === selection.planType &&
+ user?.billingFrequency === selection.billingFrequency
+ const currentRank = getSelectionRank(currentPlanType, currentEventTier)
+ const selectedRank = getSelectionRank(
+ selection.planType,
+ selection.eventTier,
+ )
+
+ return {
+ selectedPrice,
+ sameSelection,
+ selectedRank,
+ isDowngrade:
+ !user?.cancellationEffectiveDate && selectedRank < currentRank,
+ cannotSelfServe:
+ selection.planType === 'enterprise' || !selectedPrice?.paddlePlanId,
+ }
+ }
+
const submitSelection = (
intent:
| 'preview-subscription-update'
@@ -313,7 +268,10 @@ const BillingPricing = ({
formData.set('currency', selection.currency)
if (intent === 'preview-subscription-update') {
- previewFetcher.submit(formData, { method: 'POST', action: '/user-settings' })
+ previewFetcher.submit(formData, {
+ method: 'POST',
+ action: '/user-settings',
+ })
} else if (intent === 'change-subscription-plan') {
changePlanFetcher.submit(formData, {
method: 'POST',
@@ -327,39 +285,47 @@ const BillingPricing = ({
}
}
- const selectedSelection: PendingSelection = {
- planType: selectedPlanType,
- eventTier: selectedEventTier,
- billingFrequency: selectedBillingFrequency,
- currency: currencyCode,
+ const startPlanChange = (selection: PendingSelection) => {
+ setActiveSelection(selection)
+
+ if (hasActiveSubscription) {
+ if (isTrialingPaidPlan) {
+ toast.error(t('billing.cannotChangePlanDuringTrial'))
+ return
+ }
+
+ setPendingSelection(selection)
+ setIsNewPlanConfirmationModalOpened(true)
+ submitSelection('preview-subscription-update', selection)
+ return
+ }
+
+ setSelectionLoading(selection)
+ submitSelection('generate-pay-link', selection)
}
- const onPlanChange = async () => {
- if (!user || selectionLoading || sameSelection) return
+ const handlePlanSelection = (selection: PendingSelection) => {
+ const { cannotSelfServe, isDowngrade, sameSelection } =
+ getSelectionMeta(selection)
+
+ if (selectionLoading || sameSelection) return
- if (cannotSelfServe || !selectedPrice?.paddlePlanId) {
+ if (cannotSelfServe) {
toast.error(t('billing.planNotConfiguredForCheckout'))
return
}
- if (
- user.subID &&
- !user.cancellationEffectiveDate &&
- user.planCode !== 'none'
- ) {
- if (isTrialingPaidPlan) {
- toast.error(t('billing.cannotChangePlanDuringTrial'))
- return
- }
+ if (isTrialingPaidPlan) {
+ toast.error(t('billing.cannotChangePlanDuringTrial'))
+ return
+ }
- setPendingSelection(selectedSelection)
- setIsNewPlanConfirmationModalOpened(true)
- submitSelection('preview-subscription-update', selectedSelection)
+ if (isDowngrade) {
+ setDowngradeSelection(selection)
return
}
- setSelectionLoading(true)
- submitSelection('generate-pay-link', selectedSelection)
+ startPlanChange(selection)
}
const updateSubscription = () => {
@@ -367,12 +333,13 @@ const BillingPricing = ({
submitSelection('change-subscription-plan', pendingSelection)
}
- const getActionLabel = (): string => {
- if (selectedPlanType === 'enterprise') {
- return t('pricing.contactUs')
- }
+ const getActionLabel = (selection: MarketingPricingSelection): string => {
+ const { cannotSelfServe, isDowngrade, sameSelection, selectedRank } =
+ getSelectionMeta(selection)
+ const currentRank = getSelectionRank(currentPlanType, currentEventTier)
+ const isUnpaid = ['free', 'trial', 'none'].includes(user?.planCode || '')
- if (!selectedPrice?.paddlePlanId) {
+ if (cannotSelfServe) {
return t('pricing.contactUs')
}
@@ -392,278 +359,84 @@ const BillingPricing = ({
return t('pricing.downgrade')
}
- return selectedBillingFrequency === BillingFrequency.monthly
+ return selection.billingFrequency === 'monthly'
? t('pricing.switchToMonthly')
: t('pricing.switchToYearly')
}
- const yearlyDiscount = useMemo(() => {
- const monthlyPrice = getPlanPrice(
- selectedPlanType,
- selectedEventTier,
- 'monthly',
- currencyCode,
- )?.amount
- const yearlyPrice = getPlanPrice(
- selectedPlanType,
- selectedEventTier,
- 'yearly',
- currencyCode,
- )?.amount
-
- if (!monthlyPrice || !yearlyPrice) return 0
-
- const annualCostIfMonthly = monthlyPrice * 12
- const savings = annualCostIfMonthly - yearlyPrice
- const discountPercentage = (savings / annualCostIfMonthly) * 100
-
- return _round(discountPercentage, 0)
- }, [currencyCode, selectedEventTier, selectedPlanType])
-
- const toggleBillingFrequency = () => {
- setSelectedBillingFrequency((currentFrequency) =>
- currentFrequency === 'yearly' ? 'monthly' : 'yearly',
- )
- }
+ const faqItems = useMemo(() => {
+ const faqValues = {
+ lowestPlanEventsAmount:
+ EVENT_TIERS['100k'].monthlyEvents.toLocaleString('en-US'),
+ moderatePlanEventsAmount:
+ EVENT_TIERS['500k'].monthlyEvents.toLocaleString('en-US'),
+ }
- const actionLabel = getActionLabel()
+ return [0, 1, 4].map((idx) => ({
+ question: (
+ <Trans t={t} i18nKey={`main.faq.items.${idx}.q`} values={faqValues} />
+ ),
+ answer: (
+ <Trans t={t} i18nKey={`main.faq.items.${idx}.a`} values={faqValues} />
+ ),
+ }))
+ }, [t])
return (
<>
- <div className='rounded-xl border border-gray-200 bg-white p-4 sm:p-6 dark:border-white/10 dark:bg-slate-950'>
- <div className='flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between'>
- <div>
- <Text as='h2' size='2xl' weight='bold'>
- {t('common.billing')}
+ <main className='min-h-min-footer bg-gray-50 pb-16 dark:bg-slate-950'>
+ <div className='mx-auto w-full max-w-7xl px-4 pt-6 sm:px-6 lg:px-8'>
+ <Button
+ to={routes.billing}
+ variant='ghost'
+ size='sm'
+ className='mb-4 gap-1'
+ >
+ <ArrowLeftIcon className='size-4' />
+ {t('billing.backToBilling')}
+ </Button>
+ <div className='max-w-3xl'>
+ <Text as='h1' size='3xl' weight='bold'>
+ {t('billing.choosePlanTitle')}
</Text>
- <Text as='p' size='sm' colour='secondary' className='mt-1'>
- {t('pricing.planWithEvents', {
+ <Text as='p' size='base' colour='secondary' className='mt-2'>
+ {t('billing.choosePlanPageDesc', {
plan: getPlanName(currentPlanType, t),
- events: formatEventsLong(currentEvents),
+ events: formatEventsLong(
+ currentPlanLimit?.monthlyUsageLimit || 0,
+ ),
})}
</Text>
</div>
- <button
- type='button'
- onClick={toggleBillingFrequency}
- className='flex cursor-pointer items-center gap-2 rounded-lg border border-gray-200 bg-gray-100 px-3 py-2 transition-colors hover:bg-gray-200 dark:border-white/10 dark:bg-slate-900 dark:hover:bg-slate-800'
- >
- <span className='text-sm font-medium text-gray-700 dark:text-gray-200'>
- {t('pricing.billedYearly')}
- </span>
- {yearlyDiscount > 0 ? (
- <span className='rounded-md bg-emerald-100 px-1.5 py-0.5 text-xs font-semibold text-emerald-700 dark:bg-emerald-900/50 dark:text-emerald-400'>
- -{yearlyDiscount} %
- </span>
- ) : null}
- <Switch
- checked={selectedBillingFrequency === BillingFrequency.yearly}
- visualOnly
- />
- </button>
- </div>
-
- <div className='mt-5 grid gap-3 lg:grid-cols-3'>
- {planTypeOptions.map((planType) => {
- const entitlements = PLAN_ENTITLEMENTS[planType]
- const isSelected = selectedPlanType === planType
- const planMonthlyPrice =
- planType === 'enterprise'
- ? null
- : getPlanMonthlyPrice(
- planType,
- selectedEventTier,
- selectedBillingFrequency,
- currencyCode,
- )
-
- return (
- <button
- key={planType}
- type='button'
- onClick={() => setSelectedPlanType(planType)}
- className={cn(
- 'rounded-lg p-4 text-left ring-1 ring-inset transition-all duration-150',
- planType === 'enterprise'
- ? 'bg-slate-900 text-gray-50 ring-slate-700 dark:bg-slate-900 dark:text-gray-50 dark:ring-slate-700'
- : 'bg-gray-50 text-gray-950 ring-gray-200 hover:ring-gray-300 dark:bg-slate-900 dark:text-gray-50 dark:ring-slate-700 dark:hover:ring-slate-600',
- isSelected && 'ring-2 ring-slate-900 dark:ring-slate-100',
- )}
- >
- <div className='flex items-center justify-between gap-2'>
- <Text as='span' size='base' weight='semibold' colour='inherit'>
- {getPlanName(planType, t)}
- </Text>
- </div>
- <Text as='span' size='sm' colour='inherit' className='mt-3 block'>
- {planType === 'enterprise'
- ? t('pricing.custom')
- : `${currency.symbol}${formatPrice(planMonthlyPrice)}/${t(
- 'pricing.perMonth',
- )}`}
- </Text>
- <Text
- as='span'
- size='xs'
- colour='inherit'
- className='mt-1 block text-gray-500 dark:text-gray-400'
- >
- {typeof entitlements.websites === 'number'
- ? t('pricing.websiteCount', {
- count: entitlements.websites,
- })
- : t('pricing.customLimits')}
- </Text>
- </button>
- )
- })}
</div>
<div className='mt-6'>
- <Text as='p' size='sm' weight='medium' colour='secondary'>
- {t('pricing.eventVolume')}
- </Text>
- <div className='mt-3 grid gap-2 sm:grid-cols-3 lg:grid-cols-6'>
- {EVENT_TIER_CODES.map((eventTier) => {
- const tier = EVENT_TIERS[eventTier]
- const isSelected = selectedEventTier === eventTier
- return (
- <button
- key={eventTier}
- type='button'
- onClick={() => setSelectedEventTier(eventTier)}
- className={cn(
- 'rounded-lg px-3 py-2 text-left text-sm font-medium ring-1 ring-inset transition-colors',
- isSelected
- ? 'bg-slate-900 text-gray-50 ring-slate-900 dark:bg-slate-100 dark:text-slate-950 dark:ring-slate-100'
- : 'bg-gray-50 text-gray-700 ring-gray-200 hover:bg-gray-100 dark:bg-slate-900 dark:text-gray-200 dark:ring-slate-700 dark:hover:bg-slate-800',
- )}
- >
- {formatEventsLong(tier.monthlyEvents)}
- </button>
- )
- })}
- </div>
- </div>
-
- <div className='mt-6 rounded-lg bg-gray-50 p-4 ring-1 ring-gray-200 ring-inset dark:bg-slate-900 dark:ring-slate-700'>
- <div className='flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between'>
- <div>
- <Text as='p' size='base' weight='semibold'>
- {t('pricing.selectedPlanWithEvents', {
- plan: getPlanName(selectedPlanType, t),
- events: formatEventsLong(selectedEvents),
- })}
- </Text>
- <Text as='p' size='sm' colour='secondary' className='mt-1'>
- {typeof PLAN_ENTITLEMENTS[selectedPlanType].websites === 'number'
- ? t('pricing.websiteCount', {
- count: PLAN_ENTITLEMENTS[selectedPlanType].websites,
- })
- : t('pricing.customLimits')}
- , {formatReplayQuota(selectedReplayQuota, t)}
- </Text>
- </div>
- <div className='flex flex-col items-start gap-3 sm:items-end'>
- <Text as='p' size='2xl' weight='bold'>
- {selectedPlanType === 'enterprise'
- ? t('pricing.custom')
- : `${currency.symbol}${formatPrice(selectedMonthlyPrice)}/${t(
- 'pricing.perMonth',
- )}`}
- </Text>
- {cannotSelfServe ? (
- <Button to={routes.contact} size='sm' className='gap-1'>
- {t('pricing.contactUs')}
- <ArrowRightIcon className='size-4' />
- </Button>
- ) : (
- <Button
- size='sm'
- onClick={() => {
- if (actionLabel === t('pricing.downgrade')) {
- setShowDowngradeModal(true)
- } else {
- onPlanChange()
- }
- }}
- type='button'
- loading={selectionLoading}
- disabled={selectionLoading || sameSelection || !isAuthenticated}
- className='gap-1'
- >
- {actionLabel}
- {!sameSelection ? <ArrowRightIcon className='size-4' /> : null}
- </Button>
- )}
- </div>
- </div>
+ <MarketingPricing
+ metainfo={metainfo}
+ onSelectPlan={handlePlanSelection}
+ getActionLabel={getActionLabel}
+ loadingPlanType={selectionLoading?.planType ?? null}
+ disabled={Boolean(selectionLoading)}
+ />
</div>
- <div className='mt-6 grid gap-4 lg:grid-cols-2'>
- <div>
- <Text as='p' size='sm' weight='semibold'>
- {t('pricing.addons.websiteTitle')}
- </Text>
- <div className='mt-3 space-y-2'>
- {ADDONS.websiteBundles.map((bundle) => (
- <div
- key={bundle.code}
- className='flex items-center justify-between rounded-lg bg-gray-50 px-3 py-2 ring-1 ring-gray-200 ring-inset dark:bg-slate-900 dark:ring-slate-700'
- >
- <div className='flex items-center gap-2'>
- <CheckIcon className='size-4 text-gray-500 dark:text-gray-400' />
- <Text as='span' size='sm'>
- {t(bundle.labelKey, {
- amount: formatEventsLong(bundle.quantity),
- })}
- </Text>
- </div>
- <Text as='span' size='sm' colour='secondary'>
- {currency.symbol}
- {formatPrice(bundle.monthly[currencyCode])}/{t('pricing.perMonth')}
- </Text>
- </div>
- ))}
- </div>
- </div>
-
- <div>
- <Text as='p' size='sm' weight='semibold'>
- {t('pricing.addons.sessionReplayTitle')}
- </Text>
- <div className='mt-3 space-y-2'>
- {ADDONS.sessionReplayBundles.map((bundle) => (
- <div
- key={bundle.code}
- className='flex items-center justify-between rounded-lg bg-gray-50 px-3 py-2 ring-1 ring-gray-200 ring-inset dark:bg-slate-900 dark:ring-slate-700'
- >
- <div className='flex items-center gap-2'>
- <CheckIcon className='size-4 text-gray-500 dark:text-gray-400' />
- <Text as='span' size='sm'>
- {t(bundle.labelKey, {
- amount: formatEventsLong(bundle.quantity),
- })}
- </Text>
- </div>
- <Text as='span' size='sm' colour='secondary'>
- {currency.symbol}
- {formatPrice(bundle.monthly[currencyCode])}/{t('pricing.perMonth')}
- </Text>
- </div>
- ))}
- </div>
- </div>
+ <div className='mx-auto w-full max-w-4xl px-4 pt-10 sm:px-6 lg:px-8'>
+ <Text as='h2' size='2xl' weight='bold'>
+ {t('billing.planFaqTitle')}
+ </Text>
+ <FAQ items={faqItems} className='mt-3' />
</div>
- </div>
+ </main>
<div className='checkout-container' id='checkout-container' />
<Modal
- onClose={() => setShowDowngradeModal(false)}
+ onClose={() => setDowngradeSelection(null)}
onSubmit={() => {
- setShowDowngradeModal(false)
- onPlanChange()
+ if (!downgradeSelection) return
+ const selection = downgradeSelection
+ setDowngradeSelection(null)
+ startPlanChange(selection)
}}
submitText={t('common.yes')}
closeText={t('common.no')}
@@ -676,7 +449,7 @@ const BillingPricing = ({
values={{ email: CONTACT_EMAIL }}
/>
}
- isOpened={showDowngradeModal}
+ isOpened={Boolean(downgradeSelection)}
/>
<Modal
diff --git a/web/app/components/pricing/MarketingPricing.tsx b/web/app/components/pricing/MarketingPricing.tsx
index 63e41e687..146765c3f 100644
--- a/web/app/components/pricing/MarketingPricing.tsx
+++ b/web/app/components/pricing/MarketingPricing.tsx
@@ -17,6 +17,7 @@ import {
getPlanPrice,
type BillingInterval,
type CurrencyCode,
+ type EventTierCode,
type PlanTypeCode,
} from '~/lib/pricing/catalog'
import { useAuth } from '~/providers/AuthProvider'
@@ -28,6 +29,17 @@ import routes from '~/utils/routes'
interface MarketingPricingProps {
metainfo?: Metainfo
+ onSelectPlan?: (selection: MarketingPricingSelection) => void
+ getActionLabel?: (selection: MarketingPricingSelection) => string
+ loadingPlanType?: PlanTypeCode | null
+ disabled?: boolean
+}
+
+export interface MarketingPricingSelection {
+ planType: PlanTypeCode
+ eventTier: EventTierCode
+ billingFrequency: BillingInterval
+ currency: CurrencyCode
}
interface BenefitTooltip {
@@ -265,6 +277,10 @@ const BillingFrequencySwitch = ({ checked }: { checked: boolean }) => (
const MarketingPricing = ({
metainfo = DEFAULT_METAINFO,
+ onSelectPlan,
+ getActionLabel,
+ loadingPlanType,
+ disabled,
}: MarketingPricingProps) => {
const { isAuthenticated } = useAuth()
const { t } = useTranslation('common')
@@ -457,8 +473,19 @@ const MarketingPricing = ({
: null
const hasPublishedPrice = Boolean(monthlyPrice && yearlyPrice)
const canSelfServe = Boolean(
- monthlyPlan?.paddlePlanId && yearlyPlan?.paddlePlanId,
+ (isYearly ? yearlyPlan : monthlyPlan)?.paddlePlanId,
)
+ const selection: MarketingPricingSelection = {
+ planType,
+ eventTier: selectedTier,
+ billingFrequency,
+ currency: currencyCode,
+ }
+ const actionLabel =
+ getActionLabel?.(selection) ||
+ (canSelfServe
+ ? t('pricing.startFreeTrial')
+ : t('pricing.contactUs'))
return (
<div
@@ -574,14 +601,23 @@ const MarketingPricing = ({
<Button
to={
- canSelfServe
- ? isAuthenticated
- ? routes.billing
- : routes.signup
- : routes.contact
+ onSelectPlan && canSelfServe
+ ? undefined
+ : canSelfServe
+ ? isAuthenticated
+ ? routes.billing_choose_plan
+ : routes.signup
+ : routes.contact
+ }
+ onClick={
+ onSelectPlan && canSelfServe
+ ? () => onSelectPlan(selection)
+ : undefined
}
variant='primary'
size='lg'
+ loading={loadingPlanType === planType}
+ disabled={disabled}
className={cn(
'mt-4 justify-center gap-2',
isEnterprise ? 'dark' : '',
@@ -593,9 +629,7 @@ const MarketingPricing = ({
weight='semibold'
colour='inherit'
>
- {canSelfServe
- ? t('pricing.startFreeTrial')
- : t('pricing.contactUs')}
+ {actionLabel}
</Text>
<ArrowRightIcon className='size-4' />
</Button>
diff --git a/web/app/pages/UserSettings/UserSettings.tsx b/web/app/pages/UserSettings/UserSettings.tsx
index 95aaf9e3b..6f3117465 100644
--- a/web/app/pages/UserSettings/UserSettings.tsx
+++ b/web/app/pages/UserSettings/UserSettings.tsx
@@ -18,6 +18,7 @@ import {
LockIcon,
CaretDownIcon,
CreditCardIcon,
+ ArrowRightIcon,
} from '@phosphor-icons/react'
import _round from 'lodash/round'
import React, {
@@ -48,14 +49,19 @@ import {
languageFlag,
CONTACT_EMAIL,
paddleLanguageMapping,
+ CURRENCIES,
} from '~/lib/constants'
-import BillingPricing from '~/components/pricing/BillingPricing'
import { useDeduplicateFetcherResponse } from '~/hooks/useDeduplicateFetcherResponse'
import { usePaddle } from '~/hooks/usePaddle'
import { changeLanguage } from '~/i18n'
import { DEFAULT_METAINFO } from '~/lib/models/Metainfo'
import { UsageInfo } from '~/lib/models/Usageinfo'
import { User } from '~/lib/models/User'
+import {
+ ADDONS,
+ getEffectivePlanType,
+ type CurrencyCode,
+} from '~/lib/pricing/catalog'
import PaidFeature from '~/modals/PaidFeature'
import { useAuth } from '~/providers/AuthProvider'
import { useTheme } from '~/providers/ThemeProvider'
@@ -77,6 +83,7 @@ import { Text } from '~/ui/Text'
import Textarea from '~/ui/Textarea'
import Flag from '~/ui/Flag'
import TimezonePicker from '~/ui/TimezonePicker'
+import Tooltip from '~/ui/Tooltip'
import { getCookie, setCookie } from '~/utils/cookie'
import routes from '~/utils/routes'
import {
@@ -188,6 +195,9 @@ const DEFAULT_USAGE_INFO: UsageInfo = {
captchaPerc: 0,
}
+const formatBillingPrice = (amount: number) =>
+ Number.isInteger(amount) ? amount.toFixed(0) : amount.toFixed(2)
+
interface SettingsSectionProps {
title?: string
description?: string
@@ -247,9 +257,8 @@ const UserSettings = () => {
const [cancellationFeedback, setCancellationFeedback] = useState('')
const [isCancellingSubscription, setIsCancellingSubscription] =
useState(false)
- const [lastEvent, setLastEvent] = useState<{ event: string } | null>(null)
- const { openCheckout } = usePaddle({ onEvent: setLastEvent })
+ const { openCheckout } = usePaddle()
const metainfo = useMemo(() => {
if (metainfoFetcher.data?.success && metainfoFetcher.data.data) {
@@ -306,6 +315,19 @@ const UserSettings = () => {
: sessionReplaysIncluded === 'custom'
? t('pricing.custom')
: sessionReplaysIncluded || '0'
+ const currentPlanType = getEffectivePlanType(user?.planType, planCode)
+ const currentPlanName = t(`pricing.planTypes.${currentPlanType}.name`)
+ const hasActiveSubscription = isSubscriber && !cancellationEffectiveDate
+ const currencyCode = (
+ (user?.tierCurrency || metainfo.code) in CURRENCIES
+ ? user?.tierCurrency || metainfo.code
+ : 'USD'
+ ) as CurrencyCode
+ const currency = CURRENCIES[currencyCode]
+ const websiteAddon = ADDONS.websiteBundles[0]
+ const sessionReplayAddon = ADDONS.sessionReplayBundles[0]
+ const websiteAddonPrice = websiteAddon.monthly[currencyCode]
+ const sessionReplayAddonPrice = sessionReplayAddon.monthly[currencyCode]
const isTrialEnded = (() => {
if (!trialEndDate) {
@@ -1503,79 +1525,79 @@ const UserSettings = () => {
</Alert>
) : null}
- <div className='rounded-xl border border-gray-200 bg-white p-5 dark:border-slate-800 dark:bg-slate-950'>
- <Text
- as='p'
- size='sm'
- colour='secondary'
- className='mb-4'
- >
- {t('billing.usageOverview', {
- tracked: (usageInfo.total || 0).toLocaleString(),
- trackedPerc: totalUsage || 0,
- maxEvents: (maxEventsCount || 0).toLocaleString(),
- })}
- </Text>
+ <Text
+ as='p'
+ size='sm'
+ colour='secondary'
+ className='mb-4'
+ >
+ {t('billing.usageOverview', {
+ tracked: (usageInfo.total || 0).toLocaleString(),
+ trackedPerc: totalUsage || 0,
+ maxEvents: (maxEventsCount || 0).toLocaleString(),
+ })}
+ </Text>
- <div className='mb-4 grid grid-cols-2 gap-3'>
- <div className='flex items-center'>
- <div className='size-2 rounded-full bg-blue-600 dark:bg-blue-500' />
- <Text
- as='span'
- size='sm'
- colour='secondary'
- className='ml-2'
- >
- {t('billing.pageviews', {
- quantity: usageInfo.traffic || 0,
- percentage: usageInfo.trafficPerc || 0,
- })}
- </Text>
- </div>
- <div className='flex items-center'>
- <div className='size-2 rounded-full bg-fuchsia-600 dark:bg-fuchsia-500' />
- <Text
- as='span'
- size='sm'
- colour='secondary'
- className='ml-2'
- >
- {t('billing.customEvents', {
- quantity: usageInfo.customEvents || 0,
- percentage: usageInfo.customEventsPerc || 0,
- })}
- </Text>
- </div>
- <div className='flex items-center'>
- <div className='size-2 rounded-full bg-lime-600 dark:bg-lime-500' />
- <Text
- as='span'
- size='sm'
- colour='secondary'
- className='ml-2'
- >
- {t('billing.captcha', {
- quantity: usageInfo.captcha || 0,
- percentage: usageInfo.captchaPerc || 0,
- })}
- </Text>
- </div>
- <div className='flex items-center'>
- <div className='size-2 rounded-full bg-red-600 dark:bg-red-500' />
- <Text
- as='span'
- size='sm'
- colour='secondary'
- className='ml-2'
- >
- {t('billing.errors', {
- quantity: usageInfo.errors || 0,
- percentage: usageInfo.errorsPerc || 0,
- })}
- </Text>
- </div>
+ <div className='grid grid-cols-2 gap-x-6 gap-y-3'>
+ <div className='flex items-center'>
+ <div className='size-2 rounded-full bg-blue-600 dark:bg-blue-500' />
+ <Text
+ as='span'
+ size='sm'
+ colour='secondary'
+ className='ml-2'
+ >
+ {t('billing.pageviews', {
+ quantity: usageInfo.traffic || 0,
+ percentage: usageInfo.trafficPerc || 0,
+ })}
+ </Text>
+ </div>
+ <div className='flex items-center'>
+ <div className='size-2 rounded-full bg-fuchsia-600 dark:bg-fuchsia-500' />
+ <Text
+ as='span'
+ size='sm'
+ colour='secondary'
+ className='ml-2'
+ >
+ {t('billing.customEvents', {
+ quantity: usageInfo.customEvents || 0,
+ percentage: usageInfo.customEventsPerc || 0,
+ })}
+ </Text>
+ </div>
+ <div className='flex items-center'>
+ <div className='size-2 rounded-full bg-lime-600 dark:bg-lime-500' />
+ <Text
+ as='span'
+ size='sm'
+ colour='secondary'
+ className='ml-2'
+ >
+ {t('billing.captcha', {
+ quantity: usageInfo.captcha || 0,
+ percentage: usageInfo.captchaPerc || 0,
+ })}
+ </Text>
+ </div>
+ <div className='flex items-center'>
+ <div className='size-2 rounded-full bg-red-600 dark:bg-red-500' />
+ <Text
+ as='span'
+ size='sm'
+ colour='secondary'
+ className='ml-2'
+ >
+ {t('billing.errors', {
+ quantity: usageInfo.errors || 0,
+ percentage: usageInfo.errorsPerc || 0,
+ })}
+ </Text>
</div>
+ </div>
+ <div className='mt-5'>
<Text
as='p'
size='base'
@@ -1665,81 +1687,125 @@ const UserSettings = () => {
})}
</Text>
</div>
+ </div>
- <div className='mt-5 grid gap-4 border-t border-gray-200 pt-4 sm:grid-cols-3 dark:border-slate-800'>
- <div>
+ <div className='mt-6 grid gap-5 border-t border-gray-200 pt-5 sm:grid-cols-3 dark:border-slate-800'>
+ <div>
+ <div className='flex items-center gap-1.5'>
<Text as='p' size='xs' colour='muted'>
{t('billing.websites')}
</Text>
- <Text as='p' size='sm' weight='semibold' className='mt-1'>
- {(usageInfo.projects || 0).toLocaleString()} /{' '}
- {(maxProjects || 0).toLocaleString()}
- </Text>
- {purchasedWebsiteAddons ? (
- <Text as='p' size='xs' colour='muted' className='mt-1'>
- {t('billing.addedWebsites', {
- amount: purchasedWebsiteAddons.toLocaleString(),
- })}
- </Text>
- ) : null}
- <div className='mt-2 h-1.5 overflow-hidden rounded-full bg-gray-200 dark:bg-slate-800'>
- <div
- className='h-full rounded-full bg-slate-900 dark:bg-slate-100'
- style={{ width: `${projectsUsage}%` }}
- />
- </div>
+ <Tooltip
+ ariaLabel={t('billing.websitesAddonTooltip')}
+ text={t('billing.websitesAddonTooltip')}
+ />
</div>
-
- <div>
- <Text as='p' size='xs' colour='muted'>
- {t('billing.sessionReplays')}
- </Text>
- <Text as='p' size='sm' weight='semibold' className='mt-1'>
- {t('billing.perMonthQuota', {
- amount: replayLimitLabel,
+ <Text
+ as='p'
+ size='sm'
+ weight='semibold'
+ className='mt-1'
+ >
+ {(usageInfo.projects || 0).toLocaleString()} /{' '}
+ {(maxProjects || 0).toLocaleString()}
+ </Text>
+ {purchasedWebsiteAddons ? (
+ <Text
+ as='p'
+ size='xs'
+ colour='muted'
+ className='mt-1'
+ >
+ {t('billing.addedWebsites', {
+ amount: purchasedWebsiteAddons.toLocaleString(),
})}
</Text>
- <Text as='p' size='xs' colour='muted' className='mt-1'>
- {t('billing.recordedSessionsQuota')}
- </Text>
+ ) : null}
+ <div className='mt-2 h-1.5 overflow-hidden rounded-full bg-gray-200 dark:bg-slate-800'>
+ <div
+ className='h-full rounded-full bg-slate-900 dark:bg-slate-100'
+ style={{ width: `${projectsUsage}%` }}
+ />
</div>
+ </div>
- <div>
+ <div>
+ <div className='flex items-center gap-1.5'>
<Text as='p' size='xs' colour='muted'>
- {t('billing.api')}
- </Text>
- <Text as='p' size='sm' weight='semibold' className='mt-1'>
- {t('billing.perHourQuota', {
- amount: (
- maxApiKeyRequestsPerHour || 0
- ).toLocaleString(),
- })}
- </Text>
- <Text as='p' size='xs' colour='muted' className='mt-1'>
- {t('billing.currentRateLimit')}
+ {t('billing.sessionReplays')}
</Text>
+ <Tooltip
+ ariaLabel={t(
+ 'billing.sessionReplaysAddonTooltip',
+ )}
+ text={t('billing.sessionReplaysAddonTooltip')}
+ />
</div>
+ <Text
+ as='p'
+ size='sm'
+ weight='semibold'
+ className='mt-1'
+ >
+ {t('billing.perMonthQuota', {
+ amount: replayLimitLabel,
+ })}
+ </Text>
+ <Text
+ as='p'
+ size='xs'
+ colour='muted'
+ className='mt-1'
+ >
+ {t('billing.recordedSessionsQuota')}
+ </Text>
</div>
- <Text
- as='p'
- size='sm'
- colour='secondary'
- className='mt-3'
- >
- {t('billing.resetDate', {
- days: Math.ceil(
- (new Date(
- new Date().getFullYear(),
- new Date().getMonth() + 1,
- 1,
- ).getTime() -
- new Date().getTime()) /
- (1000 * 60 * 60 * 24),
- ),
- })}
- </Text>
+ <div>
+ <Text as='p' size='xs' colour='muted'>
+ {t('billing.api')}
+ </Text>
+ <Text
+ as='p'
+ size='sm'
+ weight='semibold'
+ className='mt-1'
+ >
+ {t('billing.perHourQuota', {
+ amount: (
+ maxApiKeyRequestsPerHour || 0
+ ).toLocaleString(),
+ })}
+ </Text>
+ <Text
+ as='p'
+ size='xs'
+ colour='muted'
+ className='mt-1'
+ >
+ {t('billing.currentRateLimit')}
+ </Text>
+ </div>
</div>
+
+ <Text
+ as='p'
+ size='sm'
+ colour='secondary'
+ className='mt-4'
+ >
+ {t('billing.resetDate', {
+ days: Math.ceil(
+ (new Date(
+ new Date().getFullYear(),
+ new Date().getMonth() + 1,
+ 1,
+ ).getTime() -
+ new Date().getTime()) /
+ (1000 * 60 * 60 * 24),
+ ),
+ })}
+ </Text>
</SettingsSection>
<SettingsSection
@@ -1750,43 +1816,187 @@ const UserSettings = () => {
: t('billing.selectPlan')
}
>
- <Text
- as='p'
- size='sm'
- colour='secondary'
- className='mb-4'
- >
- {t('billing.membersNotification')}
- </Text>
-
- <BillingPricing
- lastEvent={lastEvent}
- metainfo={metainfo}
- openCheckout={openCheckout}
- />
-
- <div className='mt-4 flex flex-wrap gap-3'>
- {subUpdateURL && !cancellationEffectiveDate ? (
- <Button
- size='lg'
- onClick={onUpdatePaymentDetails}
- type='button'
+ <div className='flex flex-col gap-4 border-t border-gray-200 pt-4 md:flex-row md:items-start md:justify-between dark:border-slate-800'>
+ <div className='max-w-2xl'>
+ <Text as='p' size='base' weight='semibold'>
+ {isSubscriber
+ ? t('billing.currentPlanTitle', {
+ plan: currentPlanName,
+ })
+ : t('billing.noPlanSelected')}
+ </Text>
+ <Text
+ as='p'
+ size='sm'
+ colour='secondary'
+ className='mt-1'
>
- {t('billing.update')}
- </Button>
- ) : null}
- {subCancelURL && !cancellationEffectiveDate ? (
+ {isSubscriber
+ ? t('billing.currentPlanDescription', {
+ events: (
+ maxEventsCount || 0
+ ).toLocaleString(),
+ })
+ : t('billing.noPlanDescription')}
+ </Text>
+ <Text
+ as='p'
+ size='sm'
+ colour='secondary'
+ className='mt-3'
+ >
+ {t('billing.membersNotification')}
+ </Text>
+ </div>
+
+ <div className='flex shrink-0 flex-wrap gap-3'>
<Button
- variant='danger-outline'
+ to={routes.billing_choose_plan}
size='lg'
- onClick={() => setIsCancelSubModalOpened(true)}
- type='button'
+ className='gap-1'
>
- {t('billing.cancelSub')}
+ {isSubscriber
+ ? t('billing.managePlan')
+ : t('billing.choosePlan')}
+ <ArrowRightIcon className='size-4' />
</Button>
- ) : null}
+ {subUpdateURL && !cancellationEffectiveDate ? (
+ <Button
+ variant='secondary'
+ size='lg'
+ onClick={onUpdatePaymentDetails}
+ type='button'
+ >
+ {t('billing.update')}
+ </Button>
+ ) : null}
+ {subCancelURL && !cancellationEffectiveDate ? (
+ <Button
+ variant='danger-outline'
+ size='lg'
+ onClick={() => setIsCancelSubModalOpened(true)}
+ type='button'
+ >
+ {t('billing.cancelSub')}
+ </Button>
+ ) : null}
+ </div>
</div>
</SettingsSection>
+
+ {hasActiveSubscription ? (
+ <SettingsSection
+ title={t('billing.addonsTitle')}
+ description={t('billing.addonsDesc')}
+ >
+ <div className='grid gap-6 border-t border-gray-200 pt-4 lg:grid-cols-2 dark:border-slate-800'>
+ <div>
+ <div className='flex items-start justify-between gap-3'>
+ <div>
+ <Text as='h4' size='base' weight='semibold'>
+ {t('billing.websiteAddonTitle')}
+ </Text>
+ <Text
+ as='p'
+ size='sm'
+ colour='secondary'
+ className='mt-1'
+ >
+ {t('billing.websiteAddonDescription', {
+ amount: websiteAddon.quantity,
+ unitPrice: `${currency.symbol}${formatBillingPrice(
+ websiteAddonPrice / websiteAddon.quantity,
+ )}`,
+ })}
+ </Text>
+ </div>
+ {purchasedWebsiteAddons ? (
+ <Text
+ as='span'
+ size='xs'
+ weight='semibold'
+ className='shrink-0 rounded-md bg-emerald-100 px-2 py-1 text-emerald-700 dark:bg-emerald-500/15 dark:text-emerald-300'
+ >
+ {t('billing.activeAddonAmount', {
+ amount:
+ purchasedWebsiteAddons.toLocaleString(),
+ })}
+ </Text>
+ ) : null}
+ </div>
+ <Text
+ as='p'
+ size='lg'
+ weight='bold'
+ className='mt-4'
+ >
+ {currency.symbol}
+ {formatBillingPrice(websiteAddonPrice)}
+ <Text
+ as='span'
+ size='sm'
+ weight='medium'
+ colour='secondary'
+ >
+ /{t('pricing.intervals.month')}
+ </Text>
+ </Text>
+ <Button
+ to={routes.contact}
+ variant='secondary'
+ size='lg'
+ className='mt-4 gap-1'
+ >
+ {t('billing.requestAddon')}
+ <ArrowRightIcon className='size-4' />
+ </Button>
+ </div>
+
+ <div>
+ <Text as='h4' size='base' weight='semibold'>
+ {t('billing.sessionReplayAddonTitle')}
+ </Text>
+ <Text
+ as='p'
+ size='sm'
+ colour='secondary'
+ className='mt-1'
+ >
+ {t('billing.sessionReplayAddonDescription', {
+ amount:
+ sessionReplayAddon.quantity.toLocaleString(),
+ })}
+ </Text>
+ <Text
+ as='p'
+ size='lg'
+ weight='bold'
+ className='mt-4'
+ >
+ {currency.symbol}
+ {formatBillingPrice(sessionReplayAddonPrice)}
+ <Text
+ as='span'
+ size='sm'
+ weight='medium'
+ colour='secondary'
+ >
+ /{t('pricing.intervals.month')}
+ </Text>
+ </Text>
+ <Button
+ to={routes.contact}
+ variant='secondary'
+ size='lg'
+ className='mt-4 gap-1'
+ >
+ {t('billing.requestAddon')}
+ <ArrowRightIcon className='size-4' />
+ </Button>
+ </div>
+ </div>
+ </SettingsSection>
+ ) : null}
</>
)}
</>
diff --git a/web/app/routes/billing.choose-plan.tsx b/web/app/routes/billing.choose-plan.tsx
new file mode 100644
index 000000000..511cc8c0d
--- /dev/null
+++ b/web/app/routes/billing.choose-plan.tsx
@@ -0,0 +1,68 @@
+import { useState } from 'react'
+import { useTranslation } from 'react-i18next'
+import type { LoaderFunctionArgs, MetaFunction } from 'react-router'
+import { data, redirect, useLoaderData } from 'react-router'
+import type { SitemapFunction } from 'remix-sitemap'
+
+import { serverFetch } from '~/api/api.server'
+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 { getDescription, getPreviewImage, getTitle } from '~/utils/seo'
+import {
+ createHeadersWithCookies,
+ redirectIfNotAuthenticated,
+} from '~/utils/session.server'
+
+export const sitemap: SitemapFunction = () => ({
+ exclude: true,
+})
+
+export const meta: MetaFunction = () => {
+ // eslint-disable-next-line react-hooks/rules-of-hooks
+ const { t } = useTranslation('common')
+
+ return [
+ ...getTitle(t('billing.choosePlanTitle')),
+ ...getDescription(t('description.checkout')),
+ ...getPreviewImage(
+ getOgImageUrl(t('billing.choosePlanTitle'), t('description.checkout')),
+ ),
+ ]
+}
+
+export interface BillingChoosePlanLoaderData {
+ metainfo: Metainfo
+}
+
+export async function loader({ request }: LoaderFunctionArgs) {
+ if (isSelfhosted) {
+ return redirect('/user-settings', 302)
+ }
+
+ redirectIfNotAuthenticated(request)
+
+ const metainfoResult = await serverFetch<Metainfo>(request, 'user/metainfo')
+ const loaderData: BillingChoosePlanLoaderData = {
+ metainfo: metainfoResult.data ?? DEFAULT_METAINFO,
+ }
+
+ return data(loaderData, {
+ headers: createHeadersWithCookies(metainfoResult.cookies),
+ })
+}
+
+export default function BillingChoosePlanRoute() {
+ const { metainfo } = useLoaderData<BillingChoosePlanLoaderData>()
+ const [lastEvent, setLastEvent] = useState<{ event: string } | null>(null)
+ const { openCheckout } = usePaddle({ onEvent: setLastEvent })
+
+ return (
+ <BillingPricing
+ lastEvent={lastEvent}
+ metainfo={metainfo}
+ openCheckout={openCheckout}
+ />
+ )
+}
diff --git a/web/app/utils/routes.ts b/web/app/utils/routes.ts
index dfa873cc5..6a4f3c588 100644
--- a/web/app/utils/routes.ts
+++ b/web/app/utils/routes.ts
@@ -20,6 +20,7 @@ const routes = Object.freeze({
project_settings: '/projects/settings/:id',
project: '/projects/:id',
billing: '/billing',
+ billing_choose_plan: '/billing/choose-plan',
privacy: '/privacy',
cookiePolicy: '/cookie-policy',
dpa: '/dpa',
diff --git a/web/public/locales/en.json b/web/public/locales/en.json
index 7941a3b4f..b5717d48d 100644
--- a/web/public/locales/en.json
+++ b/web/public/locales/en.json
@@ -2820,7 +2820,7 @@
"noActiveSubscriptionDescription": "We still collect incoming analytics data for your projects. Choose a paid plan to keep using Swetrix.",
"subscriptionCancelled": "Subscription cancelled",
"subscriptionCancelledDescription": "Your subscription stays active until {{date}}. After that, you will lose access to analytics data, but we will keep storing incoming events and pageviews for your projects in case you return.",
- "planUsage": "Usage",
+ "planUsage": "Monthly usage",
"usageOverview": "You have tracked {{tracked}} of {{maxEvents}} events this month ({{trackedPerc}}%).",
"pageviews": "Pageviews: {{quantity}} ({{percentage}}%)",
"customEvents": "Custom events: {{quantity}} ({{percentage}}%)",
@@ -2838,6 +2838,16 @@
"resetDate": "Usage resets on the first day of each month. {{days}} days until reset.",
"selectPlan": "Select a plan to continue using Swetrix.",
"changePlan": "You can change or cancel your plan here at any time.",
+ "choosePlan": "Choose a plan",
+ "managePlan": "Manage plan",
+ "currentPlanTitle": "{{plan}} plan",
+ "currentPlanDescription": "Your plan includes {{events}} events per month.",
+ "noPlanSelected": "No plan selected",
+ "noPlanDescription": "Choose a plan to keep Swetrix active for your projects.",
+ "backToBilling": "Back to billing",
+ "choosePlanTitle": "Choose your plan",
+ "choosePlanPageDesc": "Pick the plan type, monthly event volume, and billing period that fits your account. Your current plan is {{plan}} with {{events}} events per month.",
+ "planFaqTitle": "Plan questions",
"membersNotification": "Pageviews, custom events, CAPTCHA events, and error events count toward the account owner's plan limit. Invited project members do not need their own subscription.",
"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.",
@@ -2859,13 +2869,23 @@
"invalidPlanSelection": "Invalid plan selection",
"invalidCurrency": "Invalid currency",
"websites": "Websites",
+ "websitesAddonTooltip": "Need more websites? Add recurring website add-ons from this page.",
"addedWebsites": "+{{amount}} added",
"sessionReplays": "Session replays",
+ "sessionReplaysAddonTooltip": "Need more recorded sessions? Session replay add-ons can extend this monthly quota.",
"perMonthQuota": "{{amount}} / month",
"recordedSessionsQuota": "Recorded sessions quota",
"api": "API",
"perHourQuota": "{{amount}} / hour",
- "currentRateLimit": "Current rate limit"
+ "currentRateLimit": "Current rate limit",
+ "addonsTitle": "Add-ons",
+ "addonsDesc": "Add-ons are recurring subscription extras. They are available for active paid subscriptions.",
+ "websiteAddonTitle": "Additional websites",
+ "websiteAddonDescription": "Add websites in chunks of {{amount}} at {{unitPrice}} per website per month.",
+ "sessionReplayAddonTitle": "Additional session replays",
+ "sessionReplayAddonDescription": "Add {{amount}} recorded sessions per month. Session replay pricing is temporary while the feature is finalised.",
+ "activeAddonAmount": "{{amount}} active",
+ "requestAddon": "Request add-on"
},
"modals": {
"paidFeature": {