2.0.0 • Published 6 months ago

eleventy-plugin-umami v2.0.0

Weekly downloads
-
License
CC BY-NC-SA 4.0
Repository
github
Last release
6 months ago

eleventy-plugin-umami

Get the stats of your selfhosted umami-instance and use them in your 11ty-project using this plugin. You can find the page of the npm-package here: https://www.npmjs.com/package/eleventy-plugin-umami

How to use

  1. Install this plugin with npm install eleventy-plugin-umami
  2. In your .eleventy.js:
const umamiPlugin = require("eleventy-plugin-umami");

module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(umamiPlugin, {
    url: UMAMI_URL,
    username: UMAMI_USERNAME,
    password: UMAMI_PASSWORD,
    websiteId: UMAMI_WEBSITE_ID,
    start: moment().subtract(1, "month").valueOf(), // example values to get the stats of the last month
    end: moment().valueOf(),
  });
};

Variables

VariableDescription
urlDefines the URL of your Umami instance. Only self-hosted instances are supported.
usernameDefines the username used for logging into Umami.
passwordDefines the password used for logging into Umami.
websiteIdDefines the unique ID for your website.
startDefines the start-date of the stats. This need to be in milliseconds. The js-function for this is getTime(), moment uses valueOf().
endDefines the end-date of the stats. This need to be in milliseconds. The js-function for this is getTime(), moment uses valueOf().

Please do not use this variables in clear-text. Instead use packages like dotenv

Optional Variables

VariableDescription
urlName of the URL.
referrerName of the referrer.
titleName of the page title.
queryName of the query.
eventName of the event.
hostName of the hostname.
osName of the operating system.
browserName of the browser.
deviceName of the device (e.g., Mobile).
countryName of the country.
regionName of the region/state/province.
cityName of the city.

Usage in 11ty

This plugin creates global data which includes all of the data that the stats-endpoint of the umami-API offers

// Example-values
{
  "pageviews": { "value": 3018, "prev": 3508 },
  "visitors": { "value": 847, "prev": 910 },
  "visits": { "value": 984, "prev": 1080 },
  "bounces": { "value": 537, "prev": 628 },
  "totaltime": { "value": 150492, "prev": 164713 }
}

If you want to use it you can access the collection like this:

| Metric      | Value                       | Previous Value             |
| ----------- | --------------------------- | -------------------------- |
| `pageviews` | {{ umami.pageviews.value }} | {{ umami.pageviews.prev }} |
| `visitors`  | {{ umami.visitors.value }}  | {{ umami.visitors.prev }}  |
| `visits`    | {{ umami.visits.value }}    | {{ umami.visits.prev }}    |
| `bounces`   | {{ umami.bounces.value }}   | {{ umami.bounces.prev }}   |
| `totaltime` | {{ umami.totaltime.value }} | {{ umami.totaltime.prev }} |

which renders like this

MetricValuePrevious Value
pageviews30183508
visitors847910
visits9841080
bounces537628
totaltime150492164713

Changes in 2.0.0

  • Dependencies have been removed. This plugin now has not a single dependency anymore and instead relies on the Fetch API.
  • Instead of a collection this plugin now supplies the gathered data via global data. All you need to do is remove collections from your files, for example {{ collections.umami.pageviews.value }} turns into {{ umami.pageviews.value }}.
2.0.0

6 months ago

1.0.1

7 months ago

1.0.0

7 months ago