StatCounter Data Layer and CSV Export Guide | OpsBlu Docs

StatCounter Data Layer and CSV Export Guide

Set up the data layer for StatCounter, export data as CSV, configure URL parameters for automated downloads, and use the StatCounter API for data access.

Overview

StatCounter does not have a traditional data layer like Google Tag Manager or Google Analytics 4. Instead, it automatically collects visitor and page data through its tracking code. Custom data capabilities are limited compared to modern analytics platforms.

What StatCounter Collects Automatically

Without any configuration, StatCounter tracks:

  • Page Information: URL, title, referrer
  • Visitor Details: IP address, country, city, ISP
  • Browser Data: Browser type, version, screen resolution
  • Device Information: Operating system, device type
  • Session Data: Entry page, exit page, session duration
  • Traffic Source: Referrer, search engine, keywords

Limitations

StatCounter does NOT support:

  • Custom user properties
  • User-level variables
  • Custom dimensions
  • Enhanced ecommerce data
  • Form field values
  • Custom metadata
  • User IDs or authentication data

Built-In Data Collection

Automatic Page Metadata

StatCounter automatically captures from each page:

<!DOCTYPE html>
<html>
<head>
  <!-- Automatically captured -->
  <title>Product Page - Widget Pro</title>
  <meta name="description" content="Buy Widget Pro">
</head>
<body>
  <h1>Widget Pro</h1>

  <!-- StatCounter tracking code -->
  <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>
</body>
</html>

StatCounter records:

  • Page title: "Product Page - Widget Pro"
  • URL: Full page URL
  • Referrer: Previous page or external source

URL Parameters

URL parameters are automatically tracked and visible in reports:

<!-- All parameters are tracked automatically -->
<a href="/product?category=electronics&source=email">View Product</a>

<!-- In StatCounter reports, you'll see -->
<!-- /product?category=electronics&source=email -->

Use URL parameters for:

Dynamic Page Titles

Use JavaScript to set dynamic page titles before StatCounter loads:

// Set title before tracking
document.title = 'Product: ' + productName + ' | My Store';

// Then load StatCounter or trigger pageview
if (typeof _statcounter !== 'undefined') {
  _statcounter.record_pageview();
}

Configuration in Dashboard

Project-Level Settings

Configure what data to collect in your StatCounter dashboard:

1. Visitor Identification

Settings > Configure Stats > Visitor Identification

  • Cookie-based tracking: Default, uses cookies to identify returning visitors
  • IP-based tracking: Fallback when cookies are disabled
  • Session timeout: Configure session duration (default 30 minutes)

2. Page Grouping

Settings > Page Grouping

Group similar pages for better reporting:

Pattern: /product/*
Group Name: Products

Pattern: /blog/*
Group Name: Blog Posts

Pattern: /category/*
Group Name: Categories

3. Download Tracking

Settings > Configure Stats > Downloads

Enable tracking for specific file types:

  • PDFs: *.pdf
  • Documents: *.doc, *.docx, *.xls, *.xlsx
  • Archives: *.zip, *.rar
  • Media: *.mp3, *.mp4

Settings > Configure Stats > Exit Links

Automatically track outbound links to external domains.

5. Referrer Exclusions

Settings > Referrer Exclusions

Exclude specific referrers from reports (e.g., your own payment processor).

Custom Data Workarounds

Since StatCounter lacks native custom data support, use these strategies:

Method 1: URL-Based Data

Encode data in URLs:

// Add data to URL for tracking
function trackWithData(category, action) {
  var currentUrl = window.location.pathname;
  var trackingUrl = currentUrl + '?category=' + category + '&action=' + action;

  // Update URL
  window.history.pushState({}, '', trackingUrl);

  // Trigger tracking
  if (typeof _statcounter !== 'undefined') {
    _statcounter.record_pageview();
  }

  // Clean URL after tracking
  setTimeout(function() {
    window.history.pushState({}, '', currentUrl);
  }, 100);
}

// Usage
document.getElementById('addToCart').addEventListener('click', function() {
  trackWithData('product', 'add_to_cart');
});

Method 2: Page Title Encoding

Include data in page titles:

// Encode user segment in title
function trackUserSegment(segment) {
  var originalTitle = document.title;
  document.title = '[' + segment + '] ' + originalTitle;

  if (typeof _statcounter !== 'undefined') {
    _statcounter.record_pageview();
  }

  // Restore title
  setTimeout(function() {
    document.title = originalTitle;
  }, 100);
}

// Usage
if (isPremiumUser) {
  trackUserSegment('Premium');
} else {
  trackUserSegment('Free');
}

Method 3: Separate Projects

Create separate StatCounter projects for different data segments:

// Different tracking codes for different user types
var projectId = isPremiumUser ? '12345678' : '87654321';
var securityCode = isPremiumUser ? 'abcd1234' : '4321dcba';

// Load appropriate tracking code
var script = document.createElement('script');
script.innerHTML = `
  var sc_project=${projectId};
  var sc_invisible=1;
  var sc_security="${securityCode}";
`;
document.body.appendChild(script);

Method 4: Virtual Subdirectories

Create virtual directory structure in URLs:

// Virtual paths for user segments
function trackUserAction(userType, page) {
  var virtualPath = '/' + userType + '/' + page;

  // Update URL temporarily
  window.history.pushState({}, '', virtualPath);

  if (typeof _statcounter !== 'undefined') {
    _statcounter.record_pageview();
  }

  // Restore actual URL
  setTimeout(function() {
    window.history.pushState({}, '', window.location.pathname);
  }, 100);
}

// Usage
trackUserAction('premium-users', 'dashboard');
// Creates virtual path: /premium-users/dashboard

Visitor Filtering

IP Filtering

Dashboard > Settings > IP Blocking

Exclude specific IPs from tracking:

  1. Navigate to IP Blocking settings
  2. Add IP addresses or ranges to exclude
  3. Common uses:
    • Block your own office IP
    • Exclude development/staging servers
    • Filter out bot traffic
Example IP blocks:
Single IP: 192.168.1.100
IP Range: 192.168.1.0 - 192.168.1.255
CIDR: 192.168.1.0/24

Geographic Filtering

Dashboard > Settings > Country Exclusions

Exclude traffic from specific countries (premium feature).

Log File Exclusions

Create an exclusion list for specific pages:

Dashboard > Settings > Log File Exclusions

Exclude patterns:
/admin/*
/test/*
/staging/*
*.test.html

Data Retention

Free Plan

  • 500 most recent log entries
  • Summary statistics retained longer
  • Export data regularly for historical analysis
  • Extended log retention (varies by plan)
  • Up to 5 years of detailed logs
  • Unlimited summary statistics

Data Export

Export data for long-term storage:

  1. Dashboard > Reports
  2. Select date range
  3. Click "Export"
  4. Choose format (CSV, PDF)
  5. Download data

Validation

Verify Data Collection

1. Check Recent Visitors:

Dashboard > Recent Visitor Activity

Verify all expected data fields are populated:

  • Location
  • Browser
  • Operating system
  • Referrer
  • Page path

2. Test URL Parameters:

// Visit with parameters
window.location.href = '/page?test=value&source=validation';

Check dashboard to confirm parameters are captured.

3. Verify Page Grouping: Visit pages that should be grouped and confirm they appear under the correct group in reports.

Common Data Collection Issues

Issue Cause Solution
Missing referrer data Referrer not sent by browser Check HTTPS/HTTP mixing, some referrers blocked
Incorrect location VPN or proxy use User's actual IP is masked
Missing parameters Parameters stripped Check URL encoding, ensure parameters before hash
Wrong page titles Title set after tracking Set titles before StatCounter loads
Session timeout too short Default 30min may be too short Adjust in settings

Best Practices

URL Structure

Design URLs to be self-documenting:

Good:
/products/category/electronics/item/widget-pro
/blog/2024/01/post-title
/campaigns/spring-sale/landing

Avoid:
/p?id=123
/content?type=blog&id=456
/page?ref=abc123xyz

Page Titles

Use descriptive, consistent titles:

// Good
document.title = 'Widget Pro - Electronics - My Store';

// Include hierarchy for better reporting
document.title = 'Home > Products > Electronics > Widget Pro';

Campaign Tracking

Use standard UTM parameters:

https://example.com/product?utm_source=newsletter&utm_medium=email&utm_campaign=spring_sale

StatCounter will track the full URL including all parameters.

Data Organization

  • Keep URL structure consistent
  • Use page grouping for related pages
  • Document tracking conventions
  • Maintain naming standards

Privacy and Compliance

GDPR Considerations

StatCounter collects personal data (IP addresses). Ensure compliance:

  1. Cookie Consent: Implement consent banner
  2. Privacy Policy: Disclose StatCounter usage
  3. Data Processing Agreement: Sign DPA with StatCounter
  4. User Rights: Provide way to opt-out
// Wait for consent before loading StatCounter
function loadStatCounter() {
  var script = document.createElement('script');
  script.type = 'text/javascript';
  script.src = 'https://www.statcounter.com/counter/counter.js';
  script.async = true;
  document.body.appendChild(script);
}

// Load only after consent
if (userHasConsented()) {
  loadStatCounter();
}

IP Anonymization

StatCounter doesn't offer built-in IP anonymization. For privacy compliance:

  • Use StatCounter's IP blocking for EU users (not recommended)
  • Consider alternative analytics for sensitive sites
  • Consult legal counsel for compliance requirements

Advanced Configuration

Multiple Projects on One Site

Track different sections with different projects:

// Homepage - Project A
if (window.location.pathname === '/') {
  var sc_project = 12345678;
  var sc_security = 'abcd1234';
}
// Shop - Project B
else if (window.location.pathname.startsWith('/shop')) {
  var sc_project = 87654321;
  var sc_security = '4321dcba';
}

Conditional Tracking

Load tracking based on conditions:

// Only track production
if (window.location.hostname === 'www.example.com') {
  // Load StatCounter
}

// Skip tracking for admin users
if (!isAdminUser()) {
  // Load StatCounter
}

Reporting and Analysis

Available Reports

  • Summary Stats: Overview of traffic
  • Recent Visitors: Detailed visitor log
  • Popular Pages: Most viewed pages
  • Entry Pages: Where visitors start
  • Exit Pages: Where visitors leave
  • Referrers: Traffic sources
  • Keywords: Search terms (when available)
  • Visitor Paths: Navigation flows

Export and Integration

Export data for external analysis:

  • CSV export for spreadsheet analysis
  • PDF reports for sharing
  • Raw log data (paid plans)
  • API access (limited, paid plans)

Troubleshooting

Data Not Appearing

  1. Verify tracking code installed correctly
  2. Check IP isn't blocked
  3. Confirm project ID matches
  4. Wait adequate time (up to 30 minutes)
  5. Clear browser cache and test

Incomplete Data

  • Check JavaScript errors in console
  • Verify async loading isn't failing
  • Ensure no ad blockers
  • Confirm HTTPS/HTTP consistency

Wrong Data Values

  • Verify timezone settings
  • Check for duplicate tracking codes
  • Confirm page grouping rules
  • Review referrer exclusions

Support Resources