Skip to content

Commit

Permalink
Merge pull request #20075 from wordpress-mobile/issue/20062-20063-sit…
Browse files Browse the repository at this point in the history
…e-monitor-fixes

Site Monitor: Add analytics for tabs and fix tab colors
  • Loading branch information
AjeshRPai authored Jan 30, 2024
2 parents e0e84ab + f59c5df commit 3be9ac9
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,22 @@ import org.wordpress.android.ui.compose.components.MainTopAppBar
import org.wordpress.android.ui.compose.components.NavigationIcons
import org.wordpress.android.ui.compose.theme.AppTheme
import org.wordpress.android.util.extensions.getSerializableExtraCompat
import javax.inject.Inject

@AndroidEntryPoint
class SiteMonitorParentActivity: AppCompatActivity() {
@Inject
lateinit var siteMonitorUtils: SiteMonitorUtils

private var savedStateSparseArray = SparseArray<Fragment.SavedState>()
private var currentSelectItemId = 0

@Suppress("DEPRECATION")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

siteMonitorUtils.trackActivityLaunched()

if (savedInstanceState != null) {
savedStateSparseArray = savedInstanceState.getSparseParcelableArray(
SAVED_STATE_CONTAINER_KEY
Expand Down Expand Up @@ -98,6 +105,8 @@ class SiteMonitorParentActivity: AppCompatActivity() {
it.route == selectedTab
} ?: initialItem(getInitialTab())

siteMonitorUtils.trackTabLoaded(item.siteMonitorType)

SiteMonitorFragmentContainer(
modifier = Modifier.fillMaxSize(),
commit = getCommitFunction(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package org.wordpress.android.ui.sitemonitor

import androidx.compose.foundation.layout.Column
import androidx.compose.material3.MaterialTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.material3.Tab
import androidx.compose.material3.TabRow
import androidx.compose.material3.TabRowDefaults
import androidx.compose.material3.TabRowDefaults.tabIndicatorOffset
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.sp
import androidx.compose.ui.unit.dp

@Composable
fun SiteMonitorTabHeader(navController: (String) -> Unit) {
Expand All @@ -25,16 +28,23 @@ fun SiteMonitorTabHeader(navController: (String) -> Unit) {
)
TabRow(
selectedTabIndex = selectedTabIndex,
containerColor = MaterialTheme.colorScheme.surface,
contentColor = MaterialTheme.colorScheme.onSurface,
containerColor = MaterialTheme.colors.surface,
contentColor = MaterialTheme.colors.onSurface,
indicator = { tabPositions ->
// Customizing the indicator color and style
TabRowDefaults.Indicator(
Modifier.tabIndicatorOffset(tabPositions[selectedTabIndex]),
color = MaterialTheme.colors.onSurface,
height = 2.0.dp
)
}
) {
tabs.forEachIndexed { index, item ->
Tab(
text = {
Column (horizontalAlignment = Alignment.CenterHorizontally) {
Text(
text = stringResource(item.title),
fontSize = 12.sp,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.wordpress.android.ui.sitemonitor

import android.text.TextUtils
import android.util.Log
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down Expand Up @@ -32,7 +31,6 @@ class SiteMonitorTabViewModel @Inject constructor(
val uiState: StateFlow<SiteMonitorUiState> = _uiState

fun start(type: SiteMonitorType, urlTemplate: String, site: SiteModel) {
Log.i("Track", "TheViewModel start with $urlTemplate and $type")
this.siteMonitorType = type
this.urlTemplate = urlTemplate
this.site = site
Expand Down Expand Up @@ -106,7 +104,6 @@ class SiteMonitorTabViewModel @Inject constructor(
}

fun onUrlLoaded() {
siteMonitorUtils.trackTabLoaded(siteMonitorType)
postUiState(SiteMonitorUiState.Loaded)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ data class SiteMonitorModel(
val url: String,
val addressToLoad: String
)
enum class SiteMonitorType {
METRICS,
PHP_LOGS,
WEB_SERVER_LOGS
enum class SiteMonitorType(val analyticsDescription: String) {
METRICS("metrics"),
PHP_LOGS("php_logs"),
WEB_SERVER_LOGS("server_logs")
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.wordpress.android.ui.sitemonitor

import android.util.Log
import org.wordpress.android.WordPress
import org.wordpress.android.analytics.AnalyticsTracker
import org.wordpress.android.ui.WPWebViewActivity
Expand All @@ -26,22 +25,18 @@ class SiteMonitorUtils @Inject constructor(

fun sanitizeSiteUrl(url: String?) = url?.replace(Regex(HTTP_PATTERN), "") ?: ""

fun urlToType(url: String): SiteMonitorType {
return when {
url.contains(PHP_LOGS_PATTERN) -> SiteMonitorType.PHP_LOGS
url.contains(WEB_SERVER_LOGS_PATTERN) -> SiteMonitorType.WEB_SERVER_LOGS
else -> SiteMonitorType.METRICS
}
}

fun trackTabLoaded(siteMonitorType: SiteMonitorType) {
// todo: need to set this up properly with track events
Log.i(javaClass.simpleName, "track TabLoaded with $siteMonitorType")
analyticsTrackerWrapper.track(
AnalyticsTracker.Stat.SITE_MONITORING_TAB_SHOWN,
mapOf(
TAB_TRACK_KEY to siteMonitorType.analyticsDescription
))
}

companion object {
const val HTTP_PATTERN = "(https?://)"
const val PHP_LOGS_PATTERN = "/php"
const val WEB_SERVER_LOGS_PATTERN = "/web"
const val TAB_TRACK_KEY = "tab"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,7 @@ public enum Stat {
DEEP_LINK_FAILED,
SITE_MONITORING_SCREEN_SHOWN,
OPENED_SITE_MONITORING,
SITE_MONITORING_TAB_SHOWN,
}

private static final List<Tracker> TRACKERS = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2699,6 +2699,8 @@ public static String getEventNameForStat(AnalyticsTracker.Stat stat) {
return "site_monitoring_screen_shown";
case OPENED_SITE_MONITORING:
return "opened_site_monitoring";
case SITE_MONITORING_TAB_SHOWN:
return "site_monitoring_tab_shown";
}
return null;
}
Expand Down

0 comments on commit 3be9ac9

Please sign in to comment.