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 🙏

© 2024 – Pkg Stats / Ryan Hefner

next-umami

v0.0.4

Published

Simple integration for https://nextjs.org and https://umami.is analytics.

Downloads

165

Readme

next-umami

Simple integration for https://nextjs.org and https://umami.is analytics.

Usage

Include the Analytics Script

To enable Umami analytics in your Next.js app you'll need to expose the Umami context.

If you're using the app router include UmamiProvider inside the root layout:

// app/layout.js
import UmamiProvider from 'next-umami'

export default function RootLayout({ children }) {
  return (
    <html>
      <head>
        <UmamiProvider websiteId="a3d85e62-dc8b-4d4b-bd1f-e8a71b55d3cf" />
      </head>
      <body>{children}</body>
    </html>
  )
}

If you're using the pages router include the UmamiProvider inside _app.js:

// pages/_app.js
import UmamiProvider from 'next-umami'

export default function MyApp({ Component, pageProps }) {
  return (
    <UmamiProvider websiteId="a3d85e62-dc8b-4d4b-bd1f-e8a71b55d3cf">
      <Component {...pageProps} />
    </UmamiProvider>
  )
}

If you want to enable Umami analytics only on a single page you can wrap the page in a UmamiProvider component:

// pages/home.js
import UmamiProvider from 'next-umami'

export default function Home() {
  return (
    <UmamiProvider websiteId="a3d85e62-dc8b-4d4b-bd1f-e8a71b55d3cf">
      <h1>My Site</h1>
      {/* ... */}
    </UmamiProvider>
  )
}

UmamiProvider Props

| Name | Type | Description | | ------------ | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | websiteId | string | Website ID found in Umami dashboard. https://umami.is/docs/collect-data. | | src? | string | By default it's set to https://cloud.umami.is/script.js. You can override this in case you're self-hosting. | | hostUrl? | string | By default, Umami will send data to wherever the script is located. You can override this to send data to another location. See in docs. | | autoTrack? | boolean | By default, Umami tracks all pageviews and events for you automatically. You can disable this behavior and track events yourself using the tracker functions. See in docs. | | domains? | string[] | If you want the tracker to only run on specific domains, you can add them to your tracker script. This is a comma delimited list of domain names. Helps if you are working in a staging/development environment. See in docs. | | onLoad? | (e: any) => void | Execute code after Umami has loaded. | | onReady? | () => void \| null | Execute code after Umami's load event when it first loads and then after every subsequent component re-mount. | | onError? | (e: any) => void | Handle errors if Umami fails to load. |

Send Custom Events

The useUmami hook exposes two functions that you can call on your website if you want more control over your tracking. By default, everything is automatically collected, but you can disable this using autoTrack={false} in UmamiProvider and send the data yourself.

Pageview

Default properties are automatically sent. If you wish to override any property, use the umami.pageView function like this:

import { useUmami } from 'next-umami'

export default function Page() {
  const umami = useUmami()

  // Default Pageview
  umami.pageView()
  
  // OR

  // Custom Pageview
  umami.pageView({
    url: '/custom-pageview',
  })

  return <h1>My Page</h1>
}

Pageview Props

| Name | Type | Description | | ----------- | -------- | ---------------------------------- | | hostname? | string | Hostname of server | | language? | string | Browser language | | referrer? | string | Page referrer | | screen? | string | Screen dimensions (e.g. 1920x1080) | | title? | string | Page title | | url? | string | Page URL |

Events

Access the umami.event function like this:

import { useUmami } from 'next-umami'

export default function UmamiButtons() {
  const umami = useUmami()

  return (
    <>
      {/* Basic Event */}
      <button onClick={() => umami.event('Basic Event')}>Submit</button>

      {/* Custom Event */}
      <button
        onClick={() =>
          umami.event('Custom Event', {
            userAgent: window.navigator.userAgent,
          })
        }
      >
        Submit with custom data
      </button>
    </>
  )
}

Event Props

| Name | Type | Description | | ------- | ---------------------------------- |---------------------------| | name | string | Name of the event | | data? | Record<string, string \| number> | Custom data for the event |

  • Numbers have a max precision of 4.
  • Strings have a max length of 500.
  • Arrays are converted to a String, with the same max length of 500.
  • Objects have a max of 50 properties. Arrays are considered 1 property.