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

@vtex/raccoon-analytics

v0.2.0

Published

Send analytics events in frontend apps

Readme

@vtex/raccoon-analytics

Send events to track your frontend apps.

This is based on the work done on the following document: Analytics for frontend apps: setup

Usage

Add the dependency to your package file:

yarn add @vtex/raccoon-analytics

Import the sendAnalyticEvent function where you want to create an event:

import { sendAnalyticEvent } from '@vtex/raccoon-analytics'

Trigger the function:

sendAnalyticEvent(APP_NAME, {
  eventCategory: 'view',
  eventName: 'index-page-test',
})

The function accepts two parameters:

  1. APP_NAME, a string

[!IMPORTANT] It should have the same value for all events in a same app

  1. An object with the type DataIngestionApiFields:
type DataIngestionApiFields = {
  /**
   * The name of the event. It has to be unique throughout the app.
   */
  eventName: string
  /**
   * The type of the event, generally click for a user action and view for a page view.
   *
   * @default 'click'
   */
  eventCategory?: 'click' | 'view' | 'apiAnswer' | 'webVitals'
  /**
   * Additional informations for webVitals
   */
  metric?: WebVitalsMetric
} & Record<string, string>

Here are the fields of the WebVitalsMetric type:

type WebVitalsMetric = {
  id: string
  name: 'FCP' | 'LCP' | 'CLS' | 'FID' | 'TTFB' | 'INP'
  delta: number
  entries: []
  navigationType: 'navigate' | 'reload' | 'back_forward' | 'prerender'
  rating: 'good' | 'needs-improvement' | 'poor'
  value: number
}

The following fields are also sent automatically:

const commonFields: Record<AdminContextFields, string> = {
  account: adminContext.account,
  locale: adminContext.locale ?? 'undefined',
  production: adminContext.production ? 'true' : 'false',
  workspace: adminContext.workspace,
  device: deviceType,
  basePath: adminContext.basePath,
  path: adminContext.path ?? 'undefined',
}

adminContext comes from the adminStore of the @vtex/raccoon-next package.

Click events

The most common event. Track user interactions on links, buttons, drawers, etc. The eventCategory property has the default value click so you do not need to include it for this event.

sendAnalyticEvent(APP_NAME, {
  eventCategory: 'click',
  eventName: 'index-page-back-button',
})

View events

Events for page views:

sendAnalyticEvent(APP_NAME, {
  eventCategory: 'view',
  eventName: 'index-page',
})

Extra possibilities

As stated by the Record<string, string> part of the type DataIngestionApiFields, you can add extra informations thanks to the fact that we use the schemaless approach.

Web Vitals

You can send Web Vitals events to track the performance of your app. Here is an exmaple with the next/web-vitals package for NextJS:

import { useReportWebVitals } from 'next/web-vitals'

useReportWebVitals((metric) => {
  sendAnalyticEvent(APP_NAME, {
    eventCategory: 'webVitals',
    eventName: `webvitals_${route}`,
    webVitalMetric: metric,
  })
})

Here we use a dynamic page with {route} so that we can filter the events by page.

Fields of the WebVitalsMetric type:

type WebVitalsMetric = {
  id: string
  name: 'FCP' | 'LCP' | 'CLS' | 'FID' | 'TTFB' | 'INP'
  delta: number
  entries: []
  navigationType: 'navigate' | 'reload' | 'back_forward' | 'prerender'
  rating: 'good' | 'needs-improvement' | 'poor'
  value: number
}

Time on page

Track how much time a user spends on a page before performing an action:

sendAnalyticEvent({
  eventName: 'index-page-back-button',
  timer: a_number_in_ms,
})

Example with React:

export const usePageTimeTracker = () => {
  const startTimeRef = useRef<number | null>(null)

  useEffect(() => {
    startTimeRef.current = Date.now()

    // Cleanup on unmount
    return () => {
      startTimeRef.current = null
    }
  }, [])

  const getTimeSpent = () => {
    if (startTimeRef.current !== null) {
      const timeSpent = Date.now() - startTimeRef.current

      return timeSpent
    }

    return 0
  }

  return { getTimeSpent }
}
const { getTimeSpent } = usePageTimeTracker()

sendAnalyticEvent({
  eventName: 'index-page-back-button',
  time_on_page: getTimeSpent(),
})

More infos

Send your question on the #admin-platform or #frontend-chapter Slack channels.