Skip to content

Commit

Permalink
Set user property when user runs into metered wifi
Browse files Browse the repository at this point in the history
  • Loading branch information
seadowg committed Jun 10, 2024
1 parent 57c459c commit 78a1bda
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@ interface Analytics {
fun setParam(key: String, value: String) {
params[key] = value
}

fun setUserProperty(name: String, value: String) {
instance.setUserProperty(name, value)
}
}
}
3 changes: 3 additions & 0 deletions async/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ dependencies {
implementation(Dependencies.androidx_core_ktx)
implementation(Dependencies.kotlinx_coroutines_android)
implementation(Dependencies.androidx_work_runtime)
implementation(project(":analytics")) {
exclude("com.google.firebase")
}

testImplementation(Dependencies.hamcrest)
testImplementation(Dependencies.robolectric)
Expand Down
2 changes: 2 additions & 0 deletions async/src/main/java/org/odk/collect/async/TaskSpecWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.odk.collect.async
import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
import org.odk.collect.analytics.Analytics
import org.odk.collect.async.network.ConnectivityProvider

class TaskSpecWorker(
Expand All @@ -15,6 +16,7 @@ class TaskSpecWorker(
override fun doWork(): Result {
val cellularOnly = inputData.getBoolean(DATA_CELLULAR_ONLY, false)
if (cellularOnly && connectivityProvider.currentNetwork != Scheduler.NetworkType.CELLULAR) {
Analytics.setUserProperty("EncounteredMeteredNonCellularInTasks", "true")
return Result.retry()
}

Expand Down

0 comments on commit 78a1bda

Please sign in to comment.