diff --git a/changelog.d/5256.misc b/changelog.d/5256.misc new file mode 100644 index 0000000000..e20f52c7aa --- /dev/null +++ b/changelog.d/5256.misc @@ -0,0 +1 @@ +Analytics screen events are now tracked on screen enter instead of screen leave \ No newline at end of file diff --git a/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt b/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt index 5767acd44b..2c161feb37 100644 --- a/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt +++ b/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt @@ -68,7 +68,6 @@ import im.vector.app.features.MainActivity import im.vector.app.features.MainActivityArgs import im.vector.app.features.analytics.AnalyticsTracker import im.vector.app.features.analytics.plan.MobileScreen -import im.vector.app.features.analytics.screen.ScreenEvent import im.vector.app.features.configuration.VectorConfiguration import im.vector.app.features.consent.ConsentNotGivenHelper import im.vector.app.features.navigation.Navigator @@ -98,7 +97,6 @@ abstract class VectorBaseActivity : AppCompatActivity(), Maver * ========================================================================================== */ protected var analyticsScreenName: MobileScreen.ScreenName? = null - private var screenEvent: ScreenEvent? = null protected lateinit var analyticsTracker: AnalyticsTracker @@ -337,7 +335,9 @@ abstract class VectorBaseActivity : AppCompatActivity(), Maver override fun onResume() { super.onResume() Timber.i("onResume Activity ${javaClass.simpleName}") - screenEvent = analyticsScreenName?.let { ScreenEvent(it) } + analyticsScreenName?.let { + analyticsTracker.screen(MobileScreen(screenName = it)) + } configurationViewModel.onActivityResumed() if (this !is BugReportActivity && vectorPreferences.useRageshake()) { @@ -376,7 +376,6 @@ abstract class VectorBaseActivity : AppCompatActivity(), Maver override fun onPause() { super.onPause() - screenEvent?.send(analyticsTracker, analyticsScreenName) Timber.i("onPause Activity ${javaClass.simpleName}") rageShake.stop() diff --git a/vector/src/main/java/im/vector/app/core/platform/VectorBaseBottomSheetDialogFragment.kt b/vector/src/main/java/im/vector/app/core/platform/VectorBaseBottomSheetDialogFragment.kt index 869a12e871..ddc281fdd1 100644 --- a/vector/src/main/java/im/vector/app/core/platform/VectorBaseBottomSheetDialogFragment.kt +++ b/vector/src/main/java/im/vector/app/core/platform/VectorBaseBottomSheetDialogFragment.kt @@ -39,7 +39,6 @@ import im.vector.app.core.extensions.toMvRxBundle import im.vector.app.core.utils.DimensionConverter import im.vector.app.features.analytics.AnalyticsTracker import im.vector.app.features.analytics.plan.MobileScreen -import im.vector.app.features.analytics.screen.ScreenEvent import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import reactivecircus.flowbinding.android.view.clicks @@ -54,7 +53,6 @@ abstract class VectorBaseBottomSheetDialogFragment : BottomShe * ========================================================================================== */ protected var analyticsScreenName: MobileScreen.ScreenName? = null - private var screenEvent: ScreenEvent? = null protected lateinit var analyticsTracker: AnalyticsTracker @@ -139,12 +137,9 @@ abstract class VectorBaseBottomSheetDialogFragment : BottomShe override fun onResume() { super.onResume() Timber.i("onResume BottomSheet ${javaClass.simpleName}") - screenEvent = analyticsScreenName?.let { ScreenEvent(it) } - } - - override fun onPause() { - super.onPause() - screenEvent?.send(analyticsTracker) + analyticsScreenName?.let { + analyticsTracker.screen(MobileScreen(screenName = it)) + } } override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { diff --git a/vector/src/main/java/im/vector/app/core/platform/VectorBaseFragment.kt b/vector/src/main/java/im/vector/app/core/platform/VectorBaseFragment.kt index 6bd62707f2..70b265ff9f 100644 --- a/vector/src/main/java/im/vector/app/core/platform/VectorBaseFragment.kt +++ b/vector/src/main/java/im/vector/app/core/platform/VectorBaseFragment.kt @@ -45,7 +45,6 @@ import im.vector.app.core.extensions.toMvRxBundle import im.vector.app.core.utils.ToolbarConfig import im.vector.app.features.analytics.AnalyticsTracker import im.vector.app.features.analytics.plan.MobileScreen -import im.vector.app.features.analytics.screen.ScreenEvent import im.vector.app.features.navigation.Navigator import im.vector.lib.ui.styles.dialogs.MaterialProgressDialog import kotlinx.coroutines.flow.launchIn @@ -59,7 +58,6 @@ abstract class VectorBaseFragment : Fragment(), MavericksView * ========================================================================================== */ protected var analyticsScreenName: MobileScreen.ScreenName? = null - private var screenEvent: ScreenEvent? = null protected lateinit var analyticsTracker: AnalyticsTracker @@ -145,14 +143,15 @@ abstract class VectorBaseFragment : Fragment(), MavericksView override fun onResume() { super.onResume() Timber.i("onResume Fragment ${javaClass.simpleName}") - screenEvent = analyticsScreenName?.let { ScreenEvent(it) } + analyticsScreenName?.let { + analyticsTracker.screen(MobileScreen(screenName = it)) + } } @CallSuper override fun onPause() { super.onPause() Timber.i("onPause Fragment ${javaClass.simpleName}") - screenEvent?.send(analyticsTracker) } @CallSuper diff --git a/vector/src/main/java/im/vector/app/features/analytics/screen/ScreenEvent.kt b/vector/src/main/java/im/vector/app/features/analytics/screen/ScreenEvent.kt deleted file mode 100644 index 1ad4a1fa32..0000000000 --- a/vector/src/main/java/im/vector/app/features/analytics/screen/ScreenEvent.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.screen - -import android.os.SystemClock -import im.vector.app.features.analytics.AnalyticsTracker -import im.vector.app.features.analytics.plan.MobileScreen -import timber.log.Timber - -/** - * Track a screen display. Unique usage. - */ -class ScreenEvent(val screenName: MobileScreen.ScreenName) { - private val startTime = SystemClock.elapsedRealtime() - - // Protection to avoid multiple sending - private var isSent = false - - /** - * @param screenNameOverride can be used to override the screen name passed in constructor parameter - */ - fun send(analyticsTracker: AnalyticsTracker, - screenNameOverride: MobileScreen.ScreenName? = null) { - if (isSent) { - Timber.w("Event $screenName Already sent!") - return - } - isSent = true - analyticsTracker.screen( - MobileScreen( - screenName = screenNameOverride ?: screenName, - durationMs = (SystemClock.elapsedRealtime() - startTime).toInt() - ) - ) - } -} diff --git a/vector/src/main/java/im/vector/app/features/call/dialpad/DialPadFragment.kt b/vector/src/main/java/im/vector/app/features/call/dialpad/DialPadFragment.kt index b33ce25f55..606ba1d1e9 100644 --- a/vector/src/main/java/im/vector/app/features/call/dialpad/DialPadFragment.kt +++ b/vector/src/main/java/im/vector/app/features/call/dialpad/DialPadFragment.kt @@ -41,7 +41,6 @@ import im.vector.app.R import im.vector.app.core.extensions.singletonEntryPoint import im.vector.app.features.analytics.AnalyticsTracker import im.vector.app.features.analytics.plan.MobileScreen -import im.vector.app.features.analytics.screen.ScreenEvent import im.vector.app.features.themes.ThemeUtils class DialPadFragment : Fragment(), TextWatcher { @@ -66,15 +65,9 @@ class DialPadFragment : Fragment(), TextWatcher { analyticsTracker = singletonEntryPoint.analyticsTracker() } - private var screenEvent: ScreenEvent? = null override fun onResume() { super.onResume() - screenEvent = ScreenEvent(MobileScreen.ScreenName.Dialpad) - } - - override fun onPause() { - super.onPause() - screenEvent?.send(analyticsTracker) + analyticsTracker.screen(MobileScreen(screenName = MobileScreen.ScreenName.Dialpad)) } override fun onCreateView( diff --git a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt index f6b32973a0..47f1a9208b 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt @@ -49,7 +49,6 @@ import im.vector.app.features.MainActivity import im.vector.app.features.MainActivityArgs import im.vector.app.features.analytics.accountdata.AnalyticsAccountDataViewModel import im.vector.app.features.analytics.plan.MobileScreen -import im.vector.app.features.analytics.screen.ScreenEvent import im.vector.app.features.disclaimer.showDisclaimerDialog import im.vector.app.features.matrixto.MatrixToBottomSheet import im.vector.app.features.navigation.Navigator @@ -163,14 +162,8 @@ class HomeActivity : } private val drawerListener = object : DrawerLayout.SimpleDrawerListener() { - private var drawerScreenEvent: ScreenEvent? = null override fun onDrawerOpened(drawerView: View) { - drawerScreenEvent = ScreenEvent(MobileScreen.ScreenName.Sidebar) - } - - override fun onDrawerClosed(drawerView: View) { - drawerScreenEvent?.send(analyticsTracker) - drawerScreenEvent = null + analyticsTracker.screen(MobileScreen(screenName = MobileScreen.ScreenName.Sidebar)) } override fun onDrawerStateChanged(newState: Int) { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailActivity.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailActivity.kt index f5bf086e96..aa4ee825dc 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailActivity.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailActivity.kt @@ -36,7 +36,6 @@ import im.vector.app.core.extensions.replaceFragment import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivityRoomDetailBinding import im.vector.app.features.analytics.plan.MobileScreen -import im.vector.app.features.analytics.screen.ScreenEvent import im.vector.app.features.home.room.breadcrumbs.BreadcrumbsFragment import im.vector.app.features.home.room.detail.arguments.TimelineArgs import im.vector.app.features.home.room.detail.timeline.helper.VoiceMessagePlaybackTracker @@ -158,14 +157,8 @@ class RoomDetailActivity : } private val drawerListener = object : DrawerLayout.SimpleDrawerListener() { - private var drawerScreenEvent: ScreenEvent? = null override fun onDrawerOpened(drawerView: View) { - drawerScreenEvent = ScreenEvent(MobileScreen.ScreenName.Breadcrumbs) - } - - override fun onDrawerClosed(drawerView: View) { - drawerScreenEvent?.send(analyticsTracker) - drawerScreenEvent = null + analyticsTracker.screen(MobileScreen(screenName = MobileScreen.ScreenName.Breadcrumbs)) } override fun onDrawerStateChanged(newState: Int) { diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsBaseFragment.kt b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsBaseFragment.kt index 4185fde663..dae234eecc 100644 --- a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsBaseFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsBaseFragment.kt @@ -31,7 +31,6 @@ import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.core.utils.toast import im.vector.app.features.analytics.AnalyticsTracker import im.vector.app.features.analytics.plan.MobileScreen -import im.vector.app.features.analytics.screen.ScreenEvent import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import org.matrix.android.sdk.api.session.Session @@ -44,7 +43,6 @@ abstract class VectorSettingsBaseFragment : PreferenceFragmentCompat(), Maverick * ========================================================================================== */ protected var analyticsScreenName: MobileScreen.ScreenName? = null - private var screenEvent: ScreenEvent? = null protected lateinit var analyticsTracker: AnalyticsTracker @@ -91,17 +89,14 @@ abstract class VectorSettingsBaseFragment : PreferenceFragmentCompat(), Maverick override fun onResume() { super.onResume() Timber.i("onResume Fragment ${javaClass.simpleName}") - screenEvent = analyticsScreenName?.let { ScreenEvent(it) } + analyticsScreenName?.let { + analyticsTracker.screen(MobileScreen(screenName = it)) + } vectorActivity.supportActionBar?.setTitle(titleRes) // find the view from parent activity mLoadingView = vectorActivity.findViewById(R.id.vector_settings_spinner_views) } - override fun onPause() { - super.onPause() - screenEvent?.send(analyticsTracker) - } - abstract fun bindPref() abstract var titleRes: Int