feat(conversion): vender también en los momentos buenos, no solo en el muro
Hasta ahora el único camino al upgrade era fallar contra la cuota. Tres momentos nuevos, todos con el mismo mensaje ya validado (watermark + caducidad 7d + minutos): - Resultados (pico de satisfacción): banner para usuarios free junto a sus clips recién generados — "Like these clips? Keep them forever →" — que abre la modal de upgrade en modo 'upsell' (copy adaptado: aún tienen minutos, se vende permanencia y limpieza, no "te quedaste sin"). - Medidor del header: para free abre la modal de upgrade en vez de ir a account — antes no existía ningún camino visible a los planes desde el dashboard sin fallar primero. - Email "tus clips se borran mañana": warn_free_expiring() en el sweeper avisa el día 6 de los 7 de retención free, con descarga o upgrade como salidas. Aversión a la pérdida honesta: la fecha es real y hoy se borraba en silencio, lo que no convertía a nadie. Dedupe en memoria (peor caso tras restart: un duplicado). Eventos UpsellModalSeen/UpsellModalCheckout separados de los del muro para medir cada momento por su lado. Verificado: lógica del aviso probada contra la DB local (clip de 6.5d avisa, el de 8d ya purgeable no, segundo pase no duplica); 141 tests y build del dashboard en verde.
This commit is contained in:
parent
95a9a5ff1e
commit
c88239921e
4 changed files with 114 additions and 16 deletions
|
|
@ -79,6 +79,36 @@ async def send_clips_ready_email(email: str, job_title: str, clip_count: int,
|
||||||
await send_email(email, f"Your clips are ready — {title}", html)
|
await send_email(email, f"Your clips are ready — {title}", html)
|
||||||
|
|
||||||
|
|
||||||
|
async def send_clips_expiring_email(email: str, clip_count: int):
|
||||||
|
"""Free clips enter their last day before deletion — honest loss aversion.
|
||||||
|
|
||||||
|
The deadline is real (FREE_CLIP_RETENTION_DAYS); this simply makes it
|
||||||
|
visible instead of deleting silently. Doubles as re-engagement for users
|
||||||
|
who clipped once and went quiet.
|
||||||
|
"""
|
||||||
|
dash = f"{settings.frontend_url}/dashboard"
|
||||||
|
n = clip_count
|
||||||
|
clips = f"{n} clip" + ("s" if n != 1 else "")
|
||||||
|
html = f"""
|
||||||
|
<div style="font-family:system-ui,sans-serif;max-width:480px;margin:0 auto">
|
||||||
|
<h2>Your {clips} will be deleted tomorrow ⏳</h2>
|
||||||
|
<p>Free clips are stored for 7 days, and {('these' if n != 1 else 'this one')}
|
||||||
|
{'are' if n != 1 else 'is'} about to expire. Two ways to keep them:</p>
|
||||||
|
<ul style="line-height:1.9;padding-left:20px">
|
||||||
|
<li><strong>Download them now</strong> from your dashboard, or</li>
|
||||||
|
<li><strong>Upgrade to Starter ($12/mo)</strong> — clips stored forever,
|
||||||
|
no watermark, and 100 minutes every month.</li>
|
||||||
|
</ul>
|
||||||
|
<p><a href="{dash}" style="display:inline-block;background:#111;color:#fff;
|
||||||
|
padding:12px 20px;border-radius:8px;text-decoration:none">Save my clips</a></p>
|
||||||
|
<p style="color:#666;font-size:13px">After tomorrow they're gone for good
|
||||||
|
— we can't recover deleted clips.</p>
|
||||||
|
</div>
|
||||||
|
"""
|
||||||
|
print(f"⏳ Clips-expiring email → {email} ({clips})")
|
||||||
|
await send_email(email, f"Your {clips} will be deleted tomorrow", html)
|
||||||
|
|
||||||
|
|
||||||
async def send_out_of_minutes_email(email: str, upgrade_url: str):
|
async def send_out_of_minutes_email(email: str, upgrade_url: str):
|
||||||
"""Free user hit their monthly quota — the natural upgrade moment.
|
"""Free user hit their monthly quota — the natural upgrade moment.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ from sqlalchemy import select, delete
|
||||||
|
|
||||||
from .config import settings, VIDEO_RETENTION_GRACE_DAYS, FREE_CLIP_RETENTION_DAYS
|
from .config import settings, VIDEO_RETENTION_GRACE_DAYS, FREE_CLIP_RETENTION_DAYS
|
||||||
from . import database, storage, metering
|
from . import database, storage, metering
|
||||||
from .models import UserVideo, Subscription, Project
|
from .models import UserVideo, Subscription, Project, User
|
||||||
from .auth import get_current_user_required
|
from .auth import get_current_user_required
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
@ -333,6 +333,52 @@ async def purge_free_expired():
|
||||||
print(f"⚠️ Free retention purge failed for {user_id}: {e}")
|
print(f"⚠️ Free retention purge failed for {user_id}: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
# Video ids already covered by an expiry-warning email, so the 6-hourly sweep
|
||||||
|
# doesn't re-mail the same user four times during the warning window. Process
|
||||||
|
# memory only: after a restart the worst case is one duplicate warning.
|
||||||
|
_warned_video_ids: set = set()
|
||||||
|
|
||||||
|
|
||||||
|
async def warn_free_expiring():
|
||||||
|
"""Email free users whose clips enter their LAST day before deletion.
|
||||||
|
|
||||||
|
The 7-day free retention is the plan's strongest honest upgrade lever, but
|
||||||
|
silently deleting clips converts nobody — the user never learns they were
|
||||||
|
at risk. One email on day 6 turns the real deadline into a visible one.
|
||||||
|
"""
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
from .emails import send_clips_expiring_email
|
||||||
|
now = datetime.now(timezone.utc)
|
||||||
|
doomed_after = now - timedelta(days=FREE_CLIP_RETENTION_DAYS) # already purgeable
|
||||||
|
warn_cutoff = now - timedelta(days=FREE_CLIP_RETENTION_DAYS - 1) # < 1 day left
|
||||||
|
|
||||||
|
async with database.session() as s:
|
||||||
|
expiring = list((await s.execute(
|
||||||
|
select(UserVideo).where(UserVideo.created_at < warn_cutoff,
|
||||||
|
UserVideo.created_at >= doomed_after)
|
||||||
|
)).scalars())
|
||||||
|
|
||||||
|
by_user = {}
|
||||||
|
for v in expiring:
|
||||||
|
if v.id in _warned_video_ids:
|
||||||
|
continue
|
||||||
|
by_user.setdefault(v.user_id, []).append(v)
|
||||||
|
|
||||||
|
for user_id, vids in by_user.items():
|
||||||
|
async with database.session() as s:
|
||||||
|
if not await metering.is_free_user(s, user_id):
|
||||||
|
continue
|
||||||
|
user = await s.get(User, user_id)
|
||||||
|
if not user or not user.email:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
await send_clips_expiring_email(user.email, len(vids))
|
||||||
|
_warned_video_ids.update(v.id for v in vids)
|
||||||
|
print(f"⏳ Expiry warning sent: {len(vids)} clip(s), user {user_id}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ Expiry warning failed for {user_id}: {e}")
|
||||||
|
|
||||||
|
|
||||||
_SWEEP_INTERVAL = 6 * 3600 # every 6 hours
|
_SWEEP_INTERVAL = 6 * 3600 # every 6 hours
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -340,6 +386,7 @@ async def _sweeper_loop():
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
await asyncio.sleep(_SWEEP_INTERVAL)
|
await asyncio.sleep(_SWEEP_INTERVAL)
|
||||||
|
await warn_free_expiring()
|
||||||
await purge_expired()
|
await purge_expired()
|
||||||
await purge_free_expired()
|
await purge_free_expired()
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
|
|
|
||||||
|
|
@ -780,9 +780,14 @@ function App() {
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Cloud: minutes meter + account/sign-in */}
|
{/* Cloud: minutes meter + account/sign-in. For free users the meter
|
||||||
|
opens the upgrade modal — otherwise the only path to a plan is
|
||||||
|
failing against the quota wall. */}
|
||||||
{billingEnabled && isManaged && (
|
{billingEnabled && isManaged && (
|
||||||
<UsageMeter onClick={() => { window.location.hash = '#/account'; }} />
|
<UsageMeter onClick={() => {
|
||||||
|
if (plan === 'free') { setTopUpInfo({ context: 'upsell' }); setShowTopUp(true); }
|
||||||
|
else { window.location.hash = '#/account'; }
|
||||||
|
}} />
|
||||||
)}
|
)}
|
||||||
{billingEnabled && isSignedIn && !isManaged && (
|
{billingEnabled && isSignedIn && !isManaged && (
|
||||||
<button onClick={() => setShowPlanChoice(true)}
|
<button onClick={() => setShowPlanChoice(true)}
|
||||||
|
|
@ -1376,15 +1381,19 @@ function App() {
|
||||||
|
|
||||||
{status === 'complete' && results?.clips?.length > 0 && (
|
{status === 'complete' && results?.clips?.length > 0 && (
|
||||||
<div className="mb-2 space-y-2">
|
<div className="mb-2 space-y-2">
|
||||||
<StarBanner message="Happy with your clips?" />
|
{/* Peak-moment upsell: they just SAW their clips — sell while
|
||||||
|
they're proud of the result, before asking for stars. */}
|
||||||
{plan === 'free' && (
|
{plan === 'free' && (
|
||||||
<button
|
<button
|
||||||
onClick={() => { window.location.hash = '#/pricing'; }}
|
onClick={() => { setTopUpInfo({ context: 'upsell' }); setShowTopUp(true); }}
|
||||||
className="w-full text-left px-3 py-2 rounded-input bg-paper3 border border-rule text-sm text-muted hover:text-ink transition-colors"
|
className="w-full text-left px-3 py-2.5 rounded-input bg-paper3 border border-brass/40 hover:border-brass text-sm transition-colors"
|
||||||
>
|
>
|
||||||
Free clips carry a watermark and expire in 7 days — <span className="text-brass">upgrade to remove both</span>.
|
<span className="text-ink">Like these clips?</span>{' '}
|
||||||
|
<span className="text-muted">They carry a watermark and delete in 7 days.</span>{' '}
|
||||||
|
<span className="text-brass font-medium">Keep them forever →</span>
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
<StarBanner message="Happy with your clips?" />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
@ -1574,6 +1583,7 @@ function App() {
|
||||||
onClose={() => setShowTopUp(false)}
|
onClose={() => setShowTopUp(false)}
|
||||||
required={topUpInfo.required}
|
required={topUpInfo.required}
|
||||||
remaining={topUpInfo.remaining}
|
remaining={topUpInfo.remaining}
|
||||||
|
context={topUpInfo.context || 'wall'}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{showTrialUpgrade && (
|
{showTrialUpgrade && (
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,20 @@ const PLAN_BLURBS = {
|
||||||
pro: 'for power users',
|
pro: 'for power users',
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function TopUpModal({ onClose, required, remaining }) {
|
// context: 'wall' (default) = user hit the 402 quota wall mid-task.
|
||||||
|
// 'upsell' = user opened it voluntarily (results banner, header meter)
|
||||||
|
// — different framing: they still HAVE minutes, sell the watermark
|
||||||
|
// removal + permanence instead of "you ran out".
|
||||||
|
export default function TopUpModal({ onClose, required, remaining, context = 'wall' }) {
|
||||||
const [plans, setPlans] = useState([]);
|
const [plans, setPlans] = useState([]);
|
||||||
const [topups, setTopups] = useState([]);
|
const [topups, setTopups] = useState([]);
|
||||||
const [showTopups, setShowTopups] = useState(false);
|
const [showTopups, setShowTopups] = useState(false);
|
||||||
const [busyPrice, setBusyPrice] = useState(null);
|
const [busyPrice, setBusyPrice] = useState(null);
|
||||||
|
const isUpsell = context === 'upsell';
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
track('QuotaWallSeen', { props: { required: required ?? null, remaining: remaining ?? null } });
|
track(isUpsell ? 'UpsellModalSeen' : 'QuotaWallSeen',
|
||||||
|
{ props: { required: required ?? null, remaining: remaining ?? null } });
|
||||||
apiJson('/api/billing/plans')
|
apiJson('/api/billing/plans')
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
const monthly = (d.plans || []).filter((p) => p.interval === 'month');
|
const monthly = (d.plans || []).filter((p) => p.interval === 'month');
|
||||||
|
|
@ -44,7 +50,8 @@ export default function TopUpModal({ onClose, required, remaining }) {
|
||||||
|
|
||||||
const buy = async (entry, kind) => {
|
const buy = async (entry, kind) => {
|
||||||
setBusyPrice(entry.price_id);
|
setBusyPrice(entry.price_id);
|
||||||
track('QuotaWallCheckout', { props: { kind, plan: entry.plan || null, minutes: entry.minutes } });
|
track(isUpsell ? 'UpsellModalCheckout' : 'QuotaWallCheckout',
|
||||||
|
{ props: { kind, plan: entry.plan || null, minutes: entry.minutes } });
|
||||||
try {
|
try {
|
||||||
const { url } = await apiJson('/api/billing/checkout', {
|
const { url } = await apiJson('/api/billing/checkout', {
|
||||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||||
|
|
@ -61,14 +68,18 @@ export default function TopUpModal({ onClose, required, remaining }) {
|
||||||
const blockedByLength = typeof required === 'number' && typeof remaining === 'number';
|
const blockedByLength = typeof required === 'number' && typeof remaining === 'number';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal isOpen onClose={onClose} eyebrow="UPGRADE" title="Your video is ready to clip" size="xl">
|
<Modal isOpen onClose={onClose} eyebrow="UPGRADE"
|
||||||
|
title={isUpsell ? 'Keep your clips forever' : 'Your video is ready to clip'} size="xl">
|
||||||
{/* Goal-gradient framing: they're one step from the thing they came for. */}
|
{/* Goal-gradient framing: they're one step from the thing they came for. */}
|
||||||
<p className="text-muted text-sm mb-5">
|
<p className="text-muted text-sm mb-5">
|
||||||
{blockedByLength
|
{isUpsell
|
||||||
? <>This video needs <b className="text-ink font-medium">{required} min</b> and you have{' '}
|
? <>Your free clips carry a watermark and are deleted after <b className="text-ink font-medium">7 days</b>.
|
||||||
<b className="text-ink font-medium">{Math.max(0, Math.round((remaining || 0) * 10) / 10)} min</b> left
|
Upgrade to keep them clean, permanent, and with a bigger monthly quota.</>
|
||||||
this month. Upgrade and it starts processing right away.</>
|
: blockedByLength
|
||||||
: <>You've used your free minutes for this month. Upgrade and keep clipping right away.</>}
|
? <>This video needs <b className="text-ink font-medium">{required} min</b> and you have{' '}
|
||||||
|
<b className="text-ink font-medium">{Math.max(0, Math.round((remaining || 0) * 10) / 10)} min</b> left
|
||||||
|
this month. Upgrade and it starts processing right away.</>
|
||||||
|
: <>You've used your free minutes for this month. Upgrade and keep clipping right away.</>}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div className="grid sm:grid-cols-3 gap-3">
|
<div className="grid sm:grid-cols-3 gap-3">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue