matomo-org / matomo-nodejs-tracker Goto Github PK
View Code? Open in Web Editor NEWA Node.js wrapper for the Matomo (Piwik) tracking HTTP API
License: MIT License
A Node.js wrapper for the Matomo (Piwik) tracking HTTP API
License: MIT License
As per https://developer.matomo.org/api-reference/tracking-api:
send_image
โ If set to 0 (send_image=0
) Matomo will respond with a HTTP 204 response code instead of a GIF image. This improves performance and can fix errors if images are not allowed to be obtained directly (eg Chrome Apps). Available since Matomo 2.10.0
If this is currently set, the library treats the response as an error because it's not an explicit 200 response. 204s should probably also count as a success.
To support Matomo's new Crash Analytics feature, we'd like to add crash tracking methods in all supported tracking SDKs.
The tracking methods should be similar to the PHP SDK's methods:
public function trackPhpThrowable(\Throwable $ex, $category = false); // deduces as much information as possible
public function trackCrash($message, $type, $category, $stack, $location, $line, $column); // user supplies all information
trackCrash()
passes its parameters as the following HTTP API parameters:
$message
: sent as cra
, the crash message$type
: sent as cra_tp
, the type of crash, for example "TypeError"$category
: sent as cra_ct
(optional, it's like a custom dimension to categorise the crash, typically left empty)$stack
: sent as cra_st
, a stack trace or similar$location
: (the originating source file) sent as cra_ru
, the file name or source or something similar$line
: sent as cra_rl
, the line number in the file$column
: sent as cra_rc
, the column within the line of the fileIMPORTANT It must also pass ca=1
(stands for 'custom action') as a parameter so if the plugin is deactivated in Matomo, nothing will be tracked.
trackPhpThrowable
(or the equivalent method for the language of this SDK) should accept an exception object and deduce set the crash tracking parameters based on it. The type should be set to the exception class name or something similar.
See also the implementation in the PHP tracker:
Please let me know if there are any questions.
Hi,
It seems that the IP logged in Matomo is the IP of the server where the nodeJS app is running and not the client/visitor IP.
Is there any fix to this issue?
Thank you.
<!edit>
OK, I just read a comment of @Findus23 on another issue that say :
Technically the tracker is only intended for use in NodeJS
Does it means that matomo-nodejs-tracker
is not intended to replace the javascript code?
</!edit>
Hi there,
this issue refs matomo-org/matomo#16397 (comment)
in Matomo 4 we're changing the structure of the visitor cookie. I don't know if this SDK reads the cookie of a visitor if one is set?
In the PHP tracker we had to make this change because of it https://github.com/matomo-org/matomo-php-tracker/pull/79/files#diff-cd22a4ca6eb55e6a5ad813334624ed89L1370-L1840
The cookie was changed in https://github.com/matomo-org/matomo/pull/15774/files#diff-1279d666063b65e6d6777f902d11574fR3322-R3330
It used to contain 6 indexes (newVisitor, uuid, createTs, visitCount, currentVisitTs, lastVisitTs) but now contains only indexes:
Slot 0: newVisitor
Slot 1: uuid
Slot 2: createTs
Basically, if this tracker does read the cookie, then the tracker needs to be changed to only read the first to slots from the cookie (cookieVisitorId and createTs) see https://github.com/matomo-org/matomo-php-tracker/pull/79/files#diff-cd22a4ca6eb55e6a5ad813334624ed89L1370-L1840
All other information from the cookie list visit count, currentVisitTs, lastVisitTs is no longer needed in Matomo 4.
Error: Protocol:https: not supported.
at Object.exports.request (http.js:1840:11)
at Object.exports.get (http.js:1847:21)
at PiwikTracker.track (/Users/dxiao/Documents/Code/nodejs-cantas/node_modules/piwik-tracker/index.js:58:18)
at repl:1:7
at REPLServer.self.eval (repl.js:110:21)
at repl.js:249:20
at REPLServer.self.eval (repl.js:122:7)
at Interface. (repl.js:239:12)
at Interface.EventEmitter.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
Hello,
I want to send "search" tracking events from a nodeJS backend.
Using trackBulk
, I send events with _id, cdt, e_c, e_a, e_n, e_v
successfully (and see them reported in the Matomo web app).
However when sending _id, cdt, search, search_cat, search_count
, I see nothing in the "Site search" section of the Matomo web app, whereas site search is enabled for my site.
Am I missing something?
my own ip is the ip where all the requests come from. how can i change that?
Issue: I'm getting the error.
Unable to determine the domain name -- TypeError [ERR_INVALID_DOMAIN_NAME]: Unable to determine the domain name\n at new ClientRequest (_http_client.js:71:13)\n at request (http.js:42:10)\n at Object.get (http.js:46:13)\n at MatomoTracker.track (/.../node_modules/matomo-tracker/index.js:72:24)\n at MatomoLinkService.track (/.../matomo-link.service.js:23:21)\n at new MatomoLinkService (/.../matomo-link.service.js:20:14)\n at Injector.instantiateClass (/.../node_modules/@nestjs/core/injector/injector.js:289:19)\n at callback (/.../node_modules/@nestjs/core/injector/injector.js:76:41)\n at process._tickCallback (internal/process/next_tick.js:68:7)\n at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)"}
Expect: I send track event to matomo dashboard
My code:
import { Injectable } from '@nestjs/common';
import * as MatomoTracker from 'matomo-tracker';
@Injectable()
export class MatomoLinkService {
private matomoUrl = process.env.MATOMO_URL || 'example.de';
private matomoId = process.env.MATOMO_ID || '1';
private matomoTracker: MatomoTracker;
matomo;
constructor() {
this.matomo = new MatomoTracker(this.matomoId, this.matomoUrl, true);
console.log('this.matomo ==== ', this.matomo);
this.track({});
}
track(event: object): void {
this.matomo.track('Test 2');
}
}
`
Console.log info:
this.matomo ==== MatomoTracker {
domain: null,
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
siteId: '1',
trackerUrl: 'example.de',
agent:
{ _connectionListener: [Function: connectionListener],
METHODS:
[ 'ACL',
'BIND',
'CHECKOUT',
'CONNECT',
'COPY',
'DELETE',
'GET',
'HEAD',
'LINK',
'LOCK',
'M-SEARCH',
'MERGE',
'MKACTIVITY',
'MKCALENDAR',
'MKCOL',
'MOVE',
'NOTIFY',
'OPTIONS',
'PATCH',
'POST',
'PROPFIND',
'PROPPATCH',
'PURGE',
'PUT',
'REBIND',
'REPORT',
'SEARCH',
'SOURCE',
'SUBSCRIBE',
'TRACE',
'UNBIND',
'UNLINK',
'UNLOCK',
'UNSUBSCRIBE' ],
STATUS_CODES:
{ '100': 'Continue',
'101': 'Switching Protocols',
'102': 'Processing',
'103': 'Early Hints',
'200': 'OK',
'201': 'Created',
'202': 'Accepted',
'203': 'Non-Authoritative Information',
'204': 'No Content',
'205': 'Reset Content',
'206': 'Partial Content',
'207': 'Multi-Status',
'208': 'Already Reported',
'226': 'IM Used',
'300': 'Multiple Choices',
'301': 'Moved Permanently',
'302': 'Found',
'303': 'See Other',
'304': 'Not Modified',
'305': 'Use Proxy',
'307': 'Temporary Redirect',
'308': 'Permanent Redirect',
'400': 'Bad Request',
'401': 'Unauthorized',
'402': 'Payment Required',
'403': 'Forbidden',
'404': 'Not Found',
'405': 'Method Not Allowed',
'406': 'Not Acceptable',
'407': 'Proxy Authentication Required',
'408': 'Request Timeout',
'409': 'Conflict',
'410': 'Gone',
'411': 'Length Required',
'412': 'Precondition Failed',
'413': 'Payload Too Large',
'414': 'URI Too Long',
'415': 'Unsupported Media Type',
'416': 'Range Not Satisfiable',
'417': 'Expectation Failed',
'418': 'I\'m a Teapot',
'421': 'Misdirected Request',
'422': 'Unprocessable Entity',
'423': 'Locked',
'424': 'Failed Dependency',
'425': 'Unordered Collection',
'426': 'Upgrade Required',
'428': 'Precondition Required',
'429': 'Too Many Requests',
'431': 'Request Header Fields Too Large',
'451': 'Unavailable For Legal Reasons',
'500': 'Internal Server Error',
'501': 'Not Implemented',
'502': 'Bad Gateway',
'503': 'Service Unavailable',
'504': 'Gateway Timeout',
'505': 'HTTP Version Not Supported',
'506': 'Variant Also Negotiates',
'507': 'Insufficient Storage',
'508': 'Loop Detected',
'509': 'Bandwidth Limit Exceeded',
'510': 'Not Extended',
'511': 'Network Authentication Required' },
Agent:
{ [Function: Agent] super_: [Function], defaultMaxSockets: Infinity },
ClientRequest: { [Function: ClientRequest] super_: [Function] },
IncomingMessage: { [Function: IncomingMessage] super_: [Function] },
OutgoingMessage: { [Function: OutgoingMessage] super_: [Function] },
Server: { [Function: Server] super_: [Function] },
ServerResponse: { [Function: ServerResponse] super_: [Function] },
createServer: [Function: createServer],
get: [Function: get],
request: [Function: request],
maxHeaderSize: [Getter],
globalAgent: [Getter/Setter] } }
`
Hi there, does this library support sending to multiple site ids? i.e. does it replicate the functionality listed on these docs
Directly ship the type definitions with this package and add a type
property to package.json
.
This should be optional as we can change this (eg url rewriting to avoid ad-blockers).
I think instead of assertion, this lib should just warn.
Hi,
Sorry for posting this here but couldn't find a place to ask this question.
I am running a Node js express service where I want to report a certain action under a route.
When I run the express service and called the route, nothing happened and also no errors. But I cannot see the tracking info coming after the trigger.
Is it possible to just report to matomo that a particular action inside a route is successfully executed? I don't want to track the route but from the route, i want to talk to matomo that a certain action is completed. Is is possible to do this with this package?
It will be great if you could help me with this. I am very new to matomo.
Due to our build-pipeline we can't use require
to include the module. Using require it would't get bundled into the final build.
If we try to use import (import * as MatomoTracker from "matomo-tracker";
) we can bundle it correctly but it throws an error on runtime: TypeError: Vn is not a constructor
Is there anything we can do?
Thanks a lot
It would be useful to track custom events from nodejs.
I ran into this build error deploying to heroku once I added this tracker:
Failed to minify the code from this file:
./node_modules/matomo-tracker/index.js:96
Read more here: http://bit.ly/2tRViJ9
I just copied the code into my src
directory for now, but would be nice if this package was published pre-compiled.
I found matomo support tracking http API and provided the js client
https://developer.matomo.org/api-reference/tracking-api
Instead of use https://github.com/BonifyByForteil/react-native-matomo which requires some Android/iOS SDK dependencies (not possible to do so with managed Expo environment), could I use matomo-nodejs-tracker
for React Native App tracking?
Currently I get the error self signed certificate
. My matomo uses a self-signed cert and I've had trouble setting up letsencrypt
on it. Is this the library complaining or Matomo itself?
See matomo-org/matomo#16569 to learn more about the problem it fixes and visit https://developer.matomo.org/api-reference/tracking-api for more documentation about the new ca
parameter.
Basically, we should be sending &ca=1
along any tracking request that isn't a page view. Practically, we should for now only send &ca=1
along any event and content tracking requests.
The parameter isn't required but it helps for more accurate tracking for edge cases where a user suddenly disables eg an event, goal or ecommerce plugin but still keeps sending these requests. If the parameter is not sent, Matomo would turn the tracking request into a page view and track a page view even though the tracking request should be ignored.
Let me know if there are any questions about this.
Does this support custom dimensions? If so, perhaps it could be documented.
https://developer.matomo.org/guides/tracking-javascript-guide#custom-dimensions
Simple issue, the homepage on NPM links to matomo-tracker rather than matomo-nodejs-tracker which may confuse some.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.