Overview

ENGINEERINGSHORTURL ANALYTICS

Table of Contents

The Idea: Pushing a Beginner Concept Further
What Broke: The Geolocation IllusionData Parsing & ConsistencyShipping the Engine

The Idea: Pushing a Beginner Concept Further

I wanted to deeply learn backend development - Node.js, Express, and MongoDB - but I wanted to build something that was actually useful. When I searched for ideas, a URL shortener came up. It’s a classic beginner MVP, but I always want to inject a 'special factor' into my work.

I thought: what if the short link wasn't just a redirect, but a silent analytics engine? What if we could track a user's location, plot it on a map, and see exactly where in the world the traffic was coming from? I wanted to track whether links were shared via WhatsApp, Twitter, or ChatGPT, count unique vs. spam clicks, and visualize everything through monthly and weekly graphs.

What Broke: The Geolocation Illusion

One of the biggest problems I faced was the geographic mapping. I integrated an IP geolocation API and plotted the data using Leaflet.js. But during testing, the locations were wildly inaccurate. Instead of showing my actual location in Karnal, the heatmap would randomly place me in Delhi or Mumbai.

I spent days trying to 'fix' this, thinking my code was dropping coordinates or the API was failing. Eventually, I realized this wasn't a bug in my code - it is an inherent limitation of how the internet routes traffic. Mobile networks and ISPs route IP addresses through centralized hubs in major cities, meaning IP-based geolocation can only provide regional accuracy, not GPS-level precision.

Data Parsing & Consistency

The second major issue came from standardizing the analytics data. When categorizing users into specific regions, the external API would return highly inconsistent region and state formatting. This completely broke the map grouping logic.

I had to write middleware to sanitize, format, and strictly divide the incoming location payloads before they were pushed into the MongoDB arrays. This taught me a valuable lesson in defensive backend programming: never trust the shape of data coming from external APIs.

Shipping the Engine

Despite being a relatively small project, engineering the data pipeline - from the Express middleware capturing the user agent, to MongoDB storing the masked IPs, to EJS and Chart.js rendering the heatmaps - solidified my understanding of full-stack data flow.

"It proved that even a simple concept can be engineered into a premium, data-rich product."