Retrieve Visitor ID for GDPR Requests

Hi,

how can users of my website find out their visitor IDs in order to make GDPR requests. I know how to use matomo GDPR tool to fulfill GDPR requests but I do not know how users can find out their visitor ids that I need to look for.

Does this make sense? Can anybody tell me how this process would look like?

Thanks

Hi,

a value is stored in the cookie which starts with _pk_id. There the first value before the dot is the ID of the user.

LG

1 Like

Hi,

You can also use the getVisitorId() function:

 _paq.push([ function() { visitor_id = this.getVisitorId(); }]);
// or
let tracker=Piwik.getAsyncTracker()
let visitor_id=tracker.getVisitorId()
1 Like

HI TomCz,

sorry, I should have mentioned that I am using the no cookie settings. But thank you for your quick reply and your suggestion.

Best

Hi Lukas, thank you for your reply. Could you explain where my users have to enter this function to get their visitor_id?

Thanks

My idea was that your visitors could e.g. paste _paq.push([ function() { console.log(this.getVisitorId()); }]); into their JS console to get the visitor id.

grafik

Or you could use this as a basis for e.g. a button on your website, but keep in mind that the inner function is called asynchronously once Matomo has finished loading.

Is there any chance to get the Visitor ID if Matomo is used without cookies? The solutions above doesn’t seem to work in that case.

I need to send some additional API requests (event tracking with “values” that must not appear in the Frontend). However even if I send IP, screen resulution, User Agent etc. Matomo sets new Visitor IDs for these API calls. I guess to change this behavior I need to send the existing Visitor IDs to the API. How do I get them?

@Toru I don’t understand your needs.
Do you need to get the user visitor ID in order to remove his data from Matomo?
Can you share the code you are currently using?

No, I don’t want to remove data, I would like to add data (events): My normal website tracking is handled by Matomo without cookies and works very well.

What I’m trying to do: If a user clicks on certain links, I receive a CPC payment for it, so I want to track these clicks as events having the correct “values” (=CPCs). However, vistors/competitors must no see these values/cpcs in my website’s source code, so I don’t want to track these events via JavaScript, but via Tracking API. The API is called through the redirect page that opens when the links are clicked.

Basically this all works fine, but I can’t pass a visitor ID to the tracking API at the moment, because I don’t know how to get it. I do pass it the IP, UserAgent, display resolution etc, but still Matomo creates new Visitor IDs for the calls made via API (1 additional per visitor where all his/her events are tracked).

The API call looks like this at the moment:
matomo.php?idsite=1&rec=1&e_c=$event_cat&e_a=$event_action&e_n=$redirect_url&e_v=$cpc&rand=$UNIQUE_ID&apiv=1&urlref=$HTTP_REFERER&ua=$HTTP_USER_AGENT&lang=$HTTP_ACCEPT_LANGUAGE&cip=$REMOTE_ADDR&token_auth=$token&cookie=$cookie&res=$res;

I guess if I would pass the visitor ID to the API via the _id parameter, then the events would be assigned to the correct visitors. Is there any way to get this ID via JavaScript so that I can pass it to the redirect page, which will then pass it to the API? The reason I’m doing all this is to be able to use the Matomo advertising conversion export plugin, to use smart bidding in Google Ads without using the Google tags on my website…

On a test page with matomo tracking with JavaScript API (using _paq), it works well. But Matomo must have been loaded (as the script is deferred, if you try to read the visitor ID before you’ll get no result).
So to get the visitor ID:

let theVisitorId;
window._paq.push([ function() { theVisitorId = this.getVisitorId(); }]);

Then send this value to your server, and it will be able to add the _id parameter to the HTTP request…

Unfortunately this doesn’t work if Matomo is used cookieless. As soon as I remove _paq.push([“disableCookies”]) your code is perfectly fine, but using disableCookies it doesn’t work at all.

However in the Matomo real-time Dashboard the visitors do have VisitorIDs. I need any chance to get those IDs. My first approach was not to send these IDs, but the 100% identical fingerprints (resolution, UA, language, etc. - everything the API offers), but this leads to exactly 1 new VisitorID for every single visitor who clicks on one or more tracked links.

Could you provide a user ID? (if the user has logged-in your website)

Unfortunately not, there is no area behind a login. I would therefore have to get the Matomo VisitorID somehow. Apparently this is stored normally in the cookie, but Matomo also recognizes the user by fingerprinting. So it should be technically possible that a JavaScript call by the user is answered by the Matomo backend with the VisitorID, completely without cookie. Unfortunately I have no idea how.

At least in Europe, the abandonment of cookies is gaining ground very quickly right now, so such a function makes sense from my point of view.

Or else you can use a server generated visitor ID…
If the user start a visit session, the server creates a new visitorId (random 16 digit hex string). Then this visitor ID should be added as query param when browsing from pages to pages…

  _paq.push(['setVisitorId', visitorId]);

and in your HTTP request, you just add cid=visitorId

Very difficult, I would have to implement my own fingerpriting:

One every single page load…

  1. Determine as many individual details (display resolution etc.) as possible via JavaScript.
  2. Assign an individual UserID to these properties (if none exists yet, otherwise select it).
  3. Now (very late!) trigger the Matomo JavaScript tracking and send this internal UserID.

If an event is triggered…
4) Send the identical UserID via the HTTP API.

However the whole fingerprinting is already 100% done by Matomo and every user gets a VisitorID at the first page load. It would therefore be much easier and less error-prone if there would be a way to query this VisitorID to use it for HTTP API request.