Installing Google Analytics 4 on Squarespace | Blue Frog Docs

Installing Google Analytics 4 on Squarespace

Complete guide to setting up GA4 on Squarespace using native integration or custom code injection, with version-specific considerations.

Installing Google Analytics 4 on Squarespace

Squarespace offers a native Google Analytics integration, making it easy to add GA4 tracking to your website. This guide covers both the native integration method and custom code injection for advanced implementations.


Prerequisites

Before you begin:

  • Have a Google Analytics 4 property created in your Google Analytics account
  • Know your GA4 Measurement ID (format: G-XXXXXXXXXX)
  • Have admin access to your Squarespace website

The native integration is the easiest and most reliable method for most users.

Step 1: Get Your GA4 Measurement ID

  1. Log in to Google Analytics
  2. Navigate to Admin (gear icon in bottom left)
  3. Under Property column, click Data Streams
  4. Select your web stream (or create one if needed)
  5. Copy your Measurement ID (starts with G-)

Step 2: Add to Squarespace

  1. Log in to your Squarespace website
  2. Go to Settings > Analytics > Google Analytics
  3. Click Connect Account
  4. Paste your Measurement ID in the provided field
  5. Click Save

Step 3: Verify Installation

Using Google Analytics:

  1. In GA4, go to Reports > Realtime
  2. Open your Squarespace site in a new tab
  3. Within 30 seconds, you should see your session appear in Realtime

Using Google Tag Assistant:

  1. Install the Google Tag Assistant Chrome extension
  2. Visit your Squarespace site
  3. Click the Tag Assistant icon
  4. Verify that your GA4 tag is detected and firing

Method 2: Code Injection (Advanced)

Use this method if you need more control or want to implement custom configurations.

When to Use Code Injection

  • You need to customize the GA4 configuration
  • You want to send custom events on page load
  • You're implementing GA4 alongside other analytics tools
  • You need server-side tagging setup

Implementation Steps

  1. Go to Settings > Advanced > Code Injection
  2. In the Header section, paste the following code:
<!-- Google Analytics 4 -->
<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 (appears twice)
  2. Click Save

Custom Configuration Options

Disable Automatic Page Views:

gtag('config', 'G-XXXXXXXXXX', {
  'send_page_view': false
});

Set Custom User Properties:

gtag('config', 'G-XXXXXXXXXX', {
  'user_properties': {
    'squarespace_version': '7.1',
    'member_status': 'guest'
  }
});

Enable Enhanced Measurement:

gtag('config', 'G-XXXXXXXXXX', {
  'enhanced_measurement': {
    'scrolls': true,
    'outbound_clicks': true,
    'site_search': true,
    'video_engagement': true,
    'file_downloads': true
  }
});

Squarespace Version Considerations

Squarespace 7.0

The native integration works seamlessly on all 7.0 templates. If using code injection:

  • Scripts load consistently across all template families
  • DOM structure is more stable for custom event tracking
  • Some older templates may have unique CSS class structures

Testing Checklist:

  • Homepage
  • Blog posts
  • Product pages (if using Commerce)
  • Contact/form pages

Squarespace 7.1 (Fluid Engine)

The native integration is optimized for 7.1. Additional considerations:

Ajax Loading: 7.1 may use Ajax for certain interactions. If you notice missing page views:

// Add to Footer Code Injection
<script>
  // Track Ajax page changes
  (function() {
    var pushState = history.pushState;
    history.pushState = function() {
      pushState.apply(history, arguments);
      if (typeof gtag !== 'undefined') {
        gtag('event', 'page_view', {
          'page_location': window.location.href,
          'page_path': window.location.pathname
        });
      }
    };
  })();
</script>

Fluid Engine Dynamic Sections: Content blocks in 7.1 are more dynamic. Ensure tracking is tested across:

  • Different section layouts
  • Mobile vs. desktop views
  • All block types (especially forms and buttons)

Member Areas Integration

If your Squarespace site uses Member Areas:

Track Member vs. Non-Member Traffic

Add to your Header Code Injection (after the main GA4 code):

<script>
  // Detect if user is logged in to Member Area
  if (window.Squarespace && window.Squarespace.user) {
    window.Squarespace.onInitialize(Y, function() {
      var isMember = Y.Squarespace.User.isLoggedIn();

      if (typeof gtag !== 'undefined') {
        gtag('set', 'user_properties', {
          'member_status': isMember ? 'member' : 'guest'
        });
      }
    });
  }
</script>

This allows you to:

  • Segment member vs. guest behavior in GA4
  • Create audiences based on membership status
  • Track member-exclusive content engagement

Commerce-Specific Setup

For Squarespace Commerce sites, additional setup is recommended:

Enable Enhanced Ecommerce

The native GA4 integration includes basic eCommerce tracking, but for full functionality:

  1. Ensure GA4 eCommerce events are enabled in your property
  2. In GA4, go to Admin > Data Streams > [Your Stream] > Configure tag settings
  3. Under Enhanced measurement, ensure eCommerce events are toggled on

See Squarespace Commerce + GA4 Ecommerce Tracking for detailed implementation.


Validation & Testing

1. Real-Time Reports

  • Navigate to Reports > Realtime in GA4
  • Visit various pages on your site
  • Confirm page views appear within 30 seconds

2. DebugView

For more detailed testing:

  1. Install the Google Analytics Debugger extension
  2. Visit your Squarespace site
  3. In GA4, go to Configure > DebugView
  4. Verify events are firing correctly

3. Google Tag Assistant


Common Issues & Solutions

Issue: No Data Appearing in GA4

Possible Causes:

  • Measurement ID is incorrect
  • Ad blocker is active (test in incognito mode)
  • Code not saved properly in Squarespace
  • GA4 property is not set to "Web"

Solution:

  1. Verify Measurement ID is correct
  2. Check Code Injection is saved
  3. Test in incognito/private browsing mode
  4. Allow 24-48 hours for data to appear in standard reports (use Realtime for immediate validation)

Issue: Duplicate Tracking

Cause: Both native integration AND code injection are active

Solution:

  • Choose one method only
  • If using native integration, remove code from Code Injection
  • If using code injection, disconnect the native integration

Issue: Page Views Not Tracking on Member Pages

Cause: Member area authentication may block some tracking

Solution:

  • Ensure tracking code is in site-wide Header (not page-specific)
  • Verify that cookie consent settings aren't blocking GA4
  • Test with a member account to confirm behavior

Performance Optimization

Script Loading

The native integration automatically uses async loading for optimal performance. If using code injection, ensure you include the async attribute:

<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>

Impact on Core Web Vitals

GA4's impact on performance is minimal, but consider:

For sites with performance issues, see LCP Optimization for Squarespace.


Next Steps

Now that GA4 is installed:


Additional Resources

// SYS.FOOTER