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.
https://developer.matomo.org/api-reference/tracking-api
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.
http://localhost/matomo-4.14.1/matomo/matomo.php?e_c=Contact&e_a=Email%20Link%20Click&e_n=name%40example.com&ca=1&idsite=1&rec=1&r=771036&h=23&m=22&s=28&url=http%3A%2F%2Flocalhost%2Fbox%2F&_id=80b16aafbb1042b3&_idn=0&send_image=0&_refts=0&pdf=1&qt=0&realp=0&wma=0&fla=0&java=0&ag=0&cookie=1&res=1280x720&pv_id=ROWTRG&uadata={ābrandsā%3A[{ābrandā%3A"Chromium"%2C"version"%3A"112"}%2C{ābrandā%3A"Google%20Chrome"%2C"version"%3A"112"}%2C{ābrandā%3A"Not%3AA-Brand"%2C"version"%3A"99"}]%2C"platform"%3A"Windows"}
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ā:
@heurteph-ei
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) {
return;
}
$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 ?
Team
Anyone can please guide me on this ?
I am stuck in this from a long
Hi,
I think you can try building your request using Matomo Tracking HTTP API URL Builder to find the issue ?
Regards,
Ronan HELLO
@ronan_hello
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" */
_paq.push(["enableHeartBeatTimer"]);
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
(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
</script>
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
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
@ronan_hello
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?
http://matomo.local/index.php?module=API&method=Live.getVisitorProfile&idSite=<SITE_ID>&visitorId=<VISITOR_ID>&limitVisits=1&token_auth=<AUTH_TOKEN>
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.
http://matomo.local/index.php?module=API&method=Live.getVisitorProfile&idSite=<SITE_ID>&visitorId=<VISITOR_ID>&limitVisits=1&token_auth=<AUTH_TOKEN>
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.
@Leo1
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)
}
};
request.open(
"GET",
"http://localhost/matomo-4.14.1/matomo/index.php?module=API&method=Live.getVisitorProfile&idSite=1&visitorId=80b16aafbb1042b3&limitVisits=1&token_auth=87eb297419e2605b7a18342e2dfed373"
);
request.send();
} 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)
Thanks
you can use &format=json
in url this should return json.
https://developer.matomo.org/api-reference/reporting-api#standard-api-parameters
https://developer.matomo.org/api-reference/reporting-api#Live
@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");
_paq.push([
"trackEvent",
"Category",
"AddtoWishlist",
JSON.stringify({
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": [
"string",
"null"
],
"maxLength": 128
},
"promo_code": {
"description": "",
"type": [
"string",
"null"
],
"minLength": 8,
"maxLength": 20
}
},
"additionalProperties": false,
"required": [
"name"
]
}
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