From 78a1bda04c6c1e412514199605118bdfa4023cbd Mon Sep 17 00:00:00 2001 From: Callum Stott Date: Tue, 7 May 2024 17:55:43 +0100 Subject: [PATCH] Set user property when user runs into metered wifi --- .../src/main/java/org/odk/collect/analytics/Analytics.kt | 4 ++++ async/build.gradle.kts | 3 +++ async/src/main/java/org/odk/collect/async/TaskSpecWorker.kt | 2 ++ 3 files changed, 9 insertions(+) diff --git a/analytics/src/main/java/org/odk/collect/analytics/Analytics.kt b/analytics/src/main/java/org/odk/collect/analytics/Analytics.kt index 6bfefeb6080..033392ea33d 100644 --- a/analytics/src/main/java/org/odk/collect/analytics/Analytics.kt +++ b/analytics/src/main/java/org/odk/collect/analytics/Analytics.kt @@ -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) + } } } diff --git a/async/build.gradle.kts b/async/build.gradle.kts index 9c958ba7e33..d6eae2c48cb 100644 --- a/async/build.gradle.kts +++ b/async/build.gradle.kts @@ -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) diff --git a/async/src/main/java/org/odk/collect/async/TaskSpecWorker.kt b/async/src/main/java/org/odk/collect/async/TaskSpecWorker.kt index 873f88be48a..c3e41880436 100644 --- a/async/src/main/java/org/odk/collect/async/TaskSpecWorker.kt +++ b/async/src/main/java/org/odk/collect/async/TaskSpecWorker.kt @@ -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( @@ -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() }