Squarespace Tracking Issues | Blue Frog Docs

Squarespace Tracking Issues

Troubleshoot and resolve analytics tracking issues on Squarespace websites.

Squarespace Tracking Issues

Platform-specific guides for diagnosing and fixing analytics and tracking issues on Squarespace.

Common Issues

Events Not Firing

Debug why analytics events aren't being captured on Squarespace.

Squarespace-Specific Tracking Challenges

Squarespace 7.0 and 7.1 have different code injection capabilities, and the platform's AJAX-based navigation creates unique tracking scenarios.

Platform Code Injection Locations

Squarespace offers several code injection points with different scopes:

Settings → Advanced → Code Injection:

  • Header - Loads on all pages before </head>
  • Footer - Loads on all pages before </body>
  • Lock Page - Only on password-protected pages
  • Order Confirmation - Commerce sites only

Page-Level Code Injection:

  • Settings (gear icon) → Advanced → Page Header Code Injection
  • Loads only on specific pages
  • Overrides site-wide header injection

Code Block:

  • Insert via content editor
  • Inline code within page content
  • Limited to specific sections

Squarespace 7.0 vs 7.1 Differences:

Feature Squarespace 7.0 Squarespace 7.1
Code Injection Available Available
Developer Mode Available Not available
Custom Templates Yes (with dev mode) No
AJAX Loading Optional Default
Code Blocks Limited Enhanced

AJAX Navigation Issues

Squarespace 7.1 uses AJAX for page transitions by default, which prevents traditional pageview tracking:

Problem:

// Traditional pageview tracking only fires on initial load
gtag('config', 'G-XXXXXXXXXX', {
  'page_path': window.location.pathname
});
// This won't fire on AJAX navigations

Solution - Listen for Squarespace Route Changes:

// Squarespace 7.1 AJAX navigation handler
window.addEventListener('mercury:load', function() {
  // Fire pageview on each AJAX page transition
  if (typeof gtag !== 'undefined') {
    gtag('config', 'G-XXXXXXXXXX', {
      'page_path': window.location.pathname,
      'page_title': document.title
    });
  }

  // For dataLayer
  if (typeof dataLayer !== 'undefined') {
    dataLayer.push({
      'event': 'pageview',
      'page': window.location.pathname,
      'title': document.title
    });
  }

  console.log('AJAX page loaded:', window.location.pathname);
});

Disable AJAX Loading (Alternative):

// Add to Header Code Injection to disable AJAX
<script>
  window.addEventListener('DOMContentLoaded', function() {
    if (window.Static && window.Static.SQUARESPACE_CONTEXT) {
      window.Static.SQUARESPACE_CONTEXT.website.siteSettings.disableAjaxLoading = true;
    }
  });
</script>

Template and Version Compatibility

Squarespace 7.0 Templates:

  • Each template family has different structures
  • Custom CSS/JS may affect tracking
  • Developer Mode allows full template editing
  • Template-specific JavaScript may interfere

Squarespace 7.1 Templates:

  • Unified template system
  • All templates work similarly
  • Cannot access underlying template files
  • More consistent but less customizable

Checking Squarespace Version:

// Check version via console
console.log('Squarespace version:', window.Static?.SQUARESPACE_CONTEXT?.website?.version);

// Check if AJAX is enabled
console.log('AJAX loading:', !window.Static?.SQUARESPACE_CONTEXT?.website?.siteSettings?.disableAjaxLoading);

Commerce Tracking Limitations

Built-in Analytics:

  • Squarespace has native analytics (limited)
  • May conflict with external tracking
  • Commerce data not easily accessible via JavaScript

Accessing Commerce Data:

// Commerce data is not exposed in a standard JavaScript object
// Must use Code Injection on Thank You page

// In Settings → Advanced → Code Injection → Order Confirmation:
<script>
window.addEventListener('DOMContentLoaded', function() {
  // Scrape order data from page (not ideal but necessary)
  const orderNumber = document.querySelector('.order-number')?.textContent;
  const total = document.querySelector('.order-total')?.textContent;

  console.log('Order:', orderNumber, 'Total:', total);

  // Send to analytics
  if (typeof dataLayer !== 'undefined' && orderNumber) {
    dataLayer.push({
      'event': 'purchase',
      'transaction_id': orderNumber,
      'value': parseFloat(total?.replace(/[^0-9.]/g, ''))
    });
  }
});
</script>

