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
Method 1: Built-in Integration (Recommended)
Use Squarespace's native GA4 connection for easiest setup.
Step 1: Access Analytics Settings
- Log in to your Squarespace account
- Navigate to Settings > Analytics > External Services
- Click on Google Analytics
Step 2: Connect GA4 Property
- Click Connect Account
- Sign in to your Google account
- Grant Squarespace permission to access Analytics
- Select your GA4 property from the dropdown
- Click Save
Step 3: Verify Connection
- Visit your live site
- Check Analytics > Traffic in Squarespace
- Verify data appears in GA4 Real-time reports
- Confirm page views are being tracked
Method 2: Manual Code Injection
For custom implementations or additional tracking.
Step 1: Get GA4 Measurement ID
- Sign in to Google Analytics
- Navigate to Admin > Data Streams
- Select your web data stream
- Copy your Measurement ID (G-XXXXXXXXXX)
Step 2: Add Code to Squarespace
- Go to Settings > Advanced > Code Injection
- 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>
- Replace
G-XXXXXXXXXXwith your actual Measurement ID - 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 viewsview_item- Individual product page viewsadd_to_cart- Add to cart actionsbegin_checkout- Checkout initiationpurchase- Completed transactions
Enable Enhanced Ecommerce
- Connect GA4 using native integration (Method 1)
- Ensure you're on a Commerce plan
- Go to Settings > Analytics > External Services
- Verify Enhanced Ecommerce is enabled
- 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>
Privacy and Consent
Cookie Consent Integration
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:
- Verify Measurement ID is correct (starts with G-)
- Check if native integration is properly connected
- Ensure you're not using both native integration AND code injection
- Clear browser cache and test in incognito mode
- Verify site is published (not in preview mode)
- Check JavaScript console for errors
Duplicate Tracking
Issue: Page views counted multiple times
Solutions:
- Remove code injection if using native integration
- Check for multiple GA4 snippets in code injection
- Verify custom code doesn't duplicate native tracking
- Review third-party integrations for conflicts
- Check template custom code blocks
Ecommerce Events Missing
Issue: Commerce events not tracking
Solutions:
- Verify you're on a Commerce plan
- Ensure Enhanced Ecommerce is enabled in settings
- Use native integration for automatic ecommerce tracking
- Test with actual purchase (not preview mode)
- Check GA4 property has ecommerce enabled
- Verify currency settings match between Squarespace and GA4
Code Injection Not Working
Issue: Custom code not executing
Solutions:
- Verify you're on Business or Commerce plan
- Check for JavaScript syntax errors
- Ensure code is in Header section (not Footer for gtag)
- Wrap code in proper
<script>tags - Test in published site, not preview
- Check browser console for errors
Native Integration Connection Failing
Issue: Can't connect Google account
Solutions:
- Ensure you're logged into correct Google account
- Clear browser cookies and try again
- Use incognito mode for connection
- Verify Google account has access to GA4 property
- Try disconnecting and reconnecting
- Contact Squarespace support if issue persists
Events Not Firing on AJAX Pages
Issue: Single-page navigation breaks tracking
Solutions:
- Squarespace uses AJAX navigation by default
- Implement virtual page views for AJAX transitions
- Use Squarespace's navigation events
- Consider using GTM for better SPA tracking
- 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
- Page Views: Navigate between pages and verify in GA4 Real-time
- Commerce Events: Add product to cart, complete checkout
- Form Submissions: Submit test form and verify event
- Custom Events: Trigger custom events and check DebugView
- 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
- Enable debug mode in tracking code
- Navigate to Admin > DebugView in GA4
- Perform actions on your site
- Verify events appear in real-time
- 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:
- Navigate to specific page
- Click Settings icon
- Go to Advanced tab
- 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'});