Overview
StatCounter is primarily designed for page view tracking and visitor analytics. Unlike modern event-driven analytics platforms, StatCounter has limited custom event tracking capabilities. However, it excels at automatic tracking of page views, downloads, and exit links.
What StatCounter Tracks Automatically
- Page Views: All page visits are tracked automatically
- Download Links: PDF, ZIP, DOC, and other file downloads
- Exit Links: Clicks on outbound links
- Search Keywords: Organic search terms (when available)
- Referrers: Traffic sources and referring sites
Limitations
StatCounter does not support:
- Custom JavaScript event tracking
- Enhanced ecommerce tracking
- Custom dimensions or metrics
- Complex event parameters
- Form submission tracking (without page reload)
- Button clicks or interactions (without navigation)
Page View Tracking
Automatic Page Tracking
Once installed, StatCounter automatically tracks all page views. No additional configuration needed.
<!-- StatCounter Code (auto-tracks page views) -->
<script type="text/javascript">
var sc_project=12345678;
var sc_invisible=1;
var sc_security="abcd1234";
</script>
<script type="text/javascript"
src="https://www.statcounter.com/counter/counter.js" async></script>
Manual Page View Tracking
For Single Page Applications (SPAs) where URL changes don't trigger page reloads, manually trigger page views:
// Call this on route changes in SPAs
if (typeof _statcounter !== 'undefined' && _statcounter.record_pageview) {
_statcounter.record_pageview();
}
Example: React Router Integration
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
function useStatCounterPageViews() {
const location = useLocation();
useEffect(() => {
// Track page view on route change
if (typeof _statcounter !== 'undefined') {
_statcounter.record_pageview();
}
}, [location]);
}
// Use in your App component
function App() {
useStatCounterPageViews();
return <Router>...</Router>;
}
Example: Vue Router Integration
// In your router configuration
router.afterEach((to, from) => {
if (typeof _statcounter !== 'undefined') {
_statcounter.record_pageview();
}
});
Download Tracking
StatCounter automatically tracks downloads when configured in your project settings.
Enable Download Tracking
- Log in to StatCounter dashboard
- Go to Config > Configure Stats
- Enable "Track Downloads"
- Select file extensions to track:
- DOC/DOCX
- XLS/XLSX
- ZIP/RAR
- MP3/MP4
- Custom extensions
How It Works
When a visitor clicks a download link, StatCounter automatically records:
- File name
- File type
- Page where download was clicked
- Visitor information
<!-- Automatically tracked when download tracking is enabled -->
<a href="/files/whitepaper.pdf">Download PDF</a>
<a href="/files/report.xlsx">Download Report</a>
View Download Statistics
In your StatCounter dashboard:
- Go to "Popular Downloads"
- View most downloaded files
- See download counts and trends
- Export data for analysis
Exit Link Tracking
Track when visitors click links that take them off your site.
Enable Exit Link Tracking
- StatCounter dashboard > Config > Configure Stats
- Enable "Track Exit Links"
- Exit links are automatically monitored
What Gets Tracked
<!-- Automatically tracked as exit links -->
<a href="https://external-site.com">External Link</a>
<a href="https://partner-site.com">Partner Site</a>
<!-- Not tracked as exit links (same domain) -->
<a href="/about">About Page</a>
<a href="https://yourdomain.com/contact">Contact</a>
View Exit Link Data
Access in dashboard:
- Navigate to "Exit Links" report
- See top exit destinations
- Analyze which pages generate most exits
- Identify referring patterns
Virtual Page Views
Create virtual page views to track actions as if they were page visits.
Use Cases
- Track modal views
- Monitor tab switches
- Record form completions
- Track AJAX content loads
Implementation
// Create a virtual pageview
function trackVirtualPage(pageName) {
if (typeof _statcounter !== 'undefined') {
// Change the title temporarily
var originalTitle = document.title;
document.title = pageName;
_statcounter.record_pageview();
// Restore original title
setTimeout(function() {
document.title = originalTitle;
}, 100);
}
}
// Example usage
document.getElementById('openModal').addEventListener('click', function() {
trackVirtualPage('Modal: Contact Form');
// Open your modal
});
Track Form Submissions
// Track form submission as virtual page
document.getElementById('contactForm').addEventListener('submit', function(e) {
e.preventDefault();
// Track the submission
trackVirtualPage('Form Submitted: Contact');
// Submit the form
this.submit();
});
Custom Event Workarounds
Since StatCounter doesn't support native custom events, use these workarounds:
Method 1: URL Parameters
Add tracking parameters to your URLs:
// Redirect to a tracking URL
function trackAction(actionName) {
var trackingUrl = window.location.pathname + '?action=' + actionName;
window.history.pushState({}, '', trackingUrl);
if (typeof _statcounter !== 'undefined') {
_statcounter.record_pageview();
}
// Remove parameter after tracking
setTimeout(function() {
window.history.pushState({}, '', window.location.pathname);
}, 100);
}
// Usage
document.getElementById('signupButton').addEventListener('click', function() {
trackAction('signup_clicked');
});
Method 2: Invisible Tracking Pages
Create hidden pages for tracking specific events:
<!-- hidden-tracking-page.html -->
<!DOCTYPE html>
<html>
<head>
<title>Event: Button Clicked</title>
<!-- StatCounter code -->
</head>
<body></body>
</html>
// Load tracking page in hidden iframe
function trackCustomEvent(eventName) {
var iframe = document.createElement('iframe');
iframe.style.display = 'none';
iframe.src = '/tracking/' + eventName + '.html';
document.body.appendChild(iframe);
// Remove iframe after loading
setTimeout(function() {
document.body.removeChild(iframe);
}, 2000);
}
Configuration in Dashboard
Page View Settings
- Session Timeout: Configure how long before a new session starts (default 30 minutes)
- Ignore List: Exclude specific pages from tracking
- Page Grouping: Combine similar pages in reports
Download Settings
- File extension filters
- Minimum file size to track
- Include/exclude specific directories
Advanced Options
- Referrer tracking: Enable/disable referrer capture
- Keyword tracking: Monitor search keywords
- Country exclusions: Filter traffic by geography
Validation
Verify Page View Tracking
1. Test Page Load:
// Open browser console after page load
console.log(_statcounter);
// Should show StatCounter object if loaded correctly
2. Check Dashboard:
- Visit your site
- Wait 5-10 minutes
- Check "Recent Visitor Activity"
- Verify your visit appears
3. Test SPA Navigation:
- Navigate between routes
- Check console for errors
- Verify each route change triggers tracking
- Confirm in dashboard that paths are logged
Verify Download Tracking
- Click a download link on your site
- Wait 10-15 minutes
- Check StatCounter dashboard > Popular Downloads
- Confirm the download appears
Verify Exit Link Tracking
- Click an external link from your site
- Return to StatCounter dashboard
- Check Exit Links report
- Verify the click was recorded
Common Tracking Issues
| Issue | Cause | Solution |
|---|---|---|
| SPA routes not tracked | Manual tracking not implemented | Add record_pageview() calls on route changes |
| Downloads not appearing | Download tracking disabled | Enable in Config > Configure Stats |
| Exit links missing | Exit tracking disabled | Enable in project configuration |
| Duplicate page views | Multiple tracking calls | Ensure record_pageview() called only once per route |
| Delayed data | Normal processing time | Wait up to 30 minutes for data to appear |
Best Practices
For Traditional Websites
- Install code before
</body>on all pages - Enable download and exit link tracking
- Configure session timeout appropriately
- Use descriptive page titles for better reporting
For Single Page Applications
- Implement route change tracking
- Test thoroughly across all routes
- Use descriptive virtual page names
- Monitor console for tracking errors
General Recommendations
- Keep page titles unique and descriptive
- Use consistent URL structures
- Document all custom tracking implementations
- Regularly verify tracking is working
- Set up alerts for tracking interruptions
Troubleshooting
Page Views Not Recording
Check initialization:
// Verify StatCounter loaded
setTimeout(function() {
if (typeof _statcounter === 'undefined') {
console.error('StatCounter not loaded');
}
}, 3000);
Verify code placement:
- Code must be on every tracked page
- Should be before
</body>tag - No JavaScript errors blocking execution
Downloads Not Tracking
- Confirm download tracking is enabled in dashboard
- Check file extensions are in allowed list
- Verify links use standard
<a href>tags - Wait adequate time for data processing
SPA Tracking Issues
// Debug SPA tracking
function debugStatCounterTracking() {
if (typeof _statcounter !== 'undefined') {
console.log('StatCounter ready');
_statcounter.record_pageview();
console.log('Page view recorded');
} else {
console.error('StatCounter not available');
}
}
// Call on route changes
router.afterEach(() => {
debugStatCounterTracking();
});
Limitations and Alternatives
What StatCounter Cannot Do
- Track button clicks without page navigation
- Monitor scroll depth
- Record form field interactions
- Track video plays/pauses
- Measure engagement time accurately
- Create custom event taxonomies
When to Use Alternative Tools
Consider supplementing StatCounter with:
- Google Analytics 4: For comprehensive event tracking
- Mixpanel: For product analytics and user behavior
- Hotjar: For session recordings and heatmaps
- Plausible: For privacy-focused, simple analytics
Hybrid Approach
Many sites use StatCounter alongside other tools:
<!-- StatCounter for visitor details -->
<script>/* StatCounter code */</script>
<!-- Google Analytics for events -->
<script>/* Google Analytics code */</script>