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

Tracks Audit: Add missing bookmark events #3420

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.fragment.compose.content
import au.com.shiftyjelly.pocketcasts.compose.AppThemeWithBackground
import au.com.shiftyjelly.pocketcasts.compose.CallOnce
import au.com.shiftyjelly.pocketcasts.models.entity.Bookmark
import au.com.shiftyjelly.pocketcasts.ui.theme.Theme
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -30,6 +31,11 @@ class BookmarkFragment : Fragment() {
LaunchedEffect(Unit) { viewModel.load(BookmarkArguments.createFromArguments(arguments)) }
AppThemeWithBackground(Theme.ThemeType.DARK) {
val uiState: BookmarkViewModel.UiState by viewModel.uiState.collectAsState()

CallOnce {
viewModel.onShown()
}

BookmarkPage(
isNewBookmark = uiState.isNewBookmark,
title = uiState.title,
Expand All @@ -44,6 +50,7 @@ class BookmarkFragment : Fragment() {
}

private fun saveBookmark() {
viewModel.onSubmitBookmark()
viewModel.saveBookmark(onSaved = { bookmark, isExisting ->
bookmarkSaved(bookmark, isExisting)
})
Expand All @@ -63,6 +70,7 @@ class BookmarkFragment : Fragment() {
}

private fun close() {
viewModel.onClose()
requireActivity().run {
setResult(Activity.RESULT_CANCELED)
finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.input.TextFieldValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import au.com.shiftyjelly.pocketcasts.analytics.AnalyticsEvent
import au.com.shiftyjelly.pocketcasts.analytics.AnalyticsTracker
import au.com.shiftyjelly.pocketcasts.models.entity.Bookmark
import au.com.shiftyjelly.pocketcasts.repositories.bookmark.BookmarkManager
import au.com.shiftyjelly.pocketcasts.repositories.podcast.EpisodeManager
Expand All @@ -25,6 +27,7 @@ class BookmarkViewModel
private val episodeManager: EpisodeManager,
private val userEpisodeManager: UserEpisodeManager,
private val bookmarkManager: BookmarkManager,
private val analyticsTracker: AnalyticsTracker,
) : ViewModel(), CoroutineScope {

private lateinit var arguments: BookmarkArguments
Expand Down Expand Up @@ -114,4 +117,16 @@ class BookmarkViewModel
}
}
}

fun onShown() {
analyticsTracker.track(AnalyticsEvent.BOOKMARK_EDIT_FORM_SHOWN)
}

fun onClose() {
analyticsTracker.track(AnalyticsEvent.BOOKMARK_EDIT_FORM_DISMISSED)
}

fun onSubmitBookmark() {
analyticsTracker.track(AnalyticsEvent.BOOKMARK_EDIT_FORM_SUBMITTED)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
Expand Down Expand Up @@ -146,6 +145,12 @@ class BookmarksFragment : BaseFragment() {
addFragment(fragment)
}
},
onClearSearchTapped = {
bookmarksViewModel.clearSearchTapped()
},
onSearchBarClearButtonTapped = {
bookmarksViewModel.searchBarClearButtonTapped()
},
bottomInset = if (sourceView == SourceView.PROFILE) {
0.dp + bottomInset.value.pxToDp(LocalContext.current).dp
} else {
Expand Down Expand Up @@ -212,6 +217,7 @@ class BookmarksFragment : BaseFragment() {
private fun onShareBookmarkClick() {
lifecycleScope.launch {
val (podcast, episode, bookmark) = bookmarksViewModel.getSharedBookmark() ?: return@launch
bookmarksViewModel.onShare(podcast.uuid, episode.uuid, sourceView)
val timestamp = bookmark.timeSecs.seconds
if (FeatureFlag.isEnabled(Feature.REIMAGINE_SHARING)) {
ShareEpisodeTimestampFragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ fun BookmarksPage(
onUpgradeClicked: () -> Unit,
showOptionsDialog: (Int) -> Unit,
openFragment: (Fragment) -> Unit,
onClearSearchTapped: () -> Unit,
onSearchBarClearButtonTapped: () -> Unit,
bottomInset: Dp,
) {
val context = LocalContext.current
Expand All @@ -86,6 +88,8 @@ fun BookmarksPage(
onUpgradeClicked = onUpgradeClicked,
openFragment = openFragment,
bottomInset = bottomInset,
onClearSearchTapped = onClearSearchTapped,
onSearchBarClearButtonTapped = onSearchBarClearButtonTapped,
)
LaunchedEffect(episodeUuid) {
bookmarksViewModel.loadBookmarks(
Expand Down Expand Up @@ -132,6 +136,8 @@ private fun Content(
onSearchTextChanged: (String) -> Unit,
onUpgradeClicked: () -> Unit,
openFragment: (Fragment) -> Unit,
onClearSearchTapped: () -> Unit,
onSearchBarClearButtonTapped: () -> Unit,
bottomInset: Dp,
) {
Box(
Expand All @@ -149,6 +155,8 @@ private fun Content(
onPlayClick = onPlayClick,
onSearchTextChanged = onSearchTextChanged,
bottomInset = bottomInset,
onClearSearchTapped = onClearSearchTapped,
onSearchBarClearButtonTapped = onSearchBarClearButtonTapped,
)

is UiState.Empty -> NoBookmarksView(
Expand Down Expand Up @@ -179,6 +187,8 @@ private fun BookmarksView(
onOptionsMenuClicked: () -> Unit,
onPlayClick: (Bookmark) -> Unit,
onSearchTextChanged: (String) -> Unit,
onClearSearchTapped: () -> Unit,
onSearchBarClearButtonTapped: () -> Unit,
bottomInset: Dp,
) {
val focusRequester = remember { FocusRequester() }
Expand All @@ -193,6 +203,7 @@ private fun BookmarksView(
text = state.searchText,
placeholder = stringResource(LR.string.search),
onTextChanged = onSearchTextChanged,
onClearButtonTapped = onSearchBarClearButtonTapped,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp)
Expand All @@ -205,7 +216,14 @@ private fun BookmarksView(
state.searchText.isNotEmpty() &&
state.bookmarks.isEmpty()
) {
item { NoBookmarksInSearchView(onActionClick = { onSearchTextChanged("") }) }
item {
NoBookmarksInSearchView(
onActionClick = {
onClearSearchTapped()
onSearchTextChanged("")
},
)
}
} else {
item {
val title = stringResource(
Expand Down Expand Up @@ -294,6 +312,8 @@ private fun BookmarksPreview(
onSearchTextChanged = {},
onUpgradeClicked = {},
openFragment = {},
onClearSearchTapped = {},
onSearchBarClearButtonTapped = {},
bottomInset = 0.dp,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,18 @@ class BookmarksViewModel
return sortType as UserSetting<BookmarksSortType>
}

fun clearSearchTapped() {
analyticsTracker.track(AnalyticsEvent.BOOKMARKS_CLEAR_SEARCH_TAPPED)
}

fun searchBarClearButtonTapped() {
analyticsTracker.track(AnalyticsEvent.BOOKMARKS_SEARCHBAR_CLEAR_BUTTON_TAPPED)
}

fun onShare(podcastUuid: String, episodeUuid: String, source: SourceView) {
analyticsTracker.track(AnalyticsEvent.BOOKMARK_SHARE_TAPPED, mapOf("podcast_uuid" to podcastUuid, "episode_uuid" to episodeUuid, "source" to source.analyticsValue))
}

sealed class UiState {
data class Empty(val sourceView: SourceView) : UiState() {
val colors: NoBookmarksViewColors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ class PodcastFragment : BaseFragment(), Toolbar.OnMenuItemClickListener {
private fun onShareBookmarkClick() {
lifecycleScope.launch {
val (podcast, episode, bookmark) = viewModel.getSharedBookmark() ?: return@launch
viewModel.onBookmarkShare(podcast.uuid, episode.uuid, sourceView)
val timestamp = bookmark.timeSecs.seconds
if (FeatureFlag.isEnabled(Feature.REIMAGINE_SHARING)) {
ShareEpisodeTimestampFragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,10 @@ class PodcastViewModel
}
}

fun onBookmarkShare(podcastUuid: String, episodeUuid: String, source: SourceView) {
analyticsTracker.track(AnalyticsEvent.BOOKMARK_SHARE_TAPPED, mapOf("podcast_uuid" to podcastUuid, "episode_uuid" to episodeUuid, "source" to source.analyticsValue))
}

private fun trackEpisodeBulkEvent(event: AnalyticsEvent, count: Int) {
episodeAnalytics.trackBulkEvent(
event,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ enum class AnalyticsEvent(val key: String) {
BOOKMARK_PLAY_TAPPED("bookmark_play_tapped"),
BOOKMARKS_SORT_BY_CHANGED("bookmarks_sort_by_changed"),
BOOKMARK_DELETED("bookmark_deleted"),
BOOKMARKS_CLEAR_SEARCH_TAPPED("bookmarks_clear_search_tapped"),
BOOKMARK_DELETE_FORM_SHOWN("bookmark_delete_form_shown"),
BOOKMARK_DELETE_FORM_SUBMITTED("bookmark_delete_form_submitted"),
BOOKMARKS_SEARCHBAR_CLEAR_BUTTON_TAPPED("bookmarks_searchbar_clear_button_tapped"),
BOOKMARK_EDIT_FORM_SHOWN("bookmark_edit_form_shown"),
BOOKMARK_EDIT_FORM_DISMISSED("bookmark_edit_form_dismissed"),
BOOKMARK_EDIT_FORM_SUBMITTED("bookmark_edit_form_submitted"),
BOOKMARK_SHARE_TAPPED("bookmark_share_tapped"),
PROFILE_BOOKMARKS_SHOWN("profile_bookmarks_shown"),

/* User lifecycle events */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ object SearchBarDefaults {
fun SearchBar(
text: String,
onTextChanged: (String) -> Unit,
onClearButtonTapped: () -> Unit = {},
modifier: Modifier = Modifier,
leadingIcon: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
Expand Down Expand Up @@ -163,6 +164,7 @@ fun SearchBar(
if (text.isNotEmpty()) {
IconButton(
onClick = {
onClearButtonTapped()
onTextChanged("")
focusManager.clearFocus()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ class MultiSelectBookmarksHelper @Inject constructor(
return
}

analyticsTracker.track(
AnalyticsEvent.BOOKMARK_DELETE_FORM_SHOWN,
mapOf("source" to source.analyticsValue),
)

val count = bookmarks.size
ConfirmationDialog()
.setForceDarkTheme(source == SourceView.PLAYER)
Expand All @@ -133,6 +138,11 @@ class MultiSelectBookmarksHelper @Inject constructor(
.setIconTint(UR.attr.support_05)
.setOnConfirm {
launch {
analyticsTracker.track(
AnalyticsEvent.BOOKMARK_DELETE_FORM_SUBMITTED,
mapOf("source" to source.analyticsValue),
)

bookmarks.forEach {
bookmarkManager.deleteToSync(it.uuid)
analyticsTracker.track(
Expand Down
Loading