npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@se-studio/hubspot

v17.0.1

Published

HubSpot tracking and API-driven form rendering for Next.js marketing sites

Readme

@se-studio/hubspot

HubSpot tracking and API-driven form rendering for Next.js marketing sites.

Features

  • HubSpotAnalyticsAdapterAnalyticsAdapter for HubSpot tracking code (SPA Mode B page views, custom behavioural events)
  • HubspotDynamicForm — React renderer from HubSpot Marketing Forms API definitions
  • UTM / marketing hidden fields — auto-fills empty hidden form fields from URL query params and first-touch sessionStorage (utm_source, utm_medium, utm_campaign, utm_term, utm_content, plus any query key that matches a hidden field name)
  • createHubspotFormExternalRenderer — CMS external component factory (externalComponentType: "Hubspot form")
  • Per-form fetchGET /marketing/v3/forms/{formId} with Next.js unstable_cache (no bulk form download)

Installation

pnpm add @se-studio/hubspot

Environment variables

| Variable | Purpose | |----------|---------| | HUBSPOT_PORTAL_ID | Portal ID for tracking script and form submissions | | HUBSPOT_PAT | Private app token with forms scope (server-only, form definition fetch) |

Analytics (with GTM)

import { AnalyticsPageTracker, AnalyticsProvider, CompositeAnalyticsAdapter, ConsentAwareAdapter, GoogleTagManagerAdapter } from '@se-studio/core-ui';
import { AbTestReporter } from '@se-studio/ab-testing/components';
import { HubSpotAnalyticsAdapter, createHubSpotBootstrapScript } from '@se-studio/hubspot';
import Script from 'next/script';

const adapter = new ConsentAwareAdapter(
  new CompositeAnalyticsAdapter([
    new GoogleTagManagerAdapter({ containerId: process.env.GTM_TAG! }),
    new HubSpotAnalyticsAdapter({ portalId: process.env.HUBSPOT_PORTAL_ID! }),
  ]),
  'analytics',
  hasConsent,
);

// layout.tsx — before HubSpot script loads (no args = SSG-safe; uses window.location.pathname)
<Script id="hubspot-bootstrap" strategy="beforeInteractive"
  dangerouslySetInnerHTML={{ __html: createHubSpotBootstrapScript() }} />

<AnalyticsProvider adapter={adapter}>
  <AnalyticsPageTracker />
  <AbTestReporter />
  {children}
</AnalyticsProvider>

CMS external component

Add "Hubspot form" to your externalComponent enum. data JSON:

{
  "formId": "hubspot-form-guid",
  "portalId": "optional-override",
  "submitButtonText": "Optional label",
  "hiddenFields": { "campaign": "value" }
}
import { defineExternalComponent } from '@se-studio/core-ui';
import { createHubspotFormExternalRenderer } from '@se-studio/hubspot/external';
import { Section } from '@/framework/Section';

export const HubspotFormRegistration = defineExternalComponent({
  name: 'Hubspot form',
  renderer: createHubspotFormExternalRenderer({
    wrap: ({ information, children, componentName }) => (
      <Section information={information} componentName={componentName}>
        {children}
      </Section>
    ),
  }),
});

Hidden UTM / campaign fields

If the HubSpot form defines hidden fields whose internal names match query params (e.g. utm_source, utm_medium, utm_campaign, utm_term, utm_content), HubspotDynamicForm fills them on mount from:

  1. HubSpot form defaults (if any)
  2. First-touch sessionStorage + current URL (URL wins for keys present on the form page)
  3. CMS data.hiddenFields / data.initialValues (highest — static overrides win)

First-touch is stored under sessionStorage key se_studio_marketing_params so a visitor who lands with UTMs on / and submits on /contact-us/ still attributes correctly.

Sites that fork the form renderer should call the same helpers (do not reimplement):

import {
  applyMarketingParamsToHiddenFields,
  buildDefaultValues,
  captureMarketingParams,
} from '@se-studio/hubspot';

// Optional: call once in a root client provider so multi-page capture runs before the form mounts
captureMarketingParams();

// When seeding form state (same order as HubspotDynamicForm):
setFormData(buildDefaultValues(formDefinition, hiddenFields, initialValues));
// or applyMarketingParamsToHiddenFields(formDefinition, baseDefaults)

Submissions already send Forms API context (hutk, pageUri, pageName) via useHubspotSubmit.

Post-submit behaviour

These forms are not HubSpot’s native embed script — the package rebuilds fields from the Marketing Forms API and posts via the Forms Submit API. Redirect / thank-you must be handled in our client:

| Priority | Source | Behaviour | |----------|--------|-----------| | 1 | redirectUrlOverride prop | CMS override (e.g. Contentful externalUrl or data.successRedirectUrl) | | 2 | Submit API redirectUri | Includes HubSpot conditional redirects when returned | | 3 | Form definition postSubmitAction type redirect_url | Configured in HubSpot form editor | | 4 | inlineMessage / thank_you | Inline message on the form |

Navigation: external absolute URLs use window.location.assign; same-origin paths use Next.js router.push. Full redirect URLs are preserved (hosts are not stripped).

onSuccess: side-effect only (analytics, swap to CMS extraCopy). It does not suppress thank-you or redirect. When a redirect is configured, navigation wins after the callback.

<HubspotDynamicForm
  portalId={portalId}
  formDefinition={formDefinition}
  redirectUrlOverride={cmsExternalUrl} // optional CMS override
  onSuccess={() => setShowExtraCopy(true)} // optional; redirect still runs if set
/>

Cache revalidation

When a form changes in HubSpot, revalidate:

import { revalidateTag } from 'next/cache';
import { hubspotFormTag } from '@se-studio/hubspot/server';

revalidateTag(hubspotFormTag(formId), { expire: 0 });