From 729d9ce815d0eedeede20308c37d34d1e31b6419 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 25 Nov 2021 22:41:20 +0100 Subject: [PATCH] Create interface for the coming plan --- .../app/features/analytics/VectorAnalytics.kt | 6 +++-- .../analytics/impl/DefaultVectorAnalytics.kt | 12 +++++----- .../analytics/itf/VectorAnalyticsEvent.kt | 22 +++++++++++++++++++ .../analytics/itf/VectorAnalyticsScreen.kt | 22 +++++++++++++++++++ 4 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 vector/src/main/java/im/vector/app/features/analytics/itf/VectorAnalyticsEvent.kt create mode 100644 vector/src/main/java/im/vector/app/features/analytics/itf/VectorAnalyticsScreen.kt diff --git a/vector/src/main/java/im/vector/app/features/analytics/VectorAnalytics.kt b/vector/src/main/java/im/vector/app/features/analytics/VectorAnalytics.kt index ae119561b3..476f5ade56 100644 --- a/vector/src/main/java/im/vector/app/features/analytics/VectorAnalytics.kt +++ b/vector/src/main/java/im/vector/app/features/analytics/VectorAnalytics.kt @@ -16,6 +16,8 @@ package im.vector.app.features.analytics +import im.vector.app.features.analytics.itf.VectorAnalyticsEvent +import im.vector.app.features.analytics.itf.VectorAnalyticsScreen import kotlinx.coroutines.flow.Flow interface VectorAnalytics { @@ -62,10 +64,10 @@ interface VectorAnalytics { /** * Capture an Event */ - fun capture(event: String, properties: Map? = null) + fun capture(event: VectorAnalyticsEvent) /** * Track a displayed screen */ - fun screen(name: String, properties: Map? = null) + fun screen(screen: VectorAnalyticsScreen) } diff --git a/vector/src/main/java/im/vector/app/features/analytics/impl/DefaultVectorAnalytics.kt b/vector/src/main/java/im/vector/app/features/analytics/impl/DefaultVectorAnalytics.kt index b9d85ec30a..997bea88a5 100644 --- a/vector/src/main/java/im/vector/app/features/analytics/impl/DefaultVectorAnalytics.kt +++ b/vector/src/main/java/im/vector/app/features/analytics/impl/DefaultVectorAnalytics.kt @@ -23,6 +23,8 @@ import im.vector.app.BuildConfig import im.vector.app.features.analytics.AnalyticsConfig import im.vector.app.features.analytics.VectorAnalytics import im.vector.app.features.analytics.log.analyticsTag +import im.vector.app.features.analytics.itf.VectorAnalyticsEvent +import im.vector.app.features.analytics.itf.VectorAnalyticsScreen import im.vector.app.features.analytics.store.AnalyticsStore import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.flow.Flow @@ -152,18 +154,18 @@ class DefaultVectorAnalytics @Inject constructor( } } - override fun capture(event: String, properties: Map?) { + override fun capture(event: VectorAnalyticsEvent) { Timber.tag(analyticsTag.value).d("capture($event)") posthog ?.takeIf { userConsent == true } - ?.capture(event, properties.toPostHogProperties()) + ?.capture(event.getName(), event.getProperties()?.toPostHogProperties()) } - override fun screen(name: String, properties: Map?) { - Timber.tag(analyticsTag.value).d("screen($name)") + override fun screen(screen: VectorAnalyticsScreen) { + Timber.tag(analyticsTag.value).d("screen($screen)") posthog ?.takeIf { userConsent == true } - ?.screen(name, properties.toPostHogProperties()) + ?.screen(screen.getName(), screen.getProperties()?.toPostHogProperties()) } private fun Map?.toPostHogProperties(): Properties? { diff --git a/vector/src/main/java/im/vector/app/features/analytics/itf/VectorAnalyticsEvent.kt b/vector/src/main/java/im/vector/app/features/analytics/itf/VectorAnalyticsEvent.kt new file mode 100644 index 0000000000..c6acb3b87a --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/analytics/itf/VectorAnalyticsEvent.kt @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.analytics.itf + +interface VectorAnalyticsEvent { + fun getName(): String + fun getProperties(): Map? +} diff --git a/vector/src/main/java/im/vector/app/features/analytics/itf/VectorAnalyticsScreen.kt b/vector/src/main/java/im/vector/app/features/analytics/itf/VectorAnalyticsScreen.kt new file mode 100644 index 0000000000..7056814aaf --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/analytics/itf/VectorAnalyticsScreen.kt @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.analytics.itf + +interface VectorAnalyticsScreen { + fun getName(): String + fun getProperties(): Map? +}