track screen event when user enters the screen instead of when user leaves the screen

This commit is contained in:
NIkita Fedrunov 2022-02-18 10:23:56 +01:00
parent ec2021d6f2
commit bda92a9ab4
9 changed files with 17 additions and 45 deletions

1
changelog.d/5256.misc Normal file
View file

@ -0,0 +1 @@
Analytics screen events are now tracked on screen enter instead of screen leave

View file

@ -98,7 +98,6 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
* ========================================================================================== */
protected var analyticsScreenName: MobileScreen.ScreenName? = null
private var screenEvent: ScreenEvent? = null
protected lateinit var analyticsTracker: AnalyticsTracker
@ -337,7 +336,9 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
override fun onResume() {
super.onResume()
Timber.i("onResume Activity ${javaClass.simpleName}")
screenEvent = analyticsScreenName?.let { ScreenEvent(it) }
analyticsScreenName?.let {
ScreenEvent(it).send(analyticsTracker)
}
configurationViewModel.onActivityResumed()
if (this !is BugReportActivity && vectorPreferences.useRageshake()) {
@ -376,7 +377,6 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver
override fun onPause() {
super.onPause()
screenEvent?.send(analyticsTracker, analyticsScreenName)
Timber.i("onPause Activity ${javaClass.simpleName}")
rageShake.stop()

View file

@ -54,7 +54,6 @@ abstract class VectorBaseBottomSheetDialogFragment<VB : ViewBinding> : BottomShe
* ========================================================================================== */
protected var analyticsScreenName: MobileScreen.ScreenName? = null
private var screenEvent: ScreenEvent? = null
protected lateinit var analyticsTracker: AnalyticsTracker
@ -139,12 +138,9 @@ abstract class VectorBaseBottomSheetDialogFragment<VB : ViewBinding> : 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 {
ScreenEvent(it).send(analyticsTracker)
}
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {

View file

@ -59,7 +59,6 @@ abstract class VectorBaseFragment<VB : ViewBinding> : Fragment(), MavericksView
* ========================================================================================== */
protected var analyticsScreenName: MobileScreen.ScreenName? = null
private var screenEvent: ScreenEvent? = null
protected lateinit var analyticsTracker: AnalyticsTracker
@ -145,14 +144,15 @@ abstract class VectorBaseFragment<VB : ViewBinding> : Fragment(), MavericksView
override fun onResume() {
super.onResume()
Timber.i("onResume Fragment ${javaClass.simpleName}")
screenEvent = analyticsScreenName?.let { ScreenEvent(it) }
analyticsScreenName?.let {
ScreenEvent(it).send(analyticsTracker)
}
}
@CallSuper
override fun onPause() {
super.onPause()
Timber.i("onPause Fragment ${javaClass.simpleName}")
screenEvent?.send(analyticsTracker)
}
@CallSuper

View file

@ -16,7 +16,6 @@
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
@ -25,8 +24,6 @@ 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
@ -42,8 +39,7 @@ class ScreenEvent(val screenName: MobileScreen.ScreenName) {
isSent = true
analyticsTracker.screen(
MobileScreen(
screenName = screenNameOverride ?: screenName,
durationMs = (SystemClock.elapsedRealtime() - startTime).toInt()
screenName = screenNameOverride ?: screenName
)
)
}

View file

@ -69,12 +69,7 @@ class DialPadFragment : Fragment(), TextWatcher {
private var screenEvent: ScreenEvent? = null
override fun onResume() {
super.onResume()
screenEvent = ScreenEvent(MobileScreen.ScreenName.Dialpad)
}
override fun onPause() {
super.onPause()
screenEvent?.send(analyticsTracker)
ScreenEvent(MobileScreen.ScreenName.Dialpad).send(analyticsTracker)
}
override fun onCreateView(

View file

@ -163,14 +163,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
ScreenEvent(MobileScreen.ScreenName.Sidebar).send(analyticsTracker)
}
override fun onDrawerStateChanged(newState: Int) {

View file

@ -158,14 +158,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
ScreenEvent(MobileScreen.ScreenName.Breadcrumbs).send(analyticsTracker)
}
override fun onDrawerStateChanged(newState: Int) {

View file

@ -44,7 +44,6 @@ abstract class VectorSettingsBaseFragment : PreferenceFragmentCompat(), Maverick
* ========================================================================================== */
protected var analyticsScreenName: MobileScreen.ScreenName? = null
private var screenEvent: ScreenEvent? = null
protected lateinit var analyticsTracker: AnalyticsTracker
@ -91,17 +90,14 @@ abstract class VectorSettingsBaseFragment : PreferenceFragmentCompat(), Maverick
override fun onResume() {
super.onResume()
Timber.i("onResume Fragment ${javaClass.simpleName}")
screenEvent = analyticsScreenName?.let { ScreenEvent(it) }
analyticsScreenName?.let {
ScreenEvent(it).send(analyticsTracker)
}
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