Guides

Next.js + HubSpot: The Integration Guide, With the Gotchas (2026)

How to connect a Next.js site to HubSpot in 2026: the three ways to send form data, the server-side route we would pick, the setup steps, and what breaks in auth, webhooks and attribution.

Summarize with AI
Octo Agency cover: Next.js + HubSpot, with a purple hexagon pattern

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.

Three ways to send Next.js form data to HubSpot
MethodHow it worksAttributionWho controls the formMain risk
HubSpot embedHubSpot's script renders the form inside a client componentNative, when the tracking code is on the pageMarketing, in HubSpot's form editorThird-party script weight and styling limits
Forms submission APIYour own React form posts to HubSpot's form endpoint, ideally from the serverKept, if you pass the hutk cookie and page URL in the context objectDevelopers own the markup; marketing owns the field list in HubSpotForgetting hutk, so contacts arrive with no source
CRM objects APIYour server creates or updates the contact directly with a private app tokenLost by default: no form submission, no page context attachedDevelopers onlyContacts without browsing history, and no form-triggered workflows
Collected forms (not usable)Tracking code scrapes plain HTML formsNative, when it worksNobody, it is automaticNot 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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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

Common failure points and the documented limit behind each
AreaWhat goes wrongThe documented rule
AuthToken stops working after a staff changeRemoving the user who created a private app can make calls fail with USER_DOES_NOT_HAVE_PERMISSIONS; rotate the token
AuthToken loses scopesPrivate apps lose scopes when the account is downgraded
Rate limitsBursts return 429100 or 190 requests per 10 seconds per app, by tier; daily limit shared by all apps in the account
SearchLookups before upsert throttle firstCRM search is limited to five requests per second per account and 10,000 results per query
WebhooksDuplicate or out-of-order eventsUp to 10 retries over 24 hours; batches of up to 100 events; no guaranteed order
WebhooksSlow handler counted as failureA response slower than five seconds is retried
AttributionContacts with no sourceSubmission sent without hutk, or tracking cookies blocked by consent
AttributionOne page view per visitClient 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.

What grows with traffic, and what it costs
ItemEntry pointWhat scales it
Marketing Hub Professional$800 a month billed annually, $890 monthly; 3 core seats; 2,000 marketing contacts; $3,000 onboardingMarketing contacts; extra core seats from $45 a month
Marketing Hub Enterprise$3,600 a month; 5 core seats; 10,000 marketing contacts; $7,000 onboardingMarketing contacts; extra core seats from $75 a month
HubSpot API capacityFree and Starter 250,000 calls a day; Professional 625,000; Enterprise 1,000,000API 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 creditFunction 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.

Frequently asked questions

Can I use HubSpot forms in Next.js?

Yes, in two ways. You can embed HubSpot's form script inside a client component, which keeps editing in HubSpot but adds a third-party script and limits styling. Or you can build your own React form and post it to HubSpot's form submission API. HubSpot's collected-forms feature, which captures plain HTML forms automatically, does not support single-page apps or forms with JavaScript submit handlers, so it is not an option on a typical Next.js site.

Should I call the HubSpot API from the browser or the server?

From the server for anything authenticated. The basic form submission endpoint needs no token and accepts cross-origin requests, so a browser call works, but the secure endpoint, the CRM API and webhooks all need a private app token, which must never be shipped to the client. A Server Action or Route Handler can also read the hubspotutk cookie with Next.js's cookies function and pass it to HubSpot as hutk.

Why do contacts from my Next.js site show no traffic source in HubSpot?

Usually because the submission reached HubSpot without the hutk value, so HubSpot could not link the contact to the visitor's earlier page views. Read the hubspotutk cookie and send it in the context object with the page URI. The second cause is consent: hubspotutk is an analytics cookie under HubSpot's banner, and a visitor who declines has none. A third is missing setPath and trackPageView calls on client-side navigation.

What are HubSpot's API rate limits for a private app?

Per HubSpot's usage guidelines, Free and Starter accounts get 100 requests per 10 seconds per app and 250,000 a day per account. Professional gets 190 per 10 seconds and 625,000 a day; Enterprise 190 and 1,000,000. An API limit increase raises the burst to 250 and adds 1,000,000 a day, with at most two per account. CRM search has its own limit of five requests per second.

How do I verify HubSpot webhooks in a Next.js Route Handler?

Read the raw request body as text, then build a string of method, full URI, body and the X-HubSpot-Request-Timestamp value. Hash it with HMAC SHA-256 using the app's client secret, Base64 encode it, and compare it with the X-HubSpot-Signature-v3 header using a constant-time comparison. Reject timestamps older than five minutes. Respond within five seconds, because HubSpot retries slower responses up to 10 times over 24 hours.

Sources

  1. Use non-HubSpot forms HubSpot Knowledge Base, 2026
  2. Submit data to a form (unauthenticated) HubSpot Developers, 2026
  3. Submit data to a form (supporting authentication) HubSpot Developers, 2026
  4. API usage guidelines and limits HubSpot Developers, 2026
  5. HubSpot tracking code API HubSpot Developers, 2026
  6. Webhooks v3 API guide HubSpot Developers, 2026
  7. Validating requests HubSpot Developers, 2026
  8. Legacy private apps HubSpot Developers, 2026
  9. Search the CRM HubSpot Developers, 2026
  10. What cookies does HubSpot set in a visitor's browser? HubSpot Knowledge Base, 2026
  11. Marketing Hub pricing HubSpot, 2026
  12. hubspot-api-nodejs README HubSpot on GitHub, 2026
  13. Script component Next.js, 2026
  14. cookies Next.js, 2026
  15. Vercel pricing Vercel, 2026

Tags

  • Next.js
  • HubSpot
  • Integrations
  • Attribution
Mihajlo Stojanovic

Mihajlo Stojanovic

Co-founder, Octo Agency

Mihajlo runs the technical side of Octo Agency: Webflow builds, custom backends and the systems that keep a site editable after launch. He has shipped more than twenty Webflow sites a year as a white-label partner and writes about what survives contact with a real marketing team.

Veljko Nikolic

Reviewed by

Veljko Nikolic

Founder, Octo Agency

Veljko runs the build side of Octo Agency. He has shipped marketing sites for B2B teams in legal tech, health and manufacturing, and writes about what survives contact with a real review cycle.