Integrate HubSpot Forms with Shopify Hydrogen
This guide is for Shopify Hydrogen storefronts. Building on Next.js? See the Next.js overview.
What you will build
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.
Create the server-side submission helper
Add a Hydrogen action
Accept only known fields and bound their sizes before sending them upstream.Build the Hydrogen form
useFetcher submits without navigating away and exposes pending and response state.
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 requireslegalConsentOptions:
- 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.
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.
Use the form with Weaverse
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.