项目作者: fvdm

项目描述 :
Access a Matomo (Piwik) API from node.js
高级语言: JavaScript
项目地址: git://github.com/fvdm/nodejs-piwik.git
创建时间: 2012-05-27T17:57:48Z
项目社区:https://github.com/fvdm/nodejs-piwik

开源协议:The Unlicense

下载


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
Build Status
Coverage Status

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

  1. const matomo = require( 'piwik' ).setup( 'https://example.tld/matomo/', 'abc123' );
  2. // track a pageview
  3. matomo.track(
  4. {
  5. idsite: 1,
  6. url: 'https://mysite.tld/some/page',
  7. action_name: 'Page Title',
  8. _cvar: { '1': ['group', 'customer'] },
  9. },
  10. console.log
  11. );

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).
  1. const matomo = require( 'piwik' ).setup( 'https://example.tld/matomo/', 'abc123' );

.api

( vars, callback )

Call an API method.

argument type description
vars object see documentation
callback function (err, data)

Reporting API docs

  1. // page urls for today
  2. matomo.api(
  3. {
  4. method: 'Actions.getPageUrls',
  5. idSite: 1,
  6. period: 'day',
  7. date: 'today'
  8. },
  9. console.log
  10. );

.track

( vars, callback )

Track a hit.

argument type description
vars object or array see documentation
[callback] function (err, data)

Tracking API docs

  1. // track a pageview
  2. matomo.track(
  3. {
  4. idsite: 1,
  5. url: 'https://mysite.tld/some/page',
  6. action_name: 'Page Title',
  7. _cvar: { '1': ['group', 'customer'] },
  8. },
  9. console.log
  10. );
  11. // track many at once (log import)
  12. matomo.track(
  13. [
  14. {
  15. idsite: 1,
  16. url: 'http://mysite.tld/some/page',
  17. action_name: 'Page Title',
  18. },
  19. {
  20. idsite: 1,
  21. url: 'http://mysite.tld/blog/123-hello',
  22. action_name: 'Hello World',
  23. },
  24. ],
  25. console.log
  26. );

.loadSpammers

( callback )

Retrieve referrer spammers blocklist maintained by Matomo as an array.

Open source list

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
  1. matomo.api( props, ( err, data ) => {
  2. if ( err ) {
  3. console.log( err );
  4. return;
  5. }
  6. console.log( data );
  7. } );

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
| Buy me a coffee