-
Notifications
You must be signed in to change notification settings - Fork 742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement analytics plan #4734
Implement analytics plan #4734
Changes from all commits
e416f10
e487621
7a6f3cb
3e125bc
11f176e
55a6257
a8c29f5
0a08a50
dfb8075
ebd4dc0
f307c48
67f4355
13b4a58
db3353f
54108b8
1e3733f
e3c70d1
69a9643
c404699
880b97c
c0aa0ce
9e57263
81b8260
0008065
58197b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Analytics: send more Events |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,9 @@ import im.vector.app.core.extensions.toMvRxBundle | |
import im.vector.app.core.utils.toast | ||
import im.vector.app.features.MainActivity | ||
import im.vector.app.features.MainActivityArgs | ||
import im.vector.app.features.analytics.VectorAnalytics | ||
import im.vector.app.features.analytics.AnalyticsTracker | ||
import im.vector.app.features.analytics.plan.Screen | ||
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 | ||
|
@@ -90,6 +92,15 @@ import timber.log.Timber | |
import javax.inject.Inject | ||
|
||
abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), MavericksView { | ||
/* ========================================================================================== | ||
* Analytics | ||
* ========================================================================================== */ | ||
|
||
protected var analyticsScreenName: Screen.ScreenName? = null | ||
private var screenEvent: ScreenEvent? = null | ||
|
||
protected lateinit var analyticsTracker: AnalyticsTracker | ||
|
||
/* ========================================================================================== | ||
* View | ||
* ========================================================================================== */ | ||
|
@@ -133,7 +144,6 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver | |
private lateinit var sessionListener: SessionListener | ||
protected lateinit var bugReporter: BugReporter | ||
private lateinit var pinLocker: PinLocker | ||
protected lateinit var analytics: VectorAnalytics | ||
|
||
@Inject | ||
lateinit var rageShake: RageShake | ||
|
@@ -189,7 +199,7 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver | |
configurationViewModel = viewModelProvider.get(ConfigurationViewModel::class.java) | ||
bugReporter = singletonEntryPoint.bugReporter() | ||
pinLocker = singletonEntryPoint.pinLocker() | ||
analytics = singletonEntryPoint.analytics() | ||
analyticsTracker = singletonEntryPoint.analyticsTracker() | ||
navigator = singletonEntryPoint.navigator() | ||
activeSessionHolder = singletonEntryPoint.activeSessionHolder() | ||
vectorPreferences = singletonEntryPoint.vectorPreferences() | ||
|
@@ -324,7 +334,7 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver | |
override fun onResume() { | ||
super.onResume() | ||
Timber.i("onResume Activity ${javaClass.simpleName}") | ||
|
||
screenEvent = analyticsScreenName?.let { ScreenEvent(it) } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. out of interest, how come we track on exit rather than entry? I'm not sure if this has already been defined but it might be helpful to write up what counts as a screen view event across the different platforms There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We track on exit because we want to report the duration, and this is managed by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense, thanks for explaining! |
||
configurationViewModel.onActivityResumed() | ||
|
||
if (this !is BugReportActivity && vectorPreferences.useRageshake()) { | ||
|
@@ -363,6 +373,7 @@ abstract class VectorBaseActivity<VB : ViewBinding> : AppCompatActivity(), Maver | |
|
||
override fun onPause() { | ||
super.onPause() | ||
screenEvent?.send(analyticsTracker, analyticsScreenName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to be able to override the screen name in the if not we could use a // or non null and abstract to force all screens to supply a name
protected open val name: ScreenName? = null
screenEvent = screenName?.let { ScreenEvent(it) }
...
screenEvent?.send(analyticsTracker) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the screen name can change during the screen life. I made this for this particular case - LoginActivity |
||
Timber.i("onPause Activity ${javaClass.simpleName}") | ||
|
||
rageShake.stop() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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 | ||
|
||
import im.vector.app.features.analytics.itf.VectorAnalyticsEvent | ||
import im.vector.app.features.analytics.itf.VectorAnalyticsScreen | ||
|
||
interface AnalyticsTracker { | ||
/** | ||
* Capture an Event | ||
*/ | ||
fun capture(event: VectorAnalyticsEvent) | ||
|
||
/** | ||
* Track a displayed screen | ||
*/ | ||
fun screen(screen: VectorAnalyticsScreen) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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.extensions | ||
|
||
import im.vector.app.features.analytics.plan.JoinedRoom | ||
import org.matrix.android.sdk.api.extensions.orFalse | ||
import org.matrix.android.sdk.api.session.room.model.RoomSummary | ||
import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoom | ||
|
||
fun Int?.toAnalyticsRoomSize(): JoinedRoom.RoomSize { | ||
return when (this) { | ||
null, | ||
2 -> JoinedRoom.RoomSize.Two | ||
in 3..10 -> JoinedRoom.RoomSize.ThreeToTen | ||
in 11..100 -> JoinedRoom.RoomSize.ElevenToOneHundred | ||
in 101..1000 -> JoinedRoom.RoomSize.OneHundredAndOneToAThousand | ||
else -> JoinedRoom.RoomSize.MoreThanAThousand | ||
} | ||
} | ||
|
||
fun RoomSummary?.toAnalyticsJoinedRoom(): JoinedRoom { | ||
return JoinedRoom( | ||
isDM = this?.isDirect.orFalse(), | ||
roomSize = this?.joinedMembersCount?.toAnalyticsRoomSize() ?: JoinedRoom.RoomSize.Two | ||
) | ||
} | ||
|
||
fun PublicRoom.toAnalyticsJoinedRoom(): JoinedRoom { | ||
return JoinedRoom( | ||
isDM = false, | ||
roomSize = numJoinedMembers.toAnalyticsRoomSize() | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