Overview
StatCounter's approach to cross-domain tracking is simpler than most modern analytics platforms. Rather than sophisticated session linking, StatCounter offers two straightforward options: separate projects for each domain or using the same tracking code across multiple domains.
Key Concepts
Cross-domain tracking allows you to monitor user journeys that span multiple websites or subdomains. This is essential for:
- Main site + subdomain (www.example.com + shop.example.com)
- Multiple brand websites owned by same organization
- Sites with separate checkout or login domains
- Multi-regional sites (example.com, example.co.uk, example.de)
StatCounter's Limitations
Unlike Google Analytics or other advanced platforms, StatCounter does NOT:
- Automatically maintain sessions across domains
- Link user journeys between different domains
- Pass session IDs via URL parameters
- Unify visitor profiles across domains
Tracking Approaches
Approach 1: Separate Projects (Recommended)
Create individual StatCounter projects for each domain.
Advantages:
- Clean, isolated reporting per domain
- No cross-contamination of data
- Easier to manage permissions
- Independent settings per site
Disadvantages:
- Cannot track user journeys across domains
- Separate dashboards required
- Difficult to get unified view
When to Use:
- Completely separate business units
- Different analytics needs per domain
- No need to track cross-domain behavior
- Independent marketing teams
Implementation
<!-- On www.example.com -->
<script type="text/javascript">
var sc_project=12345678; // Project for main site
var sc_invisible=1;
var sc_security="abcd1234";
</script>
<script type="text/javascript"
src="https://www.statcounter.com/counter/counter.js" async></script>
<!-- On shop.example.com -->
<script type="text/javascript">
var sc_project=87654321; // Different project for shop
var sc_invisible=1;
var sc_security="4321dcba";
</script>
<script type="text/javascript"
src="https://www.statcounter.com/counter/counter.js" async></script>
Approach 2: Single Project Across Domains
Use the same tracking code on all domains.
Advantages:
Disadvantages:
- Sessions break when switching domains
- Users counted as "new" on each domain
- No session continuity
- Referrer shows as previous domain
When to Use:
- Total traffic volume is priority
- Subdomains of same site
- Simple aggregated reporting needed
- Budget constraints (one project only)
Implementation
<!-- Same code on ALL domains -->
<!-- www.example.com, shop.example.com, blog.example.com -->
<script type="text/javascript">
var sc_project=12345678; // Same project everywhere
var sc_invisible=1;
var sc_security="abcd1234";
</script>
<script type="text/javascript"
src="https://www.statcounter.com/counter/counter.js" async></script>
Subdomain Tracking
Same Root Domain
For subdomains under the same root domain (shop.example.com, blog.example.com):
Option A: Single Project
Use the same tracking code across all subdomains. StatCounter cookies will work automatically.
<!-- Same code on all subdomains -->
<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>
Option B: Separate Projects
Create individual projects for major subdomains:
// Conditional loading based on subdomain
var sc_project, sc_security;
if (window.location.hostname === 'www.example.com') {
sc_project = 12345678;
sc_security = 'abcd1234';
} else if (window.location.hostname === 'shop.example.com') {
sc_project = 87654321;
sc_security = '4321dcba';
} else if (window.location.hostname === 'blog.example.com') {
sc_project = 11223344;
sc_security = '5566aabb';
}
Different Root Domains
For completely different domains (example.com, example-shop.com):
Without Session Linking
Simply install the same or different tracking codes:
<!-- example.com -->
<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>
<!-- example-shop.com -->
<script type="text/javascript">
var sc_project=12345678; // Same project for combined stats
var sc_invisible=1;
var sc_security="abcd1234";
</script>
<script type="text/javascript"
src="https://www.statcounter.com/counter/counter.js" async></script>
Result: Each domain visit creates a new session. Referrer will show the previous domain.
With Custom Session Linking (Workaround)
Create a manual session linking mechanism using URL parameters:
// On source domain (example.com)
function linkToDomain(url) {
// Generate session identifier
var sessionId = getCookieValue('sc_session') || generateSessionId();
// Append to URL
var separator = url.indexOf('?') > -1 ? '&' : '?';
window.location.href = url + separator + 'sc_session=' + sessionId;
}
// On destination domain (example-shop.com)
function restoreSession() {
var urlParams = new URLSearchParams(window.location.search);
var sessionId = urlParams.get('sc_session');
if (sessionId) {
// Store session ID
document.cookie = 'sc_session=' + sessionId + '; path=/; domain=.example-shop.com';
}
}
// Call on page load
restoreSession();
Note: This is a custom solution; StatCounter doesn't natively support session linking.
Configuration
Dashboard Settings
- Log in to StatCounter
- Navigate to your project
- Config > Project Settings
- Update "Website URL" to include all domains if using single project
Multiple Domain Setup
If tracking multiple domains with one project:
- Set primary domain in project settings
- Document all domains using the code
- Use page grouping or filtering to separate domains in reports
Page Grouping by Domain
Create groups to separate domains in reports:
Settings > Page Grouping
Pattern: *example.com*
Group: Main Site
Pattern: *shop.example.com*
Group: Shop
Pattern: *blog.example.com*
Group: Blog
Validation
Verify Cross-Domain Setup
1. Test Each Domain Individually:
Visit each domain and verify tracking:
- Open each domain in a browser
- Wait 10-15 minutes
- Check StatCounter dashboard
- Confirm visits appear
2. Test Cross-Domain Navigation:
Navigate from one domain to another:
- Start on domain A
- Click link to domain B
- Check StatCounter for both visits
- Verify referrer shows domain A
3. Check Session Behavior:
// On each domain, check cookie
document.cookie.split(';').forEach(cookie => {
if (cookie.includes('sc_')) {
console.log(cookie);
}
});
4. Verify Dashboard Reporting:
- Check "Came From" report
- Verify external domains appear as referrers
- Confirm page views from all domains
- Test page grouping filters
Common Cross-Domain Issues
| Issue | Cause | Solution |
|---|---|---|
| Sessions not linking | StatCounter doesn't link sessions | Expected behavior, use separate tracking if needed |
| Duplicate counts | Same code firing twice | Check for duplicate tracking code on pages |
| Missing domains | Code not on all pages | Verify installation on all domains |
| Wrong referrer | HTTP/HTTPS mismatch | Ensure consistent protocol usage |
| Cookies not shared | Different root domains | Cookies can't be shared across different domains |
Best Practices
For Subdomains
- Use single project for subdomains of same root domain
- Consistent code placement across all subdomains
- Page grouping to separate subdomain traffic in reports
- Document all subdomains using the tracking code
For Different Domains
- Decide early: Separate or combined projects
- Document approach: Make clear which method you're using
- Test thoroughly: Verify tracking on all domains
- Monitor referrers: Use "Came From" report to track cross-domain navigation
URL Parameters
Add parameters to track cross-domain sources:
<!-- Link from domain A to domain B -->
<a href="https://shop.example.com/product?source=main_site&campaign=header">
Visit Shop
</a>
StatCounter will track the full URL including parameters.
Naming Conventions
Use clear naming for multi-domain setups:
Project Names:
- "Example.com - Main Site"
- "Shop.Example.com - E-commerce"
- "Blog.Example.com - Content"
Or combined:
- "Example.com Network - All Properties"
Reporting and Analysis
Combined Project Reporting
When using one project for multiple domains:
- Filter by domain: Use search in reports
- Page grouping: Set up groups by domain
- Export data: Filter in spreadsheets for domain-specific analysis
- Custom reports: Create separate views per domain
Separate Project Reporting
When using different projects:
- Dashboard switching: Toggle between projects
- Manual aggregation: Combine data in spreadsheets
- Individual analysis: Analyze each domain separately
- Cross-reference: Compare referrer data to see cross-domain traffic
Key Metrics to Monitor
- Cross-domain referrals: Check "Came From" for your own domains
- Session counts: Understand sessions break between domains
- Page views: Track total views across all domains
- Entry/exit pages: Identify cross-domain entry points
Advanced Configurations
Conditional Tracking
Load different projects based on environment:
var sc_project, sc_security;
// Production domains
if (location.hostname.includes('example.com')) {
sc_project = 12345678;
sc_security = 'abcd1234';
}
// Staging domains
else if (location.hostname.includes('staging.example.com')) {
sc_project = 87654321;
sc_security = '4321dcba';
}
// Development - no tracking
else {
// Don't load StatCounter
}
Custom Referrer Tracking
Track the specific page users came from:
// On destination domain, log the referrer
if (document.referrer) {
var referrerDomain = new URL(document.referrer).hostname;
if (referrerDomain.includes('example.com')) {
// User came from your other domain
console.log('Internal cross-domain traffic from:', document.referrer);
}
}
Multi-Region Setup
For international sites:
// Different projects for different regions
var region = location.hostname.split('.').pop(); // .com, .uk, .de
var projects = {
'com': { project: 12345678, security: 'abcd1234' },
'uk': { project: 23456789, security: 'bcde2345' },
'de': { project: 34567890, security: 'cdef3456' }
};
if (projects[region]) {
var sc_project = projects[region].project;
var sc_security = projects[region].security;
}
Limitations and Alternatives
StatCounter Limitations
- No automatic session linking across domains
- No unified visitor profiles
- Sessions always break on domain change
- Limited cross-domain journey analysis
When to Consider Alternatives
Consider other tools if you need:
- Full cross-domain tracking: Google Analytics, Matomo
- Unified user journeys: Mixpanel, Amplitude
- Complex multi-domain funnels: Adobe Analytics
- E-commerce across domains: Enhanced ecommerce platforms
Hybrid Approach
Use StatCounter for basic tracking + another tool for cross-domain:
<!-- StatCounter for visitor details -->
<script>/* StatCounter code */</script>
<!-- Google Analytics for cross-domain -->
<script>/* GA4 with cross-domain configured */</script>
Troubleshooting
Tracking Not Working on Second Domain
- Verify code is installed on all domains
- Check JavaScript console for errors
- Confirm project ID is correct
- Test with browser DevTools Network tab
Sessions Breaking
This is expected behavior for StatCounter. To work around:
- Use URL parameters to pass context
- Implement custom session linking
- Consider alternative analytics platforms
Referrer Not Showing
- Ensure both domains use HTTPS
- Check referrer policy headers
- Verify no privacy extensions blocking referrers
- Confirm pages are public (not password-protected)
Duplicate Tracking
- Search for multiple StatCounter codes on pages
- Check if tag manager is also adding code
- Verify plugins aren't auto-inserting tracking