Skip to content

Commit 5a4ab26

Browse files
Merge pull request #17848 from wordpress-mobile/task/17697-msd-track-posts-interaction
My Site Dashboard: track interaction with posts content
2 parents 08859e1 + d6950a9 commit 5a4ab26

File tree

9 files changed

+53
-8
lines changed

9 files changed

+53
-8
lines changed

WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ import Foundation
303303
case changeUsernameDisplayed
304304
case changeUsernameDismissed
305305

306+
// My Site Dashboard
307+
case dashboardCardItemTapped
308+
306309
/// A String that represents the event
307310
var value: String {
308311
switch self {
@@ -811,6 +814,10 @@ import Foundation
811814
case .changeUsernameDismissed:
812815
return "change_username_dismissed"
813816

817+
// My Site Dashboard
818+
case .dashboardCardItemTapped:
819+
return "my_site_dashboard_card_item_tapped"
820+
814821
} // END OF SWITCH
815822
}
816823

WordPress/Classes/ViewRelated/Aztec/ViewControllers/AztecPostViewController.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ class AztecPostViewController: UIViewController, PostEditor {
6969
mediaCoordinator.cancelUploadOfAllMedia(for: post)
7070
}
7171

72+
var entryPoint: PostEditorEntryPoint = .unknown {
73+
didSet {
74+
editorSession.entryPoint = entryPoint
75+
}
76+
}
77+
7278
/// For autosaving - The debouncer will execute local saving every defined number of seconds.
7379
/// In this case every 0.5 second
7480
///

WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/Posts/PostsCardViewController.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ extension PostsCardViewController: UITableViewDelegate {
105105
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
106106
let post = viewModel.postAt(indexPath)
107107

108-
PostListEditorPresenter.handle(post: post, in: self)
108+
WPAnalytics.track(.dashboardCardItemTapped,
109+
properties: ["type": "post", "sub_type": status.rawValue])
110+
111+
PostListEditorPresenter.handle(post: post, in: self, entryPoint: .dashboard)
109112
}
110113
}
111114

WordPress/Classes/ViewRelated/Gutenberg/GutenbergViewController.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ class GutenbergViewController: UIViewController, PostEditor, FeaturedImageDelega
7070
}
7171
}
7272

73+
var entryPoint: PostEditorEntryPoint = .unknown {
74+
didSet {
75+
editorSession.entryPoint = entryPoint
76+
}
77+
}
78+
7379
/// Maintainer of state for editor - like for post button
7480
///
7581
private(set) lazy var postEditorStateContext: PostEditorStateContext = {

WordPress/Classes/ViewRelated/Post/EditPostViewController.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class EditPostViewController: UIViewController {
1717
var insertedMedia: [Media]? = nil
1818
/// is editing a reblogged post
1919
var postIsReblogged = false
20+
/// the entry point for the editor
21+
var entryPoint: PostEditorEntryPoint = .unknown
2022

2123
private let loadAutosaveRevision: Bool
2224

@@ -139,6 +141,7 @@ class EditPostViewController: UIViewController {
139141
self?.replaceEditor(editor: editor, replacement: replacement)
140142
})
141143
editor.postIsReblogged = postIsReblogged
144+
editor.entryPoint = entryPoint
142145
showEditor(editor)
143146
}
144147

WordPress/Classes/ViewRelated/Post/PostEditor.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,12 @@ protocol PostEditor: PublishingEditor, UIViewControllerTransitioningDelegate {
101101
var replaceEditor: ReplaceEditorCallback { get }
102102

103103
var autosaver: Autosaver { get set }
104+
104105
/// true if the post is the result of a reblog
105106
var postIsReblogged: Bool { get set }
107+
108+
/// From where the editor was shown (for analytics reporting)
109+
var entryPoint: PostEditorEntryPoint { get set }
106110
}
107111

108112
extension PostEditor {
@@ -145,3 +149,9 @@ extension PostEditor {
145149
return [.visibility, .schedule, .tags, .categories]
146150
}
147151
}
152+
153+
enum PostEditorEntryPoint: String {
154+
case unknown
155+
case postsList
156+
case dashboard
157+
}

WordPress/Classes/ViewRelated/Post/PostEditorAnalyticsSession.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct PostEditorAnalyticsSession {
1010
var currentEditor: Editor
1111
var hasUnsupportedBlocks = false
1212
var outcome: Outcome? = nil
13+
var entryPoint: PostEditorEntryPoint?
1314
private let startTime = DispatchTime.now().uptimeNanoseconds
1415

1516
init(editor: Editor, post: AbstractPost) {
@@ -49,6 +50,8 @@ struct PostEditorAnalyticsSession {
4950
properties[Property.unstableGalleryWithImageBlocks] = "unknown"
5051
}
5152

53+
properties[Property.entryPoint] = (entryPoint ?? .unknown).rawValue
54+
5255
return properties.merging(commonProperties, uniquingKeysWith: { $1 })
5356
}
5457

@@ -72,7 +75,10 @@ struct PostEditorAnalyticsSession {
7275

7376
func end(outcome endOutcome: Outcome) {
7477
let outcome = self.outcome ?? endOutcome
75-
let properties: [String: Any] = [ Property.outcome: outcome.rawValue ].merging(commonProperties, uniquingKeysWith: { $1 })
78+
let properties: [String: Any] = [
79+
Property.outcome: outcome.rawValue,
80+
Property.entryPoint: (entryPoint ?? .unknown).rawValue
81+
].merging(commonProperties, uniquingKeysWith: { $1 })
7682

7783
WPAppAnalytics.track(.editorSessionEnd, withProperties: properties)
7884
}
@@ -92,6 +98,7 @@ private extension PostEditorAnalyticsSession {
9298
static let template = "template"
9399
static let startupTime = "startup_time_ms"
94100
static let unstableGalleryWithImageBlocks = "unstable_gallery_with_image_blocks"
101+
static let entryPoint = "entry_point"
95102
}
96103

97104
var commonProperties: [String: String] {

WordPress/Classes/ViewRelated/Post/PostListEditorPresenter.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ protocol EditorAnalyticsProperties: AnyObject {
1414
/// Analytics are also tracked.
1515
struct PostListEditorPresenter {
1616

17-
static func handle(post: Post, in postListViewController: EditorPresenterViewController) {
17+
static func handle(post: Post, in postListViewController: EditorPresenterViewController, entryPoint: PostEditorEntryPoint = .unknown) {
1818

1919
// Autosaves are ignored for posts with local changes.
2020
if !post.hasLocalChanges(), post.hasAutosaveRevision, let saveDate = post.dateModified, let autosaveDate = post.autosaveModifiedDate {
2121
let autosaveViewController = autosaveOptionsViewController(forSaveDate: saveDate, autosaveDate: autosaveDate, didTapOption: { loadAutosaveRevision in
22-
openEditor(with: post, loadAutosaveRevision: loadAutosaveRevision, in: postListViewController)
22+
openEditor(with: post, loadAutosaveRevision: loadAutosaveRevision, in: postListViewController, entryPoint: entryPoint)
2323
})
2424
postListViewController.present(autosaveViewController, animated: true)
2525
} else {
26-
openEditor(with: post, loadAutosaveRevision: false, in: postListViewController)
26+
openEditor(with: post, loadAutosaveRevision: false, in: postListViewController, entryPoint: entryPoint)
2727
}
2828
}
2929

@@ -46,11 +46,11 @@ struct PostListEditorPresenter {
4646
}
4747
}
4848

49-
private static func openEditor(with post: Post, loadAutosaveRevision: Bool, in postListViewController: EditorPresenterViewController) {
49+
private static func openEditor(with post: Post, loadAutosaveRevision: Bool, in postListViewController: EditorPresenterViewController, entryPoint: PostEditorEntryPoint = .unknown) {
5050
let editor = EditPostViewController(post: post, loadAutosaveRevision: loadAutosaveRevision)
5151
editor.modalPresentationStyle = .fullScreen
52+
editor.entryPoint = entryPoint
5253
postListViewController.present(editor, animated: false)
53-
WPAppAnalytics.track(.postListEditAction, withProperties: postListViewController.propertiesForAnalytics(), with: post)
5454
}
5555

5656
private static func openEditorWithCopy(with post: Post, in postListViewController: EditorPresenterViewController) {
@@ -65,6 +65,7 @@ struct PostListEditorPresenter {
6565
// Open Editor
6666
let editor = EditPostViewController(post: newPost, loadAutosaveRevision: false)
6767
editor.modalPresentationStyle = .fullScreen
68+
editor.entryPoint = .postsList
6869
postListViewController.present(editor, animated: false)
6970
// Track Analytics event
7071
WPAppAnalytics.track(.postListDuplicateAction, withProperties: postListViewController.propertiesForAnalytics(), with: post)

WordPress/Classes/ViewRelated/Post/PostListViewController.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe
563563
override func createPost() {
564564
let editor = EditPostViewController(blog: blog)
565565
editor.modalPresentationStyle = .fullScreen
566+
editor.entryPoint = .postsList
566567
present(editor, animated: false, completion: nil)
567568
WPAppAnalytics.track(.editorCreatedPost, withProperties: [WPAppAnalyticsKeyTapSource: "posts_view", WPAppAnalyticsKeyPostType: "post"], with: blog)
568569
}
@@ -576,7 +577,8 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe
576577
return
577578
}
578579

579-
PostListEditorPresenter.handle(post: post, in: self)
580+
WPAppAnalytics.track(.postListEditAction, withProperties: propertiesForAnalytics(), with: post)
581+
PostListEditorPresenter.handle(post: post, in: self, entryPoint: .postsList)
580582
}
581583

582584
private func editDuplicatePost(apost: AbstractPost) {

0 commit comments

Comments
 (0)