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'sreferer
headerua
= the user'suser-agent
headerlang
= the user'saccept-language
headercdt
= the request's UNIX timestamppf_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 agetResponseTime
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.
- I'm using it to fill
- 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 fillpf_srv
. - This option is needed when the route returns a non-HTTP response like WS or SSE.
- In this case, I'm simply filling
- The default method blindly on the framework's time measurement, but I could have done it some other way :
- always listen to both
preHandler
andonResponse
- generate the current timestamp in both hooks
- fill
cdt
with the first value - fill
pf_srv
with the subtraction of both
- always listen to both
Have I done it right ?
Could I add more data ?
Are there useful resources regarding server-side analytics on Matomo ?
Thanks !