Plugin and Extension Conflicts

Squarespace has limited third-party integrations:

Built-in Integrations:

Common Conflicts:

  • Native GA integration vs custom GTM code
  • Multiple tracking scripts for the same service
  • Cookie consent banners blocking scripts
  • Third-party chat widgets

Check for Native Integrations:

// Check if native Google Analytics is enabled
const gaScripts = document.querySelectorAll('script[src*="google-analytics"]');
console.log('Google Analytics scripts found:', gaScripts.length);

// Check for Facebook Pixel
const fbScripts = document.querySelectorAll('script[src*="facebook.net"]');
console.log('Facebook Pixel scripts found:', fbScripts.length);

// Log all external scripts
document.querySelectorAll('script[src]').forEach(script => {
  console.log('External script:', script.src);
});

Comprehensive Diagnostic Checklist

1. Verify Code Injection Location

Check Site-Wide Settings:

  • Settings → Advanced → Code Injection
  • Verify code is in Header (for tracking scripts)
  • Check for syntax errors (unclosed tags, quotes)

Validation Script:

<!-- Add to Header Code Injection -->
<script>
console.log('=== Squarespace Tracking Diagnostic ===');
console.log('Version:', window.Static?.SQUARESPACE_CONTEXT?.website?.version);
console.log('Template:', window.Static?.SQUARESPACE_CONTEXT?.website?.siteTitle);
console.log('AJAX enabled:', !window.Static?.SQUARESPACE_CONTEXT?.website?.siteSettings?.disableAjaxLoading);
console.log('Page:', window.location.pathname);
console.log('Loaded at:', new Date().toISOString());
</script>

2. Test AJAX Navigation

// Monitor all Squarespace lifecycle events
const sqsEvents = [
  'DOMContentLoaded',
  'mercury:load',  // 7.1 AJAX page load
  'mercury:unload' // 7.1 AJAX page unload
];

sqsEvents.forEach(eventName => {
  window.addEventListener(eventName, function(e) {
    console.log(`[${eventName}]`, window.location.pathname);
  });
});

3. Check Native Analytics Configuration

Disable Native Google Analytics if Using Custom:

  • Settings → Advanced → External API Keys
  • If Google Analytics is set here, it may conflict
  • Remove it if using custom GTM/GA code

Check Configuration:

// See if native GA is configured
const nativeGA = window.Static?.SQUARESPACE_CONTEXT?.website?.authenticatedAccount?.googleAnalyticsAccountId;
if (nativeGA) {
  console.warn('Native Google Analytics is configured:', nativeGA);
  console.warn('This may conflict with custom tracking code');
}

4. Inspect Squarespace Objects

// Full Squarespace context dump
console.log('Static context:', window.Static?.SQUARESPACE_CONTEXT);

// Check for commerce capabilities
const isCommerce = window.Static?.SQUARESPACE_CONTEXT?.website?.storeSettings;
console.log('Commerce enabled:', !!isCommerce);

// Check for member areas
const hasMemberAreas = window.Static?.SQUARESPACE_CONTEXT?.website?.memberAccountsEnabled;
console.log('Member areas:', hasMemberAreas);

5. Test on Different Page Types

Squarespace has different page types that may behave differently:

// Detect page type
function getSquarespacePage Type() {
  const path = window.location.pathname;
  const context = window.Static?.SQUARESPACE_CONTEXT;

  if (path === '/') return 'homepage';
  if (path.startsWith('/blog')) return 'blog';
  if (path.startsWith('/shop') || path.startsWith('/store')) return 'shop';
  if (context?.pageType) return context.pageType;

  return 'page';
}

console.log('Page type:', getSquarespacePageType());

Browser DevTools Debugging Steps

Network Tab Analysis

Filter for Tracking Requests:

Filter: /collect|/analytics|/tr|/pixel|/track

