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

plausible-api

v1.0.1

Published

📈 Unofficial Node.js client for the **API** of [Plausible Analytics](https://plausible.io/).

Downloads

51

Readme

📊 plausible-api

📈 Unofficial Node.js client for the API of Plausible Analytics.

Important note: Plausible's API is currently still in public beta. The functionality can be changed at any time. I try to keep the library up to date and adapt it to the API changes, but I cannot guarantee this.

Installation

The library can be installed as usual via npm:

npm install plausible-api

Or also using yarn:

yarn add plausible-api

Usage

The client must first be imported and an instance created:

const Plausible = require("plausible-api");

const client = new Plausible("<YOUR API KEY>");

getRealtimeVisitors

Parameters:

  • siteId (string): The domain of the website that is set at Plausible.
await client.getRealtimeVisitors("example.com");
// => 191

getTimeseries

Parameters:

  • siteId (string): The domain of the website that is set at Plausible.
  • period ("12mo" | "6mo" | "30d" | "7d" | "month" | "day"): Time periods
  • filters (string, optional): Optional filters as documented here
  • interval ("date" | "month", optional): Choose your reporting interval
await client.getTimeseries("example.com", "month", "", "date");
// => [
//      { date: '2021-02-01', value: 5968 },
//      { date: '2021-02-02', value: 1234 },
//      { date: '2021-02-03', value: 22234 },
//      { date: '2021-02-04', value: 19921 },
//      { date: '2021-02-05', value: 17892 },
//      { date: '2021-02-06', value: 1002 },
//      { date: '2021-02-07', value: 2999 },
//      { date: '2021-02-08', value: 21111 },
//      { date: '2021-02-09', value: 1222 },
//      { date: '2021-02-10', value: 3939 },
//      { date: '2021-02-11', value: 4111 },
//      { date: '2021-02-12', value: 48481 },
//      { date: '2021-02-13', value: 3012 },
//      { date: '2021-02-14', value: 59182 },
//      { date: '2021-02-15', value: 3919 },
//      { date: '2021-02-16', value: 4818 },
//      { date: '2021-02-17', value: 23124 },
//      { date: '2021-02-18', value: 12312 },
//      { date: '2021-02-19', value: 20123 },
//      { date: '2021-02-20', value: 4888 },
//      { date: '2021-02-21', value: 5922 },
//      { date: '2021-02-22', value: 27981 },
//      { date: '2021-02-23', value: 3234 },
//      { date: '2021-02-24', value: 1211 },
//      { date: '2021-02-25', value: 5790 },
//      { date: '2021-02-26', value: 9080 },
//      { date: '2021-02-27', value: 14900 },
//      { date: '2021-02-28', value: 12289 }
//    ]

aggregate

Parameters:

  • siteId (string): The domain of the website that is set at Plausible.
  • period ("12mo" | "6mo" | "30d" | "7d" | "month" | "day"): Time periods
  • metrics (Array<"visitors" | "pageviews" | "bounce_rate" | "visit_duration">): List of metrics to aggregate
  • filters (string, optional): Optional filters as documented here
await client.aggregate("example.com", "7d", [
	"visit_duration",
	"visitors",
	"pageviews",
	"bounce_rate",
	"visit_duration",
]);
// => { bounce_rate: 50, pageviews: 6, visit_duration: 14, visitors: 2 }

License

Copyright 2021 Marvin Schopf

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.