What is the Matomo visit start time?


my matomo tracking code is configured to load the matomo.js into the webpage after 10 seconds of setTimeout().

My question is what visit start time does matomo use? Is it the time when the webpage is opened, or is it the time when the matomo.js is loaded?

From the JavaScript code in the matomo.js it is not clear for me.

In several places the time is requested and set and (almost) every time a value is added. Here is one with the var r:

function am(au){
	var at;
	at=new Date();
	var av=at.getTimeAlias();
    if(r){do{at=new Date()}while(at.getTimeAlias()<r)}

and here is an another for setting the var r:

function ct(dH){
	var dG=new Date();
	var dI=dG.getTime()+dH;

and in the code are more such code points.

waiting for an answer.

Hi @melbao
I don’t know how the script works, but on my tests (Matomo 4.3), the date-time sent by the tracker (either MTM or javascript tracking) are the one of the sending, not the one of the initialization (I for example set a delay just after the following command: _mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});, but finally I got the current date-time in the HTTP request instead of the MTM initialization date-time: https://matomo-server/matomo.php?action_name=PageName&idsite=9&rec=1&r=488410&h=16&m=45&s=32&….

Hi @heurteph-ei , the question is wheter matomo use a function like document.lastModified or similar?

So whether matomo queries and uses the time of the start of the document, or whether the first ping (first request of matomo.php) is the visit start time?

On my websites the matomo.js is loaded after 10 seconds timeout.

Hi @melbao
This is what I explained in my observation: If you open the page at 10:00, then wait for 1 minute, then load Matomo JavaScript library then wait for 1 minute, then send the page view, the request time will be 10:02…

Yes, the first request time. But is this using by matomo as the visit start time? There are many calculations with the time in the matomo.js. Maybe more of that in the matomo.php?

Logically, the first request time of the matomo.php is the visit start time. But i am not really secure.

Hi @melbao
When I write: “the request time will be 10:02…”, I mean the time set in the request: https://matomo-server/matomo.php?action_name=PageName&idsite=9&rec=1&r=488410&h=10&m=02&s=00&…

Then the matomo.php has no other way to get page visit time… (and in my case, this is the client time, not server one).

Have a look at cdt param (but I advise you not to do this as this need private token_auth that will then be publicly visible…):

OK. The next question ist: How can this request time be manipulated? I need to add -10 seconds. Because, with this the reports will be are corrected.

I see only 2 solutions:

  1. Use low level HTTP API
  2. Use a proxy that adds the parameters when needed

I have make a test. It is a little bit complex.

The script matomo.js is loaded at visitor start (page load)
The _paq.push(['trackPageView']) is loaded after 10 seconds via setTimeout()
The visit start time begins with the _paq.push(['trackPageView']), also after 10 seconds. Also it has a 10 seconds time lag with that.

The _paq.push(['trackPageView']) is loaded at visitor start (page load)
The script matomo.js is loaded after 10 seconds via setTimeout()
The visit start time begins with the loading of the script matomo.js, also after 10 seconds. Also it has a 10 seconds time lag with that.

It has also always a 10 seconds time lag.
There is no possible (simple) solution to find with that.

Proxy is too much for my needs.

Hi @melbao
I see also another way to achieve your need…
Do the tracking as you already did (wait for 10 seconds before calling the tracking).
And create a plugin that differs the page view tracking date/time…