This comprehensive tracking system captures detailed visitor analytics for marketing and business intelligence purposes. The system logs data locally to your server with organized directory structure and provides rich analytics.
- Page Views - Every page visit with timestamp
- Session Data - Session duration, start/end times
- Device Information - Browser, OS, device type (mobile/desktop/tablet)
- Screen/Viewport - Screen dimensions and viewport size
- User Interactions - Clicks, scroll depth, form submissions
- Navigation - Referrer URLs, exit pages
- IP Address - Client IP (from NGINX headers)
- Geographic Data - Timezone, language preferences
- Performance - Time spent on each page
- Visitor Sessions - Unique session tracking
- Page Popularity - Most/least visited pages
- Device Distribution - Mobile vs desktop usage
- Browser Statistics - Browser market share
- Engagement Metrics - Time on site, scroll depth
- Conversion Tracking - Form submissions, contact interactions
~/bigbraincoding.com/
├── 2024/
│ ├── 12/
│ │ ├── 25/
│ │ │ ├── 14-30-45-abc12345.json # Individual event
│ │ │ ├── 14-31-22-def67890.json # Individual event
│ │ │ └── 2024-12-25-summary.json # Daily summary
│ │ └── 26/
│ │ └── ...
│ └── 2025/
│ └── 01/
│ └── ...
{
"timestamp": "2024-12-25T14:30:45.123Z",
"sessionId": "1703521845123-abc12345",
"eventType": "pageview",
"pageUrl": "https://bigbraincoding.com/services",
"referrer": "https://google.com",
"ipAddress": "192.168.1.100",
"userAgent": "Mozilla/5.0...",
"deviceInfo": {
"browser": "Chrome",
"browserVersion": "120",
"os": "Windows",
"osVersion": "10",
"deviceType": "desktop",
"screenWidth": 1920,
"screenHeight": 1080,
"viewportWidth": 1920,
"viewportHeight": 937,
"language": "en-US",
"timezone": "America/New_York"
},
"eventData": {
"scrollDepth": 75,
"element": "button",
"elementId": "contact-btn"
},
"timeOnPage": 45000
}{
"events": [
{
"timestamp": "2024-12-25T14:30:45.123Z",
"eventType": "pageview",
"sessionId": "1703521845123-abc12345",
"pageUrl": "/services",
"deviceType": "desktop",
"browser": "Chrome"
}
],
"totalEvents": 150,
"uniqueSessions": ["1703521845123-abc12345", "1703521900000-def67890"],
"lastUpdated": "2024-12-25T23:59:59.999Z"
}The tracking system is automatically initialized on all pages. No additional setup required.
import { trackEvent } from '@/lib/tracking';
// Track custom business events
trackEvent('contact_form_submitted', {
formType: 'general_inquiry',
source: 'services_page'
});
trackEvent('project_viewed', {
projectId: 'mealforge',
source: 'homepage'
});Run the analysis script to get insights:
node scripts/analyze-tracking.jsExample output:
🔍 Big Brain Coding - Tracking Data Analysis
=============================================
📊 Found data for years: 2024
📅 2024 Analysis:
──────────────────────────────────────────────────
📈 Total Events: 1,250
👥 Unique Sessions: 89
📄 Page Views: 450
🖱️ Clicks: 800
📝 Form Submissions: 12
⏱️ Average Session Duration: 145s
📱 Device Distribution:
desktop: 320 (71.1%)
mobile: 120 (26.7%)
tablet: 10 (2.2%)
🌐 Browser Distribution:
Chrome: 280 (62.2%)
Safari: 90 (20.0%)
Firefox: 50 (11.1%)
Edge: 30 (6.7%)
📄 Top Pages:
/: 150 views (33.3%)
/services: 120 views (26.7%)
/projects: 80 views (17.8%)
/contact: 60 views (13.3%)
/about: 40 views (8.9%)
- Data is stored locally on your server
- No third-party tracking services
- User consent can be integrated with your existing consent management
- Data can be easily deleted or exported
- Logs are organized by date for easy cleanup
- Old data can be automatically archived or deleted
- Summary files provide aggregated data for long-term analysis
# Optional: Custom log directory
TRACKING_LOG_DIR=/custom/path/to/logsThe system works with your existing NGINX setup and captures:
- Client IP addresses
- User-Agent strings
- Referrer information
- Request timestamps
- Traffic Sources - See which pages drive the most engagement
- Conversion Funnels - Track user journey from homepage to contact
- Content Performance - Identify most engaging content
- Device Optimization - Understand mobile vs desktop usage
- Session Duration - Measure engagement quality
- Page Depth - Understand content consumption
- Interaction Patterns - See how users interact with your site
- Exit Points - Identify where users leave
- Browser Compatibility - Ensure site works across browsers
- Device Performance - Optimize for most common devices
- Page Load Performance - Track user experience metrics
- Error Tracking - Monitor for technical issues
- Check browser console for errors
- Verify
/api/trackingendpoint is accessible - Ensure file permissions allow writing to log directory
- Check network tab for failed requests
- Ensure NGINX is forwarding
X-Forwarded-Forheaders - Check proxy configuration
- Verify server can access client IP
- Monitor log file sizes
- Implement log rotation if needed
- Consider archiving old data
- Optimize summary file generation
- Logs contain sensitive information (IPs, user agents)
- Store logs securely with appropriate permissions
- Consider encryption for sensitive data
- Implement access controls for log files
- Consider implementing rate limiting on
/api/tracking - Monitor for abuse or excessive requests
- Implement request throttling if needed
- Real-time Dashboard - Live analytics interface
- Export Functionality - CSV/JSON data export
- Advanced Filtering - Date ranges, device types, etc.
- Email Reports - Automated daily/weekly summaries
- A/B Testing - Track different page versions
- Goal Tracking - Custom conversion goals
- Google Analytics - Complement with GA4
- CRM Systems - Link visitor data to leads
- Email Marketing - Track email campaign performance
- Social Media - Monitor social traffic sources
For questions or issues with the tracking system:
- Check the browser console for JavaScript errors
- Review server logs for API endpoint issues
- Verify file permissions and directory structure
- Test with the analysis script to validate data collection
The tracking system provides comprehensive visitor analytics while maintaining privacy and compliance standards. Use this data to optimize your website, improve user experience, and drive business growth.