Update usage logging: Track average time per day each week, SP:5
Create a module that adds tracking for the average time a user spent using the app per day over a week.
What to do?
-
Add a module that provides an RccUsageLoggingJob
(provideUsageLoggingJob()
) tracking site engagement.-
.tick$ should emit every seven days - FixedLoggingData:
-
.category: 'engagement' -
.key: '7-day-usage-time-average' -
.userId: 'none' -
.requiresUserConsent: false
-
- DynamicLoggingData
-
.extraValue: -
.computableValue: <average time in minutes spent on the app per day over the last 7 days>
-
-
-
Ignore days with no usage time. -
Keep in mind that there is another similar issue: Update usage logging: Track total usage time ov... (#1036 - closed) -
Add the module to PAT and HCP
I go with anonymous again, because we skip the id -> no consent required. What do you think?
Label:
(en) Weekly average usage per day period
(de) Durschnittliche tägliche Nutzdauer während einer Woche
Description:
(en) We count the number of minutes the app is visible in average per day, over a period of 7 days. We use this number to get an idea of the extent to which the app is used generally.
(de) Wir zählen die Anzahl der Minuten, in denen die App im Durchnitt täglich sichtbar ist, über einen Zeitraum von 7 Tagen. Wir verwenden diese Zahl, um eine Vorstellung davon zu bekommen, in welchem Umfang die App im Allgemeinen genutzt wird.
In order to trigger events on .tick$ we need to collect data over time. Whenever the app is in focus start counting (or record the time), when it loses focus stop counting (or record the time). After 7 days emit the average number of minutes recorded per day over the last 7 days. After that delete all data and start counting again.
Try to store as little data as possibly.
To track if the app comes in or out of view, try the visibilitychange event.
What does 7 days mean?
I suggest the following: Count and store minutes per day. When the app gains or loses focus, check if the last day that .tick$ was triggered for lies more than 7 days in the past; if so emit the average of minutes per day of the 7 days before today (not including today) – total number devided by the number of days with usage. Store yesterday as the last day .tick$ was triggered for.
It's okay if we lose a couple of days: The user might use the app for 6 days, then take a break for 4 days, then the app should we recorded from the last 3 days of the initial period divided by 3.
Value to post
Number of total minutes within the last seven days, divided by the number of days that have non-zero usage time. Fractions are okay.
How to count?
I am not entirely sure how much code we can run after the visibilitychange event, when the visibitlystate is hidden. It might be, that some (async) code gets canceled, if the browser is closed. Same goes for the app crashing or the battery dying.
Maybe we can start an interval – when the app comes into view – ticking every minute checking the visibility state and if visible adding 1 to the count. This way if the browser exits unexpectedly, the recorded time is still saved.