HHH v4

Prevent HubSpot collecting data from specific forms

Edit
equivalent Web Development
Public

The attribute data-hs-do-not-collect is used to prevent HubSpot from collecting data from specific forms on your website.
When added to a  <form> tag, `HubSpot`'s tracking code will ignore that form and not store any submissions as contacts.
You can add the attribute in two ways:
  • 1. As a plain attribute: `<form data-hs-do-not-collect>`
  • 2. With a value: `<form data-hs-do-not-collect="true">`

<form  data-hs-do-not-collect="true">
  <input name="email" value="this@wont_be_colected.com">
</form>


Unfortunately there is no docs to source here .There are numerous complaints about this in Hubspot community ref1 , ref2

BTW Hubspot collect data only form static forms (SPAs should be covered - source )  


-----------------

In Rails you can do this:

# config/initializers/form_builder_extension.rb

class CustomRailsFormBuilder < ActionView::Helpers::FormBuilder
  # https://hhh.how/notes/2123
  def initialize(object_name, object, template, options)
    if options.delete(:hubspot_tracking).blank?
      options[:html] ||= {}
      options[:html][:data] ||= {}
      options[:html][:data][:hs_do_not_collect] = true
    end

    super(object_name, object, template, options)
  end
end

ActionView::Base.default_form_builder = CustomRailsFormBuilder