Squarespace Google Analytics Integration | Blue Frog Docs

Squarespace Google Analytics Integration

Integrate Google Analytics 4 with Squarespace for comprehensive analytics tracking.

Squarespace Google Analytics Integration

Complete guide to setting up Google Analytics 4 (GA4) on your Squarespace site for comprehensive user behavior and conversion tracking.

Overview

Squarespace provides built-in Google Analytics 4 integration with a simple connection process. The platform automatically handles basic page view tracking and, for Commerce sites, provides enhanced ecommerce tracking capabilities. Squarespace's clean integration means you can set up GA4 in minutes while still maintaining the flexibility to add custom tracking through code injection.

Key Benefits

  • Native Integration: Connect GA4 directly through Squarespace settings
  • Automatic Ecommerce: Built-in enhanced ecommerce for Squarespace Commerce
  • Code Injection: Add custom tracking without theme modification
  • Simple Setup: No technical expertise required for basic implementation
  • Commerce Analytics: Track product performance and sales data

Plan Requirements

  • GA4 Integration: Available on all Squarespace plans
  • Ecommerce Tracking: Requires Business or Commerce plan
  • Advanced Code Injection: Available on Business and Commerce plans

Installation Steps

Use Squarespace's native GA4 connection for easiest setup.

Step 1: Access Analytics Settings

  1. Log in to your Squarespace account
  2. Navigate to Settings > Analytics > External Services
  3. Click on Google Analytics

Step 2: Connect GA4 Property

  1. Click Connect Account
  2. Sign in to your Google account
  3. Grant Squarespace permission to access Analytics
  4. Select your GA4 property from the dropdown
  5. Click Save

Step 3: Verify Connection

  1. Visit your live site
  2. Check Analytics > Traffic in Squarespace
  3. Verify data appears in GA4 Real-time reports
  4. Confirm page views are being tracked

Method 2: Manual Code Injection

For custom implementations or additional tracking.

Step 1: Get GA4 Measurement ID

  1. Sign in to Google Analytics
  2. Navigate to Admin > Data Streams
  3. Select your web data stream
  4. Copy your Measurement ID (G-XXXXXXXXXX)

Step 2: Add Code to Squarespace

  1. Go to Settings > Advanced > Code Injection
  2. Paste the following in the Header section:
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-XXXXXXXXXX', {
    'send_page_view': true,
    'cookie_flags': 'SameSite=None;Secure'
  });
</script>
  1. Replace G-XXXXXXXXXX with your actual Measurement ID
  2. Click Save

Ecommerce Tracking Configuration

Automatic Ecommerce Tracking

For Squarespace Commerce sites, enhanced ecommerce is automatically enabled when using the native integration.

Tracked Events

Squarespace automatically tracks:

  • view_item_list - Product gallery views
  • view_item - Individual product page views
  • add_to_cart - Add to cart actions
  • begin_checkout - Checkout initiation
  • purchase - Completed transactions

Enable Enhanced Ecommerce

  1. Connect GA4 using native integration (Method 1)
  2. Ensure you're on a Commerce plan
  3. Go to Settings > Analytics > External Services
  4. Verify Enhanced Ecommerce is enabled
  5. Save settings

Custom Ecommerce Events

Add custom tracking for additional commerce events.

Track Product Clicks

<script>
  document.addEventListener('DOMContentLoaded', function() {
    // Track product clicks in galleries
    document.querySelectorAll('.ProductList-item a').forEach(function(link) {
      link.addEventListener('click', function() {
        var productName = this.querySelector('.ProductList-title').textContent;

        gtag('event', 'select_item', {
          'items': [{
            'item_name': productName
          }]
        });
      });
    });
  });
</script>

Track Newsletter Signups

<script>
  // Track newsletter form submissions
  document.querySelectorAll('.newsletter-form').forEach(function(form) {
    form.addEventListener('submit', function() {
      gtag('event', 'newsletter_signup', {
        'method': 'squarespace_form',
        'form_location': window.location.pathname
      });
    });
  });
</script>

Advanced Configuration

Custom Event Tracking

Add custom events through code injection.

Page-Specific Tracking

Add to Settings > Advanced > Code Injection > Header:

<script>
  window.addEventListener('load', function() {
    // Track specific page types
    if (document.body.classList.contains('homepage')) {
      gtag('event', 'page_view', {
        'page_type': 'homepage'
      });
    }

    if (document.body.classList.contains('ProductList')) {
      gtag('event', 'page_view', {
        'page_type': 'product_list'
      });
    }

    if (document.body.classList.contains('ProductItem')) {
      gtag('event', 'page_view', {
        'page_type': 'product_detail'
      });
    }
  });
</script>

Form Submission Tracking

Track Squarespace form submissions:

<script>
  document.addEventListener('DOMContentLoaded', function() {
    // Track form submissions
    document.querySelectorAll('.sqs-block-form').forEach(function(form) {
      form.addEventListener('submit', function() {
        var formName = form.querySelector('h3')?.textContent || 'Form';

        gtag('event', 'form_submit', {
          'form_name': formName,
          'page_path': window.location.pathname
        });
      });
    });
  });
</script>

Button Click Tracking

Track CTA button clicks:

<script>
  document.querySelectorAll('.sqs-block-button a').forEach(function(button) {
    button.addEventListener('click', function() {
      var buttonText = this.textContent.trim();
      var buttonUrl = this.getAttribute('href');

      gtag('event', 'button_click', {
        'button_text': buttonText,
        'button_url': buttonUrl,
        'page_location': window.location.href
      });
    });
  });
</script>

Scroll Tracking

Monitor content engagement:

<script>
  var scrollTracked = {25: false, 50: false, 75: false, 100: false};

  window.addEventListener('scroll', function() {
    var scrollHeight = document.documentElement.scrollHeight - window.innerHeight;
    var scrolled = (window.scrollY / scrollHeight) * 100;

    Object.keys(scrollTracked).forEach(function(threshold) {
      if (scrolled >= threshold && !scrollTracked[threshold]) {
        gtag('event', 'scroll', {
          'percent_scrolled': threshold,
          'page_path': window.location.pathname
        });
        scrollTracked[threshold] = true;
      }
    });
  });
</script>

Video Tracking

Track embedded video interactions:

<script>
  // Track video plays
  document.querySelectorAll('video').forEach(function(video) {
    var videoTracked = false;

    video.addEventListener('play', function() {
      if (!videoTracked) {
        gtag('event', 'video_start', {
          'video_url': video.currentSrc,
          'video_title': document.title
        });
        videoTracked = true;
      }
    });

    video.addEventListener('ended', function() {
      gtag('event', 'video_complete', {
        'video_url': video.currentSrc
      });
    });
  });
</script>

Implement GDPR-compliant tracking:

<script>
  // Set default consent to denied
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}

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

  // Update consent when user accepts
  function acceptCookies() {
    gtag('consent', 'update', {
      'analytics_storage': 'granted'
    });

    // Store consent preference
    localStorage.setItem('cookie_consent', 'granted');
  }

  // Check if consent already granted
  if (localStorage.getItem('cookie_consent') === 'granted') {
    gtag('consent', 'update', {
      'analytics_storage': 'granted'
    });
  }
</script>

IP Anonymization

Enable IP anonymization for privacy compliance:

<script>
  gtag('config', 'G-XXXXXXXXXX', {
    'anonymize_ip': true
  });
</script>

Member Area Tracking

Track Member Logins

For member areas:

<script>
  // Check if user is logged in (Squarespace member area)
  if (window.Static && window.Static.SQUARESPACE_CONTEXT.authenticatedAccount) {
    gtag('event', 'login', {
      'method': 'Squarespace'
    });

    // Set user property
    gtag('set', 'user_properties', {
      'member_status': 'logged_in'
    });
  }
</script>

Track Member Actions

