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!

Refresh trial ended banner

Blue Mouse17314c5c7258
diff --git a/web/app/components/Header/index.tsx b/web/app/components/Header/index.tsx
index 23b789673..ad788bb71 100644
--- a/web/app/components/Header/index.tsx
+++ b/web/app/components/Header/index.tsx
@@ -376,15 +376,71 @@ const Separator = () => (
</svg>
)
+const TrialBanner = () => {
+ const { t } = useTranslation('common')
+ const { user, isAuthenticated } = useAuth()
+
+ 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('header.trialBanner.ended')]
+ }
+
+ 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('header.trialBanner.endsToday')]
+ }
+ if (isTomorrow) {
+ return [TRIAL_STATUS_MAPPING.ENDS_TOMORROW, t('header.trialBanner.endsTomorrow')]
+ }
+ }
+
+ // trial ends in more than 1 day
+ const amount = Math.round(dayjs.duration(diff).asDays())
+ return [TRIAL_STATUS_MAPPING.ENDS_IN_X_DAYS, t('header.trialBanner.youHaveXDaysLeft', { amount })]
+ }, [user, t])
+
+ if (!status || isSelfhosted || !isAuthenticated) {
+ return null
+ }
+
+ return (
+ <div className='w-full bg-slate-900 text-gray-100 dark:bg-slate-900'>
+ <div className='mx-auto max-w-7xl px-4 py-2 text-center text-sm sm:px-6 lg:px-8'>
+ <span className='font-medium'>{status}</span>
+ <span className='mx-1.5'>—</span>
+ <Link to={routes.billing} className='font-semibold underline'>
+ {t('header.trialBanner.pickAPlan')}
+ </Link>
+ <span className='ml-1.5'>
+ {rawStatus === TRIAL_STATUS_MAPPING.ENDED
+ ? t('header.trialBanner.keepUsingEnded')
+ : t('header.trialBanner.keepUsing')}
+ </span>
+ </div>
+ </div>
+ )
+}
+
const AuthedHeader = ({
- rawStatus,
- status,
logoutHandler,
colourBackground,
openMenu,
}: {
- rawStatus: string | number
- status: string
logoutHandler: () => void
colourBackground: boolean
openMenu: () => void
@@ -407,21 +463,6 @@ const AuthedHeader = ({
</Link>
<div className='ml-10 hidden gap-4 space-x-1 lg:flex'>
- {user?.planCode === 'trial' ? (
- <Link
- to={routes.billing}
- className={cx('underline-animate text-base leading-6 font-semibold focus:outline-hidden', {
- 'text-amber-600': rawStatus === TRIAL_STATUS_MAPPING.ENDS_IN_X_DAYS,
- 'text-rose-600':
- rawStatus === TRIAL_STATUS_MAPPING.ENDS_TODAY ||
- rawStatus === TRIAL_STATUS_MAPPING.ENDS_TOMORROW ||
- rawStatus === TRIAL_STATUS_MAPPING.ENDED,
- })}
- key='TrialNotification'
- >
- {status}
- </Link>
- ) : null}
{user?.planCode === 'none' ? (
<Link
to={routes.billing}
@@ -604,40 +645,6 @@ const Header = ({ refPage, transparent }: HeaderProps) => {
const solutions = getSolutions(t)
- 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 = () => {
setMobileMenuOpen(false)
logout()
@@ -649,15 +656,11 @@ const Header = ({ refPage, transparent }: HeaderProps) => {
return (
<Popover>
+ <TrialBanner />
+
{/* Computer / Laptop / Tablet layout header */}
{isAuthenticated ? (
- <AuthedHeader
- rawStatus={rawStatus || ''}
- status={status || ''}
- logoutHandler={logoutHandler}
- colourBackground={!transparent}
- openMenu={openMenu}
- />
+ <AuthedHeader logoutHandler={logoutHandler} colourBackground={!transparent} openMenu={openMenu} />
) : (
<NotAuthedHeader colourBackground={!transparent} refPage={refPage} openMenu={openMenu} />
)}
@@ -767,25 +770,6 @@ const Header = ({ refPage, transparent }: HeaderProps) => {
)}
</Disclosure>
) : null}
- {!isSelfhosted && isAuthenticated && user?.planCode === 'trial' ? (
- <Link
- to={routes.billing}
- onClick={() => setMobileMenuOpen(false)}
- className={cx(
- '-mx-3 block rounded-lg px-3 py-2 text-base leading-7 font-semibold hover:bg-gray-400/20 dark:hover:bg-slate-700/50',
- {
- 'text-amber-600': rawStatus === TRIAL_STATUS_MAPPING.ENDS_IN_X_DAYS,
- 'text-rose-600':
- rawStatus === TRIAL_STATUS_MAPPING.ENDS_TODAY ||
- rawStatus === TRIAL_STATUS_MAPPING.ENDS_TOMORROW ||
- rawStatus === TRIAL_STATUS_MAPPING.ENDED,
- },
- )}
- key='TrialNotification'
- >
- {status}
- </Link>
- ) : null}
{!isSelfhosted && isAuthenticated && user?.planCode === 'none' ? (
<Link
to={routes.billing}
diff --git a/web/public/locales/de.json b/web/public/locales/de.json
index c0eddacfe..330ccd619 100644
--- a/web/public/locales/de.json
+++ b/web/public/locales/de.json
@@ -1487,6 +1487,15 @@
"signedInAs": "Angemeldet als",
"watchDemo": "Demo ansehen",
"contactSales": "Kontakt zur Verkaufsabteilung",
+ "trialBanner": {
+ "pickAPlan": "Wählen Sie einen Tarif",
+ "keepUsing": "um die Nutzung ohne Unterbrechung fortzusetzen.",
+ "keepUsingEnded": "um Swetrix weiter zu nutzen.",
+ "youHaveXDaysLeft": "Sie haben noch {{amount}} Tage in Ihrer kostenlosen Testphase",
+ "endsToday": "Deine kostenlose Testversion endet heute",
+ "endsTomorrow": "Deine kostenlose Testversion endet morgen",
+ "ended": "Ihre kostenlose Testphase ist beendet"
+ },
"solutions": {
"title": "Lösungen",
"analytics": {
diff --git a/web/public/locales/en.json b/web/public/locales/en.json
index da8318e2d..b30d6f27c 100644
--- a/web/public/locales/en.json
+++ b/web/public/locales/en.json
@@ -1487,6 +1487,15 @@
"signedInAs": "Signed in as",
"watchDemo": "Watch demo",
"contactSales": "Contact sales",
+ "trialBanner": {
+ "pickAPlan": "Pick a plan",
+ "keepUsing": "to keep using without interruption.",
+ "keepUsingEnded": "to keep using Swetrix.",
+ "youHaveXDaysLeft": "You have {{amount}} days left on your free trial",
+ "endsToday": "Your free trial ends today",
+ "endsTomorrow": "Your free trial ends tomorrow",
+ "ended": "Your free trial has ended"
+ },
"solutions": {
"title": "Solutions",
"analytics": {
diff --git a/web/public/locales/fr.json b/web/public/locales/fr.json
index 8ba03f1f6..82dbdfa56 100644
--- a/web/public/locales/fr.json
+++ b/web/public/locales/fr.json
@@ -1487,6 +1487,15 @@
"signedInAs": "Connecté en tant que",
"watchDemo": "Voir la démo",
"contactSales": "Contacter le service commercial",
+ "trialBanner": {
+ "pickAPlan": "Choisissez une formule",
+ "keepUsing": "pour continuer à l'utiliser sans interruption.",
+ "keepUsingEnded": "pour continuer à utiliser Swetrix.",
+ "youHaveXDaysLeft": "Il vous reste {{amount}} jours d'essai gratuit",
+ "endsToday": "Votre essai gratuit se termine aujourd'hui",
+ "endsTomorrow": "Votre essai gratuit se termine demain",
+ "ended": "Votre période d'essai gratuit est terminée"
+ },
"solutions": {
"title": "Solutions",
"analytics": {
diff --git a/web/public/locales/pl.json b/web/public/locales/pl.json
index 11ad5fafa..1047d26bf 100644
--- a/web/public/locales/pl.json
+++ b/web/public/locales/pl.json
@@ -1487,6 +1487,15 @@
"signedInAs": "Podpisany jako",
"watchDemo": "Obejrzyj demo",
"contactSales": "Skontaktuj się ze sprzedażą",
+ "trialBanner": {
+ "pickAPlan": "Wybierz plan",
+ "keepUsing": "aby kontynuować korzystanie bez przerw.",
+ "keepUsingEnded": "aby dalej korzystać ze Swetrix.",
+ "youHaveXDaysLeft": "Masz jeszcze {{amount}} dni bezpłatnego okresu próbnego",
+ "endsToday": "Twój okres próbny kończy się dzisiaj",
+ "endsTomorrow": "Twój okres próbny kończy się jutro",
+ "ended": "Twój bezpłatny okres próbny dobiegł końca"
+ },
"solutions": {
"title": "Rozwiązania",
"analytics": {
diff --git a/web/public/locales/uk.json b/web/public/locales/uk.json
index b4ba548a8..0a11db1b7 100644
--- a/web/public/locales/uk.json
+++ b/web/public/locales/uk.json
@@ -1487,6 +1487,15 @@
"signedInAs": "Авторизований як",
"watchDemo": "Переглянути демо",
"contactSales": "Звʼязатися з нами",
+ "trialBanner": {
+ "pickAPlan": "Оберіть план",
+ "keepUsing": "щоб і надалі користуватися без перерв.",
+ "keepUsingEnded": "щоб і надалі користуватися Swetrix.",
+ "youHaveXDaysLeft": "У вас залишилося {{amount}} днів безкоштовного пробного періоду",
+ "endsToday": "Ваш безплатний пробний період завершується сьогодні",
+ "endsTomorrow": "Ваш безплатний пробний період завершується завтра",
+ "ended": "Пробний період закінчився"
+ },
"solutions": {
"title": "Рішення",
"analytics": {