Skip to content
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

chore: Discussions Feature Analytics Improvements #115

Merged
merged 3 commits into from
Jan 23, 2025

Conversation

shafqat-muneer
Copy link

@shafqat-muneer shafqat-muneer commented Jan 21, 2025

LEARNER-10371: Discussions Feature Analytics Improvements

Added New Screen Events:

  • Discussion:Topic Viewed
  • Discussion:Post Viewed
  • Discussion:Response Viewed

Updated Old Track Events:

  • Discussion:All Posts Clicked
    • removed course_name parameter
  • Discussion:Following Posts
    • removed course_name parameter
  • Discussion:Topic Clicked
    • removed course_name and topic_name parameters
  • Discussion:Post Created
    • Bi value update
  • Discussion:Response Added
    • Bi value update
  • Discussion:Comment Added
    • Bi value update
  • Discussion:Post Follow Toggle
    • Bi value update
  • Discussion:Like Toggle
    • Bi value update
  • Discussion:Report Toggle
    • Bi value update
  • Typo Fix: Dicussion:Post Follow Toggle —> Discussion:Post Follow Toggle

@shafqat-muneer shafqat-muneer requested review from rnr and mta452 January 21, 2025 13:55
Comment on lines 37 to 41
viewModel.trackDiscussionResponseViewed(
courseID: viewModel.courseID,
threadID: viewModel.postComments?.threadID ?? "",
responseID: parentComment.commentID
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shafqat-muneer Normally the “viewed” state is tracked by .onFirstAppear (even if there was an error getting the data, the view was still “viewed”). Do we have a reason to do this in the view init function?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rnr The thread_id depends on the API response. If we put this analytics in .onFirstAppear, the thread_id will always be empty initially.

Additionally, placing it in .onFirstAppear would require waiting for the API response, which adds complexity. Since pagination is implemented on this screen, we would also need extra code to trigger the analytics for the first page only. To keep things simple, I decided to handle it here.

Regarding the error case, you're correct that the screen is still viewed. However, my point is:

  • If the analytics data is incomplete, we can skip the analytics.
  • If the user didn’t actually see the comments because of the error, it doesn’t make sense to fire the tracking event.
    WDYT?

@@ -33,7 +33,13 @@ public struct ResponsesView: View {
self.viewModel = viewModel
self.router = router
Task {
await viewModel.getResponsesData(commentID: commentID, parentComment: parentComment, page: 1)
if await viewModel.getResponsesData(commentID: commentID, parentComment: parentComment, page: 1) {
viewModel.trackDiscussionResponseViewed(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call should be part of the view model itself.

Copy link
Author

@shafqat-muneer shafqat-muneer Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two types of events: track and screen. By convention, screen events are tracked directly from views. For example, viewModel.trackSelectedTab is called in CourseContainerView.swift.

Edited: track events should also be triggered from views because all events are related to user's interactions on views.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking in a way that we should only inform the view model that the screen has appeared and then it should do all the steps that would be needed on this event like loading the data or reporting the analytics. However, if a convention is already established, then I guess it's okay. But still, we don't need to pass the parameters if they are already known to the view model as it's the case in UpgradeInfoView or AppReviewView.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, let me update parameters. thanks

@@ -255,6 +255,11 @@ public struct ThreadView: View {
Task {
await viewModel.getThreadData(thread: thread, page: 1)
}
viewModel.trackDiscussionPostViewed(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

View model should track it automatically.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replied: #115 (comment)

@@ -229,6 +229,12 @@ public struct PostsView: View {
}
}
.onFirstAppear {
if viewModel.type != .allPosts && viewModel.type != .followingPosts {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The business logic should be handled in view model.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@rnr rnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@shafqat-muneer shafqat-muneer merged commit b4cd688 into 2U/develop Jan 23, 2025
2 checks passed
@shafqat-muneer shafqat-muneer deleted the Shafqat/LEARNER-10371 branch January 23, 2025 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants