Warning
I no longer work in web development and I don't really have the time or interest in maintaining this repository anymore. It has been incompatible with umami for a while and it would take me too much time to update it. However, if anybody is interested in maintaining it, I would gladly transfer the repository and NPM package (if that's possible?)
🍙 Simple, tiny API client for Umami analytics.
npm install umami-api
import UmamiAPIClient from "umami-api";
Default options can be set with the following environment variables:
UMAMI_CLIENT_TIMEOUT_MS
: Axios timeout in milliseconds. Default:2000
.UMAMI_CLIENT_USER_AGENT
: User agent to use for requests. Default:Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Firefox/102.0
.UMAMI_CLIENT_TIME_PERIOD
: Default time period for pageviews, events, etc. Default:24h
.UMAMI_CLIENT_TIME_UNIT
: Default time unit for pageviews, events, etc. Default:hour
.UMAMI_CLIENT_TIMEZONE
: Default timezone for pageviews, events, etc. Default:America/Toronto
.UMAMI_CLIENT_METRIC_TYPE
: Default metric type to get. Default:url
.
import UmamiAPIClient from "umami-api";
const umami = new UmamiAPIClient("stats.example.com", "username", "password");
const newWebsite = await umami.createWebsite({
domain: "test.com",
name: "test.com",
enableShareUrl: false,
});
const pageviews = await newWebsite.getPageviews();
const metrics = await newWebsite.getMetrics();