Visitor grouping in visitor log page is not working as expected when record a past datetime using 'cdt'

Hi

As per subject. When I record a tracking with a past date (for example 08/08/2012) on today (09/08/2012), Piwik will group the today records with the past date record regardless whether the ‘cid’ is set or not.

Please refer to the attached example for details.

Regards
Hao

Do you set the token_auth as well ? changing the time requires to set token_auth: http://piwik.org/docs/tracking-api/reference/

Hi Matt

Yes, I had set the token auth. As you can see in image 2, the past time had been recorded correctly (which is 8 August), but it grouped with the record on 9 August which is not correct.

After reading the debug message, I realised that the problem is in the sql query of ‘core/Tracker/Visit.php’.

// In line 1014. Piwik 1.8.2
//This sql query search for the visit_last_action_time >= ( $forcedDateTime - 30 mins) and returns the latest record of a unique visitor with the same ip address. This will do the grouping correctly if you are tracking the current timestamp, but if you are tracking a past timestamp and the visitor has no record on the same past timestamp in the database, then it will be grouped to a different date.
$whereSameBothQueries = “visit_last_action_time >= ? AND idsite = ?”;

// will use INDEX index_idsite_config_datetime (idsite, config_id, visit_last_action_time)
$bindSql[] = $timeLookBack;
$bindSql[] = $this->idsite;
$where = ’ AND config_id = ?’;
$bindSql[] = $configId;
$sqlConfigId = “$select ,
0 as priority
$from
WHERE $whereSameBothQueries $where
ORDER BY visit_last_action_time DESC
LIMIT 1
”;

// will use INDEX index_idsite_idvisitor (idsite, idvisitor)
$bindSql[] = $timeLookBack;
$bindSql[] = $this->idsite;
$where = ’ AND idvisitor = ?’;
$bindSql[] = $this->visitorInfo[‘idvisitor’];
$sqlVisitorId = “$select ,
1 as priority
$from
WHERE $whereSameBothQueries $where
LIMIT 1
”;

// We join both queries and favor the one matching the visitor_id if it did match
$sql = " ( $sqlConfigId )
UNION
( $sqlVisitorId )
ORDER BY priority DESC
LIMIT 1";

For example (please refer to the images):
step 1
I add a tracking with the following details
ip: 192.168.0.1
forceVisitorId(cid): 1000000000000001
action: Test3
domain: https://test.domain.com
datetime: current timestamp (let say 09/08/2012 11:50:02)

step 2
I added a past tracking with past timestamp
ip: 192.168.0.1
forceVisitorId(cid): 1000000000000002
action: Test4
domain: https://test.domain.com
datetime: 08/08/2012 11:50:02

step 3
This 2 visits will then group together as shown in image 2

Sorry for my bad explaination, if you find hard to understand.

Regards
Hao

So is the problem is when you record a visit with current time, then page views with past time, that the time on site is not correct?

The problem is I record a past time, then it groups with a visit with later time (more than 30 mins) instead of creating a new visit.

Consider if I have only 1 visitor in my piwik:

Page view 08/08/2012
visit 1

  1. 08/08/2012 - 12:00:00 - action 1
  2. 08/08/2012 - 12:20:00 - action 2

Page view 09/08/2012
visit 1

  1. 09/08/2012 - 05:00:00 - action 4

Then I record a pass date time in between.
08/08/2012 - 02:00:00 - action 3

The result will be:
Page view 08/08/2012
visit 1

  1. 08/08/2012 - 12:00:00 - action 1
  2. 08/08/2012 - 12:20:00 - action 2

Page view 09/08/2012
visit 1
1)08/08/2012 - 02:00:00 - action 3
2)09/08/2012 - 05:00:00 - action 4

My expected result is:
Page view 08/08/2012
visit 1

  1. 08/08/2012 - 12:00:00 - action 1
  2. 08/08/2012 - 12:20:00 - action 2

visit 2

  1. 08/08/2012 - 02:00:00 - action 3

Page view 09/08/2012
visit 1

  1. 09/08/2012 - 05:00:00 - action 4

Ok thank you for the report. Can you please create a ticket at dev.piwik.org?
I cant promise we will fix it, but maybe :slight_smile:

Hi Matt

I had created a ticket. Hope you guys can fix it. :slight_smile:

Thanks.

Regards
Hao