Let’s navigate the path to success together. Fill out the form below.
// Ensure the Google Analytics 'gtag' function is available before running this script.
// This script assumes you have gtag.js (GA4) installed on your Squarespace site.
// Use a DOMContentLoaded listener to ensure the script runs after the entire HTML is loaded.
document.addEventListener('DOMContentLoaded', function() {
// Select the submit button.
// We're looking for a button or input with the name attribute set to 'submit'.
// This selector is quite robust for finding submit buttons.
const submitButton = document.querySelector('form-submit-button-label"], input[name="submit"][type="submit"]');
if (submitButton) {
// Add an event listener to the button for the 'click' event.
submitButton.addEventListener('click', function() {
// Send a custom event to Google Analytics 4 (GA4).
// 'gtag' is the global function for sending data to GA4.
// 'event' is the command to send an event.
// 'form_submission' is the custom event name. You can choose any name you like,
// but 'form_submission' is a clear and descriptive standard.
// The second argument is an object containing event parameters.
// These parameters provide more context about the event.
gtag('event', 'form_submission', {
'event_category': 'Form', // Category of the event
'event_label': 'Squarespace Contact Form', // Specific label for this form
'form_name': 'Contact Us Form' // A custom parameter for your form's name
// You can add more parameters here if needed, e.g., 'page_path': window.location.pathname
});
console.log('Google Analytics event sent: form_submission');
});
} else {
console.log('Submit button with name="submit" not found on this page.');
}
});
```