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!

added some trial logic

Blue Mouse4ec0a556f5d7
diff --git a/public/locales/en.json b/public/locales/en.json
index 8b0428f3e..f23179aa5 100644
--- a/public/locales/en.json
+++ b/public/locales/en.json
@@ -579,7 +579,8 @@
"desc": "It is free to get started and use our services.\nIf you need to handle more traffic, you probably need to upgrade your plan.\nBelow is a list of available plans. No hidden fees or other BS, everything is clear and transparent!",
"contact": "Need to track more than 1 million events per month?\nContact us at <mail>{{email}}</mail> to discuss your needs.",
"update": "Update payment details",
- "nextBillDate": "Next bill date:"
+ "nextBillDate": "Next bill date:",
+ "trialEnds": "Trial ends {{date}}"
},
"modals": {
"paidFeature": {
@@ -604,11 +605,16 @@
"yearlyBilling": "Yearly billing",
"switchToMonthly": "Switch to monthly billing",
"switchToYearly": "Switch to yearly billing",
+ "xTrialDaysLeft": "{{amount}} trial days left",
+ "trialEnded": "Trial ended",
+ "trialEndsToday": "Trial ends today",
+ "trialEndsTomorrow": "Trial ends tomorrow",
"tiers": {
"hobby": "Hobby",
"freelancer": "Freelancer",
"startup": "Startup",
"enterprise": "Enterprise",
+ "trial": "Free trial",
"upToXEVMo": "Up to {{amount}} events per month.",
"xEvMo": "{{amount}} events per month.",
"upToXVMo": "Up to {{amount}} visits per month.",
diff --git a/src/App.js b/src/App.js
index 5f4b92342..37662c5ec 100644
--- a/src/App.js
+++ b/src/App.js
@@ -85,7 +85,9 @@ const App = () => {
const dispatch = useDispatch()
const location = useLocation()
const alert = useAlert()
- const { loading, authenticated } = useSelector(state => state.auth)
+ const {
+ loading, authenticated, user,
+ } = useSelector(state => state.auth)
const { theme } = useSelector(state => state.ui.theme)
const { error } = useSelector(state => state.errors)
const { message, type } = useSelector(state => state.alerts)
@@ -166,7 +168,12 @@ const App = () => {
(!accessToken || !loading) && (
// eslint-disable-next-line react/jsx-no-useless-fragment
<Suspense fallback={<></>}>
- <Header authenticated={authenticated} theme={theme} themeType={themeType} />
+ <Header
+ authenticated={authenticated}
+ theme={theme}
+ themeType={themeType}
+ user={user}
+ />
{/* {location.pathname === routes.main && (
<Snowfall />
)} */}
diff --git a/src/components/Header/index.jsx b/src/components/Header/index.jsx
index 7acc79633..30fdce8a3 100644
--- a/src/components/Header/index.jsx
+++ b/src/components/Header/index.jsx
@@ -1,5 +1,8 @@
/* eslint-disable jsx-a11y/anchor-is-valid, react/no-unstable-nested-components */
-import React, { memo, Fragment, useRef } from 'react'
+import React, {
+ memo, Fragment, useRef, useMemo,
+} from 'react'
+import PropTypes from 'prop-types'
import { Link, NavLink } from 'react-router-dom'
import { HashLink } from 'react-router-hash-link'
import { useDispatch } from 'react-redux'
@@ -11,6 +14,10 @@ import {
Bars3Icon, XMarkIcon, DocumentTextIcon, CreditCardIcon, CircleStackIcon, RssIcon,
} from '@heroicons/react/24/outline'
import { MoonIcon, SunIcon } from '@heroicons/react/24/solid'
+import dayjs from 'dayjs'
+import utc from 'dayjs/plugin/utc'
+import duration from 'dayjs/plugin/duration'
+import cx from 'clsx'
import routes from 'routes'
import { authActions } from 'redux/actions/auth'
@@ -20,11 +27,57 @@ import {
} from 'redux/constants'
import Dropdown from 'ui/Dropdown'
-const Header = ({ authenticated, theme, themeType }) => {
+dayjs.extend(utc)
+dayjs.extend(duration)
+
+const TRIAL_STATUS_MAPPING = {
+ ENDED: 1,
+ ENDS_TODAY: 2,
+ ENDS_TOMORROW: 3,
+ ENDS_IN_X_DAYS: 4,
+}
+
+const Header = ({
+ authenticated, theme, themeType, user,
+}) => {
const { t, i18n: { language } } = useTranslation('common')
const dispatch = useDispatch()
const buttonRef = useRef()
+ const [rawStatus, status] = useMemo(() => {
+ const { trialEndDate } = (user || {})
+
+ if (!trialEndDate) {
+ return [null, null]
+ }
+
+ const now = dayjs.utc()
+ const future = dayjs.utc(trialEndDate)
+ const diff = future.diff(now)
+
+ if (diff < 0) {
+ // trial has already ended
+ return [TRIAL_STATUS_MAPPING.ENDED, t('pricing.trialEnded')]
+ }
+
+ if (diff < dayjs.duration(1, 'day').asMilliseconds()) {
+ // trial ends today or tomorrow
+ const isToday = future.isSame(now, 'day')
+ const isTomorrow = future.isSame(now.add(1, 'day'), 'day')
+
+ if (isToday) {
+ return [TRIAL_STATUS_MAPPING.ENDS_TODAY, t('pricing.trialEndsToday')]
+ }
+ if (isTomorrow) {
+ return [TRIAL_STATUS_MAPPING.ENDS_TOMORROW, t('pricing.trialEndsTomorrow')]
+ }
+ }
+
+ // trial ends in more than 1 day
+ const amount = Math.round(dayjs.duration(diff).asDays())
+ return [TRIAL_STATUS_MAPPING.ENDS_IN_X_DAYS, t('pricing.xTrialDaysLeft', { amount })]
+ }, [user, t])
+
const logoutHandler = () => {
dispatch(authActions.logout())
}
@@ -74,6 +127,18 @@ const Header = ({ authenticated, theme, themeType }) => {
</Link>
<div className='hidden ml-10 space-x-1 lg:flex'>
+ {!isSelfhosted && authenticated && user?.planCode === 'trial' && (
+ <Link
+ to={routes.billing}
+ className={cx('flex justify-center items-center text-base select-none font-medium py-2 px-2 rounded-md', {
+ 'text-amber-800 bg-amber-200 dark:bg-amber-300 hover:bg-amber-300 dark:hover:bg-amber-200': rawStatus === TRIAL_STATUS_MAPPING.ENDS_IN_X_DAYS,
+ 'text-rose-800 bg-rose-200 dark:bg-rose-300 hover:bg-rose-300 dark:hover:bg-rose-200': rawStatus === TRIAL_STATUS_MAPPING.ENDS_TODAY || rawStatus === TRIAL_STATUS_MAPPING.ENDS_TOMORROW || rawStatus === TRIAL_STATUS_MAPPING.ENDED,
+ })}
+ key='Billing'
+ >
+ {status}
+ </Link>
+ )}
<a href={BLOG_URL} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' target='_blank' rel='noreferrer noopener'>
<RssIcon className='w-5 h-5 mr-1' />
{t('footer.blog')}
@@ -310,4 +375,16 @@ const Header = ({ authenticated, theme, themeType }) => {
)
}
+Header.propTypes = {
+ authenticated: PropTypes.bool.isRequired,
+ theme: PropTypes.string.isRequired,
+ themeType: PropTypes.string.isRequired,
+ // eslint-disable-next-line react/forbid-prop-types
+ user: PropTypes.object,
+}
+
+Header.defaultProps = {
+ user: {},
+}
+
export default memo(Header)
diff --git a/src/pages/Billing/index.jsx b/src/pages/Billing/index.jsx
index 5431a90f5..19e320d8c 100644
--- a/src/pages/Billing/index.jsx
+++ b/src/pages/Billing/index.jsx
@@ -1,9 +1,10 @@
/* eslint-disable jsx-a11y/anchor-has-content, lodash/prefer-lodash-method */
-import React, { memo } from 'react'
+import React, { memo, useMemo } from 'react'
import { useTranslation, Trans } from 'react-i18next'
import { useSelector } from 'react-redux'
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
+import duration from 'dayjs/plugin/duration'
import { CONTACT_EMAIL, paddleLanguageMapping } from 'redux/constants'
import { withAuthentication, auth } from 'hoc/protected'
@@ -11,16 +12,50 @@ import Title from 'components/Title'
import Pricing from '../MainPage/Pricing'
dayjs.extend(utc)
+dayjs.extend(duration)
-const Features = () => {
+const Billing = () => {
const { user } = useSelector(state => state.auth)
const { theme } = useSelector(state => state.ui.theme)
const { t, i18n: { language } } = useTranslation('common')
const {
- nextBillDate, planCode, subUpdateURL,
+ nextBillDate, planCode, subUpdateURL, trialEndDate, timeFormat,
} = user
const isFree = planCode === 'free'
+ const isTrial = planCode === 'trial'
+
+ const trialMessage = useMemo(() => {
+ if (!trialEndDate || !isTrial) {
+ return null
+ }
+
+ const now = dayjs.utc()
+ const future = dayjs.utc(trialEndDate)
+ const diff = future.diff(now)
+
+ if (diff < 0) {
+ return t('pricing.trialEnded')
+ }
+
+ let date
+
+ if (language === 'en') {
+ if (timeFormat === '12-hour') {
+ date = dayjs(trialEndDate).locale(language).format('MMMM D, h:mm A')
+ } else {
+ date = dayjs(trialEndDate).locale(language).format('MMMM D, HH:mm')
+ }
+ } else if (timeFormat === '12-hour') {
+ date = dayjs(trialEndDate).locale(language).format('D MMMM, h:mm A')
+ } else {
+ date = dayjs(trialEndDate).locale(language).format('D MMMM, HH:mm')
+ }
+
+ return t('billing.trialEnds', {
+ date,
+ })
+ }, [language, trialEndDate, isTrial, timeFormat, t])
const onUpdatePaymentDetails = () => {
if (!window.Paddle) {
@@ -50,7 +85,7 @@ const Features = () => {
<h1 className='text-4xl font-extrabold text-gray-900 dark:text-gray-50 tracking-tight mr-2'>
{t('billing.title')}
</h1>
- {!isFree && (
+ {!isFree && !isTrial && (
<span onClick={onUpdatePaymentDetails} className='inline-flex cursor-pointer items-center border border-transparent leading-4 font-medium rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 px-4 py-2 text-sm'>
{t('billing.update')}
</span>
@@ -73,6 +108,13 @@ const Features = () => {
</span>
</div>
)}
+ {isTrial && trialMessage && (
+ <div className='text-lg text-gray-900 dark:text-gray-50 tracking-tight'>
+ <span className='font-bold'>
+ {trialMessage}
+ </span>
+ </div>
+ )}
<Pricing t={t} language={language} />
<p className='text-lg text-gray-900 dark:text-gray-50 tracking-tight mt-10'>
<Trans
@@ -90,4 +132,4 @@ const Features = () => {
)
}
-export default memo(withAuthentication(Features, auth.authenticated))
+export default memo(withAuthentication(Billing, auth.authenticated))
diff --git a/src/pages/MainPage/Pricing.jsx b/src/pages/MainPage/Pricing.jsx
index 3eba1d752..e60f9807f 100644
--- a/src/pages/MainPage/Pricing.jsx
+++ b/src/pages/MainPage/Pricing.jsx
@@ -38,6 +38,16 @@ const getNonStandardTiers = (t) => ({
t('pricing.tiers.reports'),
],
},
+ trial: {
+ name: t('pricing.tiers.trial'),
+ planCode: 'trial',
+ priceMonthly: PLAN_LIMITS.trial.priceMonthly,
+ priceYearly: PLAN_LIMITS.trial.priceYearly,
+ legacy: PLAN_LIMITS.trial.legacy,
+ includedFeatures: [
+ t('pricing.tiers.evXPlanIncl', { plan: t('pricing.tiers.freelancer') }),
+ ],
+ },
})
const getTiers = (t) => [
@@ -114,95 +124,103 @@ const BillingFrequency = {
const PricingItem = ({
tier, user, t, authenticated, billingFrequency, onPlanChange, downgradeHandler, downgrade,
planCodeLoading, planCodeID, userPlancodeID,
-}) => (
- <div
- key={tier.name}
- className={cx('relative border rounded-2xl shadow-sm divide-y bg-[#F5F5F5] dark:bg-[#212936] divide-gray-200 dark:divide-gray-500', {
- 'border-indigo-400': user.planCode === tier.planCode,
- 'border-gray-200 dark:border-gray-500': user.planCode !== tier.planCode,
- })}
- >
- {user.planCode === tier.planCode && (
- <div className='absolute inset-x-0 top-0 transform translate-y-px'>
- <div className='flex justify-center transform -translate-y-1/2'>
- <span className='inline-flex rounded-full bg-indigo-600 px-4 py-1 text-sm font-semibold tracking-wider uppercase text-white'>
- {t('pricing.currentPlan')}
- </span>
+}) => {
+ let action
+
+ if (planCodeID > userPlancodeID) {
+ action = t('pricing.upgrade')
+ } else if (downgrade) {
+ action = t('pricing.downgrade')
+ } else if (user.billingFrequency === billingFrequency || user.planCode === 'free' || user.planCode === 'trial') {
+ action = t('pricing.yourPlan')
+ } else if (billingFrequency === BillingFrequency.monthly) {
+ action = t('pricing.switchToMonthly')
+ } else {
+ action = t('pricing.switchToYearly')
+ }
+
+ return (
+ <div
+ key={tier.name}
+ className={cx('relative border rounded-2xl shadow-sm divide-y bg-[#F5F5F5] dark:bg-[#212936] divide-gray-200 dark:divide-gray-500', {
+ 'border-indigo-400': user.planCode === tier.planCode,
+ 'border-gray-200 dark:border-gray-500': user.planCode !== tier.planCode,
+ })}
+ >
+ {user.planCode === tier.planCode && (
+ <div className='absolute inset-x-0 top-0 transform translate-y-px'>
+ <div className='flex justify-center transform -translate-y-1/2'>
+ <span className='inline-flex rounded-full bg-indigo-600 px-4 py-1 text-sm font-semibold tracking-wider uppercase text-white'>
+ {t('pricing.currentPlan')}
+ </span>
+ </div>
</div>
- </div>
- )}
- <div className='p-6 border-none'>
- <h2 className='text-lg leading-6 font-semibold text-[#4D4D4D] dark:text-gray-50 text-center'>{tier.name}</h2>
- {tier.mostPopular && !authenticated && (
- <p className='absolute top-0 py-1.5 px-4 bg-indigo-600 rounded-full text-xs font-semibold uppercase tracking-wide text-white transform -translate-y-1/2'>
- {t('pricing.mostPopular')}
- </p>
)}
- {tier.legacy && (
- <p className='absolute top-0 left-2 py-1 px-2 bg-yellow-500 rounded-full text-xs font-semibold uppercase tracking-wide text-white transform translate-y-4'>
- {t('pricing.legacy')}
+ <div className='p-6 border-none'>
+ <h2 className='text-lg leading-6 font-semibold text-[#4D4D4D] dark:text-gray-50 text-center'>{tier.name}</h2>
+ {tier.mostPopular && !authenticated && (
+ <p className='absolute top-0 py-1.5 px-4 bg-indigo-600 rounded-full text-xs font-semibold uppercase tracking-wide text-white transform -translate-y-1/2'>
+ {t('pricing.mostPopular')}
+ </p>
+ )}
+ {tier.legacy && (
+ <p className='absolute top-0 left-2 py-1 px-2 bg-yellow-500 rounded-full text-xs font-semibold uppercase tracking-wide text-white transform translate-y-4'>
+ {t('pricing.legacy')}
+ </p>
+ )}
+ <p className='mt-4 text-center'>
+ <span className='text-4xl font-bold text-[#4D4D4D] dark:text-gray-50'>
+ $
+ {billingFrequency === BillingFrequency.monthly ? tier.priceMonthly : tier.priceYearly}
+ </span>
+ &nbsp;
+ <span className='text-base font-medium text-gray-500 dark:text-gray-400'>
+ /
+ {t(billingFrequency === BillingFrequency.monthly ? 'pricing.perMonth' : 'pricing.perYear')}
+ </span>
</p>
- )}
- <p className='mt-4 text-center'>
- <span className='text-4xl font-bold text-[#4D4D4D] dark:text-gray-50'>
- $
- {billingFrequency === BillingFrequency.monthly ? tier.priceMonthly : tier.priceYearly}
- </span>
- &nbsp;
- <span className='text-base font-medium text-gray-500 dark:text-gray-400'>
- /
- {t(billingFrequency === BillingFrequency.monthly ? 'pricing.perMonth' : 'pricing.perYear')}
- </span>
- </p>
- {authenticated ? (
- <span
- onClick={() => downgrade ? downgradeHandler(tier) : onPlanChange(tier)}
- className={cx('inline-flex items-center justify-center mt-8 w-full rounded-md py-2 text-sm font-semibold text-white text-center select-none', {
- 'bg-indigo-600 hover:bg-indigo-700 cursor-pointer': planCodeLoading === null && (tier.planCode !== user.planCode || (user.billingFrequency !== billingFrequency && user.planCode !== 'free')),
- 'bg-indigo-400 cursor-default': planCodeLoading !== null || (tier.planCode === user.planCode && (user.billingFrequency === billingFrequency || user.planCode === 'free')),
- })}
- >
- {planCodeLoading === tier.planCode && (
- <Spin />
- )}
- {planCodeID > userPlancodeID
- ? t('pricing.upgrade')
- : downgrade
- ? t('pricing.downgrade')
- : (user.billingFrequency === billingFrequency || user.planCode === 'free')
- ? t('pricing.yourPlan')
- : billingFrequency === BillingFrequency.monthly
- ? t('pricing.switchToMonthly')
- : t('pricing.switchToYearly')}
- </span>
- ) : (
- <Link
- className='mt-8 block w-full bg-indigo-600 rounded-md py-2 text-sm font-semibold text-white text-center hover:bg-indigo-700'
- to={routes.signup}
- aria-label={t('titles.signup')}
- >
- {tier.planCode === 'free' ? t('common.getStarted') : t('pricing.upgrade')}
- </Link>
- )}
- </div>
- <div className='px-6 border-none'>
- <hr className='w-full mx-auto border border-gray-300 dark:border-gray-600' />
- </div>
- <div className='pt-6 pb-8 px-6 border-none'>
- <h3 className='text-xs font-medium text-gray-900 dark:text-gray-50 tracking-wide uppercase'>
- {t('pricing.whatIncl')}
- </h3>
- <ul className='mt-6 space-y-4'>
- {_map(tier.includedFeatures, (feature) => (
- <li key={feature} className='flex space-x-3'>
- <CheckIcon className='flex-shrink-0 h-5 w-5 text-green-500' aria-hidden='true' />
- <span className='text-sm text-gray-500 dark:text-gray-200'>{feature}</span>
- </li>
- ))}
- </ul>
+ {authenticated ? (
+ <span
+ onClick={() => downgrade ? downgradeHandler(tier) : onPlanChange(tier)}
+ className={cx('inline-flex items-center justify-center mt-8 w-full rounded-md py-2 text-sm font-semibold text-white text-center select-none', {
+ 'bg-indigo-600 hover:bg-indigo-700 cursor-pointer': planCodeLoading === null && (tier.planCode !== user.planCode || (user.billingFrequency !== billingFrequency && user.planCode !== 'free')),
+ 'bg-indigo-400 cursor-default': planCodeLoading !== null || (tier.planCode === user.planCode && (user.billingFrequency === billingFrequency || user.planCode === 'free' || user.planCode === 'trial')),
+ })}
+ >
+ {planCodeLoading === tier.planCode && (
+ <Spin />
+ )}
+ {action}
+ </span>
+ ) : (
+ <Link
+ className='mt-8 block w-full bg-indigo-600 rounded-md py-2 text-sm font-semibold text-white text-center hover:bg-indigo-700'
+ to={routes.signup}
+ aria-label={t('titles.signup')}
+ >
+ {tier.planCode === 'free' ? t('common.getStarted') : t('pricing.upgrade')}
+ </Link>
+ )}
+ </div>
+ <div className='px-6 border-none'>
+ <hr className='w-full mx-auto border border-gray-300 dark:border-gray-600' />
+ </div>
+ <div className='pt-6 pb-8 px-6 border-none'>
+ <h3 className='text-xs font-medium text-gray-900 dark:text-gray-50 tracking-wide uppercase'>
+ {t('pricing.whatIncl')}
+ </h3>
+ <ul className='mt-6 space-y-4'>
+ {_map(tier.includedFeatures, (feature) => (
+ <li key={feature} className='flex space-x-3'>
+ <CheckIcon className='flex-shrink-0 h-5 w-5 text-green-500' aria-hidden='true' />
+ <span className='text-sm text-gray-500 dark:text-gray-200'>{feature}</span>
+ </li>
+ ))}
+ </ul>
+ </div>
</div>
- </div>
-)
+ )
+}
const Pricing = ({ t, language }) => {
const dispatch = useDispatch()
@@ -249,7 +267,7 @@ const Pricing = ({ t, language }) => {
}, [lastEvent, dispatch, t])
const onPlanChange = (tier) => {
- if (planCodeLoading === null && (user.planCode !== tier.planCode || (user.billingFrequency !== billingFrequency && user.planCode !== 'free'))) {
+ if (planCodeLoading === null && (user.planCode !== tier.planCode || (user.billingFrequency !== billingFrequency && user.planCode !== 'free' && user.planCode !== 'trial'))) {
setPlanCodeLoading(tier.planCode)
if (!window.Paddle) {
diff --git a/src/redux/constants/index.js b/src/redux/constants/index.js
index b57be5f86..c96ce426e 100644
--- a/src/redux/constants/index.js
+++ b/src/redux/constants/index.js
@@ -264,6 +264,14 @@ export const PLAN_LIMITS = {
maxAlerts: 1,
legacy: true,
},
+ trial: {
+ monthlyUsageLimit: 100000,
+ maxProjects: 20,
+ maxAlerts: 20,
+ legacy: false,
+ priceMonthly: 0,
+ priceYearly: 0,
+ },
hobby: {
monthlyUsageLimit: 10000,
maxProjects: 20,