Where is the visitor id and session id in query params when event goes to matomo.php?


@heurteph-ei can you please guide me.

nHi @pkr2
The Visitor id is: _id=0b8dcbc625000da2
The session is deduced from the user ID… If the user does’t do anything for 30 minutes and then comes back, then a new session is started. But you can manually start a new session ( new_visit=1) or change the default session duration.


hi @heurteph-ei
Thanks for giving me your time to reply.
I am still having some query, please guide.

What I have observed so far with Matomo is that they have a visit ID internally for their visitors, and that visit ID is nothing but a session ID, which has a default time of 30 minutes of inactivity; after 30 minutes of inactivity, it will generate a new visit ID for the same visitor ID.
So my question is this:
How can we send this VisitId or Session Id from the client side to the Matomo PHP backend, which is internally maintained by Matomo?
as I tried by adding this on the client side (HTML JS): onclick=“_paq.push([‘trackEvent’, ‘Contact’, ‘Email Link Click’, ‘name@example.com’]);”> Email Us
This will send this behind the scenes.

Where is the VisitId or SessionId in this? I’m using the Matomo Extension (Kafka Plugin), and I want this session ID to be in my Kafka topic as well. (Actually these trackers are overriding the request and pushing these request params to kafka).

Hi @pkr2

Unfortunately this is not possible. The visit ID seems to be a kind of database primary key (new visit? → new ID) when Matomo detect an action be part of a new visit…
Maybe you could ask for a new feature to Matomo GitHub: “Be able to set a custom visit ID”:

I don’t want set my own visitId Be able to set a custom visit ID
I want matomo’s inbuilt visit Id or Session Id of visitor need to send to matomo.php
becuase MatomoKafka tracker override the request method

public function onStartTrackRequests(Tracker $tracker, RequestSet $requestSet)
        foreach ($requestSet->getRequests() as $request) {
            try {
                $json = json_encode($request->getParams(), JSON_THROW_ON_ERROR);
            } catch (JsonException $e) {
            $this->topic->produce(RD_KAFKA_PARTITION_UA, 0, $json);
        parent::onStartTrackRequests($tracker, $requestSet); // TODO: Change the autogenerated stub

So you are saying that there is no way in Matomo to get the current visit ID or session ID of the visitor ?

Anyone can please guide me on this ?
I am stuck in this from a long


I think you can try building your request using Matomo Tracking HTTP API URL Builder to find the issue ?


Thanks for giving me your time to reply
Right now im using Matomo JS tracker

<script type="text/javascript">
      // Matomo Start
      var _paq = (window._paq = window._paq || []);
      /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
      (function () {
        var u = "//localhost/matomo-4.14.1/matomo/";
        _paq.push(["setTrackerUrl", u + "matomo.php"]);
        _paq.push(["setSiteId", "1"]);
        var d = document,
          g = d.createElement("script"),
          s = d.getElementsByTagName("script")[0];
        g.async = true;
        g.src = u + "matomo.js";
        s.parentNode.insertBefore(g, s);
      // / Matomo Config End

I want MatomoVisit ID, which is nothing but a session ID. How can I get the current running visit ID for my visitor in my JS code ?
I checked in network console when event request goes to matomo.php
i check their payload and i found sessionId or visitId is not passing to the matomo server
How can we get the sessionId ?
Please guide

In the HTTP API URL Builder that you suggest,
visit ID or session ID is not there.

Team, I don’t want to set a custom visit ID.
I want to append the Matomo-created sessionID or visitId for the visitor to every request.
I am using the Kafka extension they are overriding the matomo request, and there I want to get the session ID as well in the received payload.

There is &_id= in this generator in recommended section

I guess the visitor ID is stored in a cookie or defined by Matomo right on the server, that’s not a parameter

No, I am talking about sessionId or visitId not the visitorId
I know _id contains visitor id

Hi pkr2,

maybe something like this could work?


Get the visitorId from the “&_id=” URL-Parameter for example, to use it in the above API-request.

This response will include an array “lastVisits” (we use “limitVisits”-Parameter to get only the last visit) for the given visitorId. Maybe the “idVisit”-Key in this array is what you are looking for.

But I am not sure if the request will return the current and active visit also or if it will only return old and already closed visits. I cant test this at the moment, you need to check this yourself.

@ronan_hello @Leo1 @heurteph-ei
There is no native method in JS through which I can get the current running session ID for the current visitor.


Do we need to call this API every time to get the current running session of the visitor?

I think you’ll need to call the API as the ID gets created on the serverside by Matomo when creating the visit.

However you dont have to call the API on each request. You could store the visitId in the sessionstorage and only fetch the API again if the session was expired, or something similar… But probably better to always fetch the API so you dont miss if matomo assigned a new visitID.

thanks for giving me your time to reply

i am getting xml as a response.

$("#btnMatomoVisitId").click(function () {
          if (typeof _paq !== "undefined") {
            // Wait for Matomo to finish loading
            var request = new XMLHttpRequest();
            request.onreadystatechange = function () {
              if (this.readyState == 4 && this.status == 200) {
                var response = JSON.parse(this.responseText);
                console.log("response", response)
          } else {
            console.log("Matomo tracking code not loaded yet.");

API giving XML as a response

111:1 Uncaught SyntaxError: Unexpected token '<', "<?xml vers"... is not valid JSON
    at JSON.parse (<anonymous>)
    at request.onreadystatechange ((index):707:37)


you can use &format=json in url this should return json.



1 Like

@Leo1 , yes i got it.
I have on more question in the context of matomo, as i saw they have the custom dimensions inside action dimensions where we can define our custom event which we want to capture
For example if we declare the event of addToCart
then there is no option in matomo where we can define the fields which we want to capture in our addToCart event ? means where we can define our schema corresponding to our events and set the validations which fields are required or not

every field which we want to capture against addToCart are in free in nature. i.e means you can add whatever you want and send to the Matomo server

$("#btnAddToCartMatomo").click(function () {
          console.log("Send add-to cart to matomo");
              product_id: "P12345",
              product_name: "Gaming Console PS5",
              product_price: 50000.99,
              product_qty: 1,

So in this, whatever extra field you can pass that will goes to the matomo server
But i dont want this, If this event fields are not satisfying to the schema then it would be maintain in somekind of error.log aur if satisy then only goes to the matomo server.

Do we need to rely on third-party libraries like Ajv or create your own validation functions to achieve this ?
or is there any somekind of plugin is available through which i can define the schema and validations according to my events

Below is the code of snowplow tracker where we are defining the schema

  "$schema": "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#",
  "description": "Schema for an example event",
  "self": {
    "vendor": "com.snowplowanalytics",
    "name": "example_event",
    "format": "jsonschema",
    "version": "1-0-0"
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "maxLength": 128
    "job_role": {
      "description": "",
      "type": [
      "maxLength": 128
    "promo_code": {
      "description": "",
      "type": [
      "minLength": 8,
      "maxLength": 20
  "additionalProperties": false,
  "required": [

way to call this above snowplow schema , against our coming JSON payload

$("#btnSnowPlow").click(function () {
          window.snowplow("trackSelfDescribingEvent", {
            event: {
              schema: "iglu:com.example/my-schema/jsonschema/1-0-0",
              data: {
                name: "John",
                job_role: "CEO",
                promo_code: "3306330877",
          console.log("Snowplow success");

If it not satisy the schema, then it goes to bad state

Thanks Leo :pray: