🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Refactor subscription page and enhance pricing features
Bill Yangad2c08e9a22b
diff --git a/client/src/app/subscribe/page.tsx b/client/src/app/subscribe/page.tsxindex 96df9032f..90ca45b40 100644--- a/client/src/app/subscribe/page.tsx+++ b/client/src/app/subscribe/page.tsx@@ -1,19 +1,8 @@"use client";-import { Badge } from "@/components/ui/badge";-import { Button } from "@/components/ui/button";-import {- Card,- CardContent,- CardDescription,- CardFooter,- CardHeader,- CardTitle,-} from "@/components/ui/card";import { Slider } from "@/components/ui/slider";import { authClient } from "@/lib/auth";import { STRIPE_PRICES } from "@/lib/stripe";-import { cn } from "@/lib/utils";import { Check } from "lucide-react";import { useState } from "react";import { toast } from "sonner";@@ -25,25 +14,15 @@ const EVENT_TIERS = [100_000, 250_000, 500_000, 1_000_000, 2_000_000, 5_000_000, 10_000_000,];-// Define types for plans-interface PlanTemplate {- id: "pro";- name: string;- price?: string;- interval?: string;- description: string;- baseFeatures: string[];- color: string;-}--interface Plan extends PlanTemplate {- price: string;- interval: string;- features: string[];- monthlyPrice?: number;- annualPrice?: number;- savings?: string;-}+// Define plan features+const PRO_FEATURES = [+ "Unlimited websites",+ "Unlimited team members",+ "Real-time analytics",+ "Custom events",+ "Funnels & user flows",+ "All features",+];interface StripePrice {priceId: string;@@ -55,23 +34,6 @@ interface StripePrice {};}-// Plan templates - only Pro plan since free tier is removed-const PLAN_TEMPLATES: PlanTemplate[] = [- {- id: "pro",- name: "Pro",- description: "Advanced analytics for growing projects",- baseFeatures: ["5 year data retention", "Priority support"],- color:- "bg-gradient-to-br from-green-50 to-emerald-100 dark:from-green-800 dark:to-emerald-800",- },-];--// Format price with dollar sign-function getFormattedPrice(price: number): string {- return `$${price}`;-}-// Find the appropriate price for a tier at current event limitfunction findPriceForTier(eventLimit: number,@@ -98,18 +60,10 @@ function findPriceForTier(return selectedPlan;}-// Calculate savings percentage between monthly and annual plans-function calculateSavings(monthlyPrice: number, annualPrice: number): string {- const monthlyCost = monthlyPrice * 12;- const savings = monthlyCost - annualPrice;- const savingsPercent = Math.round((savings / monthlyCost) * 100);- return `Save ${savingsPercent}%`;-}-export default function Subscribe() {const [eventLimitIndex, setEventLimitIndex] = useState<number>(0); // Default to 100k (index 0)const [isAnnual, setIsAnnual] = useState<boolean>(true);- const [isLoading, setIsLoading] = useState(false);+ const [isLoading, setIsLoading] = useState<boolean>(false);const { data: sessionData } = authClient.useSession();const eventLimit = EVENT_TIERS[eventLimitIndex];@@ -177,187 +131,172 @@ export default function Subscribe() {setEventLimitIndex(value[0]);}- // Find the current prices for each tier based on the event limit- const interval = isAnnual ? "year" : "month";- const proPricing = findPriceForTier(eventLimit, interval);-- // Also get monthly prices for savings calculation- const proMonthly = findPriceForTier(eventLimit, "month");- const proAnnual = findPriceForTier(eventLimit, "year");-- // Generate plan objects with current state- const plans: Plan[] = PLAN_TEMPLATES.map((template) => {- const plan = { ...template } as Plan;-- const tierPrice = proPricing;- plan.price = tierPrice ? getFormattedPrice(tierPrice.price) : "$19+";- plan.interval = isAnnual ? "year" : "month";-- if (proMonthly && proAnnual) {- plan.monthlyPrice = proMonthly.price;- plan.annualPrice = proAnnual.price;- plan.savings = calculateSavings(proMonthly.price, proAnnual.price);- }-- // Add event limit feature at the beginning- const eventFeature = `${Math.max(- eventLimit,- 100_000- ).toLocaleString()} events per month`;- plan.features = [eventFeature, ...plan.baseFeatures];-- return plan;- });+ // Get pricing information+ const proPricing = findPriceForTier(eventLimit, isAnnual ? "year" : "month");+ const monthlyPrice = findPriceForTier(eventLimit, "month")?.price || 0;+ const annualPrice = findPriceForTier(eventLimit, "year")?.price || 0;return (<StandardPage>- <div className="container mx-auto py-12">- <div className="mb-12 text-center max-w-3xl mx-auto">- <h1 className="text-4xl font-bold tracking-tight mb-4 ">- Choose Your Analytics Plan+ <div className="container mx-auto py-12 px-4">+ <div className="mb-10 text-center max-w-3xl mx-auto">+ <h1 className="text-4xl md:text-5xl font-bold tracking-tight pb-4 text-transparent bg-clip-text bg-gradient-to-b from-white via-gray-200 to-gray-400">+ Simple, Transparent Pricing</h1>- <p className="text-lg text-neutral-600 dark:text-neutral-400 mb-6">- Upgrade for more events and advanced features- </p>- <p className="text-neutral-500 dark:text-neutral-400">- Your 14-day trial gives you access to all Pro features with up to- 100,000 events. Subscribe to continue using the service after your- trial ends.+ <p className="text-lg text-neutral-300 mb-6">+ Privacy-friendly analytics with all the features you need to grow</p></div>- <div className="max-w-xl mx-auto">- {plans.map((plan) => (- <div key={plan.id} className="transition-all duration-300 h-full">- <Card- className={`flex flex-col h-full transition-transform duration-300 transform hover:scale-[1.01] hover:shadow-md cursor-pointer overflow-hidden`}- >- <div className={`${plan.color} h-3 w-full`}></div>-- <CardHeader className="pb-4">- <CardTitle className="text-3xl">{plan.name}</CardTitle>- <CardDescription>- <p>{plan.description}</p>- </CardDescription>- </CardHeader>-- <CardContent className="pb-0">- {/* Billing toggle buttons */}- <div className="flex justify-center mb-6">- <div className="bg-neutral-100 dark:bg-neutral-800 p-1 rounded-lg inline-flex relative">+ {/* Pricing card */}+ <div className="max-w-lg mx-auto">+ <div className="bg-neutral-800/50 rounded-xl border border-neutral-700 overflow-hidden">+ <div className="p-6">+ {/* Slider section */}+ <div className="mb-6">+ <div className="flex justify-between mb-3 items-center">+ <div>+ <h3 className="font-semibold mb-2">Events per month</h3>+ <div className="text-3xl font-bold text-emerald-400">+ {eventLimit.toLocaleString()}+ </div>+ </div>+ <div className="flex flex-col items-end">+ {/* Billing toggle */}+ <div className="flex gap-3 mb-2 text-sm"><buttononClick={() => setIsAnnual(false)}- className={cn(- "px-6 py-2 rounded-lg text-sm font-medium transition-all",+ className={`px-3 py-1 rounded-full transition-colors ${!isAnnual- ? "bg-white dark:bg-neutral-700 shadow-sm text-black dark:text-white"- : "text-neutral-600 dark:text-neutral-400 hover:text-neutral-900 dark:hover:text-neutral-200"- )}+ ? "bg-emerald-500/20 text-emerald-400 font-medium"+ : "text-neutral-400 hover:text-neutral-200"+ }`}>Monthly</button>- <div className="relative">- <button- onClick={() => setIsAnnual(true)}- className={cn(- "px-6 py-2 rounded-lg text-sm font-medium transition-all",- isAnnual- ? "bg-white dark:bg-neutral-700 shadow-sm text-black dark:text-white"- : "text-neutral-600 dark:text-neutral-400 hover:text-neutral-900 dark:hover:text-neutral-200"- )}- >- Annual- </button>- <Badge- className="absolute -top-4 -right-2 text-white border-0 pointer-events-none"- variant="green"- >- 2 months free- </Badge>- </div>+ <button+ onClick={() => setIsAnnual(true)}+ className={`px-3 py-1 rounded-full transition-colors ${+ isAnnual+ ? "bg-emerald-500/20 text-emerald-400 font-medium"+ : "text-neutral-400 hover:text-neutral-200"+ }`}+ >+ Annual+ <span className="ml-1 text-xs text-emerald-500">+ -17%+ </span>+ </button></div>- </div>-- {/* Event slider */}- <div className="mb-6">- <div className="mb-4">- <div className="flex justify-between mb-2 items-center">- <div className="text-neutral-600 dark:text-neutral-400 text-sm">- Events per month- <div className="font-bold text-lg text-white">- {eventLimit.toLocaleString()}+ <div className="text-right">+ {isAnnual ? (+ <>+ <span className="text-3xl font-bold">+ ${annualPrice}+ </span>+ <span className="ml-1 text-neutral-400">/year</span>+ <div className="text-sm text-neutral-400">+ ${Math.round(annualPrice / 12)}/mo</div>- </div>- <div className="flex items-baseline">- <span className="text-3xl font-bold text-neutral-900 dark:text-white">- {plan.price}+ </>+ ) : (+ <>+ <span className="text-3xl font-bold">+ ${monthlyPrice}</span>- {plan.interval && (- <span className="ml-1 text-neutral-500">- /{plan.interval}- </span>- )}- </div>- </div>+ <span className="ml-1 text-neutral-400">/month</span>+ </>+ )}</div>+ </div>+ </div>++ <Slider+ defaultValue={[0]}+ max={EVENT_TIERS.length - 1}+ min={0}+ step={1}+ onValueChange={handleSliderChange}+ className="mb-3"+ />++ <div className="flex justify-between text-xs text-neutral-400">+ {EVENT_TIERS.map((tier, index) => (+ <span+ key={index}+ className={+ eventLimitIndex === index+ ? "font-bold text-emerald-400"+ : ""+ }+ >+ {tier >= 1_000_000+ ? `${tier / 1_000_000}M`+ : `${tier / 1_000}K`}+ </span>+ ))}+ </div>+ </div>++ <div className="space-y-4 mb-6">+ {PRO_FEATURES.map((feature, i) => (+ <div key={i} className="flex items-center">+ <Check className="h-4 w-4 text-emerald-400 mr-3 shrink-0" />+ <span>{feature}</span>+ </div>+ ))}+ </div>- <Slider- defaultValue={[0]} // Default to index 0 (100k)- max={EVENT_TIERS.length - 1}- min={0}- step={1}- onValueChange={handleSliderChange}- className="mb-3"- />+ <button+ onClick={handleSubscribe}+ className="w-full bg-emerald-600 hover:bg-emerald-500 text-white font-medium px-5 py-3 rounded-xl shadow-lg shadow-emerald-900/20 transform hover:-translate-y-0.5 transition-all duration-200 focus:outline-none focus:ring-2 focus:ring-emerald-500 focus:ring-opacity-50 disabled:opacity-50 disabled:pointer-events-none"+ disabled={isLoading}+ >+ {isLoading ? "Processing..." : "Subscribe Now"}+ </button>- <div className="flex justify-between text-xs text-neutral-500">- {EVENT_TIERS.map((tier, index) => (- <span- key={index}- className={- eventLimitIndex === index- ? "font-bold text-white"- : ""- }- >- {tier >= 1_000_000- ? `${tier / 1_000_000}M`- : `${tier / 1_000}K`}- </span>- ))}- </div>- </div>- </CardContent>+ <p className="text-center text-sm text-neutral-400 mt-4">+ Secure checkout powered by Stripe. Cancel anytime.+ </p>+ </div>+ </div>++ {/* FAQ section */}+ <div className="mt-10 space-y-6">+ <h3 className="text-xl font-semibold mb-4">+ Frequently Asked Questions+ </h3>++ <div className="bg-neutral-800/20 p-5 rounded-lg border border-neutral-700">+ <h4 className="font-medium mb-2">What counts as an event?</h4>+ <p className="text-neutral-300">+ An event is either a pageview or a custom event that you create+ on your website. Pageviews are tracked automatically, while+ custom events can be defined to track specific user+ interactions.+ </p>+ </div>- <CardContent className={"pt-0 flex-grow"}>- <div className="w-full h-px bg-neutral-200 dark:bg-neutral-800 mb-4"></div>- <ul className="space-y-3 text-sm">- {plan.features.map((feature, i) => (- <li key={`${feature}-${i}`} className="flex items-start">- <Check- className={`mr-2 h-4 w-4 ${- i === 0 ? "text-emerald-400" : "text-green-400"- } shrink-0`}- />- <span>{feature}</span>- </li>- ))}- </ul>- </CardContent>+ <div className="bg-neutral-800/20 p-5 rounded-lg border border-neutral-700">+ <h4 className="font-medium mb-2">Can I change my plan later?</h4>+ <p className="text-neutral-300">+ Absolutely. You can upgrade, downgrade, or cancel your plan at+ any time through your account settings.+ </p>+ </div>- <CardFooter>- <Button- onClick={handleSubscribe}- className="w-full"- disabled={isLoading}- variant="success"- >- {isLoading ? "Processing..." : `Subscribe to ${plan.name}`}- </Button>- </CardFooter>- </Card>+ <div className="bg-neutral-800/20 p-5 rounded-lg border border-neutral-700">+ <h4 className="font-medium mb-2">+ What happens if I go over my event limit?+ </h4>+ <p className="text-neutral-300">+ We'll notify you when you're approaching your limit. You can+ either upgrade to a higher plan or continue with your current+ plan (events beyond the limit won't be tracked). Remember, an+ event is either a pageview or a custom event you've defined.+ </p></div>- ))}+ </div></div></div></StandardPage>diff --git a/docs/src/app/pricing/page.jsx b/docs/src/app/pricing/page.jsxindex 0ec76fec5..421c6223f 100644--- a/docs/src/app/pricing/page.jsx+++ b/docs/src/app/pricing/page.jsx@@ -167,6 +167,13 @@ export default function Pricing() {<div className="mt-10 space-y-6"><h3 className="text-xl font-semibold mb-4">Frequently Asked Questions</h3>+ <div className="bg-neutral-800/20 p-5 rounded-lg border border-neutral-700">+ <h4 className="font-medium mb-2">What counts as an event?</h4>+ <p className="text-neutral-300">+ An event is either a pageview or a custom event that you create on your website. Pageviews are tracked automatically, while custom events can be defined to track specific user interactions.+ </p>+ </div>+<div className="bg-neutral-800/20 p-5 rounded-lg border border-neutral-700"><h4 className="font-medium mb-2">Can I change my plan later?</h4><p className="text-neutral-300">@@ -177,7 +184,7 @@ export default function Pricing() {<div className="bg-neutral-800/20 p-5 rounded-lg border border-neutral-700"><h4 className="font-medium mb-2">What happens if I go over my event limit?</h4><p className="text-neutral-300">- We'll notify you when you're approaching your limit. You can either upgrade to a higher plan or continue with your current plan (events beyond the limit won't be tracked).+ We'll notify you when you're approaching your limit. You can either upgrade to a higher plan or continue with your current plan (events beyond the limit won't be tracked). Remember, an event is either a pageview or a custom event you've defined.</p></div></div>