Jump to content

Accelerate

Circle Member
  • Posts

    2
  • Joined

  • Last visited

Everything posted by Accelerate

  1. Seems adding <script> tags in the "post submit HTML" of the form block is not working anymore in 7.1 🤨 ...which is quite annoying! Based on the idea of @foleyatwork I rewrote it to have it working on 7.1 Paste this code in the footer code injection of the whole website: <script> document.addEventListener('DOMContentLoaded', function() { console.log('Squarespace ready'); document.querySelectorAll('.form-block').forEach((formBlock) => { const jsonStr = formBlock.querySelector('script[id*=form-context]').textContent; const formName = JSON.parse(jsonStr).formName; formBlock.onsubmit = function() { // Facebook Lead event example fbq("track", "Lead", {content_category: 'form', content_name: formName}); // Google Lead event example gtag('event', 'generate_lead', {event_category:'form', event_label: formName}); }; }); }, false); </script> Hope it helps.
  2. Yeah unfortunately at the moment the Squarespace form, wipe out any value you inject in the hidden field as soon as you type something in the form itself. Not sure if a bug or a "by design" decision to force using the hidden field only with value coming from the query string in the URL (as for their official doc https://support.squarespace.com/hc/en-us/articles/206543997-Tracking-form-block-referral-sources ) Anyway if and ever this will work again, here's an example of code that doesn't use jQuery and extract basic info from the geolocation API: <script> document.addEventListener('DOMContentLoaded', function() { fetch('https://ipapi.co/json/') .then(function (response) { response.json().then(jsonData => { if (document.getElementsByName("SQF_YourHiddenFieldName").length != 0) { //set ip address for form submission document.getElementsByName("SQF_YourHiddenFieldName")[0].value = jsonData.ip + " | " + jsonData.city + " | " + jsonData.country_name + " | " + jsonData.org; } }); }) }, false); </script> You can put that in the Footer or maybe just in the "contact us" page. If you are on Squarespace 7 and not 7.1 you might need to wrap your code in window.Squarespace.onInitialize(Y, function () {...}); instead of document.addEventListener('DOMContentLoaded', function() {...}, false); Hope it helps.
×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.