Overview
Subscription tracking helps you monitor your SaaS revenue metrics, understand user subscription behavior, and predict churn. The SDK provides automatic payment provider detection (Stripe, Paddle, Chargebee) and comprehensive subscription lifecycle tracking.Quick Start
1
Identify Users with Subscription Data
When users sign up or subscribe, identify them with subscription properties:
2
Track Subscription Events
Track lifecycle events as they happen:
3
Monitor Churn Risk
Use built-in churn prediction to identify at-risk users:
Subscription Properties
Automatic Provider Detection
The SDK can auto-detect subscription data from Stripe, Paddle, and Chargebee by scanning browser globals and localStorage.How It Works
Fromsrc/subscription-detection.ts:412-431:
Detection Confidence
Each provider detection returns a confidence score (0-100):- 30+: Provider SDK loaded (e.g.,
window.Stripe) - 50+: Found provider-specific localStorage keys
- 70+: Extracted subscription data from localStorage
- 100: Full subscription details including pricing
Stripe Detection
Fromsrc/subscription-detection.ts:29-166, the SDK checks:
window.Stripeobject present (+30 confidence)- LocalStorage keys containing “stripe”, “customer_id”, “subscription_id” (+20)
- Subscription object with plan data (+30)
- Valid customer ID starting with
cus_(+10)
When Detection Runs
Fromsrc/analytics.ts:1377-1434, auto-detection runs:
- 1 second after SDK initialization (allows provider SDKs to load)
- Only in browser environments (
windowexists) - Results merged with manually-set subscription data (manual takes precedence)
Subscription Lifecycle Events
Track Subscription Started
Track Trial Started
Track Upgrades
Track Downgrades
Track Cancellations
Track Payment Events
Churn Risk Prediction
The SDK calculates churn risk based on user behavior:Churn Risk Factors
Fromsrc/analytics.ts:630-720, risk is calculated using:
Risk Calculation
- Engagement Score < 20: +30 risk points
- Inactive > 30 days: +40 risk points
- Feature Adoption < 20%: +15 risk points
- Support Tickets > 5: +10 risk points
- Negative Feedback > 3: +20 risk points
- Payment Failures > 2: +30 risk points
- Low: 0-24 (healthy user)
- Medium: 25-49 (monitor)
- High: 50-74 (intervention needed)
- Critical: 75-100 (immediate action)
Revenue Metrics
Track MRR/ARR
The SDK automatically calculates ARR from MRR and vice versa:Get Current Subscription
Auto-Enrichment
All events are automatically enriched with subscription context: Fromsrc/analytics.ts:1141-1166:
subscription_statussubscription_plansubscription_mrrsubscription_provideris_paid_user
Use Cases
Stripe Integration
Retention Campaigns
Best Practices
Subscription Tracking Tips:
- Always use cents for monetary amounts (9900 = $99.00)
- Track all lifecycle events (start, upgrade, downgrade, cancel)
- Include cancellation reasons for analysis
- Monitor churn risk and intervene early
- Segment users by plan tier for targeted campaigns
- Never log full credit card numbers (PCI compliance)
- Use auto-detection for faster integration
Troubleshooting
Auto-Detection Not Working
- Check payment provider SDK is loaded (e.g.,
window.Stripe) - Verify subscription data is in localStorage
- Enable debug mode:
config.debug = true - Wait 1 second after page load for detection to run
Subscription Data Not Persisting
Subscription data is stored in localStorage. If not persisting:- Check browser allows localStorage
- Verify you’re calling
identify()with subscription data - Check for localStorage quota errors