Skip to content

Commit

Permalink
Merge pull request #1740 from planetary-social/bdm/129-analytics
Browse files Browse the repository at this point in the history
added analytics for feed source selection and lists #129
  • Loading branch information
bryanmontz authored Jan 23, 2025
2 parents 1f66275 + 7231221 commit 99f4b48
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added List detail view. [#155](https://github.com/verse-pbc/issues/issues/155)
- Added view for managing users in a list. [#135](https://github.com/verse-pbc/issues/issues/135)
- Added ability to delete lists. [#136](https://github.com/verse-pbc/issues/issues/136)
- Added analytics for feed source selection and lists. [#129](https://github.com/verse-pbc/issues/issues/129)

### Internal Changes
- Added function for creating a new list and a test verifying list editing. [#112](https://github.com/verse-pbc/issues/issues/112)
Expand Down
63 changes: 63 additions & 0 deletions Nos/Service/Analytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,67 @@ class Analytics {
func mentionsAutocompleteOpened() {
track("Mentions Autocomplete Opened")
}

// MARK: - Feed Source

/// Tracks when the user selects a list from the feed picker at the top of the home feed.
func listFeedOpened() {
track("List Feed Opened")
}

/// Tracks when the user selects a relay from the feed picker at the top of the home feed.
func relayFeedOpened() {
track("Relay Feed Opened")
}

/// Tracks when the user selects the Following feed at the top of the home feed.
func followFeedOpened() {
track("Follow Feed Opened")
}

/// Tracks when the user opens the ``FeedCustomizerView``.
func feedCustomizerOpened() {
track("Feed Customizer Opened")
}

/// Tracks when the user closes the ``FeedCustomizerView``.
func feedCustomizerClosed() {
track("Feed Customizer Closed")
}

/// Tracks when the user toggles on a list in the ``FeedCustomizerView``.
func listPinned() {
track("List Pinned")
}

/// Tracks when the user toggles off a list in the ``FeedCustomizerView``.
func listUnpinned() {
track("List Unpinned")
}

/// Tracks when the user toggles on a relay in the ``FeedCustomizerView``.
func relayPinned() {
track("Relay Pinned")
}

/// Tracks when the user toggles off a relay in the ``FeedCustomizerView``.
func relayUnpinned() {
track("Relay Unpinned")
}

// MARK: - Lists

/// Tracks when the user creates a new list.
func listCreated() {
track("List Created")
}

/// Tracks when the user edits a list.
/// - Parameter numberOfUsers: The number of users in the list.
func listEdited(numberOfUsers: Int) {
track(
"List Edited",
properties: ["Number of users": numberOfUsers]
)
}
}
4 changes: 4 additions & 0 deletions Nos/Views/Home/FeedCustomizerView.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Dependencies
import SwiftUI

enum FeedTab: String {
Expand Down Expand Up @@ -31,6 +32,7 @@ extension FeedTab: NosSegmentedPickerItem {

struct FeedCustomizerView: View {

@Dependency(\.analytics) private var analytics
@Environment(FeedController.self) var feedController
let author: Author
@Binding var shouldNavigateToLists: Bool
Expand Down Expand Up @@ -73,6 +75,7 @@ struct FeedCustomizerView: View {
font: .clarity(.semibold, textStyle: .footnote),
image: Image(systemName: "slider.horizontal.3")
) {
analytics.feedCustomizerClosed()
shouldNavigateToLists = true
}
}
Expand All @@ -97,6 +100,7 @@ struct FeedCustomizerView: View {
}
.padding()
.onTapGesture {
analytics.feedCustomizerClosed()
shouldNavigateToRelays = true
}
},
Expand Down
11 changes: 11 additions & 0 deletions Nos/Views/Home/FeedPicker.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import CoreData
import Dependencies
import SwiftUI

/// A picker view used to pick which source a feed should show notes from.
struct FeedPicker: View {
@Environment(FeedController.self) var feedController
@Dependency(\.analytics) private var analytics

var body: some View {
BeveledContainerView {
Expand All @@ -12,6 +14,15 @@ struct FeedPicker: View {
HStack(spacing: 0) {
ForEach(feedController.enabledSources, id: \.self) { source in
Button(action: {
switch source {
case .following:
analytics.followFeedOpened()
case .relay:
analytics.relayFeedOpened()
case .list:
analytics.listFeedOpened()
}

withAnimation(nil) {
feedController.selectedSource = source
}
Expand Down
18 changes: 18 additions & 0 deletions Nos/Views/Home/FeedSourceToggleView.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Dependencies
import SwiftUI

struct FeedSourceToggleView<Content: View, EmptyPlaceholder: View>: View {
@Dependency(\.analytics) private var analytics
@Environment(FeedController.self) var feedController

let author: Author
Expand Down Expand Up @@ -48,6 +50,22 @@ struct FeedSourceToggleView<Content: View, EmptyPlaceholder: View>: View {
.fixedSize(horizontal: false, vertical: true)
.padding(.vertical, 10)
.onChange(of: item.isOn) { _, _ in
switch item.source {
case .list:
if item.isOn {
analytics.listPinned()
} else {
analytics.listUnpinned()
}
case .relay:
if item.isOn {
analytics.relayPinned()
} else {
analytics.relayUnpinned()
}
default:
break
}
feedController.toggleSourceEnabled(item.source)
}
}
Expand Down
6 changes: 6 additions & 0 deletions Nos/Views/Home/HomeFeedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ struct HomeFeedView: View {
}
ToolbarItem(placement: .navigationBarTrailing) {
Button {
if showFeedSelector {
analytics.feedCustomizerClosed()
} else {
analytics.feedCustomizerOpened()
}

withAnimation {
showFeedSelector.toggle()
showFeedTip = false
Expand Down
9 changes: 9 additions & 0 deletions Nos/Views/Lists/AuthorListManageUsersView.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Dependencies
import Logger
import SwiftUI

Expand All @@ -19,6 +20,7 @@ struct AuthorListManageUsersView: View {
}
}

@Dependency(\.analytics) private var analytics
@Environment(\.dismiss) private var dismiss
@Environment(RelayService.self) private var relayService
@Environment(CurrentUser.self) private var currentUser
Expand Down Expand Up @@ -153,6 +155,13 @@ struct AuthorListManageUsersView: View {
} else {
dismiss()
}

switch mode {
case .create:
analytics.listCreated()
case .update:
analytics.listEdited(numberOfUsers: authors.count)
}
} catch {
Log.error("Error when creating list: \(error.localizedDescription)")
}
Expand Down

0 comments on commit 99f4b48

Please sign in to comment.