<script>
  // Track member area navigation
  document.querySelectorAll('.member-area-link').forEach(function(link) {
    link.addEventListener('click', function() {
      gtag('event', 'member_action', {
        'action': 'page_view',
        'area': this.getAttribute('data-area')
      });
    });
  });
</script>

Troubleshooting

Tracking Not Working

Issue: No data appearing in GA4

Solutions:

  1. Verify Measurement ID is correct (starts with G-)
  2. Check if native integration is properly connected
  3. Ensure you're not using both native integration AND code injection
  4. Clear browser cache and test in incognito mode
  5. Verify site is published (not in preview mode)
  6. Check JavaScript console for errors

Duplicate Tracking

Issue: Page views counted multiple times

Solutions:

  1. Remove code injection if using native integration
  2. Check for multiple GA4 snippets in code injection
  3. Verify custom code doesn't duplicate native tracking
  4. Review third-party integrations for conflicts
  5. Check template custom code blocks

Ecommerce Events Missing

Issue: Commerce events not tracking

Solutions:

  1. Verify you're on a Commerce plan
  2. Ensure Enhanced Ecommerce is enabled in settings
  3. Use native integration for automatic ecommerce tracking
  4. Test with actual purchase (not preview mode)
  5. Check GA4 property has ecommerce enabled
  6. Verify currency settings match between Squarespace and GA4

Code Injection Not Working

Issue: Custom code not executing

Solutions:

  1. Verify you're on Business or Commerce plan
  2. Check for JavaScript syntax errors
  3. Ensure code is in Header section (not Footer for gtag)
  4. Wrap code in proper <script> tags
  5. Test in published site, not preview
  6. Check browser console for errors

Native Integration Connection Failing

Issue: Can't connect Google account

Solutions:

  1. Ensure you're logged into correct Google account
  2. Clear browser cookies and try again
  3. Use incognito mode for connection
  4. Verify Google account has access to GA4 property
  5. Try disconnecting and reconnecting
  6. Contact Squarespace support if issue persists

Events Not Firing on AJAX Pages

Issue: Single-page navigation breaks tracking

Solutions:

  1. Squarespace uses AJAX navigation by default
  2. Implement virtual page views for AJAX transitions
  3. Use Squarespace's navigation events
  4. Consider using GTM for better SPA tracking
  5. Test with AJAX disabled to isolate issue

Testing and Verification

Enable Debug Mode

Add to code injection for testing:

<script>
  gtag('config', 'G-XXXXXXXXXX', {
    'debug_mode': true
  });
</script>

Test Checklist

  1. Page Views: Navigate between pages and verify in GA4 Real-time
  2. Commerce Events: Add product to cart, complete checkout
  3. Form Submissions: Submit test form and verify event
  4. Custom Events: Trigger custom events and check DebugView
  5. Cross-Device: Test on mobile and desktop

Browser Console Testing

// Check dataLayer contents
console.log(window.dataLayer);

// Manually fire test event
gtag('event', 'test_event', {'test_param': 'test_value'});

// Verify gtag function exists
console.log(typeof gtag);

Use GA4 DebugView

  1. Enable debug mode in tracking code
  2. Navigate to Admin > DebugView in GA4
  3. Perform actions on your site
  4. Verify events appear in real-time
  5. Check event parameters are correct

Best Practices

Avoid Tracking Preview Mode

Prevent tracking during site editing:

<script>
  // Only track on live published site
  if (!window.location.href.includes('.squarespace.com/config/')) {
    gtag('config', 'G-XXXXXXXXXX');
  }
</script>

Page-Specific Code Injection

Use page settings for page-specific tracking:

  1. Navigate to specific page
  2. Click Settings icon
  3. Go to Advanced tab
  4. Add page-specific tracking code

Organize Custom Events

Use consistent naming conventions:

// Good - descriptive and consistent
gtag('event', 'product_click', {'category': 'ecommerce'});

// Bad - inconsistent naming
gtag('event', 'clicked', {'thing': 'product'});
// SYS.FOOTER