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 = ; // Initialize with your site ID and Matomo URLvar matomo = 1 'http://mywebsite.com/matomo.php'; // Optional: Respond to tracking errorsmatomo; // Track a request URL:// Either as a simple string …matomo; // … or provide further options:matomo; // … 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
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:
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:
1 'http://matomo.my-site.com/my-file.php' true)// OK