Time on page tracking doesn't seem to work correctly

Hello!

I’m developing a Flutter app and I’m trying to do some pretty simple use case of tracking screen views and counting time spent by user on those pages using custom reports with a dimension - “Time on page”.

I use a trackScreen method whenever a user opens some page. I also have an ability to disable tracking at any time, at which point I use the optOut method. I also differentiate between authenticated and unauthenticated user. If the user is logged in I send his userId using setUserId as well as tracking a custom dimension for that purpose. If the user is logged out I set their userId as ‘N/A’ instead. I use dispatch method after all of the above mentioned calls to make sure they are sent immediately.

A scenario I am testing is the following:

  1. Enter the Test page as an authenticated user and stay there for 1 minute
  2. Disable tracking and wait on the page for 30 seconds
  3. Log out, go back to the page and wait 90 seconds

While the screens are tracked correctly and separately for the authenticated and unauthenticated user the times on page are wildly off. I get 1 minute and 54 seconds for the authenticated user and 0s for the logged out user.

It’s especially concerning, because I can’t find any possible reason why that would be the time tracked. If the optOut method didn’t stop the tracking then the time shouldn’t be more than 1 min 30s. If the unauthenticated user time was added to the authenticated user’s time it should be at least 2min 30s. I can’t make any sense of it.

I’d appreciate any help and suggestions.

Hi there!

Did you check the tracker debugger? You can see the raw logs of every event there, and I would recommend you to check the events in the scenario you were testing and compare their timestamps to see how much time the user was on page.
You might have to run the test again since tracker debugger only holds sessions and events from the last six hours.

If the time you get from the tracker debugger is different than the one you see in the report, that might be a bug.

Another thing, if you want to reset the current userID, setting it’s value to null would be more convinient for you, since "N/A" will be treated as a normal value and won’t delete the userID.

Thanks for the answer.

As far as I can see the Session Log report provides pretty much the same functionality as the debugger, so without repeating the test for now, yes the times are more or less the same, which would suggest that perhaps the problem is with the flutter_piwikpro library and not the reports.

I will do some more testing tomorrow and see what I can find out.