Page MenuHomePhabricator

Add custom variable data to matomo via nginx logs
Closed, ResolvedPublic


We need to be able to let matomo know if a user is logged in or anonymous.
We have that data in nginx and need to send it to matomo as a custom variable

Event Timeline

I'm currently playing with setting a has_session token in the nginx json log output to see if that can be picked up as a custom dimension in matomo

Looks like the python scripts uses custom variables instead of custom dimensions.
It's slightly different way to achieve the same thing.
I'm adding the custom variables plugin, which is provided directly from matomo.

Okay, I've got the data structure coming out of nginx looking good, for example here's a snippet of the log output when I'm authenticated:

"args": {"_cvar": {"1": ["has_session", 1]}}

vs unauthenticated:

"args": {"_cvar": {"1": ["has_session", 0]}}

but it looks like the json format for the log ingest script hardcodes custom variables and doesn't actually parse that bit of the log.

It looks like I just need to add a little code to merge the log argument dictionary with the one hardcoded in the script

This started out as a 4 hour spike, which I've now exceeded. It's pretty clear what I need to do here, so I'll just reuse this as the task for getting custom variable data into matomo.

jsn.sherman renamed this task from Evaluate adding custom variables to matomo logs [4hr] to Add custom variable data to matomo via nginx logs.May 7 2021, 5:55 PM
jsn.sherman updated the task description. (Show Details)

Okay, I'm in the process of exploring how to connect custom variables (which can be page- or -visit-scoped) to custom visitor segments, which can be used in scheduled reports. This is one of those areas where every piece is configurable and has impact on how things are counted, so I'm plowing through various combinations to see clearly and consicely we can answer the question

What percentage of users who arrive on the homepage (logged out) log in?