Create interface for the coming plan

This commit is contained in:
Benoit Marty 2021-11-25 22:41:20 +01:00 committed by Benoit Marty
parent f05ed4c6cc
commit 729d9ce815
4 changed files with 55 additions and 7 deletions

View File

@ -16,6 +16,8 @@
package im.vector.app.features.analytics 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 import kotlinx.coroutines.flow.Flow
interface VectorAnalytics { interface VectorAnalytics {
@ -62,10 +64,10 @@ interface VectorAnalytics {
/** /**
* Capture an Event * Capture an Event
*/ */
fun capture(event: String, properties: Map<String, Any>? = null) fun capture(event: VectorAnalyticsEvent)
/** /**
* Track a displayed screen * Track a displayed screen
*/ */
fun screen(name: String, properties: Map<String, Any>? = null) fun screen(screen: VectorAnalyticsScreen)
} }

View File

@ -23,6 +23,8 @@ import im.vector.app.BuildConfig
import im.vector.app.features.analytics.AnalyticsConfig import im.vector.app.features.analytics.AnalyticsConfig
import im.vector.app.features.analytics.VectorAnalytics import im.vector.app.features.analytics.VectorAnalytics
import im.vector.app.features.analytics.log.analyticsTag 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 im.vector.app.features.analytics.store.AnalyticsStore
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
@ -152,18 +154,18 @@ class DefaultVectorAnalytics @Inject constructor(
} }
} }
override fun capture(event: String, properties: Map<String, Any>?) { override fun capture(event: VectorAnalyticsEvent) {
Timber.tag(analyticsTag.value).d("capture($event)") Timber.tag(analyticsTag.value).d("capture($event)")
posthog posthog
?.takeIf { userConsent == true } ?.takeIf { userConsent == true }
?.capture(event, properties.toPostHogProperties()) ?.capture(event.getName(), event.getProperties()?.toPostHogProperties())
} }
override fun screen(name: String, properties: Map<String, Any>?) { override fun screen(screen: VectorAnalyticsScreen) {
Timber.tag(analyticsTag.value).d("screen($name)") Timber.tag(analyticsTag.value).d("screen($screen)")
posthog posthog
?.takeIf { userConsent == true } ?.takeIf { userConsent == true }
?.screen(name, properties.toPostHogProperties()) ?.screen(screen.getName(), screen.getProperties()?.toPostHogProperties())
} }
private fun Map<String, Any>?.toPostHogProperties(): Properties? { private fun Map<String, Any>?.toPostHogProperties(): Properties? {

View File

@ -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<String, Any>?
}

View File

@ -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<String, Any>?
}