Skip to content

Commit

Permalink
Analytics logged for screens loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
cristhianescobar committed Aug 25, 2024
1 parent fb48ec3 commit 9059f7d
Show file tree
Hide file tree
Showing 18 changed files with 182 additions and 59 deletions.
9 changes: 6 additions & 3 deletions android/app-newm/src/main/java/io/newm/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,24 @@ class HomeActivity : ComponentActivity() {
is Screen.UserAccount -> ui<ProfileUiState> { state, modifier ->
ProfileUi(
state = state,
modifier = modifier
modifier = modifier,
eventLogger = eventLogger
)
}

is NFTLibrary -> ui<NFTLibraryState> { state, modifier ->
NFTLibraryScreenUi(
state = state,
modifier = modifier
modifier = modifier,
eventLogger = eventLogger
)
}

is Screen.EditProfile -> ui<ProfileEditUiState> { state, modifier ->
ProfileEditUi(
state = state,
modifier = modifier
modifier = modifier,
eventLogger = eventLogger
)
}

Expand Down
4 changes: 2 additions & 2 deletions android/app-newm/src/main/java/io/newm/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ class LoginActivity : ComponentActivity() {
}

is LoginLandingScreen -> ui<WelcomeScreenUiState> { state, modifier ->
WelcomeScreenUi(modifier, state)
WelcomeScreenUi(modifier, state, eventLogger)
}

is LoginScreen -> ui<LoginScreenUiState> { state, modifier ->
LoginScreenUi().Content(state, modifier)
}

is ResetPasswordScreen -> ui<ResetPasswordScreenUiState> { state, modifier ->
ResetPasswordScreenUi().Content(state = state, modifier = modifier)
ResetPasswordScreenUi(eventLogger).Content(state = state, modifier = modifier)
}

else -> null
Expand Down
6 changes: 1 addition & 5 deletions android/app-newm/src/main/java/io/newm/NewmAppComposable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ internal fun NewmApp(
modifier = Modifier,
sheetState = sheetState,
sheetContent = {
LaunchedEffect(Unit) {
eventLogger.logPageLoad("Music Player")
}

MusicPlayerScreen(
eventLogger = eventLogger,
onNavigateUp = {
Expand All @@ -155,7 +151,6 @@ internal fun NewmApp(
MiniPlayer(
modifier = Modifier.clickable {
coroutineScope.launch {
eventLogger.logClickEvent("Mini Player")
sheetState.show()
}
},
Expand Down Expand Up @@ -221,6 +216,7 @@ internal fun NewmBottomNavigation(
selectedLabelColor = DarkPink,
onClick = {
eventLogger.logClickEvent("Account")
eventLogger.logPageLoad("Account")
onNavigationSelected(Screen.UserAccount)
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import androidx.compose.material.rememberModalBottomSheetState
import androidx.compose.material.rememberSwipeableState
import androidx.compose.material.swipeable
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -72,6 +73,7 @@ import io.newm.screens.library.NFTLibraryEvent.PlaySong
import io.newm.screens.library.screens.EmptyWalletScreen
import io.newm.screens.library.screens.LinkWalletScreen
import io.newm.screens.library.screens.ZeroSearchResults
import io.newm.shared.public.analytics.NewmAppEventLogger
import io.newm.shared.public.models.NFTTrack
import kotlinx.coroutines.launch
import kotlin.math.roundToInt
Expand All @@ -82,7 +84,8 @@ internal const val TAG_NFT_LIBRARY_SCREEN = "TAG_NFT_LIBRARY_SCREEN"
@Composable
fun NFTLibraryScreenUi(
modifier: Modifier = Modifier,
state: NFTLibraryState
state: NFTLibraryState,
eventLogger: NewmAppEventLogger
) {
Column(
modifier = modifier
Expand All @@ -91,22 +94,47 @@ fun NFTLibraryScreenUi(
.testTag(TAG_NFT_LIBRARY_SCREEN),
) {
when (state) {
NFTLibraryState.Loading -> LoadingScreen()
NFTLibraryState.Loading -> {
LaunchedEffect(Unit) {
eventLogger.logPageLoad("NFT Library Loading")
}
LoadingScreen()
}

is NFTLibraryState.LinkWallet -> LinkWalletScreen(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 16.dp),
) { newmWalletConnectionId ->
val eventSink = state.onConnectWallet
eventSink(newmWalletConnectionId)
is NFTLibraryState.LinkWallet -> {
LaunchedEffect(Unit) {
eventLogger.logPageLoad("NFT Library Link Wallet")
}
LinkWalletScreen(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 16.dp),
) { newmWalletConnectionId ->
val eventSink = state.onConnectWallet
eventSink(newmWalletConnectionId)
}
}

NFTLibraryState.EmptyWallet -> {
LaunchedEffect(Unit) {
eventLogger.logPageLoad("NFT Library Empty Wallet")
}
EmptyWalletScreen(eventLogger)
}

is NFTLibraryState.Error -> {
LaunchedEffect(Unit) {
eventLogger.logPageLoad("NFT Library Error Screen")
}
ErrorScreen(state.message)
}

NFTLibraryState.EmptyWallet -> EmptyWalletScreen()
is NFTLibraryState.Error -> ErrorScreen(state.message)
is NFTLibraryState.Content -> {
val eventSink = state.eventSink

LaunchedEffect(Unit) {
eventLogger.logPageLoad("NFT Library Song List")
}
Text(
text = stringResource(id = R.string.title_nft_library),
modifier = Modifier.padding(16.dp),
Expand All @@ -129,7 +157,8 @@ fun NFTLibraryScreenUi(
onDownloadSong = { trackId -> eventSink(OnDownloadTrack(trackId)) },
refresh = { eventSink(NFTLibraryEvent.OnRefresh) },
refreshing = state.refreshing,
onApplyFilters = { filters -> eventSink(OnApplyFilters(filters)) }
eventLogger = eventLogger,
onApplyFilters = { filters -> eventSink(OnApplyFilters(filters)) },
)
}
}
Expand All @@ -150,7 +179,8 @@ private fun NFTTracks(
onDownloadSong: (String) -> Unit,
refresh: () -> Unit,
refreshing: Boolean,
onApplyFilters: (NFTLibraryFilters) -> Unit
eventLogger: NewmAppEventLogger,
onApplyFilters: (NFTLibraryFilters) -> Unit,
) {
val scope = rememberCoroutineScope()
val filterSheetState = rememberModalBottomSheetState(ModalBottomSheetValue.Hidden)
Expand Down Expand Up @@ -219,7 +249,7 @@ private fun NFTTracks(
modifier = Modifier.align(Alignment.TopCenter)
)

SongFilterBottomSheet(filterSheetState, filters, onApplyFilters)
SongFilterBottomSheet(filterSheetState, filters, onApplyFilters, eventLogger)
}
}

Expand Down Expand Up @@ -257,7 +287,7 @@ private fun TrackRowItemWrapper(
TrackRowItem(
track = track,
onClick = onPlaySong,
modifier = if(DOWNLOAD_UI_ENABLED) Modifier.offset {
modifier = if (DOWNLOAD_UI_ENABLED) Modifier.offset {
IntOffset(
x = -swipeableState.offset.value.roundToInt(),
y = 0
Expand Down Expand Up @@ -340,7 +370,8 @@ fun PreviewNftLibrary() {
),
refreshing = false,
eventSink = {}
)
),
eventLogger = NewmAppEventLogger()
)
}
}
Expand All @@ -350,7 +381,8 @@ fun PreviewNftLibrary() {
fun PreviewNftLibraryLoading() {
NewmTheme(darkTheme = true) {
NFTLibraryScreenUi(
state = NFTLibraryState.Loading
state = NFTLibraryState.Loading,
eventLogger = NewmAppEventLogger()
)
}
}
Expand All @@ -360,7 +392,8 @@ fun PreviewNftLibraryLoading() {
fun PreviewNftLibraryEmptyWallet() {
NewmTheme(darkTheme = true) {
NFTLibraryScreenUi(
state = NFTLibraryState.EmptyWallet
state = NFTLibraryState.EmptyWallet,
eventLogger = NewmAppEventLogger()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.material.ModalBottomSheetState
import androidx.compose.material.ModalBottomSheetValue
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
Expand All @@ -39,6 +40,7 @@ import io.newm.core.theme.Purple
import io.newm.core.theme.White
import io.newm.core.theme.inter
import io.newm.core.ui.utils.iconGradient
import io.newm.shared.public.analytics.NewmAppEventLogger


private val buttonGradient =
Expand All @@ -49,12 +51,18 @@ private val buttonGradient =
fun SongFilterBottomSheet(
sheetState: ModalBottomSheetState,
filters: NFTLibraryFilters,
onApplyFilters: (NFTLibraryFilters) -> Unit
onApplyFilters: (NFTLibraryFilters) -> Unit,
eventLogger: NewmAppEventLogger
) {
LocalIsBottomBarVisible.current.value = sheetState.targetValue != ModalBottomSheetValue.Expanded
ModalBottomSheetLayout(
sheetState = sheetState,
sheetContent = {
if (sheetState.targetValue == ModalBottomSheetValue.Expanded) {
LaunchedEffect(Unit) {
eventLogger.logPageLoad("NFT Library Filter")
}
}
Box(
modifier = Modifier
.background(Black90)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
Expand All @@ -22,7 +23,7 @@ import io.newm.shared.public.analytics.NewmAppEventLogger
private const val RECORD_STORE_URL = "https://recordstore.newm.io/"

@Composable
fun EmptyWalletScreen() {
fun EmptyWalletScreen(eventLogger: NewmAppEventLogger) {
val context = LocalContext.current

Box(
Expand All @@ -48,6 +49,7 @@ fun EmptyWalletScreen() {
modifier = Modifier.padding(all = 16.dp),
text = "Visit the Record Store",
onClick = {
eventLogger.logClickEvent("Visit the Record Store")
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(RECORD_STORE_URL)))
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
Expand All @@ -23,14 +24,14 @@ import io.newm.core.ui.permissions.rememberRequestPermissionIntent
import io.newm.core.ui.wallet.ConnectWalletPanel
import io.newm.feature.barcode.scanner.BarcodeScannerActivity
import io.newm.screens.library.TAG_NFT_LIBRARY_SCREEN
import io.newm.shared.public.analytics.NewmAppEventLogger

@Composable
fun LinkWalletScreen(
modifier: Modifier = Modifier,
onConnectWallet: (String) -> Unit
) {
val context = LocalContext.current

val launcher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult()
) { result: ActivityResult ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.material.MaterialTheme
import androidx.compose.material.ModalBottomSheetLayout
import androidx.compose.material.ModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
Expand All @@ -20,12 +21,14 @@ import io.newm.core.theme.Black90
import io.newm.core.theme.Gray400
import io.newm.core.ui.buttons.PrimaryButton
import io.newm.core.ui.buttons.SecondaryButton
import io.newm.shared.public.analytics.NewmAppEventLogger

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun ProfileBottomSheetLayout(
modifier: Modifier = Modifier,
sheetState: ModalBottomSheetState,
eventLogger: NewmAppEventLogger,
onLogout: () -> Unit,
onShowTermsAndConditions: () -> Unit,
onShowPrivacyPolicy: () -> Unit,
Expand All @@ -35,6 +38,11 @@ fun ProfileBottomSheetLayout(
modifier = modifier,
sheetState = sheetState,
sheetContent = {
if(sheetState.isVisible) {
LaunchedEffect(Unit) {
eventLogger.logPageLoad("Account Options")
}
}
Column(
modifier = Modifier
.fillMaxWidth()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import io.newm.screens.profile.ProfileForm
import io.newm.screens.profile.ProfileHeader
import io.newm.screens.profile.edit.ProfileEditUiState.Content
import io.newm.screens.profile.edit.ProfileEditUiState.Loading
import io.newm.shared.public.analytics.NewmAppEventLogger
import io.newm.shared.public.models.User
import io.newm.shared.public.models.canEditName
import io.newm.shared.public.models.mocks.mockUsers
Expand All @@ -54,13 +55,15 @@ internal const val TAG_PROFILE_SCREEN = "TAG_PROFILE_SCREEN"
fun ProfileEditUi(
modifier: Modifier,
state: ProfileEditUiState,
eventLogger: NewmAppEventLogger
) {
when (state) {
Loading -> LoadingScreen()
is Content -> {
ProfileEditUiContent(
modifier = modifier,
state = state,
eventLogger = eventLogger
)
}
}
Expand All @@ -71,6 +74,7 @@ fun ProfileEditUi(
private fun ProfileEditUiContent(
modifier: Modifier = Modifier,
state: Content,
eventLogger: NewmAppEventLogger
) {
val onEvent = state.eventSink
val profile = state.profile
Expand All @@ -81,6 +85,7 @@ private fun ProfileEditUiContent(
ProfileBottomSheetLayout(
modifier = modifier,
sheetState = sheetState,
eventLogger = eventLogger,
onLogout = { onEvent(OnLogout) },
onShowTermsAndConditions = { onEvent(OnShowTermsAndConditions) },
onShowPrivacyPolicy = { onEvent(OnShowPrivacyPolicy) }
Expand Down Expand Up @@ -170,7 +175,8 @@ private fun ProfileScreenPreview() {
confirmPasswordState = TextFieldState(),
errorMessage = null,
eventSink = {},
)
),
eventLogger = NewmAppEventLogger()
)
}
}
Expand Down
Loading

0 comments on commit 9059f7d

Please sign in to comment.