I need help! Our Snowplow (v2.18.2) instance is not tracking Hubspot form submissions.
For standard forms we see a Self describing event “SD Event: focus_form” and “SD Event: submit_form” but for Hubspot Snowplow does not pick up any activity ( no data being sent )
Wrapping instance.plugins.snowplow.enableFormTracking() in a window.onload = () => {} function / Also tried event listeners and a few other DOM load functions
Running instance.plugins.snowplow.enableFormTracking() in console. This returns undefined but form tracking still not working
I suspect it’s something to do with the fact that the form seems to populate in an on the page
If I understand correctly, the form is inside an embedded iframe while the Snowplow tracker is initialized on the parent page? Unfortunately, this is not supported – the form needs to be embedded on the same page as the tracker.
You could theoretically inject code into the iframe that initializes the tracker and enable form tracking but that requires that the content in the iframe is from the same domain as the parent page which I assume is not the case since you are loading the form from HubSpot.
Here is a related question where the user wants to track a form within an iframe.
Just a quick note that we have released version 3.4 of the JavaScript tracker that brings the ability to track forms inside certain types of iframes (which also includes Hubspot forms). Here is an excerpt from the docs:
Tracking forms embedded inside iframes
The options for tracking forms inside of iframes are limited – browsers block access to contents of iframes that are from different domains than the parent page. We are not able to provide a solution to track events using trackers initialized on the parent page in such cases. However, since version 3.4, it is possible to track events from forms embedded in iframes loaded from the same domain as the parent page or iframes created using JavaScript on the parent page (e.g., HubSpot forms).
In case you are able to access form elements inside an iframe, you can pass them in the options.forms argument when calling enableFormTracking on the parent page. This will enable form tracking for the specific form elements. The feature may also be used for forms not embedded in iframes, but it’s most useful in this particular case.
The following example shows how to identify the form elements inside an iframe and pass them to the enableFormTracking function:
let iframe = document.getElementById('form_iframe'); // find the element for the iframe
let forms = iframe.contentWindow.document.getElementsByTagName('form'); // find form elements inside the iframe
enableFormTracking({
options: {
forms: forms // pass the embedded forms when enabling form tracking
},
});