Visualize country borders from different times in history (2000 BC-1994)
As seen on r/dataisbeautiful.
The app provides country information through two sources:
- Wikipedia (default) - Fetches real-time information from Wikipedia
- AI-powered - Uses Google Gemini AI to generate country information with historical context
You can switch between these sources using the toggle button in the footer.
The app uses Redis to cache AI responses for improved performance:
- β‘ Instant responses for previously requested countries/years
- π° Reduced API costs - Fewer calls to Google Gemini
- π§ Smart expiration - 1-hour cache TTL keeps content fresh
- π Analytics tracking - Cache hit/miss rates in Google Analytics
See REDIS_SETUP.md for detailed setup instructions.
The app includes comprehensive Google Analytics tracking for the AI feature to understand user engagement and performance:
Provider Usage:
toggle_provider- When users switch between Wikipedia and AIenable_ai/disable_ai- AI feature activation/deactivationprovider_restored- When preference is loaded from localStoragesession_provider_active- Active provider per session
AI Requests:
request_initiated- AI request startedresponse_success- Successful AI responseresponse_time_success- Response time for successful requestsresponse_length- Character count of AI responsesresponse_word_count- Word count of AI responsesrequest_failed- Failed AI requestsapi_error- API-specific errors with status codesapi_key_missing- Missing API key events
Cache Performance:
cache_hit- Response served from Redis cache (faster)cache_miss- No cached response, API call madecache_error- Redis unavailable (fallback to API)cache_write_success- Response successfully cachedcache_write_error- Failed to cache response
Content Display:
popup_displayed- When popups show AI vs Wikipedia contentcontent_displayed- Successful content displaycontent_error_displayed- Error content shown to userscontent_empty_displayed- Empty/no content scenariospopup_closed- User closes information popups
Performance Metrics:
- Response times (success/failure)
- Content quality metrics (word count, character count)
- Error rates and types
- User engagement patterns
All AI-related events use the category "AI Feature" for easy filtering in Google Analytics.
Analytics tracking is anonymized and focuses on feature usage patterns rather than personal information. No API keys or sensitive data are tracked.
- Node.js 18+ and yarn
- Google Gemini API key (free tier available)
- Google Analytics 4 property (optional, for analytics)
git clone https://github.com/nrgapple/historic-country-borders-app.git
cd historic-country-borders-app
yarn installCreate a .env.local file:
# Optional for analytics
NEXT_PUBLIC_GA_FOUR=your_google_analytics_id
# Optional for map features
NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN=your_mapbox_token
# Redis for AI response caching (required for caching)
REDIS_URL=your_redis_connection_string
# Required for AI features (server-side only)
GEMINI_API_KEY=your_gemini_api_key_here- Visit Google AI Studio
- Sign in with your Google account
- Click "Create API Key"
- Copy the generated key to your
.env.localfile
Benefits:
- β 60 requests per minute (generous free tier)
- β No credit card required
- β High-quality AI responses
- β Excellent historical knowledge
- Set up Redis on Vercel or any Redis provider
- Add the
REDIS_URLenvironment variable to your project - See REDIS_SETUP.md for detailed instructions
Benefits:
- β‘ Instant responses for cached content
- π° Reduces API usage and costs
- π§ Automatic 1-hour cache expiration
- π Cache performance analytics
- Visit Google Analytics
- Create a new GA4 property
- Get your Measurement ID (format: G-XXXXXXXXXX)
- Add to your
.env.localfile
yarn devOpen http://localhost:3000 to view the app.
# Run all tests
yarn test
# Run tests in watch mode
yarn test:watch
# Run specific test files
yarn test hooks/__tests__/useAI.test.tsx"AI information requires Gemini API key setup"
- Add your Gemini API key to
.env.local - Restart the development server
- See GEMINI_SETUP.md for detailed setup
Slow AI responses
- Normal response time: 1-3 seconds
- Check your internet connection
- Gemini API has rate limits (60 requests/minute)
Empty or error responses
- Try switching to Wikipedia temporarily
- Check browser console for detailed error messages
- Verify your API key is valid
To view AI feature analytics in Google Analytics:
- Go to Events β All Events
- Filter by Event Category = "AI Feature"
- Key metrics to monitor:
toggle_provider- Feature adoptionresponse_successvsrequest_failed- Success rateresponse_time_success- Performancecontent_displayed- User engagement
The app tracks several performance metrics:
- Response Times: Average AI response time vs Wikipedia
- Success Rates: AI request success/failure ratios
- Content Quality: Word count and length of AI responses
- User Engagement: How users interact with AI vs Wikipedia content
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
MIT License - see LICENSE for details.
- Historical border data from World Historical Gazetteer
- AI powered by Google Gemini
- Maps powered by Mapbox
- Analytics by Google Analytics 4
