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

@elianvancutsem/mostvisitedpages

v0.0.9

Published

This package fetches and returns your most viewed pages based on Google Analytics

Downloads

4

Readme

MostVisitedPages

Package created to fetch your x most frequent visited pages from Google Analytics and the Google Analytics Data API.

Both TypeScript and ESModules are supported

Installation

npm i @elianvancutsem/mostvisitedpages

or use a CDN like Skypack

import { MostVisitedPages } from "https://cdn.skypack.dev/@elianvancutsem/[email protected]";

Using @elianvancutsem/mostvisitedpages

The MostVisitedPages constructor takes in two required parameters: credentials & propertyId and one possible undefined parameter options.

credentials

Credentials has two variables; client_email and private_key. Both of these can be created by creating a JSON Service Account.

Follow the Official Google Analytics Data API documentation for more information about how to do this.

propertyId

The PropertyId is the PropertyID of the Google analytics property.

NOTE: the Service account should be added with read & analyze access to the property.

options

The options parameter will be used for more configuration options in the future, but is only used right now to exclude certain url's from the return array. The only downside to this is that if you set a limit on your request and x number of url's are exluded, the result will return xresults less instead of your set limit

Example

import { MostVisitedPages } from "@elianvancutsem/mostvisitedpages";

const testEmail = "xxx"
const testKey = "xxx"
const options = {
    exludeUrls = ['www.elian.codes/']
}

const mostVisitedPages = new MostVisitedPages({client_email: testEmail, private_key: testKey}, 'xxxxxxxx', options)

Functions

getPageViews(limit?: number)

Function that returns an array of the x most viewed pages in the last 90 days according to Google Analytics.

This function returns an array of the Page type (which can be imported from @elianvancutsem/mostvisitedpages)

The limit parameter provides a limit to the number of pages returned, will default to 10 if none is set.

getPageViewsSince(startDate: string, limit?: number)

Works like getPageViews() but with a required startDate.

The startDate parameter can be a date like 2021-10-01 (YYYY-MM-DD) or can be a sring like NdaysAgo or yesterday. It will default to the past 90 days if none is provided.

getAllPageViewsSince(startDate: string)

Works like getPageViewsSince() but without a limit on pages.

getActiveUsers(limit?: number)

works like getPageViews(), but returns the active users instead of the views.

getActiveUsersSince(startDate: string, limit?: number)

works like getPageViewsSince(), but returns the active users instead of the views.

Types

types can be imported from @elianvancutsem/mostvisitedpages like the following:

import { Page } from '@elianvancutsem/mostvisitedpages';

Options

{
    excludeUrls?: string[]
}

Page

{
    title: string
    url: string
    views?: number
    users?: number
}

Credentials

{
    client_email: string
    private_key: string
}

CommonJS Support

To use this package with CommonJS, use require(@elianvancutsem/mostvisitedpages) instead of import. Below is an example

const mvp = require("@elianvancutsem/mostvisitedpages");

const testEmail = "xxx"
const testKey = "xxx"

const mostVisitedPages = new mvp.MostVisitedPages({client_email: testEmail, private_key: testKey}, 'xxxxxxxx')

const getReport = async () => {
    console.log(await mostVisitedPages.getPageViewsSince('yesterday', 4));
}

getReport();

Full Example

import { MostVisitedPages } from "@elianvancutsem/mostvisitedpages";

const testEmail = "xxx"
const testKey = "xxx"

const mostVisitedPages = new MostVisitedPages({client_email: testEmail, private_key: testKey}, 'xxxxxxxx')

const getReport = async () => {
    console.log(await mostVisitedPages.getPageViewsSince('yesterday', 4));
}

getReport();