@@ -50,6 +50,9 @@ private const val INSTALL_STATUS_PROPERTY_NAME = "install_status"
5050private const val ENVIRONMENT_ADDED_PROPERTY_NAME = " environment_added"
5151private const val LOAD_WARNING_APPEARED_PROPERTY_NAME = " load_warning_appeared"
5252private const val JIRA_FIELD_COPIED_PROPERTY_NAME = " jira_field_copied"
53+ private const val USER_REQUESTED_COURSE_PROPERTY_NAME = " user_requested_course"
54+ private const val MEANINGFUL_ACTIONS_DAYS_PROPERTY_NAME = " meaningful_actions_days"
55+ private const val MEANINGFUL_ACTIONS_AVG_PROPERTY_NAME = " meaningful_actions_avg"
5356
5457enum class InstallStatus { Active , Uninstalled , Disabled }
5558
@@ -155,6 +158,11 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
155158 }
156159
157160
161+ private fun identify (properties : Map <String , Any ?>, propertiesSetOnce : Map <String , Any ?>? = null) {
162+ postHog?.identify(UniqueGeneratedUserId .userId, properties, propertiesSetOnce)
163+ }
164+
165+
158166 private fun capture (eventName : String ) {
159167 capture(eventName, mapOf ())
160168 }
@@ -206,12 +214,22 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
206214 )
207215 }
208216
209- fun registerEmail (email : String , courseRequested : Boolean ) {
210- postHog?.identify(
211- UniqueGeneratedUserId .userId, mapOf (
217+ fun registerUserRequestedCourse () {
218+ identify(
219+ mapOf (
220+ USER_REQUESTED_COURSE_PROPERTY_NAME to PersistenceService .getInstance().isUserRequestedCourse()
221+ )
222+ )
223+ }
224+
225+
226+ fun registerEmail (email : String ) {
227+
228+ identify(
229+ mapOf (
212230 " email" to getEmailForEvent(),
213231 INSTALL_STATUS_PROPERTY_NAME to getCurrentInstallStatus(),
214- " user_requested_course " to courseRequested.toString ()
232+ USER_REQUESTED_COURSE_PROPERTY_NAME to PersistenceService .getInstance().isUserRequestedCourse ()
215233 )
216234 )
217235 postHog?.alias(UniqueGeneratedUserId .userId, email)
@@ -687,7 +705,7 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
687705 capture(" project closed" , mapOf (" open.projects" to openProjects))
688706 }
689707
690- fun registerPluginUninstalled (): String {
708+ fun registerPluginUninstalled () {
691709
692710 SessionMetadataProperties .getInstance().put(CURRENT_INSTALL_STATUS_KEY , InstallStatus .Uninstalled )
693711
@@ -700,7 +718,9 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
700718 ENVIRONMENT_ADDED_PROPERTY_NAME to PersistenceService .getInstance().isEnvironmentAdded(),
701719 LOAD_WARNING_APPEARED_PROPERTY_NAME to PersistenceService .getInstance().isLoadWarningAppeared(),
702720 JIRA_FIELD_COPIED_PROPERTY_NAME to PersistenceService .getInstance().isJiraFieldCopied(),
703- " user_requested_course" to " false"
721+ USER_REQUESTED_COURSE_PROPERTY_NAME to PersistenceService .getInstance().isUserRequestedCourse(),
722+ MEANINGFUL_ACTIONS_DAYS_PROPERTY_NAME to EngagementScoreService .getInstance().getLatestRegisteredActiveDays(),
723+ MEANINGFUL_ACTIONS_AVG_PROPERTY_NAME to EngagementScoreService .getInstance().getLatestRegisteredAverage()
704724 )
705725 )
706726 }
@@ -710,10 +730,9 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
710730 INSTALL_STATUS_PROPERTY_NAME + " _timestamp" to SessionMetadataProperties .getInstance().getCreatedAsString(CURRENT_INSTALL_STATUS_KEY )
711731 )
712732 )
713- return UniqueGeneratedUserId .userId
714733 }
715734
716- fun registerPluginDisabled (): String {
735+ fun registerPluginDisabled () {
717736
718737 SessionMetadataProperties .getInstance().put(CURRENT_INSTALL_STATUS_KEY , InstallStatus .Disabled )
719738
@@ -726,7 +745,9 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
726745 ENVIRONMENT_ADDED_PROPERTY_NAME to PersistenceService .getInstance().isEnvironmentAdded(),
727746 LOAD_WARNING_APPEARED_PROPERTY_NAME to PersistenceService .getInstance().isLoadWarningAppeared(),
728747 JIRA_FIELD_COPIED_PROPERTY_NAME to PersistenceService .getInstance().isJiraFieldCopied(),
729- " user_requested_course" to " false"
748+ USER_REQUESTED_COURSE_PROPERTY_NAME to PersistenceService .getInstance().isUserRequestedCourse(),
749+ MEANINGFUL_ACTIONS_DAYS_PROPERTY_NAME to EngagementScoreService .getInstance().getLatestRegisteredActiveDays(),
750+ MEANINGFUL_ACTIONS_AVG_PROPERTY_NAME to EngagementScoreService .getInstance().getLatestRegisteredAverage()
730751 )
731752 )
732753 }
@@ -736,7 +757,6 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
736757 INSTALL_STATUS_PROPERTY_NAME + " _timestamp" to SessionMetadataProperties .getInstance().getCreatedAsString(CURRENT_INSTALL_STATUS_KEY )
737758 )
738759 )
739- return UniqueGeneratedUserId .userId
740760 }
741761
742762
@@ -913,11 +933,10 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
913933 )
914934 )
915935
916- postHog?.identify(
917- UniqueGeneratedUserId .userId,
936+ identify(
918937 mapOf (
919938 LOAD_WARNING_APPEARED_PROPERTY_NAME + " _timestamp" to PersistenceService .getInstance().getLoadWarningAppearedTimestamp(),
920- " user_requested_course " to " false "
939+ USER_REQUESTED_COURSE_PROPERTY_NAME to PersistenceService .getInstance().isUserRequestedCourse()
921940 ),
922941 mapOf (
923942 LOAD_WARNING_APPEARED_PROPERTY_NAME to PersistenceService .getInstance().isLoadWarningAppeared(),
@@ -945,11 +964,10 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
945964 )
946965 registerUserAction(eventName, eventDetails)
947966
948- postHog?.identify(
949- UniqueGeneratedUserId .userId,
967+ identify(
950968 mapOf (
951969 ENVIRONMENT_ADDED_PROPERTY_NAME + " _timestamp" to PersistenceService .getInstance().getEnvironmentAddedTimestamp(),
952- " user_requested_course " to " false "
970+ USER_REQUESTED_COURSE_PROPERTY_NAME to PersistenceService .getInstance().isUserRequestedCourse()
953971 ),
954972 mapOf (
955973 ENVIRONMENT_ADDED_PROPERTY_NAME to PersistenceService .getInstance().isEnvironmentAdded()
@@ -977,11 +995,10 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
977995 mutableDetails
978996 )
979997
980- postHog?.identify(
981- UniqueGeneratedUserId .userId,
998+ identify(
982999 mapOf (
9831000 JIRA_FIELD_COPIED_PROPERTY_NAME + " _timestamp" to PersistenceService .getInstance().getJiraFieldCopiedTimestamp(),
984- " user_requested_course " to " false "
1001+ USER_REQUESTED_COURSE_PROPERTY_NAME to PersistenceService .getInstance().isUserRequestedCourse()
9851002 ),
9861003 mapOf (
9871004 JIRA_FIELD_COPIED_PROPERTY_NAME to PersistenceService .getInstance().isJiraFieldCopied()
@@ -1062,4 +1079,25 @@ class ActivityMonitor(private val project: Project, cs: CoroutineScope) : Dispos
10621079 capture(" backend-data-found" )
10631080 }
10641081
1082+ fun registerEngagementScore (activeDays : Long , average : Long ) {
1083+
1084+ val details = mapOf (
1085+ MEANINGFUL_ACTIONS_DAYS_PROPERTY_NAME to activeDays,
1086+ MEANINGFUL_ACTIONS_AVG_PROPERTY_NAME to average,
1087+ INSTALL_STATUS_PROPERTY_NAME to getCurrentInstallStatus(),
1088+ USER_REQUESTED_COURSE_PROPERTY_NAME to PersistenceService .getInstance().isUserRequestedCourse()
1089+ )
1090+
1091+ capture(" daily engagement score" , details)
1092+
1093+ identify(
1094+ mapOf (
1095+ MEANINGFUL_ACTIONS_DAYS_PROPERTY_NAME to activeDays,
1096+ MEANINGFUL_ACTIONS_AVG_PROPERTY_NAME to average
1097+ )
1098+ )
1099+
1100+ }
1101+
1102+
10651103}
0 commit comments