From f9a6be85ba275ce2f1740074ea9afa6c80897e7c Mon Sep 17 00:00:00 2001 From: Itunu Raimi Date: Thu, 17 Oct 2024 21:55:09 +0100 Subject: [PATCH 1/3] track mentions opened --- Nos/Controller/NoteEditorController.swift | 6 ++++++ Nos/Service/Analytics.swift | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/Nos/Controller/NoteEditorController.swift b/Nos/Controller/NoteEditorController.swift index a6b9182f3..2ee6bfa93 100644 --- a/Nos/Controller/NoteEditorController.swift +++ b/Nos/Controller/NoteEditorController.swift @@ -1,3 +1,4 @@ +import Dependencies import Foundation import SwiftUI import UIKit @@ -9,6 +10,8 @@ import UIKit /// when the user indicates they are ready to post it. @Observable class NoteEditorController: NSObject, UITextViewDelegate { + @ObservationIgnored @Dependency(\.analytics) private var analytics + /// The height that fits all entered text. This value will be updated by `NoteUITextViewRepresentable` /// automatically, and should be used to set the frame of `NoteUITextViewRepresentable` from SwiftUI. This is done /// to work around some incompatibilities between UIKit and SwiftUI where the UITextView won't expand properly. @@ -75,6 +78,7 @@ import UIKit /// Check if `@` was appended and show the mentionsAutoComplete list. guard text == "@" else { return } showMentionsAutocomplete = true + analytics.openedMentions() } /// Appends the given URL and adds the default link styling attributes. Will append a space before the link @@ -231,11 +235,13 @@ import UIKit private func checkForMentionsAutocomplete(in textView: UITextView, at range: NSRange) -> Bool { if textView.text.count == 0 { showMentionsAutocomplete = true + analytics.openedMentions() return true } else { let lastCharacter = (textView.text as NSString).character(at: max(range.location - 1, 0)) if let scalar = UnicodeScalar(lastCharacter), CharacterSet.whitespacesAndNewlines.contains(scalar) { showMentionsAutocomplete = true + analytics.openedMentions() return true } } diff --git a/Nos/Service/Analytics.swift b/Nos/Service/Analytics.swift index 320350e15..9efb4f9fb 100644 --- a/Nos/Service/Analytics.swift +++ b/Nos/Service/Analytics.swift @@ -297,4 +297,8 @@ class Analytics { func cancelledUploadSourceSelection() { track("Cancelled Upload Source Selection") } + + func openedMentions() { + track("Mentions Opened") + } } From a27563a63ed3cb314714b762aaa66ffd00372dbe Mon Sep 17 00:00:00 2001 From: Itunu Raimi Date: Fri, 18 Oct 2024 13:58:13 +0100 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5febe2bf..d5d65e7f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Internal Changes - Migrate ObservableObject to @Observable where possible [#1458](https://github.com/planetary-social/nos/issues/1458) - Added the Create Account onboarding screen. Currently behind the “New Onboarding Flow” feature flag. [#1594](https://github.com/planetary-social/nos/issues/1594) +- Track opening mentions with Posthog. [#1480](https://github.com/planetary-social/nos/issues/1480) ## [0.2.2] - 2024-10-11Z From 555b5df614fada8bfa6d9a3d041fe32d67d5bc03 Mon Sep 17 00:00:00 2001 From: Itunu Raimi Date: Fri, 18 Oct 2024 17:16:19 +0100 Subject: [PATCH 3/3] incorporate review feedback --- Nos/Controller/NoteEditorController.swift | 13 ++++++++----- Nos/Controller/SearchController.swift | 2 +- Nos/Service/Analytics.swift | 8 ++++---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Nos/Controller/NoteEditorController.swift b/Nos/Controller/NoteEditorController.swift index 2ee6bfa93..811200980 100644 --- a/Nos/Controller/NoteEditorController.swift +++ b/Nos/Controller/NoteEditorController.swift @@ -19,8 +19,14 @@ import UIKit /// A variable that controls whether the mention autocomplete window should be shown. This window is triggered /// by typing an '@' symbol and allows the user to search for another user to mention in their note. - var showMentionsAutocomplete = false - + var showMentionsAutocomplete = false { + didSet { + if showMentionsAutocomplete { + analytics.mentionsAutocompleteOpened() + } + } + } + /// The view the user will use for editing. Should only be set by ``NoteTextEditor/NoteUITextViewRepresentable``. var textView: UITextView? { didSet { @@ -78,7 +84,6 @@ import UIKit /// Check if `@` was appended and show the mentionsAutoComplete list. guard text == "@" else { return } showMentionsAutocomplete = true - analytics.openedMentions() } /// Appends the given URL and adds the default link styling attributes. Will append a space before the link @@ -235,13 +240,11 @@ import UIKit private func checkForMentionsAutocomplete(in textView: UITextView, at range: NSRange) -> Bool { if textView.text.count == 0 { showMentionsAutocomplete = true - analytics.openedMentions() return true } else { let lastCharacter = (textView.text as NSString).character(at: max(range.location - 1, 0)) if let scalar = UnicodeScalar(lastCharacter), CharacterSet.whitespacesAndNewlines.contains(scalar) { showMentionsAutocomplete = true - analytics.openedMentions() return true } } diff --git a/Nos/Controller/SearchController.swift b/Nos/Controller/SearchController.swift index 1c84b6d79..f06507bb6 100644 --- a/Nos/Controller/SearchController.swift +++ b/Nos/Controller/SearchController.swift @@ -87,7 +87,7 @@ class SearchController: ObservableObject { case .discover: analytics.searchedDiscover() case .mentions: - analytics.searchedMentions() + analytics.mentionsAutocompleteCharactersEntered() } } self.authorResults = self.authors(named: query) diff --git a/Nos/Service/Analytics.swift b/Nos/Service/Analytics.swift index 9efb4f9fb..945396d5e 100644 --- a/Nos/Service/Analytics.swift +++ b/Nos/Service/Analytics.swift @@ -161,8 +161,8 @@ class Analytics { } /// Tracks when the user submits a search on the Mentions screen. - func searchedMentions() { - track("Mentions Search Started") + func mentionsAutocompleteCharactersEntered() { + track("Mentions Autocomplete Characters Entered") } /// Tracks when the user taps on a search result on the Discover screen. @@ -298,7 +298,7 @@ class Analytics { track("Cancelled Upload Source Selection") } - func openedMentions() { - track("Mentions Opened") + func mentionsAutocompleteOpened() { + track("Mentions Autocomplete Opened") } }