Integrate HubSpot Forms with Shopify Hydrogen
HubSpot forms can collect contact, sample-request, wholesale, and product-enquiry leads from a Shopify Hydrogen storefront. The most portable architecture submits the storefront form to a Hydrogen action, validates it on the server, and forwards only approved fields to HubSpot.
This guide is based on maintained Weaverse Hydrogen implementations. File names and route paths are examples, not required project structure.
What you will build
A server boundary lets you enforce validation, consent, bot protection, and a stable response shape without coupling the UI to HubSpot.
Prerequisites
- A published HubSpot form.
- The HubSpot account ID and form GUID.
- HubSpot internal field names for every submitted field.
- A Hydrogen server runtime such as Shopify Oxygen.
Add the identifiers to local and deployed environment configuration:
The Forms submission endpoint does not require a private access token, but keeping the identifiers server-side makes environment changes and abuse controls easier. If you later call HubSpot CRM APIs, keep that private app token in a separate server-only variable.
Create the server-side submission helper
Do not log the request body because it contains customer personal data.
Add a Hydrogen action
Accept only known fields and bound their sizes before sending them upstream.
Register the file using your project’s route convention, for example:
HubSpot field names are account-specific internal names, not their visible labels. Confirm each name in the form definition instead of guessing or copying a client implementation.
useFetcher submits without navigating away and exposes pending and response state.
For localized storefronts, generate the action URL with the same locale-aware route helper used elsewhere in the theme.
Map product and enquiry context
A product sample or wholesale form often needs additional context such as product title, SKU, URL, enquiry type, or company name. Treat browser-submitted product data as untrusted.
Prefer sending a Shopify product ID or handle, then resolve authoritative product details on the server before mapping them to HubSpot. If that is unnecessary, validate and bound every hidden value exactly like visible inputs.
Handle consent correctly
A checked box in your storefront does not automatically configure HubSpot’s legal-consent model. If the HubSpot form requires legalConsentOptions:
- Copy the required subscription type and consent wording from the form’s HubSpot configuration.
- Display the same consent meaning to the shopper.
- Include HubSpot’s required legal-consent payload in the server request.
- Keep proof of consent aligned with your privacy policy and regional requirements.
Do not infer marketing consent from a general contact-form submission.
Add abuse protection
A public form route should include:
- Server-side field validation.
- Request-size and field-length limits.
- Rate limiting by a privacy-aware key.
- Bot protection such as hCaptcha or Turnstile.
- Generic upstream errors that do not reveal HubSpot responses.
- Logging that excludes names, emails, messages, and tokens.
See the Klaviyo contact-form guide for a complete hCaptcha pattern that can be reused before the HubSpot request.
Wrap the form in a Weaverse section when merchants should control its heading, description, layout, or page placement. Keep field names and server configuration in code or deployment settings; exposing arbitrary HubSpot field names in Studio can create invalid or unsafe mappings.
Useful Studio settings include:
- Heading and introductory text.
- Submit and success labels.
- Layout and spacing.
- Optional product-context display.
Test the integration
- Submit every valid form variant.
- Confirm the submission appears on the correct HubSpot form.
- Check that each value maps to the intended property.
- Test malformed emails, overlong fields, missing consent, and duplicate clicks.
- Simulate a HubSpot failure and confirm the storefront returns a generic retry message.
- Verify bot protection and rate limiting.
- Repeat submission after client-side route navigation.
- Test localized route prefixes and translated messages.
Production checklist
- The account ID and form GUID point to the intended environment.
- Field names match the published HubSpot form.
- Private CRM tokens never reach the browser.
- Consent semantics match HubSpot and the storefront policy.
- Validation, bot protection, and rate limits run before HubSpot.
- PII is excluded from logs.
- Success is confirmed in HubSpot, not only in the browser.
Official resources