# piwik

> Track hits, access your Piwik API, or retrieve the referrer spammers list.

Latest version **1.0.10** (published 2024-03-29) · Unlicense license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install piwik
pnpm add piwik
yarn add piwik
bun add piwik
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.10 |
| Published | 2024-03-29 |
| First published | 2012-05-27 |
| Weekly downloads | 0 |
| License | Unlicense |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=14 |
| Dependencies | 1 |
| Unpacked size | 13.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 38 |
| Author | Franklin |
| Maintainers | franklin |
| Keywords | analytics, api, piwik, statistics, stats, tracking |

## Links

- npm: https://www.npmjs.com/package/piwik
- Repository: https://github.com/fvdm/nodejs-piwik
- Homepage: https://github.com/fvdm/nodejs-piwik#readme
- Issues: https://github.com/fvdm/nodejs-piwik/issues
- npm.io page: https://npm.io/package/piwik

## Dependencies (1)

- [httpreq](https://npm.io/package/httpreq.md) ^0.5.2

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 1.0.10 (latest) — 2024-03-29
- 1.0.9 — 2017-12-12
- 1.0.8 — 2016-12-19
- 1.0.6 — 2016-05-25
- 1.0.5 — 2016-03-29
- 1.0.4 — 2015-09-23
- 1.0.3 — 2015-09-18
- 1.0.1 — 2015-07-15
- 1.0.0 — 2015-06-27
- 0.4.1 — 2015-03-19
- 0.4.0 — 2015-03-02
- 0.3.0 — 2014-12-22
- 0.2.0 — 2013-08-09
- 0.1.0 — 2012-05-27

## README

# piwik (Matomo)

Track hits and access a Matomo API with Node.js

_The package is named after the previous name of Matomo.
I don't feel like changing the name, because people are using it in their apps._

[![npm](https://img.shields.io/npm/v/piwik.svg?maxAge=3600)](https://www.npmjs.com/package/piwik)
[![Build Status](https://travis-ci.org/fvdm/nodejs-piwik.svg?branch=master)](https://travis-ci.org/fvdm/nodejs-piwik)
[![Coverage Status](https://coveralls.io/repos/github/fvdm/nodejs-piwik/badge.svg?branch=master)](https://coveralls.io/github/fvdm/nodejs-piwik?branch=master)

* [Node.js](https://nodejs.org)
* [Matomo](https://matomo.org)
* [API documentation](https://developer.matomo.org/api-reference/reporting-api-introduction)
* [Release notes](https://github.com/fvdm/nodejs-piwik/releases)


# DEPRECATION NOTICE

This package is too old to modernize.
Since there are much better modern alternatives available,
the code with not be updated anymore. The GitHub repo will be archived.


## Example

```js
const matomo = require( 'piwik' ).setup( 'https://example.tld/matomo/', 'abc123' );

// track a pageview
matomo.track(
  {
    idsite:      1,
    url:         'https://mysite.tld/some/page',
    action_name: 'Page Title',
    _cvar:       { '1': ['group', 'customer'] },
  },
  console.log
);
```


## Installation

`npm install piwik`


## .setup
**( baseURL, [token], [timeout] )**

In order to use this module you need to start with `setup()`.

argument  | type    | description
:---------|:--------|:-----------
baseURL   | string  | The URL to your Matomo installation. Both HTTP and HTTPS are supported.
[token]   | string  | Your API access token. Either set `token` or include `token_auth` in the `baseURL`.
[timeout] | integer | Wait time in ms, default `5000` (5 seconds).

```js
const matomo = require( 'piwik' ).setup( 'https://example.tld/matomo/', 'abc123' );
```


## .api
**( vars, callback )**

Call an API method.


argument | type     | description
:--------|:---------|:----------------------
vars     | object   | see [documentation](https://developer.matomo.org/api-reference/reporting-api-introduction)
callback | function | `(err, data)`


[Reporting API docs](https://developer.matomo.org/api-reference/reporting-api-introduction)


```js
// page urls for today
matomo.api(
  {
    method:   'Actions.getPageUrls',
    idSite:   1,
    period:   'day',
    date:     'today'
  },
  console.log
);
```


## .track
**( vars, callback )**

Track a hit.


argument   | type            | description
:----------|:----------------|:-----------
vars       | object or array | see [documentation](https://developer.matomo.org/api-reference/tracking-api)
[callback] | function        | `(err, data)`


[Tracking API docs](https://developer.matomo.org/api-reference/tracking-api)


```js
// track a pageview
matomo.track(
  {
    idsite:      1,
    url:         'https://mysite.tld/some/page',
    action_name: 'Page Title',
    _cvar:       { '1': ['group', 'customer'] },
  },
  console.log
);

// track many at once (log import)
matomo.track(
  [
    {
      idsite:      1,
      url:         'http://mysite.tld/some/page',
      action_name: 'Page Title',
    },
    {
      idsite:      1,
      url:         'http://mysite.tld/blog/123-hello',
      action_name: 'Hello World',
    },
  ],
  console.log
);
```


## .loadSpammers
**( callback )**

Retrieve referrer spammers blocklist maintained by Matomo as an _array_.

[Open source list](https://github.com/matomo-org/referrer-spam-blacklist)


## Callback and Errors

The callback function receives two parameters: `err` and `data`.
When an error occurs `err` is an instance of `Error`.
When all is good `err` is `null` and `data` is set.


message          | description            | additional
:----------------|:-----------------------|:----------
request failed   | Request cannot be made | see `err.error`
http error       | HTTP error             | `err.code` and `err.body`
api error        | API error              | `err.text`
track failed     | Track method failed    | `err.data`


```js
matomo.api( props, ( err, data ) => {
  if ( err ) {
    console.log( err );
    return;
  }

  console.log( data );
} );
```


## Unlicense

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org>


## Author

[Franklin](https://fvdm.com)
| [Buy me a coffee](https://fvdm.com/donating)

---
_Source: https://npm.io/package/piwik · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
