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.