Skip to content

Commit

Permalink
Tracks Audit: Tweaks for tracking (#3423)
Browse files Browse the repository at this point in the history
  • Loading branch information
mebarbosa authored Jan 13, 2025
1 parent 43eb1a5 commit 99b3a52
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import androidx.interpolator.view.animation.FastOutSlowInInterpolator
import androidx.transition.ChangeBounds
import androidx.transition.TransitionManager

fun TextView.readMore(collapsedLines: Int) {
fun TextView.readMore(collapsedLines: Int, onTextClicked: () -> Unit = {}) {
maxLines = collapsedLines
ellipsize = TextUtils.TruncateAt.END
setOnClickListener {
onTextClicked()
val transition = ChangeBounds().apply {
duration = 200
interpolator = FastOutSlowInInterpolator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class PodcastAdapter(
private val onEpisodeRowLongPress: (PodcastEpisode) -> Unit,
private val onBookmarkRowLongPress: (Bookmark) -> Unit,
private val onFoldersClicked: () -> Unit,
private val onPodcastDescriptionClicked: () -> Unit,
private val onNotificationsClicked: () -> Unit,
private val onSettingsClicked: () -> Unit,
private val playButtonListener: PlayButton.OnClickListener,
Expand Down Expand Up @@ -318,7 +319,9 @@ class PodcastAdapter(
podcast.podcastDescription
}
holder.binding.bottom.description.setLinkTextColor(tintColor)
holder.binding.bottom.description.readMore(3)
holder.binding.bottom.description.readMore(3) {
onPodcastDescriptionClicked()
}
holder.binding.bottom.authorText.text = podcast.author
holder.binding.bottom.authorText.isVisible = podcast.author.isNotBlank()
holder.binding.bottom.authorImage.isVisible = podcast.author.isNotBlank()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,9 @@ class PodcastFragment : BaseFragment(), Toolbar.OnMenuItemClickListener {
sortType = settings.podcastBookmarksSortType.flow.value,
).asObservable(),
fragmentManager = parentFragmentManager,
onPodcastDescriptionClicked = {
analyticsTracker.track(AnalyticsEvent.PODCAST_SCREEN_PODCAST_DESCRIPTION_TAPPED)
},
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import androidx.core.os.BundleCompat
import androidx.core.os.bundleOf
import androidx.fragment.app.viewModels
import androidx.fragment.compose.content
import au.com.shiftyjelly.pocketcasts.analytics.AnalyticsEvent
import au.com.shiftyjelly.pocketcasts.analytics.AnalyticsTracker
import au.com.shiftyjelly.pocketcasts.analytics.SourceView
import au.com.shiftyjelly.pocketcasts.models.entity.PodcastEpisode
import au.com.shiftyjelly.pocketcasts.reimagine.clip.ShareClipViewModel.SnackbarMessage
Expand Down Expand Up @@ -67,6 +69,9 @@ class ShareClipFragment : BaseDialogFragment() {
@Inject
lateinit var sharingClient: SharingClient

@Inject
lateinit var analyticsTracker: AnalyticsTracker

@Inject
lateinit var clipAnalyticsFactory: ClipAnalytics.Factory

Expand Down Expand Up @@ -114,6 +119,9 @@ class ShareClipFragment : BaseDialogFragment() {
assetController = assetController,
listener = listener,
snackbarHostState = snackbarHostState,
onNavigationButtonTapped = { analyticsTracker.track(AnalyticsEvent.SHARE_SCREEN_NAVIGATION_BUTTON_TAPPED) },
onEditTapped = { analyticsTracker.track(AnalyticsEvent.SHARE_SCREEN_EDIT_BUTTON_TAPPED) },
onCloseTapped = { analyticsTracker.track(AnalyticsEvent.SHARE_SCREEN_CLOSE_BUTTON_TAPPED) },
)

LaunchedEffect(Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.animateIntOffsetAsState
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.background
Expand Down Expand Up @@ -130,6 +129,9 @@ internal fun ShareClipPage(
useEpisodeArtwork: Boolean,
useKeyboardInput: Boolean,
assetController: BackgroundAssetController,
onNavigationButtonTapped: () -> Unit,
onEditTapped: () -> Unit,
onCloseTapped: () -> Unit,
listener: ShareClipPageListener,
state: ClipPageState = rememberClipPageState(
firstVisibleItemIndex = (clipRange.startInSeconds - 10).coerceAtLeast(0),
Expand All @@ -150,6 +152,9 @@ internal fun ShareClipPage(
useKeyboardInput = useKeyboardInput,
assetController = assetController,
listener = listener,
onNavigationButtonTapped = onNavigationButtonTapped,
onEditTapped = onEditTapped,
onCloseTapped = onCloseTapped,
state = state,
snackbarHostState = snackbarHostState,
)
Expand All @@ -166,13 +171,15 @@ internal fun ShareClipPage(
useKeyboardInput = useKeyboardInput,
assetController = assetController,
listener = listener,
onNavigationButtonTapped = onNavigationButtonTapped,
onEditTapped = onEditTapped,
onCloseTapped = onCloseTapped,
state = state,
snackbarHostState = snackbarHostState,
)
}
}

@OptIn(ExperimentalFoundationApi::class)
@Composable
private fun VerticalClipPage(
episode: PodcastEpisode?,
Expand All @@ -187,6 +194,9 @@ private fun VerticalClipPage(
useKeyboardInput: Boolean,
assetController: BackgroundAssetController,
listener: ShareClipPageListener,
onNavigationButtonTapped: () -> Unit,
onEditTapped: () -> Unit,
onCloseTapped: () -> Unit,
state: ClipPageState,
snackbarHostState: SnackbarHostState,
) {
Expand All @@ -213,6 +223,7 @@ private fun VerticalClipPage(
sharingState = sharingState,
shareColors = shareColors,
selectedCard = selectedCard,
onEditTapped = onEditTapped,
listener = listener,
state = state,
)
Expand All @@ -239,14 +250,18 @@ private fun VerticalClipPage(
shareColors = shareColors,
useKeyboardInput = useKeyboardInput,
selectedCard = selectedCard,
onNavigationButtonTapped = onNavigationButtonTapped,
listener = listener,
state = state,
)
}
}
CloseButton(
shareColors = shareColors,
onClick = listener::onClose,
onClick = {
onCloseTapped()
listener.onClose()
},
modifier = Modifier
.padding(top = 12.dp, end = 12.dp)
.align(Alignment.TopEnd),
Expand All @@ -273,6 +288,9 @@ private fun HorizontalClipPage(
useKeyboardInput: Boolean,
assetController: BackgroundAssetController,
listener: ShareClipPageListener,
onNavigationButtonTapped: () -> Unit,
onCloseTapped: () -> Unit,
onEditTapped: () -> Unit,
state: ClipPageState,
snackbarHostState: SnackbarHostState,
) {
Expand All @@ -289,6 +307,7 @@ private fun HorizontalClipPage(
sharingState = sharingState,
shareColors = shareColors,
selectedCard = CardType.Horizontal,
onEditTapped = onEditTapped,
listener = listener,
state = state,
)
Expand Down Expand Up @@ -323,6 +342,7 @@ private fun HorizontalClipPage(
useKeyboardInput = useKeyboardInput,
selectedCard = CardType.Horizontal,
listener = listener,
onNavigationButtonTapped = onNavigationButtonTapped,
state = state,
modifier = Modifier.weight(1f),
)
Expand All @@ -334,7 +354,10 @@ private fun HorizontalClipPage(
}
CloseButton(
shareColors = shareColors,
onClick = listener::onClose,
onClick = {
onCloseTapped()
listener.onClose()
},
modifier = Modifier
.padding(top = 12.dp, end = 12.dp)
.align(Alignment.TopEnd),
Expand All @@ -352,6 +375,7 @@ private fun DescriptionContent(
sharingState: SharingState,
shareColors: ShareColors,
selectedCard: CardType,
onEditTapped: () -> Unit,
listener: ShareClipPageListener,
state: ClipPageState,
) {
Expand Down Expand Up @@ -420,7 +444,10 @@ private fun DescriptionContent(
indication = ripple(color = shareColors.accent),
onClickLabel = stringResource(LR.string.share_clip_edit_label),
role = Role.Button,
onClick = listener::onShowClipSelection,
onClick = {
onEditTapped()
listener.onShowClipSelection()
},
)
.padding(vertical = 4.dp, horizontal = 16.dp),
)
Expand All @@ -439,7 +466,6 @@ private fun DescriptionContent(
}
}

@OptIn(ExperimentalFoundationApi::class)
@Composable
private fun PagingContent(
episode: PodcastEpisode,
Expand Down Expand Up @@ -527,6 +553,7 @@ private fun PageControlsContent(
useKeyboardInput: Boolean,
selectedCard: CardType,
listener: ShareClipPageListener,
onNavigationButtonTapped: () -> Unit,
state: ClipPageState,
modifier: Modifier = Modifier,
) {
Expand All @@ -547,6 +574,7 @@ private fun PageControlsContent(
useKeyboardInput = useKeyboardInput,
selectedCard = selectedCard,
listener = listener,
onNavigationButtonTapped = onNavigationButtonTapped,
state = state,
)
Step.PlatformSelection -> SharingControls(
Expand Down Expand Up @@ -574,6 +602,7 @@ private fun ClipControls(
shareColors: ShareColors,
useKeyboardInput: Boolean,
selectedCard: CardType,
onNavigationButtonTapped: () -> Unit,
listener: ShareClipPageListener,
state: ClipPageState,
) {
Expand All @@ -598,6 +627,8 @@ private fun ClipControls(
)
BaseRowButton(
onClick = {
onNavigationButtonTapped()

if (!sharingState.iSharing) {
when (selectedCard) {
CardType.Vertical, CardType.Horizontal, CardType.Square -> {
Expand Down Expand Up @@ -827,6 +858,9 @@ internal fun ShareClipPagePreview(
useKeyboardInput = useKeyboardInput,
assetController = BackgroundAssetController.preview(),
listener = ShareClipPageListener.Preview,
onNavigationButtonTapped = {},
onCloseTapped = {},
onEditTapped = {},
state = rememberClipPageState(
firstVisibleItemIndex = 0,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class EpisodeArtworkConfigurationFragment : BaseFragment() {
toggle = SettingRowToggle.Checkbox(checked = configuration.useEpisodeArtwork(element), enabled = configuration.useEpisodeArtwork),
modifier = Modifier.toggleable(value = configuration.useEpisodeArtwork(element), role = Role.Checkbox) { newValue ->
if (configuration.useEpisodeArtwork) {
analyticsTracker.track(AnalyticsEvent.SETTINGS_ADVANCED_EPISODE_ARTWORK_CUSTOMIZATION_ELEMENT_TOGGLED, mapOf("enabled" to newValue, "element" to element.name.lowercase()))
analyticsTracker.track(AnalyticsEvent.SETTINGS_ADVANCED_EPISODE_ARTWORK_CUSTOMIZATION_ELEMENT_TOGGLED, mapOf("enabled" to newValue, "element" to element.analyticsValue))
}
onUpdateConfiguration(if (newValue) configuration.enable(element) else configuration.disable(element))
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ enum class AnalyticsEvent(val key: String) {
PODCAST_SCREEN_OPTIONS_TAPPED("podcast_screen_options_tapped"),
PODCAST_SCREEN_TOGGLE_ARCHIVED("podcast_screen_toggle_archived"),
PODCAST_SCREEN_TOGGLE_SUMMARY("podcast_screen_toggle_summary"),
PODCAST_SCREEN_PODCAST_DESCRIPTION_TAPPED("podcast_screen_podcast_description_tapped"),
PODCAST_SCREEN_SHARE_TAPPED("podcast_screen_share_tapped"),
PODCASTS_SCREEN_SORT_ORDER_CHANGED("podcasts_screen_sort_order_changed"),
PODCASTS_SCREEN_EPISODE_GROUPING_CHANGED("podcasts_screen_episode_grouping_changed"),
Expand Down Expand Up @@ -674,6 +675,9 @@ enum class AnalyticsEvent(val key: String) {
SHARE_SCREEN_PLAY_TAPPED("share_screen_play_tapped"),
SHARE_SCREEN_PAUSE_TAPPED("share_screen_pause_tapped"),
SHARE_SCREEN_CLIP_SHARED("share_screen_clip_shared"),
SHARE_SCREEN_NAVIGATION_BUTTON_TAPPED("share_screen_navigation_button_tapped"),
SHARE_SCREEN_EDIT_BUTTON_TAPPED("share_screen_edit_button_tapped"),
SHARE_SCREEN_CLOSE_BUTTON_TAPPED("share_screen_close_button_tapped"),

/* Pocket Casts Champion */
POCKET_CASTS_CHAMPION_DIALOG_SHOWN("pocket_casts_champion_dialog_shown"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ data class ArtworkConfiguration(
fun disable(element: Element) = copy(enabledElements = enabledElements - element)

enum class Element(
val analyticsValue: String,
internal val key: String,
) {
Filters("filters"),
UpNext("up_next"),
Downloads("downloads"),
Files("files"),
Starred("starred"),
Bookmarks("bookmarks"),
ListeningHistory("listening_history"),
Podcasts("podcasts"),
Filters(key = "filters", analyticsValue = "filters"),
UpNext(key = "up_next", analyticsValue = "upnext"),
Downloads(key = "downloads", analyticsValue = "downloads"),
Files(key = "files", analyticsValue = "files"),
Starred(key = "starred", analyticsValue = "starred"),
Bookmarks(key = "bookmarks", analyticsValue = "bookmarks"),
ListeningHistory(key = "listening_history", analyticsValue = "listeninghistory"),
Podcasts(key = "podcasts", analyticsValue = "podcasts"),
;

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import timber.log.Timber

class SystemBatteryRestrictions @Inject constructor(@ApplicationContext private val context: Context) {

enum class Status {
Unrestricted,
Optimized,
Restricted,
Other,
enum class Status(val analyticsValue: String) {
Unrestricted("unrestricted"),
Optimized("optimized"),
Restricted("restricted"),
Other("other"),
;
// "Other" occurs when battery use is unrestricted but background processing is restricted
// The only way I know that users can get into this state is if the app is set to be restricted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class BatteryRestrictionsSettingsFragment : BaseFragment() {
activity?.onBackPressed()
},
onClick = {
analyticsTracker.track(AnalyticsEvent.BATTERY_RESTRICTIONS_TOGGLED, mapOf("current_status" to batteryRestrictions.status.name.lowercase()))
analyticsTracker.track(AnalyticsEvent.BATTERY_RESTRICTIONS_TOGGLED, mapOf("current_status" to batteryRestrictions.status.analyticsValue))
batteryRestrictions.promptToUpdateBatteryRestriction(context)
},
openUrl = { url ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private class PodcastSelectAdapter(val list: List<SelectablePodcast>, @ColorInt
}

private fun PodcastSelectFragmentSource?.toEventProperty(): Map<String, String> {
return this?.name?.let { mapOf("source" to it.lowercase()) } ?: emptyMap()
return this?.analyticsValue?.let { mapOf("source" to it) } ?: emptyMap()
}

@Parcelize
Expand All @@ -301,9 +301,9 @@ private data class PodcastSelectFragmentArgs(
val source: PodcastSelectFragmentSource,
) : Parcelable

enum class PodcastSelectFragmentSource {
AUTO_ADD,
DOWNLOADS,
NOTIFICATIONS,
FILTERS,
enum class PodcastSelectFragmentSource(val analyticsValue: String) {
AUTO_ADD("auto_add"),
DOWNLOADS("downloads"),
NOTIFICATIONS("notifications"),
FILTERS("filters"),
}

0 comments on commit 99b3a52

Please sign in to comment.