Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pixel: Add tab activity stats to a daily pixel #5278

Merged
merged 22 commits into from
Nov 19, 2024

Conversation

0nko
Copy link
Member

@0nko 0nko commented Nov 15, 2024

Task/Issue URL: https://app.asana.com/0/1207418217763355/1208414748460831/f

Description

This PR adds the following parameters to the m_tab_manager_clicked_daily pixel:

  • tab_count: The number of open tabs
  • tab_active_7d: The number of tabs access within the last 7 days
  • tab_inactive_1w: Tabs not accessed for more than a week, but less than 2 weeks
  • tab_inactive_2w: Tabs not accessed for more than 2 weeks, but less than 3 weeks
  • tab_inactive_3w: Tabs not accessed for at least 3 weeks

All stats are reported within buckets due to privacy reasons:

image

A new column was added to the TabEntity — the lastAccessTime, which is updated every time a tab is activated.

Steps to test this PR

DB migration

  • Run the app with existing data with a previous DB version
  • Verify the migration to version 56 succeeds (no crashes)

Pixel firing

  • Run the app
  • Open the tab switcher
  • Verify the m_tab_manager_clicked_daily pixel is fired with all of the parameters mentioned above

Last access time updates

  • Run the app and access a couple of different tabs
  • Open the App Inspector in AS
  • Select the DDG process
  • Select the app.db database
  • Select the tabs table
  • Verify the lastAccessTime was updated for the access tabs using correct time

@0nko 0nko force-pushed the feature/ondrej/tab-activity-stats branch from c4762cf to 04acf5e Compare November 18, 2024 14:43
@karlenDimla karlenDimla self-assigned this Nov 19, 2024
import org.mockito.Mockito.mock
import org.mockito.kotlin.whenever

class DefaultTabStatsBucketingTest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn’t have to be an Android Test, we can move it to unitTest instead and run it as such.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

}

@Test
fun testGetNumberOfOpenTabsExactly1() = runBlocking {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of runBlocking, runTest is better to use in tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call 👍

}
}

@ContributesBinding(AppScope::class)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious q, does it have to be AppScope?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, it could have been FragmentScope, as well, but since the only dependency here is the TabManager which is also scoped in AppScope, this allows the class to be used from anywhere.

val inactive2w = viewModelScope.async(dispatchers.io()) { tabStatsBucketing.getTabsActiveTwoWeeksAgo() }
val inactive3w = viewModelScope.async(dispatchers.io()) { tabStatsBucketing.getTabsActiveMoreThanThreeWeeksAgo() }

viewModelScope.launch {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to run this on io as well, since we have a bunch of await() calls here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

Copy link
Contributor

@karlenDimla karlenDimla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and works as expected. A few comments that would be good to clarify before merging.

@0nko
Copy link
Member Author

0nko commented Nov 19, 2024

@karlenDimla I’ve addressed your comments in the code.

@0nko 0nko merged commit 6befcda into develop Nov 19, 2024
5 checks passed
@0nko 0nko deleted the feature/ondrej/tab-activity-stats branch November 19, 2024 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants