Skip to content

Commit b0dc269

Browse files
authored
Merge pull request #98 from TelemetryDeck/feat/pirate-referral
Pirate metrics alignment
2 parents 860686f + 0727d25 commit b0dc269

File tree

22 files changed

+376
-34
lines changed

22 files changed

+376
-34
lines changed

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

Lines changed: 100 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Context
44
import android.content.pm.ApplicationInfo
55
import com.telemetrydeck.sdk.params.Acquisition
66
import com.telemetrydeck.sdk.params.Activation
7+
import com.telemetrydeck.sdk.params.ErrorCategory
78
import com.telemetrydeck.sdk.params.Navigation
89
import com.telemetrydeck.sdk.params.Revenue
910
import com.telemetrydeck.sdk.providers.AccessibilityProvider
@@ -72,7 +73,6 @@ class TelemetryDeck(
7273
navigate(navigationStatus.getLastDestination(), destinationPath, customUserID)
7374
}
7475

75-
@ExperimentalFeature
7676
override fun acquiredUser(channel: String, params: Map<String, String>, customUserID: String?) {
7777
val signalParams = mergeMapsWithOverwrite(params, mapOf(
7878
Acquisition.Channel.paramName to channel
@@ -84,7 +84,6 @@ class TelemetryDeck(
8484
)
8585
}
8686

87-
@ExperimentalFeature
8887
override fun leadStarted(leadId: String, params: Map<String, String>, customUserID: String?) {
8988
val signalParams = mergeMapsWithOverwrite(params, mapOf(
9089
Acquisition.LeadId.paramName to leadId
@@ -96,7 +95,6 @@ class TelemetryDeck(
9695
)
9796
}
9897

99-
@ExperimentalFeature
10098
override fun leadConverted(leadId: String, params: Map<String, String>, customUserID: String?) {
10199
val signalParams = mergeMapsWithOverwrite(params, mapOf(
102100
Acquisition.LeadId.paramName to leadId
@@ -108,7 +106,6 @@ class TelemetryDeck(
108106
)
109107
}
110108

111-
@ExperimentalFeature
112109
override fun onboardingCompleted(
113110
params: Map<String, String>,
114111
customUserID: String?
@@ -120,7 +117,6 @@ class TelemetryDeck(
120117
)
121118
}
122119

123-
@ExperimentalFeature
124120
override fun coreFeatureUsed(
125121
featureName: String,
126122
params: Map<String, String>,
@@ -155,6 +151,76 @@ class TelemetryDeck(
155151
)
156152
}
157153

154+
override fun referralSent(
155+
receiversCount: Int,
156+
kind: String?,
157+
params: Map<String, String>,
158+
customUserID: String?
159+
) {
160+
val referralParams = mutableMapOf(
161+
com.telemetrydeck.sdk.params.Referral.ReceiversCount.paramName to receiversCount.toString()
162+
)
163+
if (kind != null) {
164+
referralParams[com.telemetrydeck.sdk.params.Referral.Kind.paramName] = kind
165+
}
166+
val signalParams = mergeMapsWithOverwrite(params, referralParams)
167+
signal(
168+
com.telemetrydeck.sdk.signals.Referral.Sent.signalName,
169+
params = signalParams,
170+
customUserID = customUserID
171+
)
172+
}
173+
174+
override fun userRatingSubmitted(
175+
rating: Int,
176+
comment: String?,
177+
params: Map<String, String>,
178+
customUserID: String?
179+
) {
180+
if (rating < 0 || rating > 10) {
181+
logger?.error("userRatingSubmitted: rating must be between 0 and 10, got $rating")
182+
return
183+
}
184+
val referralParams = mutableMapOf(
185+
com.telemetrydeck.sdk.params.Referral.RatingValue.paramName to rating.toString()
186+
)
187+
if (comment != null) {
188+
referralParams[com.telemetrydeck.sdk.params.Referral.RatingComment.paramName] = comment
189+
}
190+
val signalParams = mergeMapsWithOverwrite(params, referralParams)
191+
signal(
192+
com.telemetrydeck.sdk.signals.Referral.UserRatingSubmitted.signalName,
193+
params = signalParams,
194+
customUserID = customUserID
195+
)
196+
}
197+
198+
override fun errorOccurred(
199+
id: String,
200+
category: ErrorCategory?,
201+
message: String?,
202+
parameters: Map<String, String>,
203+
floatValue: Double?,
204+
customUserID: String?
205+
) {
206+
val errorParams = mutableMapOf(
207+
com.telemetrydeck.sdk.params.Error.Id.paramName to id
208+
)
209+
if (category != null) {
210+
errorParams[com.telemetrydeck.sdk.params.Error.Category.paramName] = category.rawValue
211+
}
212+
if (message != null) {
213+
errorParams[com.telemetrydeck.sdk.params.Error.Message.paramName] = message
214+
}
215+
val signalParams = mergeMapsWithOverwrite(parameters, errorParams)
216+
signal(
217+
com.telemetrydeck.sdk.signals.Error.Occurred.signalName,
218+
params = signalParams,
219+
floatValue = floatValue,
220+
customUserID = customUserID
221+
)
222+
}
223+
158224
override suspend fun send(
159225
signalType: String,
160226
clientUser: String?,
@@ -448,7 +514,6 @@ class TelemetryDeck(
448514
getInstance()?.navigate(destinationPath, customUserID = customUserID)
449515
}
450516

451-
@ExperimentalFeature
452517
override fun acquiredUser(
453518
channel: String,
454519
params: Map<String, String>,
@@ -457,7 +522,6 @@ class TelemetryDeck(
457522
getInstance()?.acquiredUser(channel, params, customUserID)
458523
}
459524

460-
@ExperimentalFeature
461525
override fun leadStarted(
462526
leadId: String,
463527
params: Map<String, String>,
@@ -466,7 +530,6 @@ class TelemetryDeck(
466530
getInstance()?.leadStarted(leadId, params, customUserID)
467531
}
468532

469-
@ExperimentalFeature
470533
override fun leadConverted(
471534
leadId: String,
472535
params: Map<String, String>,
@@ -475,15 +538,13 @@ class TelemetryDeck(
475538
getInstance()?.leadConverted(leadId, params, customUserID)
476539
}
477540

478-
@ExperimentalFeature
479541
override fun onboardingCompleted(
480542
params: Map<String, String>,
481543
customUserID: String?
482544
) {
483545
getInstance()?.onboardingCompleted(params, customUserID)
484546
}
485547

486-
@ExperimentalFeature
487548
override fun coreFeatureUsed(
488549
featureName: String,
489550
params: Map<String, String>,
@@ -500,6 +561,35 @@ class TelemetryDeck(
500561
getInstance()?.paywallShown(reason, params, customUserID)
501562
}
502563

564+
override fun referralSent(
565+
receiversCount: Int,
566+
kind: String?,
567+
params: Map<String, String>,
568+
customUserID: String?
569+
) {
570+
getInstance()?.referralSent(receiversCount, kind, params, customUserID)
571+
}
572+
573+
override fun userRatingSubmitted(
574+
rating: Int,
575+
comment: String?,
576+
params: Map<String, String>,
577+
customUserID: String?
578+
) {
579+
getInstance()?.userRatingSubmitted(rating, comment, params, customUserID)
580+
}
581+
582+
override fun errorOccurred(
583+
id: String,
584+
category: ErrorCategory?,
585+
message: String?,
586+
parameters: Map<String, String>,
587+
floatValue: Double?,
588+
customUserID: String?
589+
) {
590+
getInstance()?.errorOccurred(id, category, message, parameters, floatValue, customUserID)
591+
}
592+
503593
override suspend fun send(
504594
signalType: String,
505595
clientUser: String?,

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

Lines changed: 92 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.telemetrydeck.sdk
22

3+
import com.telemetrydeck.sdk.params.ErrorCategory
34
import java.util.UUID
45

56
interface TelemetryDeckClient {
@@ -34,35 +35,59 @@ interface TelemetryDeckClient {
3435
fun navigate(destinationPath: String, customUserID: String? = null)
3536

3637
/**
37-
* Send a `TelemetryDeck.Acquisition.userAcquired` signal with the provided channel.
38+
* Tracks user acquisition through a specific marketing or organic channel.
39+
*
40+
* Sends signal: `TelemetryDeck.Acquisition.userAcquired`
41+
*
42+
* @param channel The acquisition channel (e.g., "organic", "facebook_ads", "google_search").
43+
* @param params A map of additional string key-value pairs that provide further context about the signal.
44+
* @param customUserID An optional string specifying a custom user identifier.
3845
*/
39-
@ExperimentalFeature
4046
fun acquiredUser(channel: String, params: Map<String, String> = emptyMap(), customUserID: String? = null)
4147

4248

4349
/**
44-
* Send a `TelemetryDeck.Acquisition.leadStarted` signal with the provided leadId.
50+
* Tracks when a potential customer begins the conversion process.
51+
*
52+
* Sends signal: `TelemetryDeck.Acquisition.leadStarted`
53+
*
54+
* @param leadId A unique identifier for the lead (e.g., email, signup ID).
55+
* @param params A map of additional string key-value pairs that provide further context about the signal.
56+
* @param customUserID An optional string specifying a custom user identifier.
4557
*/
46-
@ExperimentalFeature
4758
fun leadStarted(leadId: String, params: Map<String, String> = emptyMap(), customUserID: String? = null)
4859

4960

5061
/**
51-
* Send a `TelemetryDeck.Acquisition.leadConverted` signal with the provided leadId.
62+
* Tracks when a lead successfully converts to a user.
63+
*
64+
* Sends signal: `TelemetryDeck.Acquisition.leadConverted`
65+
*
66+
* @param leadId The unique identifier for the lead that converted.
67+
* @param params A map of additional string key-value pairs that provide further context about the signal.
68+
* @param customUserID An optional string specifying a custom user identifier.
5269
*/
53-
@ExperimentalFeature
5470
fun leadConverted(leadId: String, params: Map<String, String> = emptyMap(), customUserID: String? = null)
5571

5672
/**
57-
* Send a `TelemetryDeck.Activation.onboardingCompleted` signal.
73+
* Tracks when a user successfully completes the onboarding process.
74+
*
75+
* Sends signal: `TelemetryDeck.Activation.onboardingCompleted`
76+
*
77+
* @param params A map of additional string key-value pairs that provide further context about the signal.
78+
* @param customUserID An optional string specifying a custom user identifier.
5879
*/
59-
@ExperimentalFeature
6080
fun onboardingCompleted(params: Map<String, String> = emptyMap(), customUserID: String? = null)
6181

6282
/**
63-
* Send a `TelemetryDeck.Activation.coreFeatureUsed` signal.
83+
* Tracks when a user engages with a core feature of the application.
84+
*
85+
* Sends signal: `TelemetryDeck.Activation.coreFeatureUsed`
86+
*
87+
* @param featureName The name of the core feature that was used.
88+
* @param params A map of additional string key-value pairs that provide further context about the signal.
89+
* @param customUserID An optional string specifying a custom user identifier.
6490
*/
65-
@ExperimentalFeature
6691
fun coreFeatureUsed(
6792
featureName: String,
6893
params: Map<String, String> = emptyMap(),
@@ -245,5 +270,62 @@ interface TelemetryDeckClient {
245270
customUserID: String? = null
246271
)
247272

273+
/**
274+
* Tracks when a user sends a referral to others.
275+
*
276+
* Sends signal: `TelemetryDeck.Referral.sent`
277+
*
278+
* @param receiversCount The number of receivers the referral was sent to (defaults to 1).
279+
* @param kind Optional string describing the kind of referral (e.g., "email", "social_share").
280+
* @param params A map of additional string key-value pairs that provide further context about the signal.
281+
* @param customUserID An optional string specifying a custom user identifier.
282+
*/
283+
fun referralSent(
284+
receiversCount: Int = 1,
285+
kind: String? = null,
286+
params: Map<String, String> = emptyMap(),
287+
customUserID: String? = null
288+
)
289+
290+
/**
291+
* Tracks when a user submits a rating for the application.
292+
*
293+
* Sends signal: `TelemetryDeck.Referral.userRatingSubmitted`
294+
*
295+
* Note: Rating values are validated to be between 0 and 10 inclusive.
296+
*
297+
* @param rating The rating value (must be between 0 and 10 inclusive).
298+
* @param comment Optional comment accompanying the rating.
299+
* @param params A map of additional string key-value pairs that provide further context about the signal.
300+
* @param customUserID An optional string specifying a custom user identifier.
301+
*/
302+
fun userRatingSubmitted(
303+
rating: Int,
304+
comment: String? = null,
305+
params: Map<String, String> = emptyMap(),
306+
customUserID: String? = null
307+
)
308+
309+
/**
310+
* Tracks when an error occurs in the application.
311+
*
312+
* Sends signal: `TelemetryDeck.Error.occurred`
313+
*
314+
* @param id A unique identifier for the error (e.g., error code, exception class name).
315+
* @param category The category of the error (e.g., thrown exception, user input, app state).
316+
* @param message An optional error message describing what went wrong.
317+
* @param parameters A map of additional string key-value pairs that provide further context about the error.
318+
* @param floatValue An optional floating-point number that can be used to provide numerical data about the error.
319+
* @param customUserID An optional string specifying a custom user identifier.
320+
*/
321+
fun errorOccurred(
322+
id: String,
323+
category: ErrorCategory? = null,
324+
message: String? = null,
325+
parameters: Map<String, String> = emptyMap(),
326+
floatValue: Double? = null,
327+
customUserID: String? = null
328+
)
329+
248330
val configuration: TelemetryManagerConfiguration?
249331
}

lib/src/main/java/com/telemetrydeck/sdk/params/AppInfo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.telemetrydeck.sdk.params
22

3-
internal enum class AppInfo(val paramName: String) {
3+
enum class AppInfo(val paramName: String) {
44
BuildNumber("TelemetryDeck.AppInfo.buildNumber"),
55
Version("TelemetryDeck.AppInfo.version"),
66
VersionAndBuildNumber("TelemetryDeck.AppInfo.versionAndBuildNumber"),

lib/src/main/java/com/telemetrydeck/sdk/params/Calendar.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.telemetrydeck.sdk.params
22

3-
internal enum class Calendar(val paramName: String) {
3+
enum class Calendar(val paramName: String) {
44
DayOfMonth("TelemetryDeck.Calendar.dayOfMonth"),
55
DayOfWeek("TelemetryDeck.Calendar.dayOfWeek"),
66
DayOfYear("TelemetryDeck.Calendar.dayOfYear"),

lib/src/main/java/com/telemetrydeck/sdk/params/Device.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.telemetrydeck.sdk.params
22

33

4-
internal enum class Device(val paramName: String) {
4+
enum class Device(val paramName: String) {
55
Architecture("TelemetryDeck.Device.architecture"),
66
ModelName("TelemetryDeck.Device.modelName"),
77
OperatingSystem("TelemetryDeck.Device.operatingSystem"),
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.telemetrydeck.sdk.params
2+
3+
enum class Error(val paramName: String) {
4+
Id("TelemetryDeck.Error.id"),
5+
Category("TelemetryDeck.Error.category"),
6+
Message("TelemetryDeck.Error.message"),
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.telemetrydeck.sdk.params
2+
3+
enum class ErrorCategory(val rawValue: String) {
4+
ThrownException("thrown-exception"),
5+
UserInput("user-input"),
6+
AppState("app-state")
7+
}

lib/src/main/java/com/telemetrydeck/sdk/params/Navigation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.telemetrydeck.sdk.params
22

3-
internal enum class Navigation(val paramName: String) {
3+
enum class Navigation(val paramName: String) {
44
SchemaVersion("TelemetryDeck.Navigation.schemaVersion"),
55
Identifier("TelemetryDeck.Navigation.identifier"),
66
SourcePath("TelemetryDeck.Navigation.sourcePath"),

lib/src/main/java/com/telemetrydeck/sdk/params/Purchase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.telemetrydeck.sdk.params
22

3-
internal enum class Purchase(val paramName: String) {
3+
enum class Purchase(val paramName: String) {
44
Type("TelemetryDeck.Purchase.type"),
55
CountryCode("TelemetryDeck.Purchase.countryCode"),
66
CurrencyCode("TelemetryDeck.Purchase.currencyCode"),

0 commit comments

Comments
 (0)