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

nuxt-hubspot

v0.0.2

Published

HubSpot analytics integration for Nuxt with typesafe event tracking and DevTools panel

Readme

nuxt-hubspot

npm version npm downloads License Nuxt

HubSpot analytics integration for Nuxt. Typesafe event tracking with auto page views, identify gating, and a Nuxt DevTools panel.

Features

  • Auto page tracking — tracks route changes automatically via Vue Router
  • Identify gating — optionally block events until a user is identified
  • Typesafe events — createTracker<EventMap>() gives autocomplete and type checking on event names and properties
  • DevTools panel — see all events in real-time inside Nuxt DevTools
  • Dev mode — events are logged to DevTools instead of sent to HubSpot during development
  • Zero config in dev — works without a portal ID in development mode

Quick Setup

Install the module:

pnpm add nuxt-hubspot

Add it to nuxt.config.ts:

export default defineNuxtConfig({
  modules: ['nuxt-hubspot'],

  hubspot: {
    // Option 1: set portal ID here
    hubspotPortalId: '12345678',
  },
})

Or use an environment variable instead:

NUXT_PUBLIC_HUBSPOT_PORTAL_ID=12345678

Usage

Basic tracking

useHubspot() is auto-imported and provides the core API:

const { identify, log, page, reset } = useHubspot()

// Identify a user (required before events fire, unless requireIdentify is false)
identify('[email protected]', { name: 'Jane Doe', plan: 'pro' })

// Track a custom event
log('form_submitted', { formId: 'contact', source: 'homepage' })

// Track a page view manually (automatic by default)
page({ page: '/custom-path', source: 'app' })

// Reset on logout
reset()

Typesafe events with createTracker

Define your event map and get full type checking:

// composables/useTracking.ts
type TrackingEventMap = {
  newsletter_sent: { newsletter_id: number, subject: string }
  social_media_posted: { post_group_id: number, platform: string }
  form_submitted: { form_id: string }
}

export const useTracking = () => {
  const { identify, page, reset } = useHubspot()
  const track = createTracker<TrackingEventMap>()

  return { identify, page, reset, track }
}

Then use it in your components:

<script setup lang="ts">
const { track } = useTracking()

// Autocompletes event names, enforces correct properties
track('newsletter_sent', { newsletter_id: 1, subject: 'Weekly update' })

// Type error: unknown event
track('invalid_event', {})

// Type error: wrong properties
track('newsletter_sent', { wrong_prop: true })
</script>

Configuration

| Option | Type | Default | Description | |---|---|---|---| | hubspotPortalId | string | — | HubSpot portal ID. Also accepts NUXT_PUBLIC_HUBSPOT_PORTAL_ID env var. | | autoPageTracking | boolean | true | Automatically track page views on route changes. | | requireIdentify | boolean | true | Block log and page events until identify() is called. Set to false for anonymous tracking. | | sendDevMetrics | boolean | false | Send events to HubSpot in development mode. By default, dev events only go to the DevTools panel. |

API

useHubspot()

Auto-imported composable returning the HubSpot client:

| Method | Signature | Description | |---|---|---| | log | (event: string, properties?: Record<string, unknown>) => void | Track a custom event. | | identify | (userId: string, traits?: Record<string, unknown>) => void | Identify a user by ID (typically email). | | page | (properties?: Record<string, unknown>) => void | Track a page view with optional properties. | | reset | () => void | Clear the identified user and reset the HubSpot session. |

When the module is disabled (no portal ID in production), all methods are safe no-ops.

createTracker<EventMap>()

Auto-imported factory that returns a typesafe track function:

const track = createTracker<{ my_event: { count: number } }>()
track('my_event', { count: 42 }) // ok
track('my_event', { wrong: true }) // type error
track('unknown', {}) // type error

DevTools

When Nuxt DevTools is enabled, a HubSpot tab appears showing:

  • All events in real-time (identify, track, page, reset)
  • Expandable rows with syntax-highlighted event data
  • Type filter chips
  • Identified/anonymous status indicator
  • Clear button

Events are sent via BroadcastChannel so the DevTools panel works regardless of iframe nesting.

How It Works

The module uses the analytics library with the @analytics/hubspot plugin under the hood. In development mode, events go to the DevTools panel instead of HubSpot. In production, the HubSpot tracking script is loaded and events are forwarded to your HubSpot portal.

Development

# Install dependencies
pnpm install

# Generate type stubs
pnpm dev:prepare

# Develop with playground + devtools client
pnpm dev

# Run tests
pnpm test

# Lint
pnpm lint

# Build for production
pnpm prepack

License

MIT