Skip to content

Commit aa755bb

Browse files
committed
feat(#82): allow floatValue and customUserID to be specified when ending duration signal
1 parent 0f89b33 commit aa755bb

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

lib/src/androidTest/java/com/telemetrydeck/sdk/TelemetryDeckTest.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,30 @@ class TelemetryDeckTest {
315315
}
316316
}
317317

318+
@UiThreadTest
319+
@Test
320+
fun allows_for_duration_tracking_with_floatvalue_customer_id() {
321+
val signalCache = startTelemetryDeck(
322+
prepareBuilder()
323+
)
324+
325+
// act
326+
TelemetryDeck.startDurationSignal("type")
327+
TelemetryDeck.stopAndSendDurationSignal("type", floatValue = 10.0, customUserID = "user")
328+
329+
330+
verify {
331+
signalCache.add(withArg {
332+
assertEquals("type", it.type)
333+
val duration =
334+
it.payload.find { it.startsWith("TelemetryDeck.Signal.durationInSeconds:") }
335+
assertNotNull(duration)
336+
assertEquals(10.0, it.floatValue)
337+
assertEquals("04f8996da763b7a969b1028ee3007569eaf3a635486ddab211d512c85b9df8fb", it.clientUser)
338+
})
339+
}
340+
}
341+
318342

319343
private fun prepareBuilder(): TelemetryDeck.Builder {
320344
val httpClient = mockk<TelemetryApiClient>()

lib/src/main/java/com/telemetrydeck/sdk/TelemetryDeck.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,20 @@ class TelemetryDeck(
164164
trackingProvider.startTracking(signalName, parameters)
165165
}
166166

167-
override fun stopAndSendDurationSignal(signalName: String, parameters: Map<String, String>) {
167+
override fun stopAndSendDurationSignal(signalName: String, parameters: Map<String, String>, floatValue: Double?, customUserID: String?) {
168168
val trackingProvider = this.providers.find { it is DurationSignalTrackerProvider } as? DurationSignalTrackerProvider
169169
if (trackingProvider == null) {
170170
this.logger?.error("stopAndSendDurationSignal requires the DurationSignalTrackerProvider to be registered")
171171
return
172172
}
173173
val params = trackingProvider.stopTracking(signalName, parameters)
174174
if (params != null) {
175-
processSignal(signalName, params = params)
175+
processSignal(
176+
signalName,
177+
params = params,
178+
floatValue = floatValue,
179+
customUserID = customUserID
180+
)
176181
}
177182
}
178183

@@ -428,9 +433,11 @@ class TelemetryDeck(
428433

429434
override fun stopAndSendDurationSignal(
430435
signalName: String,
431-
parameters: Map<String, String>
436+
parameters: Map<String, String>,
437+
floatValue: Double?,
438+
customUserID: String?
432439
) {
433-
getInstance()?.stopAndSendDurationSignal(signalName, parameters)
440+
getInstance()?.stopAndSendDurationSignal(signalName, parameters, floatValue, customUserID)
434441
}
435442

436443
override val signalCache: SignalCache?

lib/src/main/java/com/telemetrydeck/sdk/TelemetryDeckClient.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,11 @@ interface TelemetryDeckClient {
138138
*
139139
* @param signalName The name of the signal that was previously started with [startDurationSignal]
140140
* @param parameters Additional parameters to include with the signal. These will be merged with the parameters provided at the start.
141+
* @param floatValue An optional floating-point number that can be used to provide numerical data about the signal.
142+
* @param customUserID An optional string specifying a custom user identifier. If provided, it will override the default user identifier from the configuration.
141143
*
142144
*/
143-
fun stopAndSendDurationSignal(signalName: String, parameters: Map<String, String> = emptyMap())
145+
fun stopAndSendDurationSignal(signalName: String, parameters: Map<String, String> = emptyMap(), floatValue: Double? = null, customUserID: String? = null)
144146

145147
val configuration: TelemetryManagerConfiguration?
146148
}

0 commit comments

Comments
 (0)