Visitor Id as a variable

Why isn’t there a built-in variable to access Visitor Id from a “Custom HTML” tag in the tag-manager?

Hi @Stig_Christensen
The visitor ID is under control of Matomo, then not accessible, but you can use the user ID instead. See below the simplified MTM Configuration variable example:

Thanks for the response. I am a little confused. We are using Matomo Analytics and Matomo Tag Manager (not Google). But I guess you answer applices to this as well?

1 Like

Great. So you advice is to enrich the analytics data with a user identity, and not the other way around ( grabbing the visitor ID from the analytics data). Right? I also think trying to read the Visitor ID from a cookies seems very fragile.

Hi @Stig_Christensen

My screenshot has been made from Matomo Tag Manager :wink:
Then the response was for Matomo Analytics and Matomo Tag Manager

by bad, this response was to @jobeydn

We are using Matomo Analytics and Matomo Tag Manager (not Google). But I guess you answer applices to this as well?

Hi @Stig_Christensen

Be careful with privacy purposes, when doing this…
Normally, Matomo can manage visitor ID by itself. Why do you need to interfere with its normal behavior?

Thanks for the interest.

Our goal is to correlate the analytics data with some custom tracking on logon. On logon to our site we are using the Tag Manager to trigger a API call to the backend. In the backend we know the user Identity. Our first attempt was to send the VisitorId along to the backend. But there isn’t any variable in the Tag Manager holding the VisitorId . Reading a cookie seems fragile.

Instead we could enrich the analytics data (using the User ID) with out session cookie (in our case ASP.NET_SessionId). Having this in the backend and in the User ID we can correlate analytics data with the user Identity

@Stig_Christensen
I think the Matomo doc indicates that user ID is already doing the job:

When a visitor connects to your website but is not initially logged in, their visit is associated with a >Visitor ID by default. This is a unique identifier for that specific visit that is not attributed to a specific user. However, once that user logs into their account and you set a User ID for this visitor, then all actions such as page views are linked to the User ID and not the visitor ID. Any previously tracked action for this visitor before the user was logged in is also associated with this User ID.

When a user logs in, Matomo counts all actions before and after logging in as one user, one visit, and one unique visitor.