Hello,

I'm creating fastify-matomo, a plugin for the fastify back-end framework on NodeJS.

I looked at the tracking API and tried to fill every field I could :

  • action_name = route method + path (e.g. GET /item/:id)
  • url = the full request URL
  • _id = the user's IP address & user-agent header concatenated and hashed using CRC-64 (one of the rare hashing algorithms I found that outputs 16-chars hexadecimal strings)
  • urlref = the user's referer header
  • ua = the user's user-agent header
  • lang = the user's accept-language header
  • cdt = the request's UNIX timestamp
  • pf_srv = the server's response time (unless the plugin is set to run at request time)

Some fastify-specific details :

  • By default, the plugin is set to run at response time, i.e. when the onResponse hook is fired, which provides a getResponseTime method.
    • I'm using it to fill pf_srv (rounded, because it returns a decimal value in milliseconds).
    • I'm also using it to fill cdt, by subtracting it from the current timestamp.
  • The plugin can be set to run at request time, i.e. when the preHandler hook is fired.
    • In this case, I'm simply filling cdt with the current timestamp, and don't fill pf_srv.
    • This option is needed when the route returns a non-HTTP response like WS or SSE.
  • The default method blindly on the framework's time measurement, but I could have done it some other way :
    • always listen to both preHandler and onResponse
    • generate the current timestamp in both hooks
    • fill cdt with the first value
    • fill pf_srv with the subtraction of both

Have I done it right ?
Could I add more data ?
Are there useful resources regarding server-side analytics on Matomo ?

Thanks !

Edit Report
Pub: 17 Jan 2022 18:31 UTC
Views: 121