Intermediate 3-4 hours · 2 APIs
Build a URL Shortener with Analytics
Create short links and track where your visitors come from using IP geolocation for basic analytics.
APIs Used
Data Flow
User Action
API Call
Transform
Output
How It Works
1
User submits a long URL to be shortened
2
Create a short link using the Bitly API
3
When visitors click, log their IP and get geolocation
4
Display analytics dashboard with click counts and visitor locations
Code Outline
Pseudocode / JavaScript
// 1. Shorten a URL with Bitly
const shortenRes = await fetch('https://api-ssl.bitly.com/v4/shorten', {
method: 'POST',
headers: { 'Authorization': 'Bearer YOUR_BITLY_TOKEN', 'Content-Type': 'application/json' },
body: JSON.stringify({ long_url: 'https://example.com/very-long-article-url' })
});
const { link: shortUrl } = await shortenRes.json();
console.log(`Short URL: ${shortUrl}`);
// 2. Get click analytics from Bitly
const clicksRes = await fetch(
`https://api-ssl.bitly.com/v4/bitlinks/${shortUrl.replace('https://', '')}/clicks/summary`,
{ headers: { 'Authorization': 'Bearer YOUR_BITLY_TOKEN' } }
);
const { total_clicks } = await clicksRes.json();
// 3. Geolocate a sample visitor IP
const geoRes = await fetch(
'https://api.ipgeolocation.io/ipgeo?apiKey=YOUR_API_KEY&ip=8.8.8.8'
);
const { city, country_name } = await geoRes.json();
// 4. Display analytics
console.log(`Total clicks: ${total_clicks}`);
console.log(`Sample visitor: ${city}, ${country_name}`); Recipe Details
Difficulty Intermediate
Time 3-4 hours
APIs Used 2
Related Recipes
Related Tutorials
Note: These recipes are AI-generated suggestions based on API capabilities. Actual implementation may vary. Always refer to official API documentation for the latest specifications.