From 6f00fc914287bd8bc8b575fcea99effc647a5930 Mon Sep 17 00:00:00 2001 From: Steven de Tilly Date: Wed, 6 Dec 2023 14:22:33 -0500 Subject: [PATCH 1/3] deprecate publishers and promises in trikot analytics --- .../api/android/analytics-viewmodel.api | 7 +++ .../api/jvm/analytics-viewmodel.api | 7 +++ .../SimpleTrackableViewModelAction.kt | 18 +++++++ .../analytics/TrackableViewModelAction.kt | 7 +++ .../analytics/api/android/analytics.api | 6 +++ .../analytics/api/jvm/analytics.api | 6 +++ .../trikot/analytics/AnalyticsService.kt | 54 +++++++++++++++++++ .../analytics/AnalyticsServiceLogger.kt | 9 ++++ .../trikot/analytics/EmptyAnalyticsService.kt | 9 ++++ .../firebase-ktx/api/firebase-ktx.api | 1 + .../analytics/FirebaseAnalyticsService.kt | 27 ++++++++++ .../mixpanel-ktx/api/mixpanel-ktx.api | 1 + .../analytics/MixpanelAnalyticsService.kt | 9 ++++ .../firebase/FirebaseAnalyticsService.swift | 4 ++ .../mixpanel/MixpanelAnalyticsService.swift | 4 ++ 15 files changed, 169 insertions(+) create mode 100644 trikot-analytics/analytics-viewmodel/src/commonMain/kotlin/com/mirego/trikot/analytics/SimpleTrackableViewModelAction.kt diff --git a/trikot-analytics/analytics-viewmodel/api/android/analytics-viewmodel.api b/trikot-analytics/analytics-viewmodel/api/android/analytics-viewmodel.api index bf6036f37..981d138e7 100644 --- a/trikot-analytics/analytics-viewmodel/api/android/analytics-viewmodel.api +++ b/trikot-analytics/analytics-viewmodel/api/android/analytics-viewmodel.api @@ -1,3 +1,10 @@ +public class com/mirego/trikot/analytics/SimpleTrackableViewModelAction : com/mirego/trikot/viewmodels/properties/ViewModelAction { + public fun (Lcom/mirego/trikot/analytics/AnalyticsEvent;Ljava/util/Map;Lkotlin/jvm/functions/Function1;)V + public synthetic fun (Lcom/mirego/trikot/analytics/AnalyticsEvent;Ljava/util/Map;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun execute ()V + public fun execute (Ljava/lang/Object;)V +} + public class com/mirego/trikot/analytics/TrackableViewModelAction : com/mirego/trikot/viewmodels/properties/ViewModelAction { public fun (Lcom/mirego/trikot/analytics/AnalyticsEvent;Ljava/util/Map;Lkotlin/jvm/functions/Function1;)V public fun (Lcom/mirego/trikot/analytics/AnalyticsEvent;Lorg/reactivestreams/Publisher;Lkotlin/jvm/functions/Function1;)V diff --git a/trikot-analytics/analytics-viewmodel/api/jvm/analytics-viewmodel.api b/trikot-analytics/analytics-viewmodel/api/jvm/analytics-viewmodel.api index bf6036f37..981d138e7 100644 --- a/trikot-analytics/analytics-viewmodel/api/jvm/analytics-viewmodel.api +++ b/trikot-analytics/analytics-viewmodel/api/jvm/analytics-viewmodel.api @@ -1,3 +1,10 @@ +public class com/mirego/trikot/analytics/SimpleTrackableViewModelAction : com/mirego/trikot/viewmodels/properties/ViewModelAction { + public fun (Lcom/mirego/trikot/analytics/AnalyticsEvent;Ljava/util/Map;Lkotlin/jvm/functions/Function1;)V + public synthetic fun (Lcom/mirego/trikot/analytics/AnalyticsEvent;Ljava/util/Map;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun execute ()V + public fun execute (Ljava/lang/Object;)V +} + public class com/mirego/trikot/analytics/TrackableViewModelAction : com/mirego/trikot/viewmodels/properties/ViewModelAction { public fun (Lcom/mirego/trikot/analytics/AnalyticsEvent;Ljava/util/Map;Lkotlin/jvm/functions/Function1;)V public fun (Lcom/mirego/trikot/analytics/AnalyticsEvent;Lorg/reactivestreams/Publisher;Lkotlin/jvm/functions/Function1;)V diff --git a/trikot-analytics/analytics-viewmodel/src/commonMain/kotlin/com/mirego/trikot/analytics/SimpleTrackableViewModelAction.kt b/trikot-analytics/analytics-viewmodel/src/commonMain/kotlin/com/mirego/trikot/analytics/SimpleTrackableViewModelAction.kt new file mode 100644 index 000000000..9e2ddd647 --- /dev/null +++ b/trikot-analytics/analytics-viewmodel/src/commonMain/kotlin/com/mirego/trikot/analytics/SimpleTrackableViewModelAction.kt @@ -0,0 +1,18 @@ +package com.mirego.trikot.analytics + +import com.mirego.trikot.viewmodels.properties.ViewModelAction +import com.mirego.trikot.viewmodels.properties.ViewModelActionBlock + +open class SimpleTrackableViewModelAction(private val event: AnalyticsEvent, private val properties: AnalyticsPropertiesType = mapOf(), actionBlock: ViewModelActionBlock) : + ViewModelAction(actionBlock) { + + override fun execute() { + super.execute() + AnalyticsConfiguration.analyticsManager.trackEvent(event, properties) + } + + override fun execute(actionContext: Any?) { + super.execute(actionContext) + AnalyticsConfiguration.analyticsManager.trackEvent(event, properties) + } +} diff --git a/trikot-analytics/analytics-viewmodel/src/commonMain/kotlin/com/mirego/trikot/analytics/TrackableViewModelAction.kt b/trikot-analytics/analytics-viewmodel/src/commonMain/kotlin/com/mirego/trikot/analytics/TrackableViewModelAction.kt index db11cfc37..aa8dbb6d0 100644 --- a/trikot-analytics/analytics-viewmodel/src/commonMain/kotlin/com/mirego/trikot/analytics/TrackableViewModelAction.kt +++ b/trikot-analytics/analytics-viewmodel/src/commonMain/kotlin/com/mirego/trikot/analytics/TrackableViewModelAction.kt @@ -5,6 +5,13 @@ import com.mirego.trikot.viewmodels.properties.ViewModelAction import com.mirego.trikot.viewmodels.properties.ViewModelActionBlock import org.reactivestreams.Publisher +@Deprecated( + message = "Deprecated. Please use AnalyticsEvent", + replaceWith = ReplaceWith( + expression = "AnalyticsEvent", + imports = ["com.mirego.trikot.analytics.AnalyticsEvent"] + ) +) open class TrackableViewModelAction(private val event: AnalyticsEvent, private val properties: Publisher = mapOf().just(), actionBlock: ViewModelActionBlock) : ViewModelAction(actionBlock) { constructor(event: AnalyticsEvent, properties: AnalyticsPropertiesType, actionBlock: ViewModelActionBlock) : this(event, properties.just(), actionBlock) diff --git a/trikot-analytics/analytics/api/android/analytics.api b/trikot-analytics/analytics/api/android/analytics.api index 8aecfae57..b24947a8c 100644 --- a/trikot-analytics/analytics/api/android/analytics.api +++ b/trikot-analytics/analytics/api/android/analytics.api @@ -11,6 +11,7 @@ public abstract interface class com/mirego/trikot/analytics/AnalyticsEvent { public abstract interface class com/mirego/trikot/analytics/AnalyticsService { public static final field Companion Lcom/mirego/trikot/analytics/AnalyticsService$Companion; public abstract fun distinctAppId ()Lcom/mirego/trikot/streams/reactive/promise/Promise; + public abstract fun distinctDeviceId (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun getName ()Ljava/lang/String; public abstract fun identifyUser (Ljava/lang/String;Ljava/util/Map;)V public abstract fun incrementUserProperties (Ljava/util/Map;)V @@ -26,6 +27,7 @@ public abstract interface class com/mirego/trikot/analytics/AnalyticsService { public final class com/mirego/trikot/analytics/AnalyticsService$Companion : com/mirego/trikot/analytics/AnalyticsService { public fun distinctAppId ()Lcom/mirego/trikot/streams/reactive/promise/Promise; + public fun distinctDeviceId (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun getName ()Ljava/lang/String; public fun identifyUser (Ljava/lang/String;Ljava/util/Map;)V public fun incrementUserProperties (Ljava/util/Map;)V @@ -40,15 +42,18 @@ public final class com/mirego/trikot/analytics/AnalyticsService$Companion : com/ } public final class com/mirego/trikot/analytics/AnalyticsServiceKt { + public static final fun identifyUser (Lcom/mirego/trikot/analytics/AnalyticsService;Ljava/lang/String;Ljava/util/Map;)V public static final fun identifyUser (Lcom/mirego/trikot/analytics/AnalyticsService;Ljava/lang/String;Lorg/reactivestreams/Publisher;)V public static final fun logout (Lcom/mirego/trikot/analytics/AnalyticsService;Z)V public static synthetic fun logout$default (Lcom/mirego/trikot/analytics/AnalyticsService;ZILjava/lang/Object;)V + public static final fun trackEvent (Lcom/mirego/trikot/analytics/AnalyticsService;Lcom/mirego/trikot/analytics/AnalyticsEvent;Ljava/util/Map;)V public static final fun trackEvent (Lcom/mirego/trikot/analytics/AnalyticsService;Lcom/mirego/trikot/analytics/AnalyticsEvent;Lorg/reactivestreams/Publisher;)V } public final class com/mirego/trikot/analytics/AnalyticsServiceLogger : com/mirego/trikot/analytics/AnalyticsService { public fun (Lcom/mirego/trikot/analytics/AnalyticsService;)V public fun distinctAppId ()Lcom/mirego/trikot/streams/reactive/promise/Promise; + public fun distinctDeviceId (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun getName ()Ljava/lang/String; public fun identifyUser (Ljava/lang/String;Ljava/util/Map;)V public fun incrementUserProperties (Ljava/util/Map;)V @@ -65,6 +70,7 @@ public final class com/mirego/trikot/analytics/AnalyticsServiceLogger : com/mire public final class com/mirego/trikot/analytics/EmptyAnalyticsService : com/mirego/trikot/analytics/AnalyticsService { public fun ()V public fun distinctAppId ()Lcom/mirego/trikot/streams/reactive/promise/Promise; + public fun distinctDeviceId (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun getName ()Ljava/lang/String; public fun identifyUser (Ljava/lang/String;Ljava/util/Map;)V public fun incrementUserProperties (Ljava/util/Map;)V diff --git a/trikot-analytics/analytics/api/jvm/analytics.api b/trikot-analytics/analytics/api/jvm/analytics.api index 8aecfae57..b24947a8c 100644 --- a/trikot-analytics/analytics/api/jvm/analytics.api +++ b/trikot-analytics/analytics/api/jvm/analytics.api @@ -11,6 +11,7 @@ public abstract interface class com/mirego/trikot/analytics/AnalyticsEvent { public abstract interface class com/mirego/trikot/analytics/AnalyticsService { public static final field Companion Lcom/mirego/trikot/analytics/AnalyticsService$Companion; public abstract fun distinctAppId ()Lcom/mirego/trikot/streams/reactive/promise/Promise; + public abstract fun distinctDeviceId (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public abstract fun getName ()Ljava/lang/String; public abstract fun identifyUser (Ljava/lang/String;Ljava/util/Map;)V public abstract fun incrementUserProperties (Ljava/util/Map;)V @@ -26,6 +27,7 @@ public abstract interface class com/mirego/trikot/analytics/AnalyticsService { public final class com/mirego/trikot/analytics/AnalyticsService$Companion : com/mirego/trikot/analytics/AnalyticsService { public fun distinctAppId ()Lcom/mirego/trikot/streams/reactive/promise/Promise; + public fun distinctDeviceId (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun getName ()Ljava/lang/String; public fun identifyUser (Ljava/lang/String;Ljava/util/Map;)V public fun incrementUserProperties (Ljava/util/Map;)V @@ -40,15 +42,18 @@ public final class com/mirego/trikot/analytics/AnalyticsService$Companion : com/ } public final class com/mirego/trikot/analytics/AnalyticsServiceKt { + public static final fun identifyUser (Lcom/mirego/trikot/analytics/AnalyticsService;Ljava/lang/String;Ljava/util/Map;)V public static final fun identifyUser (Lcom/mirego/trikot/analytics/AnalyticsService;Ljava/lang/String;Lorg/reactivestreams/Publisher;)V public static final fun logout (Lcom/mirego/trikot/analytics/AnalyticsService;Z)V public static synthetic fun logout$default (Lcom/mirego/trikot/analytics/AnalyticsService;ZILjava/lang/Object;)V + public static final fun trackEvent (Lcom/mirego/trikot/analytics/AnalyticsService;Lcom/mirego/trikot/analytics/AnalyticsEvent;Ljava/util/Map;)V public static final fun trackEvent (Lcom/mirego/trikot/analytics/AnalyticsService;Lcom/mirego/trikot/analytics/AnalyticsEvent;Lorg/reactivestreams/Publisher;)V } public final class com/mirego/trikot/analytics/AnalyticsServiceLogger : com/mirego/trikot/analytics/AnalyticsService { public fun (Lcom/mirego/trikot/analytics/AnalyticsService;)V public fun distinctAppId ()Lcom/mirego/trikot/streams/reactive/promise/Promise; + public fun distinctDeviceId (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun getName ()Ljava/lang/String; public fun identifyUser (Ljava/lang/String;Ljava/util/Map;)V public fun incrementUserProperties (Ljava/util/Map;)V @@ -65,6 +70,7 @@ public final class com/mirego/trikot/analytics/AnalyticsServiceLogger : com/mire public final class com/mirego/trikot/analytics/EmptyAnalyticsService : com/mirego/trikot/analytics/AnalyticsService { public fun ()V public fun distinctAppId ()Lcom/mirego/trikot/streams/reactive/promise/Promise; + public fun distinctDeviceId (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun getName ()Ljava/lang/String; public fun identifyUser (Ljava/lang/String;Ljava/util/Map;)V public fun incrementUserProperties (Ljava/util/Map;)V diff --git a/trikot-analytics/analytics/src/commonMain/kotlin/com/mirego/trikot/analytics/AnalyticsService.kt b/trikot-analytics/analytics/src/commonMain/kotlin/com/mirego/trikot/analytics/AnalyticsService.kt index b8b1ef141..a7104714c 100644 --- a/trikot-analytics/analytics/src/commonMain/kotlin/com/mirego/trikot/analytics/AnalyticsService.kt +++ b/trikot-analytics/analytics/src/commonMain/kotlin/com/mirego/trikot/analytics/AnalyticsService.kt @@ -20,8 +20,20 @@ interface AnalyticsService { /* The distinctAppId associated with the current device */ + @Deprecated( + message = "Deprecated. Please use distinctDeviceId()", + replaceWith = ReplaceWith( + expression = "distinctDeviceId()", + imports = ["com.mirego.trikot.analytics.distinctDeviceId"] + ) + ) fun distinctAppId(): Promise + /* + The distinctDeviceId associated with the current device + */ + suspend fun distinctDeviceId(): String + /* userId: Id of the logged in user properties: Properties associated with the user @@ -76,8 +88,17 @@ interface AnalyticsService { currentAnalyticsService().isEnabled = value } + @Deprecated( + message = "Deprecated. Please use distinctDeviceId()", + replaceWith = ReplaceWith( + expression = "distinctDeviceId()", + imports = ["com.mirego.trikot.analytics.distinctDeviceId"] + ) + ) override fun distinctAppId() = currentAnalyticsService().distinctAppId() + override suspend fun distinctDeviceId() = currentAnalyticsService().distinctDeviceId() + override fun identifyUser(userId: String, properties: AnalyticsPropertiesType) { currentAnalyticsService().identifyUser(userId, properties) } @@ -116,6 +137,13 @@ interface AnalyticsService { event: Event to track, will be store using toString() method properties: Publisher of property to store with the event. Publisher MUST return a value. */ +@Deprecated( + message = "Deprecated. Please use the one without a Publisher", + replaceWith = ReplaceWith( + expression = "trackEvent(event, propertiesMap)", + imports = ["com.mirego.trikot.analytics.trackEvent"] + ) +) fun AnalyticsService.trackEvent( event: AnalyticsEvent, properties: Publisher @@ -125,16 +153,42 @@ fun AnalyticsService.trackEvent( } } +/* +event: Event to track, will be store using toString() method +properties: Property to store with the event. + */ +fun AnalyticsService.trackEvent( + event: AnalyticsEvent, + propertiesMap: AnalyticsPropertiesType +) { + trackEvent(event, propertiesMap) +} + /* userId: Id of the logged in user properties: Publisher of property to store with the event. Publisher MUST return a value. */ +@Deprecated( + message = "Deprecated. Please use the one without a Publisher", + replaceWith = ReplaceWith( + expression = "trackEvent(event, propertiesMap)", + imports = ["com.mirego.trikot.analytics.identifyUser"] + ) +) fun AnalyticsService.identifyUser(userId: String, properties: Publisher) { properties.first().subscribe(CancellableManager()) { identifyUser(userId, it) } } +/* + userId: Id of the logged in user + properties: Property to store with the event. + */ +fun AnalyticsService.identifyUser(userId: String, propertiesMap: AnalyticsPropertiesType) { + identifyUser(userId, propertiesMap) +} + /* UnIdentify the current logged in user */ diff --git a/trikot-analytics/analytics/src/commonMain/kotlin/com/mirego/trikot/analytics/AnalyticsServiceLogger.kt b/trikot-analytics/analytics/src/commonMain/kotlin/com/mirego/trikot/analytics/AnalyticsServiceLogger.kt index b5041db33..26b9cd6b9 100644 --- a/trikot-analytics/analytics/src/commonMain/kotlin/com/mirego/trikot/analytics/AnalyticsServiceLogger.kt +++ b/trikot-analytics/analytics/src/commonMain/kotlin/com/mirego/trikot/analytics/AnalyticsServiceLogger.kt @@ -14,8 +14,17 @@ class AnalyticsServiceLogger(private val analyticsService: AnalyticsService) : A private val superProperties = AtomicReference(mapOf()) + @Deprecated( + message = "Deprecated. Please use distinctDeviceId()", + replaceWith = ReplaceWith( + expression = "distinctDeviceId()", + imports = ["com.mirego.trikot.analytics.distinctDeviceId"] + ) + ) override fun distinctAppId() = analyticsService.distinctAppId() + override suspend fun distinctDeviceId() = analyticsService.distinctDeviceId() + override fun identifyUser(userId: String, properties: AnalyticsPropertiesType) { println( """ diff --git a/trikot-analytics/analytics/src/commonMain/kotlin/com/mirego/trikot/analytics/EmptyAnalyticsService.kt b/trikot-analytics/analytics/src/commonMain/kotlin/com/mirego/trikot/analytics/EmptyAnalyticsService.kt index 0430450ed..d30698090 100644 --- a/trikot-analytics/analytics/src/commonMain/kotlin/com/mirego/trikot/analytics/EmptyAnalyticsService.kt +++ b/trikot-analytics/analytics/src/commonMain/kotlin/com/mirego/trikot/analytics/EmptyAnalyticsService.kt @@ -7,8 +7,17 @@ class EmptyAnalyticsService : AnalyticsService { override var isEnabled = false + @Deprecated( + message = "Deprecated. Please use distinctDeviceId()", + replaceWith = ReplaceWith( + expression = "distinctDeviceId()", + imports = ["com.mirego.trikot.analytics.distinctDeviceId"] + ) + ) override fun distinctAppId() = Promise.resolve("ANALYTICS_SERVICE_NOT_CONFIGURED_DISTINCT_ID") + override suspend fun distinctDeviceId() = "ANALYTICS_SERVICE_NOT_CONFIGURED_DISTINCT_ID" + override fun identifyUser(userId: String, properties: AnalyticsPropertiesType) { } diff --git a/trikot-analytics/firebase-ktx/api/firebase-ktx.api b/trikot-analytics/firebase-ktx/api/firebase-ktx.api index b18a79a24..329c61983 100644 --- a/trikot-analytics/firebase-ktx/api/firebase-ktx.api +++ b/trikot-analytics/firebase-ktx/api/firebase-ktx.api @@ -2,6 +2,7 @@ public final class com/mirego/trikot/analytics/FirebaseAnalyticsService : com/mi public fun (Landroid/content/Context;Z)V public synthetic fun (Landroid/content/Context;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun distinctAppId ()Lcom/mirego/trikot/streams/reactive/promise/Promise; + public fun distinctDeviceId (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun getName ()Ljava/lang/String; public fun identifyUser (Ljava/lang/String;Ljava/util/Map;)V public fun incrementUserProperties (Ljava/util/Map;)V diff --git a/trikot-analytics/firebase-ktx/src/main/java/com/mirego/trikot/analytics/FirebaseAnalyticsService.kt b/trikot-analytics/firebase-ktx/src/main/java/com/mirego/trikot/analytics/FirebaseAnalyticsService.kt index 5d0af3c79..6eb9b9ca9 100644 --- a/trikot-analytics/firebase-ktx/src/main/java/com/mirego/trikot/analytics/FirebaseAnalyticsService.kt +++ b/trikot-analytics/firebase-ktx/src/main/java/com/mirego/trikot/analytics/FirebaseAnalyticsService.kt @@ -4,6 +4,9 @@ import android.content.Context import android.os.Bundle import com.google.firebase.analytics.FirebaseAnalytics import com.mirego.trikot.streams.reactive.promise.Promise +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.suspendCancellableCoroutine +import kotlin.coroutines.resume class FirebaseAnalyticsService(context: Context, analyticsEnabled: Boolean = true) : AnalyticsService { @@ -23,6 +26,13 @@ class FirebaseAnalyticsService(context: Context, analyticsEnabled: Boolean = tru private var superProperties = emptyMap() + @Deprecated( + message = "Deprecated. Please use distinctDeviceId()", + replaceWith = ReplaceWith( + expression = "distinctDeviceId()", + imports = ["com.mirego.trikot.analytics.distinctDeviceId"] + ) + ) override fun distinctAppId() = Promise.create { resolve, reject -> firebaseAnalytics.appInstanceId .addOnCompleteListener { task -> @@ -40,6 +50,23 @@ class FirebaseAnalyticsService(context: Context, analyticsEnabled: Boolean = tru } } + override suspend fun distinctDeviceId() = suspendCancellableCoroutine { continuation -> + firebaseAnalytics.appInstanceId + .addOnCompleteListener { task -> + val result = task.result + if (task.isSuccessful && result != null) { + continuation.resume(result) + } else if (!task.isSuccessful) { + continuation.cancel(Throwable(task.exception)) + } else { + continuation.cancel(Throwable("Empty result")) + } + } + .addOnCanceledListener { + continuation.cancel(Throwable("Canceled")) + } + } + override fun identifyUser(userId: String, properties: AnalyticsPropertiesType) { firebaseAnalytics.setUserId(userId) properties.forEach { diff --git a/trikot-analytics/mixpanel-ktx/api/mixpanel-ktx.api b/trikot-analytics/mixpanel-ktx/api/mixpanel-ktx.api index cc88281f0..ac3cedb36 100644 --- a/trikot-analytics/mixpanel-ktx/api/mixpanel-ktx.api +++ b/trikot-analytics/mixpanel-ktx/api/mixpanel-ktx.api @@ -2,6 +2,7 @@ public final class com/mirego/trikot/analytics/MixpanelAnalyticsService : com/mi public fun (Landroid/content/Context;Ljava/lang/String;Z)V public synthetic fun (Landroid/content/Context;Ljava/lang/String;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V public fun distinctAppId ()Lcom/mirego/trikot/streams/reactive/promise/Promise; + public fun distinctDeviceId (Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public fun getName ()Ljava/lang/String; public fun identifyUser (Ljava/lang/String;Ljava/util/Map;)V public fun incrementUserProperties (Ljava/util/Map;)V diff --git a/trikot-analytics/mixpanel-ktx/src/main/java/com/mirego/trikot/analytics/MixpanelAnalyticsService.kt b/trikot-analytics/mixpanel-ktx/src/main/java/com/mirego/trikot/analytics/MixpanelAnalyticsService.kt index 4018d7d8c..e7d33a6f2 100644 --- a/trikot-analytics/mixpanel-ktx/src/main/java/com/mirego/trikot/analytics/MixpanelAnalyticsService.kt +++ b/trikot-analytics/mixpanel-ktx/src/main/java/com/mirego/trikot/analytics/MixpanelAnalyticsService.kt @@ -25,8 +25,17 @@ class MixpanelAnalyticsService( override val name: String = "MixpanelAnalytics" + @Deprecated( + message = "Deprecated. Please use distinctDeviceId()", + replaceWith = ReplaceWith( + expression = "distinctDeviceId()", + imports = ["com.mirego.trikot.analytics.distinctDeviceId"] + ) + ) override fun distinctAppId() = Promise.resolve(mixpanelAnalytics.distinctId) + override suspend fun distinctDeviceId(): String = mixpanelAnalytics.distinctId + override fun identifyUser(userId: String, properties: AnalyticsPropertiesType) { mixpanelAnalytics.identify(userId) mixpanelAnalytics.people.identify(userId) diff --git a/trikot-analytics/swift-extensions/firebase/FirebaseAnalyticsService.swift b/trikot-analytics/swift-extensions/firebase/FirebaseAnalyticsService.swift index 87897ec19..23c88f1e3 100644 --- a/trikot-analytics/swift-extensions/firebase/FirebaseAnalyticsService.swift +++ b/trikot-analytics/swift-extensions/firebase/FirebaseAnalyticsService.swift @@ -20,6 +20,10 @@ public class FirebaseAnalyticsService: AnalyticsService { PromiseCompanion().resolve(value: Analytics.appInstanceID) as! Promise } + public func distinctDeviceId() -> NSString { + Analytics.appInstanceID() + } + public func identifyUser(userId: String, properties: [String: Any]) { Analytics.setUserID(userId) properties.forEach { Analytics.setUserProperty(anyToString($0.value), forName: $0.key) } diff --git a/trikot-analytics/swift-extensions/mixpanel/MixpanelAnalyticsService.swift b/trikot-analytics/swift-extensions/mixpanel/MixpanelAnalyticsService.swift index ee4c3ef06..15c6e8451 100644 --- a/trikot-analytics/swift-extensions/mixpanel/MixpanelAnalyticsService.swift +++ b/trikot-analytics/swift-extensions/mixpanel/MixpanelAnalyticsService.swift @@ -22,6 +22,10 @@ public class MixpanelAnalyticsService: AnalyticsService { PromiseCompanion().resolve(value: Mixpanel.mainInstance().distinctId) as! Promise } + public func distinctDeviceId() -> NSString { + Mixpanel.mainInstance().distinctId + } + public func identifyUser(userId: String, properties: [String: Any]) { Mixpanel.mainInstance().identify(distinctId: userId) Mixpanel.mainInstance().people.set(properties: properties.asMixpanelProperties) From 214e508b1e085b045abe7be9ef4f196ef2dbd610 Mon Sep 17 00:00:00 2001 From: Steven de Tilly Date: Wed, 6 Dec 2023 15:53:14 -0500 Subject: [PATCH 2/3] fix swift files --- .../swift-extensions/firebase/FirebaseAnalyticsService.swift | 2 +- .../swift-extensions/mixpanel/MixpanelAnalyticsService.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/trikot-analytics/swift-extensions/firebase/FirebaseAnalyticsService.swift b/trikot-analytics/swift-extensions/firebase/FirebaseAnalyticsService.swift index 23c88f1e3..873eb36d6 100644 --- a/trikot-analytics/swift-extensions/firebase/FirebaseAnalyticsService.swift +++ b/trikot-analytics/swift-extensions/firebase/FirebaseAnalyticsService.swift @@ -21,7 +21,7 @@ public class FirebaseAnalyticsService: AnalyticsService { } public func distinctDeviceId() -> NSString { - Analytics.appInstanceID() + Analytics.appInstanceID() as! NSString } public func identifyUser(userId: String, properties: [String: Any]) { diff --git a/trikot-analytics/swift-extensions/mixpanel/MixpanelAnalyticsService.swift b/trikot-analytics/swift-extensions/mixpanel/MixpanelAnalyticsService.swift index 15c6e8451..20db018b1 100644 --- a/trikot-analytics/swift-extensions/mixpanel/MixpanelAnalyticsService.swift +++ b/trikot-analytics/swift-extensions/mixpanel/MixpanelAnalyticsService.swift @@ -23,7 +23,7 @@ public class MixpanelAnalyticsService: AnalyticsService { } public func distinctDeviceId() -> NSString { - Mixpanel.mainInstance().distinctId + Mixpanel.mainInstance().distinctId as NSString } public func identifyUser(userId: String, properties: [String: Any]) { From 87a2f127b90e58fb710017dc5186d932ef4ed8b1 Mon Sep 17 00:00:00 2001 From: Steven de Tilly Date: Wed, 6 Dec 2023 16:08:44 -0500 Subject: [PATCH 3/3] ktlint fix --- .../java/com/mirego/trikot/analytics/FirebaseAnalyticsService.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/trikot-analytics/firebase-ktx/src/main/java/com/mirego/trikot/analytics/FirebaseAnalyticsService.kt b/trikot-analytics/firebase-ktx/src/main/java/com/mirego/trikot/analytics/FirebaseAnalyticsService.kt index 6eb9b9ca9..8303ed711 100644 --- a/trikot-analytics/firebase-ktx/src/main/java/com/mirego/trikot/analytics/FirebaseAnalyticsService.kt +++ b/trikot-analytics/firebase-ktx/src/main/java/com/mirego/trikot/analytics/FirebaseAnalyticsService.kt @@ -4,7 +4,6 @@ import android.content.Context import android.os.Bundle import com.google.firebase.analytics.FirebaseAnalytics import com.mirego.trikot.streams.reactive.promise.Promise -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.suspendCancellableCoroutine import kotlin.coroutines.resume