Check Squarespace's Own Analytics:

  • Squarespace sends data to squarespace.com/api/v1/stats
  • These are for built-in analytics dashboard
  • Separate from your external tracking

Common Request Patterns:

google-analytics.com/collect - Google Analytics (Universal)
google-analytics.com/g/collect - Google Analytics 4
googletagmanager.com/gtm.js - Google Tag Manager
facebook.com/tr - Facebook Pixel
squarespace.com/api/v1/stats - Squarespace internal

Console Debugging

// Comprehensive tracking check
console.log('=== Tracking Debug ===');
console.log('dataLayer:', window.dataLayer);
console.log('gtag:', typeof window.gtag);
console.log('ga:', typeof window.ga);
console.log('fbq:', typeof window.fbq);
console.log('google_tag_manager:', window.google_tag_manager);

// Check for errors in previous page loads
const errors = window.performance?.getEntriesByType('navigation');
console.log('Page load errors:', errors);

// Monitor script loading
const observer = new PerformanceObserver((list) => {
  list.getEntries().forEach((entry) => {
    if (entry.initiatorType === 'script') {
      console.log('Script loaded:', entry.name, entry.duration + 'ms');
    }
  });
});
observer.observe({ entryTypes: ['resource'] });

Application Tab Storage

// Check for tracking cookies
document.cookie.split(';').forEach(cookie => {
  const [name, value] = cookie.trim().split('=');
  if (name.startsWith('_ga') || name.startsWith('_gid') || name.startsWith('_fb')) {
    console.log('Tracking cookie:', name, value);
  }
});

// Check localStorage
['gtm', 'ga', 'fb', 'analytics'].forEach(key => {
  const stored = localStorage.getItem(key);
  if (stored) console.log('LocalStorage', key, stored);
});

Common Symptoms and Causes

Symptom Likely Cause Solution
Pageviews only on initial load AJAX navigation not tracked Add mercury:load event listener
Code not executing Syntax error in Code Injection Validate HTML/JavaScript syntax
Tracking on some pages only Page-level code injection used Move to site-wide Header injection
Duplicate tracking Native + custom integration Remove native integration from settings
Scripts load slowly Too many external scripts Consolidate with Tag Manager
E-commerce data missing No JavaScript access to order data Scrape from Thank You page DOM
Tracking blocked Ad blocker or consent tool Implement consent management
Different data 7.0 vs 7.1 AJAX behavior difference Handle mercury:load events
GTM preview not working AJAX navigation interferes Refresh preview after navigation
Customer ID not available No member area or not logged in Check member authentication

Tag Manager Troubleshooting

Google Tag Manager Setup

Installation:

<!-- Add to Settings → Advanced → Code Injection → Header -->

<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXX');</script>
<!-- End Google Tag Manager -->
<!-- Add to Settings → Advanced → Code Injection → Footer (before </body>) -->

<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

Data Layer for AJAX Pages:

<script>
// Initialize dataLayer
window.dataLayer = window.dataLayer || [];

// Push initial pageview
dataLayer.push({
  'event': 'pageview',
  'page': window.location.pathname,
  'title': document.title
});

// Handle AJAX navigation (Squarespace 7.1)
window.addEventListener('mercury:load', function() {
  dataLayer.push({
    'event': 'pageview',
    'page': window.location.pathname,
    'title': document.title
  });
  console.log('GTM pageview pushed:', window.location.pathname);
});
</script>

GTM Preview Mode Issues:

  • Preview may break after AJAX navigation
  • Solution: Refresh preview mode or disable AJAX
  • Use GTM debug extension instead

Commerce Tracking

Product Page Tracking

// Product detail view (limited data available)
window.addEventListener('DOMContentLoaded', function() {
  const productTitle = document.querySelector('.ProductItem-details-title')?.textContent;
  const productPrice = document.querySelector('.product-price')?.textContent;

  if (productTitle) {
    dataLayer.push({
      'event': 'productDetail',
      'productName': productTitle,
      'productPrice': productPrice
    });
  }
});

Add to Cart Tracking

