Analytics and Tracking Requirements
What You'll Learn
You'll discover what click metrics a URL shortener must collect and understand how those choices multiply your storage footprint.
Why Track Link Activity?
When you shorten a URL, the real value isn't just the short link—it's knowing who clicked it, when, and from where. Users expect dashboards showing link performance, which transforms a simple redirect service into an analytics platform.
Core Metrics to Track
Click count: The simplest metric—increment a counter per redirect. Minimal storage (one integer per short URL).
Timestamp: Recording when each click happens enables time-series graphs ("clicks per hour"). Requires storing one timestamp per click event.
Geographic location: Derived from IP address (country, city). Lets users see "50% of clicks from California." Adds location codes (2–10 bytes) per click.
Referrer source: Where did the clicker come from? (Twitter, email, direct). Captured from HTTP headers. Variable-length strings (10–200 bytes average).
Device/Browser: Mobile vs desktop, Chrome vs Safari. Parsed from User-Agent headers. Another 20–50 bytes per event.
Storage Impact
Here's the multiplication effect: Without analytics, storing "abc123 → long-url" takes ~500 bytes. But if you track individual clicks with full context, each click adds 100–300 bytes:
- 1 million redirects → 100–300 MB of analytics data
- Over time, analytics storage dwarfs URL mapping storage
This is why many systems use sampling (track 10% of clicks) or aggregation (store hourly summaries, not raw events).
Retention Considerations
Combined with your link expiration policies (Lesson 1504), decide: keep raw click logs for 30 days, then archive? Delete analytics when the link expires?
Key Takeaway:
Analytics requirements transform a URL shortener from a simple key-value store into a high-volume event logging system where tracking data grows orders of magnitude larger than URL mappings themselves.