HubSpot's own documentation rules out the lazy option for most Next.js sites. Its non-HubSpot forms tool, which scrapes ordinary HTML forms through the tracking code, states that "the form must not be on a single-page app" and must not have JavaScript bound to its submit event (HubSpot Knowledge Base, updated 20 October 2026). A Next.js site breaks both conditions on almost every page. So the integration has to be built on purpose, and how it is built decides whether marketing still sees where its leads came from.
This guide covers the three ways to connect the two, the one we would choose, a step list, what breaks and what it costs at scale. Every limit comes from HubSpot's, Next.js's or Vercel's own documentation, read on 17 November 2026.
What the pairing is for
Next.js is the framework teams pick when the site is also a product: a logged-in area, a quote builder, an app sharing a design system with the marketing pages. HubSpot is where sales and marketing already live. The integration has one job: every meaningful visitor action on the Next.js side should arrive in HubSpot as the right contact, with the right source.
If you are still choosing the front end, see "Webflow or Next.js for a Marketing Site? The Decision in Four Questions". For a move off HubSpot CMS, see "HubSpot CMS to Webflow: Keep the CRM, Move the Site, Lose Nothing in Attribution". This page assumes Next.js is decided and HubSpot stays.
The three ways to connect them
There are three working patterns, plus the collected-forms shortcut that HubSpot's documentation rules out for this stack.
| Method | How it works | Attribution | Who controls the form | Main risk |
|---|---|---|---|---|
| HubSpot embed | HubSpot's script renders the form inside a client component | Native, when the tracking code is on the page | Marketing, in HubSpot's form editor | Third-party script weight and styling limits |
| Forms submission API | Your own React form posts to HubSpot's form endpoint, ideally from the server | Kept, if you pass the hutk cookie and page URL in the context object | Developers own the markup; marketing owns the field list in HubSpot | Forgetting hutk, so contacts arrive with no source |
| CRM objects API | Your server creates or updates the contact directly with a private app token | Lost by default: no form submission, no page context attached | Developers only | Contacts without browsing history, and no form-triggered workflows |
| Collected forms (not usable) | Tracking code scrapes plain HTML forms | Native, when it works | Nobody, it is automatic | Not supported on single-page apps or forms with JavaScript submit handlers |
Sources: HubSpot Knowledge Base, Use non-HubSpot forms (2026); HubSpot Forms API v3 reference (2026)
The embed. The quickest route, for teams where marketing changes forms weekly. The cost is a third-party script and styling that fights your design system.
The Forms submission API. The submit endpoint, POST to api.hsforms.com/submissions/v3/integration/submit/{portalId}/{formGuid}, needs no authentication and supports cross-origin requests. A secure version "requires authentication and has higher rate limits", and is the one to call from a server. Either way the data lands as a real form submission, so form-triggered workflows and lists behave normally.
The CRM API. Writing contacts straight into the CRM is right for product events, such as a trial signup inside the app, and wrong for marketing forms, because it skips the form layer that HubSpot's attribution and automation hang off.
The route we would use, and why
For a B2B marketing site built in Next.js, we would use a custom React form that posts to a Server Action or Route Handler, which then calls HubSpot's secure form submission endpoint with a private app token. We build applications in Next.js, so this is a pattern we would choose for our own stack, and we state that bias plainly.
The form renders on the server, matches the design system and adds no third-party script. The token never reaches the browser. The server can read the hubspotutk cookie with Next.js's cookies function, which is asynchronous since version 15 and readable in Server Functions and Route Handlers (Next.js docs, updated 6 November 2026), and put it in the hutk field with the page URI and page name. Marketing still owns the field list, consent text and workflows in HubSpot. The CRM API is kept for in-app events.
Step list
- Create the form in HubSpot. Add every field the React form will send, plus consent text if you collect it. Note the portal ID and form GUID.
- Create a private app. Give it only the scopes it needs. HubSpot issues a bearer access token; store it as a server-only environment variable, never with a public prefix.
- Install the tracking code once. Load it with next/script in the root layout. Next.js describes afterInteractive, the default, as the strategy for "tag managers" and "analytics" (Next.js Script docs, updated 21 August 2026). If a tag manager also injects the tracking code, remove one of the two copies so each page loads it once.
- Track client-side navigation. In a small client component that watches the pathname, push setPath with the new path, then trackPageView, to the _hsq queue. HubSpot's tracking code API documents exactly this pattern for single-page applications.
- Build the Server Action. Validate input, read hubspotutk, build the fields array with objectTypeId 0-1 for contact properties, add context with hutk, pageUri and pageName, and post to the secure endpoint.
- Map HubSpot's errors to the UI. INVALID_EMAIL, REQUIRED_FIELD and BLOCKED_EMAIL go back to the visitor. FIELD_NOT_IN_FORM_DEFINITION, INVALID_HUTK and FORM_HAS_RECAPTCHA_ENABLED go to your logs, because they are configuration faults.
- Add webhooks only if HubSpot must talk back. If a deal stage should change something in the app, subscribe to that event and verify every request, as below.
- Test attribution end to end. Visit from a tagged campaign URL in a clean browser, browse three pages, submit, and check the contact's source and page views in HubSpot.
What breaks: auth, webhooks and attribution
| Area | What goes wrong | The documented rule |
|---|---|---|
| Auth | Token stops working after a staff change | Removing the user who created a private app can make calls fail with USER_DOES_NOT_HAVE_PERMISSIONS; rotate the token |
| Auth | Token loses scopes | Private apps lose scopes when the account is downgraded |
| Rate limits | Bursts return 429 | 100 or 190 requests per 10 seconds per app, by tier; daily limit shared by all apps in the account |
| Search | Lookups before upsert throttle first | CRM search is limited to five requests per second per account and 10,000 results per query |
| Webhooks | Duplicate or out-of-order events | Up to 10 retries over 24 hours; batches of up to 100 events; no guaranteed order |
| Webhooks | Slow handler counted as failure | A response slower than five seconds is retried |
| Attribution | Contacts with no source | Submission sent without hutk, or tracking cookies blocked by consent |
| Attribution | One page view per visit | Client navigation without setPath and trackPageView |
Sources: HubSpot legacy private apps, usage guidelines, CRM search guide, Webhooks v3 guide and tracking code API (read 17 November 2026)
Auth. A private app token string does not change on its own, which is convenient until the person who created the app leaves. Create the app from an admin account that will outlive the project, and put token rotation in the handover document.
Rate limits. A form endpoint will rarely get near 250,000 calls a day. The trap is code that searches for a contact before every update. HubSpot's official Node client ships with a built-in limiter and, when configured, retries 429 and 5xx responses up to six times (HubSpot api-client README on GitHub).
Webhooks. HubSpot signs each request with an X-HubSpot-Signature-v3 header: an HMAC SHA-256 of the method, URI, raw body and timestamp, keyed with the app's client secret and Base64 encoded. Its docs say to reject timestamps older than five minutes and to compare with a constant-time function. In a Route Handler, read the raw body as text before parsing it, or the hash will not match. Then acknowledge fast and do the work in a queue, because anything over five seconds is retried, and make every handler idempotent, because retries and reordering are normal.
Attribution. HubSpot's hubspotutk and __hstc cookies last six months and are classed as analytics cookies under its cookie banner (HubSpot Knowledge Base, updated 9 September 2026). If a visitor declines, there is no hutk to send, and the contact arrives without browsing history. That is correct behaviour, not a bug, but source reports will undercount in proportion to how many visitors decline, and the team should know that before comparing periods.
Cost at scale
The hosting side is small. The CRM side is not.
| Item | Entry point | What scales it |
|---|---|---|
| Marketing Hub Professional | $800 a month billed annually, $890 monthly; 3 core seats; 2,000 marketing contacts; $3,000 onboarding | Marketing contacts; extra core seats from $45 a month |
| Marketing Hub Enterprise | $3,600 a month; 5 core seats; 10,000 marketing contacts; $7,000 onboarding | Marketing contacts; extra core seats from $75 a month |
| HubSpot API capacity | Free and Starter 250,000 calls a day; Professional 625,000; Enterprise 1,000,000 | API limit increase add-on: 250 per 10 seconds and 1,000,000 more a day each, maximum two |
| Vercel Pro hosting | $20 a month base, $20 per developer seat, with a $20 usage credit | Function invocations from $0.60 per million beyond the included amount |
Sources: HubSpot Marketing Hub pricing page and API usage guidelines; Vercel pricing page (read 17 November 2026)
A site taking 10,000 form submissions a month makes about 10,000 form API calls, a fraction of one day's Starter allowance, and the same number of function invocations, well under a cent at Vercel's listed overage rate. Those 10,000 new contacts, if all marketed to, are five times Professional's included marketing contacts. HubSpot does not list the price of extra contact tiers or the API add-on on the pages we read, so get those from sales before you commit to a volume plan.
What this means for a team wiring Next.js to HubSpot
Decide who owns the form first. If marketing must change fields without a deploy, use the embed and accept the script. If the site has a design system and a performance budget, use your own form, submit through the server with hutk and page context, and track client-side navigation by hand. Keep direct CRM writes for product events, verify every webhook signature, and budget for marketing contacts rather than for servers. Our web apps service page explains how we would scope an integration like this.


