'Android Matomo sends actions in multiple visits

Hi I'm using Matomo for Android and i have this issue were Matomo sends each action as a single visit instead of all actions of the visit as one visit. So for example each page i open in the last 5 seconds will be sends in one visit each.

Example: I open the Start screen and then the search screen and then result screen. I would have 3 different visits in matomo dashboard with only one page view per visit. So one visit for start screen, one for search and one for result.

In iOS i dont have this issue, there it sends all my actions in one single Visit, as it should.

What could be the Problem? I implemented the getTracker() method in the abstract class for all my pages so it should be fine and like in iOS.



Solution 1:[1]

Did you try to define a userId or visitorId when creating the tracker? You could generate a unique userID on first startup of the app and store it in the shared preferences, while you create a visitorID on each startup and thus track the current session. You can explicitly set those ids then, e.g:

TrackerBuilder
   .createDefault(BuildConfig.MATOMO_URI, BuildConfig.MATOMO_SITE_ID)
   .build(Matomo.getInstance(c))
   .setUserId(userIdFromSharedPrefs)
   .setVisitorId(visitorIdGeneratedOnEachStartup)

Tracking works fine for me then, actions are rolled up and postet for the current visitor session bundles in the visit.

If you don't define them, the Matomo Android API should create and persist a default visitorID, but no userID to "mimic behaviour like in iOS" (as stated here: https://github.com/matomo-org/matomo-sdk-android/pull/256 which was a commit following this discussion: https://github.com/matomo-org/matomo-sdk-android/issues/255) However, I also faces troubles with this implementation and Thus I started setting these ids on my own, and it works as expected.

Mind though, that the behaviour could also depend on the Matomo version you use for Android and on the Server...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Luigi_Papardelle