Coder Social home page Coder Social logo

matomo-nodejs-tracker's Introduction

Matomo Tracker NPM version Build Status

A wrapper for the Matomo Tracking HTTP API

Usage

First, install matomo-tracker as a dependency:

npm install --save matomo-tracker

Then, use it in your project:

var MatomoTracker = require('matomo-tracker');

// Initialize with your site ID and Matomo URL
var matomo = new MatomoTracker(1, 'http://mywebsite.com/matomo.php');

// Optional: Respond to tracking errors
matomo.on('error', function(err) {
  console.log('error tracking request: ', err);
});

// Track a request URL:
// Either as a simple string …
matomo.track('http://example.com/track/this/url');

// … or provide further options:
matomo.track({
  url: 'http://example.com/track/this/url',
  action_name: 'This will be shown in your dashboard',
  ua: 'Node.js v0.10.24',
  cvar: JSON.stringify({
    '1': ['custom variable name', 'custom variable value']
  })
});

// … or trackBulk:
var events = [{
  '_id': 'AA814767-7B1F-5C81-8F1D-8E47AD7D2982',
  'cdt': '2018-03-22T02:32:22.867Z',
  'e_c': 'Buy',
  'e_a': 'rightButton',
  'e_v': '2'
},{
  '_id': 'AA814767-7B1F-5C81-8F1D-8E47AD7D2982',
  'cdt': '2018-03-22T02:33:52.962Z',
  'e_c': 'Buy',
  'e_a': 'leftButton',
  'e_v': '4'
}];
matomo.trackBulk(events, (resData) => {
  // done.
})

That's it. For a complete list of options, see Matomo's Tracking HTTP API Reference.

Advanced usage

If you renamed the tracking file piwik.php or matomo.php of your matomo instance, the following error will be thrown:

new MatomoTracker(1, 'http://matomo.my-site.com/my-file.php'))
// ERROR: A tracker URL must end with "matomo.php" or "piwik.php"

To skip this check, simply pass true as third argument to the constructor:

new MatomoTracker(1, 'http://matomo.my-site.com/my-file.php', true))
// OK

License

MIT License

matomo-nodejs-tracker's People

Contributors

fhemberger avatar findus23 avatar greenkeeperio-bot avatar cherry avatar michaelhidalgo avatar strugee avatar frencil avatar tibianmod avatar gedankennebel avatar toub avatar richie765 avatar tsteur avatar yantze avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.