I have created a form listener that is listening for when a form has loaded on the page. This is the script:
<script type="text/javascript">
window.addEventListener('message', function(event) {
if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormReady') {
window.dataLayer.push({
'event': 'hubspot-form-ready',
'hs-form-guid': event.data.id
});
}
});
</script>
I have a similar script that works for 'onFormSubmitted' just fine, but I can't seem to get anything to work for 'onFormReady'.
My end goal is to listen for the form to make sure it has loaded on the page, then use that event to manipulate the form (e.g. add cookie values to hidden form fields). I just have to make sure the form is loaded first.
Has anyone done anything similar to this?