// Monitor add to cart buttons
document.addEventListener('click', function(e) {
  const addToCartBtn = e.target.closest('.sqs-add-to-cart-button');

  if (addToCartBtn) {
    console.log('Add to cart clicked');

    // Get product info from page
    const productName = document.querySelector('.ProductItem-details-title')?.textContent;
    const productPrice = document.querySelector('.product-price')?.textContent;

    dataLayer.push({
      'event': 'addToCart',
      'productName': productName,
      'productPrice': productPrice
    });
  }
}, true);

Purchase Tracking

On Order Confirmation Page:

<!-- Settings → Advanced → Code Injection → Order Confirmation Page -->
<script>
window.addEventListener('DOMContentLoaded', function() {
  // Extract order details from page
  const orderNumber = document.querySelector('.order-number, .confirmation-number')?.textContent?.trim();
  const totalElement = document.querySelector('.order-total-value, .order-total');
  const orderTotal = totalElement?.textContent?.replace(/[^0-9.]/g, '');

  if (orderNumber && orderTotal) {
    dataLayer.push({
      'event': 'purchase',
      'transactionId': orderNumber,
      'transactionTotal': parseFloat(orderTotal),
      'currency': 'USD' // Adjust as needed
    });

    console.log('Purchase tracked:', orderNumber, orderTotal);
  } else {
    console.warn('Could not extract order data');
  }
});
</script>

Built-in Cookie Banner:

  • Settings → Cookies & Visitor Data
  • Can block tracking scripts
  • Manage via Squarespace settings

Custom Consent Implementation:

// Check for consent before loading tracking
function hasConsent() {
  // Check Squarespace cookie consent
  const consent = document.cookie.match(/ss_cookieAllowed=([^;]+)/);
  return consent && consent[1] === '1';
}

function initTracking() {
  if (hasConsent()) {
    loadGoogleAnalytics();
    loadFacebookPixel();
  } else {
    console.log('Waiting for cookie consent');

    // Check periodically for consent
    const consentCheck = setInterval(function() {
      if (hasConsent()) {
        clearInterval(consentCheck);
        loadGoogleAnalytics();
        loadFacebookPixel();
      }
    }, 500);
  }
}

function loadGoogleAnalytics() {
  // Load GA script
  const script = document.createElement('script');
  script.src = 'https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX';
  script.async = true;
  document.head.appendChild(script);

  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'G-XXXXXXXXXX');
}

// Run on page load
window.addEventListener('DOMContentLoaded', initTracking);

Google Consent Mode:

// Set default consent state
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}

gtag('consent', 'default', {
  'ad_storage': 'denied',
  'analytics_storage': 'denied',
  'ad_user_data': 'denied',
  'ad_personalization': 'denied',
  'wait_for_update': 500
});

// Update when user consents
function updateConsent() {
  if (hasConsent()) {
    gtag('consent', 'update', {
      'ad_storage': 'granted',
      'analytics_storage': 'granted',
      'ad_user_data': 'granted',
      'ad_personalization': 'granted'
    });
  }
}

window.addEventListener('DOMContentLoaded', updateConsent);

When to Contact Support

Contact Squarespace Support When:

Platform-Level Issues:

  • Code Injection not saving
  • Built-in analytics not working
  • Commerce checkout errors
  • Template-specific bugs

Provide to Squarespace:

  1. Site URL
  2. Template version (7.0 or 7.1)
  3. Screenshots of Code Injection settings
  4. Browser and device information
  5. Specific pages affected

Contact Analytics Vendor When:

  • Events firing but not in reports
  • Data discrepancies
  • Attribution issues
  • API integration problems

Provide to Vendor:

  1. Network tab screenshots showing requests
  2. Console logs with event data
  3. Property/tracking IDs
  4. Example page URLs

Contact Developer When:

  • Custom code not working
  • Complex AJAX tracking needed
  • Advanced e-commerce tracking
  • Custom member area tracking

Provide to Developer:

  1. Current code implementation
  2. Desired tracking behavior
  3. Console errors
  4. Example tracking events

General Fixes

For universal tracking concepts, see the Global Tracking Issues Hub.

// SYS.FOOTER