In the article below I’m gonna show you how to track HubSpot forms.

After creating the form inside your HubSpot account, you will be prompted with a code to embed on your website:

In order to get the submitted data, make sure to add this code after the formId property. This will send the form data to the redirect URL as query string parameters.

  ,onFormSubmit: function($form) {
     let redirectUrl = JSON.parse( $form[0].elements.hs_context.value ).redirectUrl;
     if( redirectUrl ){
            redirectUrl += (( redirectUrl.includes("?") ) ? "&"+ $form.serialize() : "?"+ $form.serialize() )
            window.location = redirectUrl
     }
 }

The final code should look like this: