|
| 1 | +'use client' |
| 2 | + |
| 3 | +import React, { useState, useMemo } from 'react' |
| 4 | +import { DollarSign, TrendingDown, Clock, MousePointer2, AlertCircle, Info, ArrowRight, TrendingUp } from 'lucide-react' |
| 5 | +import BreadcrumbSchema from '@/components/seo/BreadcrumbSchema' |
| 6 | + |
| 7 | +export default function ApiLatencyCalculator() { |
| 8 | + const [monthlyRevenue, setMonthlyRevenue] = useState(10000) |
| 9 | + const [currentLatency, setCurrentLatency] = useState(500) |
| 10 | + const [targetLatency, setTargetLatency] = useState(100) |
| 11 | + |
| 12 | + const stats = useMemo(() => { |
| 13 | + // Industry Benchmark: 100ms = 1% conversion/revenue loss |
| 14 | + const latencyDiff = Math.max(0, currentLatency - targetLatency) |
| 15 | + const lossPercentage = (latencyDiff / 100) * 1.0 |
| 16 | + const monthlyLoss = (monthlyRevenue * lossPercentage) / 100 |
| 17 | + const annualLoss = monthlyLoss * 12 |
| 18 | + const projectedRevenue = monthlyRevenue + monthlyLoss |
| 19 | + |
| 20 | + return { |
| 21 | + monthlyLoss, |
| 22 | + annualLoss, |
| 23 | + lossPercentage, |
| 24 | + projectedRevenue |
| 25 | + } |
| 26 | + }, [monthlyRevenue, currentLatency, targetLatency]) |
| 27 | + |
| 28 | + return ( |
| 29 | + <div className="min-h-screen bg-white dark:bg-slate-950 py-12 px-4 sm:px-6 lg:px-8 transition-colors duration-300"> |
| 30 | + <BreadcrumbSchema name="API Latency Cost Calculator" slug="api-latency-calculator" /> |
| 31 | + |
| 32 | + <div className="max-w-5xl mx-auto"> |
| 33 | + <div className="text-center mb-12"> |
| 34 | + <div className="inline-flex items-center justify-center p-3 bg-red-100 dark:bg-red-900/30 text-red-600 dark:text-red-400 rounded-2xl mb-4 border border-red-200 dark:border-red-800"> |
| 35 | + <TrendingDown className="w-8 h-8" /> |
| 36 | + </div> |
| 37 | + <h1 className="text-4xl font-extrabold text-gray-900 dark:text-white mb-4 tracking-tight">API Latency Cost Calculator</h1> |
| 38 | + <p className="text-xl text-gray-500 dark:text-slate-400 max-w-2xl mx-auto"> |
| 39 | + Discover how much revenue your business is losing due to slow API response times and network latency. |
| 40 | + </p> |
| 41 | + </div> |
| 42 | + |
| 43 | + <div className="grid grid-cols-1 lg:grid-cols-3 gap-8"> |
| 44 | + {/* Inputs Section */} |
| 45 | + <div className="lg:col-span-1 space-y-6"> |
| 46 | + <div className="bg-white dark:bg-slate-900 rounded-3xl border border-gray-100 dark:border-slate-800 p-8 shadow-sm"> |
| 47 | + <h2 className="text-sm font-bold text-gray-400 dark:text-slate-500 uppercase tracking-widest mb-6">Business Metrics</h2> |
| 48 | + |
| 49 | + <div className="space-y-6"> |
| 50 | + <div> |
| 51 | + <label className="block text-xs font-bold text-gray-500 dark:text-slate-400 uppercase mb-2">Monthly Revenue ($)</label> |
| 52 | + <div className="relative"> |
| 53 | + <DollarSign className="absolute left-4 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400" /> |
| 54 | + <input |
| 55 | + type="number" |
| 56 | + value={monthlyRevenue} |
| 57 | + onChange={(e) => setMonthlyRevenue(Math.max(0, parseInt(e.target.value) || 0))} |
| 58 | + className="w-full pl-10 pr-4 py-3 bg-gray-50 dark:bg-slate-800 border border-gray-200 dark:border-slate-700 rounded-xl font-bold text-gray-900 dark:text-white focus:ring-2 focus:ring-red-500 outline-none transition-all" |
| 59 | + /> |
| 60 | + </div> |
| 61 | + </div> |
| 62 | + |
| 63 | + <div> |
| 64 | + <label className="block text-xs font-bold text-gray-500 dark:text-slate-400 uppercase mb-2">Current Latency (ms)</label> |
| 65 | + <div className="relative"> |
| 66 | + <Clock className="absolute left-4 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400" /> |
| 67 | + <input |
| 68 | + type="number" |
| 69 | + value={currentLatency} |
| 70 | + onChange={(e) => setCurrentLatency(Math.max(0, parseInt(e.target.value) || 0))} |
| 71 | + className="w-full pl-10 pr-4 py-3 bg-gray-50 dark:bg-slate-800 border border-gray-200 dark:border-slate-700 rounded-xl font-bold text-gray-900 dark:text-white focus:ring-2 focus:ring-red-500 outline-none transition-all" |
| 72 | + /> |
| 73 | + </div> |
| 74 | + </div> |
| 75 | + |
| 76 | + <div> |
| 77 | + <label className="block text-xs font-bold text-gray-500 dark:text-slate-400 uppercase mb-2">Target Latency (ms)</label> |
| 78 | + <div className="relative"> |
| 79 | + <TrendingUp className="absolute left-4 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400" /> |
| 80 | + <input |
| 81 | + type="number" |
| 82 | + value={targetLatency} |
| 83 | + onChange={(e) => setTargetLatency(Math.max(0, parseInt(e.target.value) || 0))} |
| 84 | + className="w-full pl-10 pr-4 py-3 bg-gray-50 dark:bg-slate-800 border border-gray-200 dark:border-slate-700 rounded-xl font-bold text-gray-900 dark:text-white focus:ring-2 focus:ring-green-500 outline-none transition-all" |
| 85 | + /> |
| 86 | + </div> |
| 87 | + </div> |
| 88 | + </div> |
| 89 | + </div> |
| 90 | + |
| 91 | + <div className="bg-amber-50 dark:bg-amber-900/10 rounded-3xl p-6 border border-amber-100 dark:border-amber-900/30"> |
| 92 | + <div className="flex gap-3"> |
| 93 | + <AlertCircle className="w-5 h-5 text-amber-600 shrink-0 mt-0.5" /> |
| 94 | + <p className="text-xs text-amber-800 dark:text-amber-400 leading-relaxed font-medium"> |
| 95 | + <strong>The 100ms Rule:</strong> Amazon found that every 100ms of latency cost them 1% in sales. Google found an extra 500ms delay caused a 20% drop in traffic. |
| 96 | + </p> |
| 97 | + </div> |
| 98 | + </div> |
| 99 | + </div> |
| 100 | + |
| 101 | + {/* Results Section */} |
| 102 | + <div className="lg:col-span-2 space-y-8"> |
| 103 | + <div className="bg-gray-900 rounded-3xl p-10 text-white shadow-2xl relative overflow-hidden group"> |
| 104 | + <div className="absolute top-0 right-0 p-8 opacity-10 group-hover:opacity-20 transition-opacity"> |
| 105 | + <DollarSign className="w-32 h-32" /> |
| 106 | + </div> |
| 107 | + |
| 108 | + <div className="relative z-10"> |
| 109 | + <h3 className="text-sm font-bold text-gray-400 uppercase tracking-widest mb-8">Estimated Revenue Loss</h3> |
| 110 | + |
| 111 | + <div className="grid grid-cols-1 md:grid-cols-2 gap-12"> |
| 112 | + <div> |
| 113 | + <span className="block text-gray-400 text-xs font-bold uppercase mb-2">Monthly Loss</span> |
| 114 | + <span className="text-4xl md:text-5xl font-extrabold text-red-500 tracking-tight"> |
| 115 | + ${stats.monthlyLoss.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })} |
| 116 | + </span> |
| 117 | + </div> |
| 118 | + <div> |
| 119 | + <span className="block text-gray-400 text-xs font-bold uppercase mb-2">Annual Impact</span> |
| 120 | + <span className="text-4xl md:text-5xl font-extrabold text-white tracking-tight"> |
| 121 | + ${stats.annualLoss.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })} |
| 122 | + </span> |
| 123 | + </div> |
| 124 | + </div> |
| 125 | + |
| 126 | + <div className="mt-12 pt-8 border-t border-gray-800"> |
| 127 | + <div className="flex items-center justify-between"> |
| 128 | + <div> |
| 129 | + <span className="block text-gray-500 text-xs font-bold uppercase mb-1">Conversion Drop</span> |
| 130 | + <span className="text-xl font-bold text-amber-500">-{stats.lossPercentage.toFixed(1)}%</span> |
| 131 | + </div> |
| 132 | + <div className="text-right"> |
| 133 | + <span className="block text-gray-500 text-xs font-bold uppercase mb-1">Potential Monthly Revenue</span> |
| 134 | + <span className="text-xl font-bold text-green-500">${stats.projectedRevenue.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}</span> |
| 135 | + </div> |
| 136 | + </div> |
| 137 | + </div> |
| 138 | + </div> |
| 139 | + </div> |
| 140 | + |
| 141 | + <div className="bg-white dark:bg-slate-900 rounded-3xl border border-gray-100 dark:border-slate-800 p-8"> |
| 142 | + <div className="flex items-center gap-3 mb-6"> |
| 143 | + <Info className="w-5 h-5 text-blue-500" /> |
| 144 | + <h2 className="text-lg font-bold text-gray-900 dark:text-white">Why This Matters</h2> |
| 145 | + </div> |
| 146 | + <div className="prose prose-sm dark:prose-invert max-w-none text-gray-600 dark:text-slate-400"> |
| 147 | + <p> |
| 148 | + Latency is silent conversion killer. In the world of modern web applications, user expectations are at an all-time high. A delay that feels insignificant to a developer can be the difference between a completed sale and a bounced visitor. |
| 149 | + </p> |
| 150 | + <div className="grid grid-cols-1 md:grid-cols-2 gap-6 mt-6"> |
| 151 | + <div className="p-4 bg-gray-50 dark:bg-slate-800 rounded-2xl border border-gray-100 dark:border-slate-700"> |
| 152 | + <h4 className="font-bold text-gray-900 dark:text-white mb-2 flex items-center gap-2"> |
| 153 | + <MousePointer2 className="w-4 h-4 text-blue-500" /> UX Impact |
| 154 | + </h4> |
| 155 | + <p className="text-xs">Users perceive delays over 100ms as non-instant, breaking the flow of interaction and reducing trust in the platform.</p> |
| 156 | + </div> |
| 157 | + <div className="p-4 bg-gray-50 dark:bg-slate-800 rounded-2xl border border-gray-100 dark:border-slate-700"> |
| 158 | + <h4 className="font-bold text-gray-900 dark:text-white mb-2 flex items-center gap-2"> |
| 159 | + <TrendingUp className="w-4 h-4 text-green-500" /> SEO Benefits |
| 160 | + </h4> |
| 161 | + <p className="text-xs">Google's Core Web Vitals (specifically LCP and INP) directly influence search rankings based on site responsiveness.</p> |
| 162 | + </div> |
| 163 | + </div> |
| 164 | + </div> |
| 165 | + </div> |
| 166 | + </div> |
| 167 | + </div> |
| 168 | + |
| 169 | + {/* Footer Ad Slot */} |
| 170 | + <div className="mt-16 min-h-[250px] bg-gray-50 dark:bg-slate-900/50 rounded-3xl border border-dashed border-gray-200 dark:border-slate-800 flex items-center justify-center"> |
| 171 | + <span className="text-xs font-bold text-gray-400 uppercase tracking-widest">Ad Placement</span> |
| 172 | + </div> |
| 173 | + </div> |
| 174 | + </div> |
| 175 | + ) |
| 176 | +} |
0 commit comments