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-lytics

v0.1.0

Published

Zero-config Analytics stack for Next.js that just works.

Downloads

4

Readme

next-lytics

Zero-config Analytics stack for Next.js that just works.

Run your own Segment-like analytics multiplexer, powered by the Analytics package.

The primary motivation behind this was to just have an inclusive, startup-collection of analytics that are packaged together rather than yarn add analytics-package-xyz 10 times for every new project. By taking advantage of Next.js tree shaking we only include the plugins during build-time that are being used.

Installation

1. Add the next-lytics package

yarn add next-lytics

2. Add the Analytics Provider to app.jsx

// pages/_app.jsx

import AnalyticsProvider from "next-lytics"
import { FullStory } from "next-lytics/plugins"

const plugins = [
  FullStory({
    org: "12345",
  }),
  // ... add more plugins here
]

function MyApp({ Component, pageProps }) {
  return (
    <AnalyticsProvider plugins={plugins}>
      <Component {...pageProps} />
    </AnalyticsProvider>
  )
}

export default MyApp

3. Use in your Components

import { useAnalytics } from "next-lytics"

export default function MyComponent() {
  const { track } = useAnalytics()

  return (
    <button onClick={() => track("Button Clicked")}>Click me to track</button>
  )
}

Methods

track

Track an analytics event. Full documentation: https://github.com/DavidWells/analytics#analyticstrack

page

Trigger page view. Full documentation: https://github.com/DavidWells/analytics#analyticspage.

Note - The Analytics provider will automatically track Next.js page views, only use this if you need to trigger a custom page event.

identify

Identify a user. Full documentation: https://github.com/DavidWells/analytics#analyticsidentify

Plugins

next-lytics supports a number of plugins out of the box by default but can be extended easily.

Any anaytics plugin listed in here can be added to the Analytics stack: https://github.com/DavidWells/analytics#analytic-plugins

Built-In Plugins

Our goal is to support the major analytics platforms that any new Next.js project/startup would likely use, without the need to npm install a ton of external libraries.

Amplitude

Full documentation on plugin here: https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-amplitude

import { Amplitude } from "next-lytics/plugins"

const plugins = [
  Amplitude({
    apiKey: "token",
  }),
]

| Option | Type | Required | Description | Default | | :-------- | :------- | -------- | ------------------------- | ------- | | apiKey | string | yes | Amplitude project API key | | options | object | | Amplitude SDK options |

Google Analytics

Full documentation on plugin here: https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-google-analytics

import { GoogleAnalytics } from "next-lytics/plugins"

const plugins = [
  GoogleAnalytics({
    trackingId: "UA-1234567",
  }),
]

Configuration

| Option | Type | Required | Description | Default | | :---------------------------- | :-------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | | trackingId | string | yes | Google Analytics site tracking Id | | debug | boolean | | Enable Google Analytics debug mode | | anonymizeIp | boolean | | Enable Anonymizing IP addresses sent to Google Analytics. See details below | | customDimensions | object | | Map Custom dimensions to send extra information to Google Analytics. See details below | | resetCustomDimensionsOnPage | object | | Reset custom dimensions by key on analytics.page() calls. Useful for single page apps. | | setCustomDimensionsToPage | boolean | | Mapped dimensions will be set to the page & sent as properties of all subsequent events on that page. If false, analytics will only pass custom dimensions as part of individual events | | instanceName | string | | Custom tracker name for google analytics. Use this if you need multiple googleAnalytics scripts loaded | | customScriptSrc | string | | Custom URL for google analytics script, if proxying calls | | cookieConfig | object | | Additional cookie properties for configuring the ga cookie | | tasks | object | | Set custom google analytic tasks |

FullStory

Website: https://fullstory.com/

Repository: https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-fullstory#readme

import { FullStory } from "next-lytics/plugins"

const plugins = [
  FullStory({
    org: "12345",
  }),
]

Configuration

| Option | Type | Required | Description | Default | | ------ | -------- | -------- | -------------------------------------------------------------- | ------- | | org | string | yes | FullStory account's org ID. The _fs_org value in settings. | |

Plausible

Website: https://plausible.io/

Repository: https://github.com/DavidWells/analytics/tree/master/packages/analytics-plugin-fullstory#readme

import { Plausible } from "next-lytics/plugins"

const plugins = [
  Plausible({
    domain: "example.com",
  }),
]

Configuration

| Option | Type | Required | Description | Default | | -------------- | -------- | -------- | ----------------------------------------------------------------- | ------------------------ | | domain | string | yes | Your site's domain, as declared by you in Plausible's settings | location.hostname | | hashMode | bool | | Enables tracking based on URL hash changes. | false | | trackLocalhost | bool | | Enables tracking on localhost. | false | | apiHost | string | | Plausible's API host to use. Change this if you are self-hosting. | 'https://plausible.io' |

LogRocket

Full documentation on plugin here: https://github.com/ian/analytics/tree/main/packages/logrocket

import { LogRocket } from "next-lytics/plugins"

const plugins = [
  LogRocket({
    appId: "123456",
  }),
]

Configuration

| Option | Type | Required | Description | Default | | ------ | -------- | -------- | --------------------- | ------- | | appId | string | yes | Your LogRocket App ID |

Indicative

Website: https://www.indicative.com/

Repository: https://github.com/ian/analytics/tree/main/packages/indicative

import { Indicative } from "next-lytics/plugins"

const plugins = [
  Indicative({
    apiKey: "123456",
  }),
]

Configuration

| Option | Type | Required | Description | Default | | ------ | -------- | -------- | ----------------------- | ------- | | apiKey | string | yes | Your Indicative API key |

Splitbee

Website: https://splitbee.io/

Repository: https://github.com/ian/analytics/tree/main/packages/splitbee

import { Splitbee } from "next-lytics/plugins"

const plugins = [
  Splitbee({
    token: "123456",
  }),
]

Configuration

| Option | Type | Required | Description | Default | | ------ | -------- | -------- | ----------------------- | ------- | | token | string | yes | Your Splitbee API token |

Adding a Custom Plugin

Just install the plugin and add it to your plugins config. You can use any Analytics compatible plugin from here: https://github.com/DavidWells/analytics#analytic-plugins

yarn add analytics-custom-plugin
import CustomPlugin from "analytics-custom-plugin"

const plugins = [
  CustomPlugin({
    id: "xyz",
    // ... other config
  }),
]