Skip to content

Commit

Permalink
Add faphub metric (#700)
Browse files Browse the repository at this point in the history
**Background**

Right now we can't understand how many users use faphub catalog

**Changes**

Add faphub metrics

**Test plan**

Test each metric event
  • Loading branch information
LionZXY authored Sep 19, 2023
1 parent 5381497 commit 2d46bec
Show file tree
Hide file tree
Showing 21 changed files with 88 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/internal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ jobs:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
ORG_GRADLE_PROJECT_version_code: ${{ steps.vars.outputs.minor_version }}
ORG_GRADLE_PROJECT_version_name: "${{ steps.vars.outputs.major_version }}.${{ steps.vars.outputs.minor_version }}"
ORG_GRADLE_PROJECT_countly_url: ${{ secrets.COUNTLY_URL_PROD }}
ORG_GRADLE_PROJECT_countly_app_key: ${{ secrets.COUNTLY_APP_KEY_PROD }}
run: |
export $(cat .github/workflows/targets/${{ matrix.target }}.env | xargs)
./gradlew :instances:app:assembleInternal :instances:app:bundleInternal
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- [Feature] Scroll on Infrared Screen
- [Feature] Check Self Update App in Options (only for github)
- [Feature] Fap Catalog save sort
- [Feature] Check Self Update App in Optiond (only for github)
- [Feature] Add metrics for faphub
- [FIX] Use by default dark theme in Wear OS
- [FIX] Use default splashscreen in Wear OS
- [FIX] Fix compose layout in Wear OS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import com.flipperdevices.metric.api.events.ComplexEvent
import com.flipperdevices.metric.api.events.SimpleEvent

interface MetricApi {
fun reportSimpleEvent(simpleEvent: SimpleEvent)
fun reportSimpleEvent(simpleEvent: SimpleEvent, arg: String? = null)
fun reportComplexEvent(complexEvent: ComplexEvent)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@ enum class SimpleEvent(val id: String) {
SHARE_FILE("share_file"),
SAVE_DUMP("save_dump"),
MFKEY32("mfkey32"),
OPEN_NFC_DUMP_EDITOR("open_nfc_dump_editor")
OPEN_NFC_DUMP_EDITOR("open_nfc_dump_editor"),
OPEN_FAPHUB("open_faphub"),
OPEN_FAPHUB_CATEGORY("open_faphub_category"),
OPEN_FAPHUB_SEARCH("open_faphub_search"),
OPEN_FAPHUB_APP("open_faphub_app"),
INSTALL_FAPHUB_APP("install_faphub_app"),
HIDE_FAPHUB_APP("hide_faphub_app"),
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ class MetricApiImpl @Inject constructor(
) : MetricApi, LogTagProvider {
override val TAG = "MetricApi"

override fun reportSimpleEvent(simpleEvent: SimpleEvent) {
override fun reportSimpleEvent(simpleEvent: SimpleEvent, arg: String?) {
try {
countlyApi.reportEvent(simpleEvent.id)
countlyApi.reportEvent(simpleEvent.id, params = mapOf("arg" to arg))
} catch (e: Exception) {
error(e) { "Failed to report to Countly simple event: ${simpleEvent.id}" }
}
try {
clickhouseApi.reportSimpleEvent(simpleEvent)
clickhouseApi.reportSimpleEvent(simpleEvent, simpleEventArg = arg)
} catch (e: Exception) {
error(e) { "Failed to report to Clickhouse simple event: ${simpleEvent.id}" }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import com.flipperdevices.metric.api.events.ComplexEvent
import com.flipperdevices.metric.api.events.SimpleEvent

interface ClickhouseApi {
fun reportSimpleEvent(simpleEvent: SimpleEvent)
fun reportSimpleEvent(simpleEvent: SimpleEvent, simpleEventArg: String?)
fun reportComplexEvent(complexEvent: ComplexEvent)
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class ClickhouseApiImpl @Inject constructor(
private val scope = CoroutineScope(SupervisorJob())
private val sessionUUID by lazy { UUID.randomUUID() }

override fun reportSimpleEvent(simpleEvent: SimpleEvent) {
@Suppress("CyclomaticComplexMethod")
override fun reportSimpleEvent(simpleEvent: SimpleEvent, simpleEventArg: String?) {
val openTarget = when (simpleEvent) {
SimpleEvent.APP_OPEN -> OpenOuterClass.Open.OpenTarget.APP
SimpleEvent.OPEN_SAVE_KEY -> OpenOuterClass.Open.OpenTarget.SAVE_KEY
Expand All @@ -79,12 +80,22 @@ class ClickhouseApiImpl @Inject constructor(
SimpleEvent.SAVE_DUMP -> OpenOuterClass.Open.OpenTarget.SAVE_DUMP
SimpleEvent.MFKEY32 -> OpenOuterClass.Open.OpenTarget.MFKEY32
SimpleEvent.OPEN_NFC_DUMP_EDITOR -> OpenOuterClass.Open.OpenTarget.OPEN_NFC_DUMP_EDITOR
SimpleEvent.OPEN_FAPHUB -> OpenOuterClass.Open.OpenTarget.OPEN_FAPHUB
SimpleEvent.OPEN_FAPHUB_CATEGORY -> OpenOuterClass.Open.OpenTarget.OPEN_FAPHUB_CATEGORY
SimpleEvent.OPEN_FAPHUB_SEARCH -> OpenOuterClass.Open.OpenTarget.OPEN_FAPHUB_SEARCH
SimpleEvent.OPEN_FAPHUB_APP -> OpenOuterClass.Open.OpenTarget.OPEN_FAPHUB_APP
SimpleEvent.INSTALL_FAPHUB_APP -> OpenOuterClass.Open.OpenTarget.INSTALL_FAPHUB_APP
SimpleEvent.HIDE_FAPHUB_APP -> OpenOuterClass.Open.OpenTarget.HIDE_FAPHUB_APP
}

scope.launch(Dispatchers.Default) {
reportToServerSafe(
metricEventsCollection {
open = open {
target = openTarget
if (simpleEventArg != null) {
this.arg = simpleEventArg
}
}
}
)
Expand Down
2 changes: 1 addition & 1 deletion components/analytics/metric/impl/src/main/proto
Submodule proto updated 1 files
+7 −0 events/open.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import javax.inject.Inject

@ContributesBinding(AppGraph::class, MetricApi::class)
class NoopMetricApiImpl @Inject constructor() : MetricApi {
override fun reportSimpleEvent(simpleEvent: SimpleEvent) = Unit
override fun reportSimpleEvent(simpleEvent: SimpleEvent, arg: String?) = Unit

override fun reportComplexEvent(complexEvent: ComplexEvent) = Unit
}
2 changes: 2 additions & 0 deletions components/faphub/category/impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ dependencies {
implementation(projects.components.faphub.target.api)
implementation(projects.components.faphub.errors.api)

implementation(projects.components.analytics.metric.api)

implementation(projects.components.bridge.dao.api)

// Compose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import com.flipperdevices.faphub.installation.button.api.FapButtonSize
import com.flipperdevices.faphub.installation.button.api.FapInstallationUIApi
import com.flipperdevices.faphub.installation.button.api.toFapButtonConfig
import com.flipperdevices.faphub.search.api.FapHubSearchEntryApi
import com.flipperdevices.metric.api.MetricApi
import com.flipperdevices.metric.api.events.SimpleEvent
import com.squareup.anvil.annotations.ContributesBinding
import com.squareup.anvil.annotations.ContributesMultibinding
import kotlinx.serialization.encodeToString
Expand All @@ -30,7 +32,8 @@ class FapHubCategoryApiImpl @Inject constructor(
private val searchEntryApi: FapHubSearchEntryApi,
private val fapScreenApi: FapScreenApi,
private val fapInstallationUIApi: FapInstallationUIApi,
private val errorsRenderer: FapHubComposableErrorsRenderer
private val errorsRenderer: FapHubComposableErrorsRenderer,
private val metricApi: MetricApi
) : FapHubCategoryApi {
private val categoryArguments = listOf(
navArgument(CATEGORY_OPEN_PATH_KEY) {
Expand All @@ -52,6 +55,7 @@ class FapHubCategoryApiImpl @Inject constructor(
onBack = navController::popBackStack,
onOpenSearch = { navController.navigate(searchEntryApi.start()) },
onOpenFapItem = {
metricApi.reportSimpleEvent(SimpleEvent.OPEN_FAPHUB_APP, it.applicationAlias)
navController.navigate(fapScreenApi.getFapScreen(it.id))
},
errorsRenderer = errorsRenderer,
Expand Down
2 changes: 2 additions & 0 deletions components/faphub/fapscreen/impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ dependencies {
implementation(projects.components.core.ui.navigation)
implementation(projects.components.core.ui.dialog)

implementation(projects.components.analytics.metric.api)

implementation(projects.components.bridge.dao.api)

// Compose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import com.flipperdevices.faphub.report.api.FapReportFeatureEntry
import com.flipperdevices.faphub.target.api.FlipperTargetProviderApi
import com.flipperdevices.inappnotification.api.InAppNotificationStorage
import com.flipperdevices.inappnotification.api.model.InAppNotification
import com.flipperdevices.metric.api.MetricApi
import com.flipperdevices.metric.api.events.SimpleEvent
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
Expand All @@ -46,7 +48,8 @@ class FapScreenViewModel @VMInject constructor(
private val targetProviderApi: FlipperTargetProviderApi,
private val fapReportFeatureEntry: FapReportFeatureEntry,
private val fapHubHideApi: FapHubHideItemApi,
private val inAppNotificationStorage: InAppNotificationStorage
private val inAppNotificationStorage: InAppNotificationStorage,
private val metricApi: MetricApi
) : ViewModel(), LogTagProvider {
override val TAG = "FapScreenViewModel"

Expand Down Expand Up @@ -85,6 +88,10 @@ class FapScreenViewModel @VMInject constructor(
warn { "#onPressHide calls when fapScreenLoadingStateFlow is null or not loaded" }
return
}
metricApi.reportSimpleEvent(
SimpleEvent.HIDE_FAPHUB_APP,
loadingState.fapItem.applicationAlias
)
viewModelScope.launch(Dispatchers.Default) {
if (isHidden) {
fapHubHideApi.unHideItem(loadingState.fapItem.id)
Expand Down
2 changes: 2 additions & 0 deletions components/faphub/installation/queue/impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ dependencies {
implementation(projects.components.faphub.target.api)
implementation(projects.components.faphub.installation.manifest.api)

implementation(projects.components.analytics.metric.api)

implementation(projects.components.bridge.api)
implementation(projects.components.bridge.pbutils)
implementation(projects.components.bridge.service.api)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import com.flipperdevices.core.log.info
import com.flipperdevices.faphub.installation.queue.api.model.FapActionRequest
import com.flipperdevices.faphub.installation.queue.impl.executor.FapActionExecutor
import com.flipperdevices.faphub.installation.queue.impl.model.FapInternalQueueState
import com.flipperdevices.metric.api.MetricApi
import com.flipperdevices.metric.api.events.SimpleEvent
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
Expand All @@ -25,7 +27,8 @@ import kotlinx.coroutines.withContext
import javax.inject.Inject

class FapQueueRunner @Inject constructor(
private val fapActionExecutor: FapActionExecutor
private val fapActionExecutor: FapActionExecutor,
private val metricApi: MetricApi
) : LogTagProvider {
override val TAG = "FapQueueRunner"

Expand All @@ -51,6 +54,7 @@ class FapQueueRunner @Inject constructor(
}

suspend fun enqueueSync(actionRequest: FapActionRequest) {
reportMetric(actionRequest)
if (actionRequest is FapActionRequest.Cancel) {
cancelTasksForApplicationUid(actionRequest)
} else {
Expand All @@ -63,6 +67,18 @@ class FapQueueRunner @Inject constructor(
}
}

private fun reportMetric(actionRequest: FapActionRequest) {
when (actionRequest) {
is FapActionRequest.Cancel,
is FapActionRequest.Delete,
is FapActionRequest.Update -> {}
is FapActionRequest.Install -> metricApi.reportSimpleEvent(
SimpleEvent.INSTALL_FAPHUB_APP,
actionRequest.applicationAlias
)
}
}

private suspend fun loop() {
info { "Start loop" }
val currentJob = takeJobForLoop() ?: return
Expand Down
2 changes: 2 additions & 0 deletions components/faphub/main/impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ dependencies {
implementation(projects.components.faphub.category.api)
implementation(projects.components.faphub.fapscreen.api)

implementation(projects.components.analytics.metric.api)

// Compose
implementation(libs.compose.ui)
implementation(libs.compose.tooling)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import com.flipperdevices.faphub.main.api.FapHubHandleDeeplink
import com.flipperdevices.faphub.main.api.FapHubMainScreenApi
import com.flipperdevices.faphub.search.api.FapHubSearchEntryApi
import com.flipperdevices.main.impl.composable.ComposableFapHubMainScreen
import com.flipperdevices.metric.api.MetricApi
import com.flipperdevices.metric.api.events.SimpleEvent
import com.squareup.anvil.annotations.ContributesBinding
import com.squareup.anvil.annotations.ContributesMultibinding
import javax.inject.Inject
Expand All @@ -29,7 +31,8 @@ class FapHubMainScreenApiImpl @Inject constructor(
private val searchEntryApi: FapHubSearchEntryApi,
private val categoryEntryApi: FapHubCategoryApi,
private val fapScreenApi: FapScreenApi,
private val installedApi: FapInstalledApi
private val installedApi: FapInstalledApi,
private val metricApi: MetricApi
) : FapHubMainScreenApi, FapHubHandleDeeplink {
private fun start(): String = "@${ROUTE.name}"

Expand All @@ -48,19 +51,23 @@ class FapHubMainScreenApiImpl @Inject constructor(
catalogTabComposable = {
catalogTabApi.ComposableCatalogTab(
onOpenFapItem = {
metricApi.reportSimpleEvent(SimpleEvent.OPEN_FAPHUB_APP, it.applicationAlias)
navController.navigate(fapScreenApi.getFapScreen(it.id))
},
onCategoryClick = {
metricApi.reportSimpleEvent(SimpleEvent.OPEN_FAPHUB_CATEGORY, it.name)
navController.navigate(categoryEntryApi.open(it))
}
)
},
installedTabComposable = {
installedApi.ComposableInstalledTab(onOpenFapItem = {
metricApi.reportSimpleEvent(SimpleEvent.OPEN_FAPHUB_APP, it)
navController.navigate(fapScreenApi.getFapScreen(it))
})
},
onOpenSearch = {
metricApi.reportSimpleEvent(SimpleEvent.OPEN_FAPHUB_SEARCH)
navController.navigate(searchEntryApi.start())
},
installedNotificationCount = readyToUpdateCount
Expand Down
2 changes: 2 additions & 0 deletions components/faphub/search/impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ dependencies {
implementation(projects.components.faphub.target.api)
implementation(projects.components.faphub.errors.api)

implementation(projects.components.analytics.metric.api)

implementation(projects.components.bridge.dao.api)

// Compose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import com.flipperdevices.faphub.installation.button.api.FapInstallationUIApi
import com.flipperdevices.faphub.installation.button.api.toFapButtonConfig
import com.flipperdevices.faphub.search.api.FapHubSearchEntryApi
import com.flipperdevices.faphub.search.impl.composable.ComposableSearchScreen
import com.flipperdevices.metric.api.MetricApi
import com.flipperdevices.metric.api.events.SimpleEvent
import com.squareup.anvil.annotations.ContributesBinding
import com.squareup.anvil.annotations.ContributesMultibinding
import javax.inject.Inject
Expand All @@ -24,7 +26,8 @@ import javax.inject.Provider
class FapHubSearchEntryApiImpl @Inject constructor(
fapScreenApiProvider: Provider<FapScreenApi>,
private val fapInstallationUIApi: FapInstallationUIApi,
private val errorsRenderer: FapHubComposableErrorsRenderer
private val errorsRenderer: FapHubComposableErrorsRenderer,
private val metricApi: MetricApi
) : FapHubSearchEntryApi {
private val fapScreenApi by fapScreenApiProvider

Expand All @@ -36,6 +39,7 @@ class FapHubSearchEntryApiImpl @Inject constructor(
ComposableSearchScreen(
onBack = { navController.popBackStack() },
onFapItemClick = {
metricApi.reportSimpleEvent(SimpleEvent.OPEN_FAPHUB_APP, it.name)
navController.navigate(fapScreenApi.getFapScreen(it.id))
},
errorsRenderer = errorsRenderer,
Expand Down
1 change: 1 addition & 0 deletions components/hub/impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies {
implementation(projects.components.hub.api)
implementation(projects.components.faphub.maincard.api)
implementation(projects.components.faphub.main.api)
implementation(projects.components.analytics.metric.api)

implementation(projects.components.core.di)
implementation(projects.components.core.preference)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import com.flipperdevices.faphub.main.api.FapHubMainScreenApi
import com.flipperdevices.faphub.maincard.api.MainCardApi
import com.flipperdevices.hub.api.HubFeatureEntry
import com.flipperdevices.hub.impl.composable.ComposableHub
import com.flipperdevices.metric.api.MetricApi
import com.flipperdevices.metric.api.events.SimpleEvent
import com.flipperdevices.nfc.attack.api.NFCAttackFeatureEntry
import com.flipperdevices.screenstreaming.api.ScreenStreamingFeatureEntry
import com.squareup.anvil.annotations.ContributesBinding
Expand All @@ -29,7 +31,8 @@ class HubFeatureEntryImpl @Inject constructor(
private val nfcAttackFeatureEntry: NFCAttackFeatureEntry,
private val mainCardApi: MainCardApi,
private val screenStreamingFeatureEntry: ScreenStreamingFeatureEntry,
private val fapHubMainScreenApi: FapHubMainScreenApi
private val fapHubMainScreenApi: FapHubMainScreenApi,
private val metricApi: MetricApi
) : HubFeatureEntry {
override fun start() = "@${ROUTE.name}"

Expand Down Expand Up @@ -62,6 +65,7 @@ class HubFeatureEntryImpl @Inject constructor(
top = 14.dp
),
onClick = {
metricApi.reportSimpleEvent(SimpleEvent.OPEN_FAPHUB)
navController.navigate(fapHubMainScreenApi.ROUTE.name)
}
)
Expand Down

0 comments on commit 2d46bec

Please sign in to comment.