// This function runs once the page elements are ready $w.onReady(function () { // Get a reference to your form element const myForm = $w("#wixForms1"); // IMPORTANT: Replace 'contactForm' with your actual Wix Form ID // Add an event listener for successful form submission myForm.onWixFormSubmitted(() => { console.log("Wix Form submitted successfully! Pushing event to Data Layer."); // Push a custom event to the Data Layer for GTM // You can also push additional data if needed, e.g., form fields if (typeof dataLayer !== 'undefined') { dataLayer.push({ 'event': 'wix_form_submission', 'form_id': myForm.id, 'form_name': 'My Contact Form' // Optional: Add a descriptive name // 'email': $w("#emailInput").value // Example: If you want to capture form field values }); } else { console.warn("dataLayer is not defined. Google Tag Manager might not be installed correctly."); } }); // Optional: Listen for form submission errors myForm.onWixFormSubmittedError((error) => { console.error("Wix Form submission error:", error); if (typeof dataLayer !== 'undefined') { dataLayer.push({ 'event': 'wix_form_submission_error', 'form_id': myForm.id, 'error_message': error.message }); } }); });
top of page
bottom of page