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

nuxt-analytic-reports

v1.0.3

Published

Nuxt Analytic Reports Module

Downloads

15

Readme

Nuxt Analytic Reports Module

npm version npm downloads License Nuxt

This SSR-enabled Nuxt module allows running of reports via the Google Analytics Data API, and includes pre-defined reports and composables for trending and popular posts, as well as an AnalyticsWidget component for trending and popular posts.

API responses are cached on the server side and expire

Features

  • Filtering of paths (exact strings or RegEx) from report data, filtering parameters are supplied to the API
  • String removal (exact string or RegEx)
  • Trending and Popular reports, composables and a AnalyticeWidget component.

TODO:

  • Ability to define your own reports: this is partially implemented, need to figure out the best way to pass functions to the module from the configuration.

Quick Setup

  1. Add nuxt-analytic-reports dependency to your project
# Using pnpm
pnpm add -D nuxt-analytic-reports

# Using yarn
yarn add --dev nuxt-analytic-reports

# Using npm
npm install --save-dev nuxt-analytic-reports
  1. Add nuxt-analytic-reports to the modules section of nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    'nuxt-analytic-reports'
  ]
})
  1. Add configuration for the module:
export default defineNuxtConfig({
  // ...
  analyticsData: {
    // Specify the path to your GA credentials file or use `credentials` with the data itself
    credentialsFile: "./example/service-account.json",
    // The GA4 property ID you are accessing
    propertyId: "343159656",
    // Clear API response cache after 15 minutes (value is in seconds)
    cacheTimeout: 15 * 60,
    // Use `filteredPaths` to exclude paths from your query, i.e. if you
    // don't want the homepage or contact page.
    filteredPaths: {
      // Exact path filters
      exact: ["/references"],
      // RegEx Path filters -- ex: filter any first-level paths (i.e. "/blog" "/projects")
      regEx: [`^/(\\w+)?\\/?$`]
    },

    // removeStrings will remove any matching text from the pageTitles in results
    removeStrings: {
      // Exact matches, ex: removing trailing tags from the title
      exact: [` - Larry Williamson`],
      // and/or RegEx matches
      regEx: [` - .* - Larry Williamson`]
    }
    // ...
  }
});

That's it! You can now use Nuxt Analytics Data Module in your Nuxt app ✨

Usage

$analyticsData

The retrieved data is stored in useState('analyticsData') as well as provided in the Nuxt application as $analyticsData

const {$analyticsData} = useNuxtApp()

const analyticsData = useState("analyticsData")

Data is formatted like this:


{
  "popular": {
    "/blog": {
      "pageTitle": "Blog",
      "screenPageViews": "129"
    },
    "/blog/countdown-for-vue-with-composables": {
      "pageTitle": "Building a Countdown Component for Vue with Composables",
      "screenPageViews": "96"
    }
  },
  "trending": {
    "/": {
      "pageTitle": "Home",
      "screenPageViews": "999999"
    }
  }
}

usePopular and useTrending composables

Provides the specific data from the analyticsData object

const allPopular = await usePopular()
const allTrending = await useTrending()

usePagePopular and usePageTrending composables

Returns a boolean indicating whether a page is within popular or trending page lists. If no argument is supplied it uses the current route path.

<template>
  <nav>
    <NuxtLink :to="/blog">Blog<span v-if="trendingBlog"> 🔥</span></NuxtLink>
  </nav>
</template>
<script lang="ts" setup>
  const popular = await usePagePopular()
  const trending = await usePageTrending()

  const popularBlog = await usePagePopular("/blog")
  const trendingBlog = await usePageTrending("/blog")
</script>

Then

Development

# Install dependencies
npm install

# Generate type stubs
npm run dev:prepare

# Develop with the example
npm run dev

# Build the example
npm run dev:build

# Run ESLint
npm run lint

# Run Vitest
npm run test
npm run test:watch

# Release new version
npm run release