Overview
Retention analysis shows how many visitors return to your site over time. Sparklytics tracks retention cohorts automatically — no additional setup required beyond standard pageview tracking.
How Retention Works
Sparklytics groups visitors into cohorts based on their first visit date, then tracks how many return in subsequent periods.Example: Weekly Cohorts
| Cohort Start | Week 0 | Week 1 | Week 2 | Week 3 |
|---|---|---|---|---|
| Feb 3 | 100% | 32% | 24% | 18% |
| Feb 10 | 100% | 28% | 22% | — |
| Feb 17 | 100% | 35% | — | — |
| Feb 24 | 100% | — | — | — |
- Week 0: Always 100% (all new visitors)
- Week 1: Percentage who returned 1 week later
- Week 2: Percentage who returned 2 weeks later
Granularity Options
Day
Track daily retention for the first 30 days:- Short-term engagement analysis
- Apps with daily active users
- Quick A/B test validation
Week
Track weekly retention for up to 12 weeks:- SaaS products
- Content sites with weekly publishing
- Medium-term engagement trends
Month
Track monthly retention for up to 12 months:- Long-term user behavior
- Annual subscription products
- Low-frequency usage patterns
API Reference
Endpoint
Query Parameters
Start date in
YYYY-MM-DD format (required)End date in
YYYY-MM-DD format (required)Cohort period:
day, week, or monthNumber of periods to track. Defaults:
- Day: 30 (max 30)
- Week: 8 (max 12)
- Month: 12 (max 12)
IANA timezone for cohort boundaries (e.g.,
America/New_York)Response
Response Fields
ISO 8601 date string representing the cohort start
Total unique visitors who first visited during this cohort period
Zero-indexed period offset (0 = first visit period)
Number of cohort members who returned in this period
Retention rate as a percentage (visitors / cohort_size × 100)
Implementation Details
Granularity Parsing
Fromcrates/sparklytics-server/src/routes/retention.rs:47:
Period Limits
Fromcrates/sparklytics-server/src/routes/retention.rs:67:
Concurrency Control
Retention queries are computationally expensive, so they’re rate-limited with a semaphore:429 Too Many Requests.
Filtering Retention Data
Apply standard filters to analyze retention for specific segments:Available Filters
All standard filters work with retention:filter_countryfilter_regionfilter_cityfilter_browserfilter_osfilter_devicefilter_page— Entry page filterfilter_referrerfilter_utm_sourcefilter_utm_mediumfilter_utm_campaign
Dashboard Visualization
The retention heatmap component provides an interactive view:Color Scale
Fromdashboard/components/retention/RetentionHeatmap.tsx:
- 0-10%: Light gray (very low retention)
- 10-25%: Yellow to orange (low retention)
- 25-50%: Orange to light green (moderate retention)
- 50-75%: Green (good retention)
- 75-100%: Dark green (excellent retention)
Tooltip
Hover over any cell to see:Performance Considerations
DuckDB (Self-Hosted)
Retention queries on DuckDB can be slow for large datasets:- < 1M events: Sub-second queries
- 1M-10M events: 1-5 seconds
- > 10M events: Consider upgrading to ClickHouse
ClickHouse (Cloud)
ClickHouse provides near-constant query time:- < 1M events: < 100ms
- 100M+ events: < 500ms
- 1B+ events: < 2 seconds
ClickHouse vs DuckDB speedup: 10–68x at 100k, 47–239x at 1M
Use Cases
Product-Market Fit
Measure whether users come back after their first visit:- Week 1: > 30%
- Week 4: > 20%
- Week 8: > 15%
Feature Launch Impact
Compare retention before and after a feature launch:Onboarding Optimization
Filter by entry page to see if different landing pages affect retention:Campaign Effectiveness
Compare retention across traffic sources:Best Practices
Choose the Right Granularity
- Daily: Apps with daily active users (DAU focus)
- Weekly: Most SaaS products (default choice)
- Monthly: Enterprise tools, infrequent-use products
Set Realistic Period Counts
Don’t request more periods than you have data:Use Filters for Segmentation
Compare retention across:- Device types (mobile vs desktop)
- Geographic regions
- Traffic sources
- Landing pages
Monitor Trends, Not Absolutes
Retention rates vary by industry. Focus on:- Trends over time: Is retention improving?
- Relative comparisons: Which segments retain better?
- Inflection points: Where does retention stabilize?
Troubleshooting
”Query timeout” Error
If you see a 408 response:- Dataset is too large for DuckDB
- Too many concurrent retention queries
- Reduce date range
- Reduce
max_periods - Add more filters to narrow the dataset
- Upgrade to ClickHouse for large datasets
Sparse Data
If cohorts show 0% retention:- Insufficient traffic: Need at least ~100 visitors per cohort for meaningful data
- Date range too recent: Later cohorts won’t have data for future periods yet
- Filters too restrictive: Broaden filters or remove them
Next Steps
Sessions
Drill down into individual user sessions
Journey Analysis
Explore what returning users do on subsequent visits