From d7892ba66523e0d7337d503aacdf103804f21e1e Mon Sep 17 00:00:00 2001 From: Jorge Bernal Date: Mon, 9 Mar 2020 16:33:19 +0100 Subject: [PATCH 1/2] Add editor startup time to editor_session_start --- .../ViewRelated/Post/PostEditorAnalyticsSession.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/WordPress/Classes/ViewRelated/Post/PostEditorAnalyticsSession.swift b/WordPress/Classes/ViewRelated/Post/PostEditorAnalyticsSession.swift index ab1eae5d03ba..188ca2651ad5 100644 --- a/WordPress/Classes/ViewRelated/Post/PostEditorAnalyticsSession.swift +++ b/WordPress/Classes/ViewRelated/Post/PostEditorAnalyticsSession.swift @@ -10,6 +10,7 @@ struct PostEditorAnalyticsSession { var hasUnsupportedBlocks = false var outcome: Outcome? = nil var template: String? + private let startTime = DispatchTime.now().uptimeNanoseconds init(editor: Editor, post: AbstractPost) { currentEditor = editor @@ -40,7 +41,12 @@ struct PostEditorAnalyticsSession { } private func startEventProperties(with unsupportedBlocks: [String]) -> [String: Any] { + // On Android, we are tracking this in milliseconds, which seems like a good enough time scale + // Let's make sure to round the value and send an integer for consistency + let startupTimeNanoseconds = DispatchTime.now().uptimeNanoseconds - startTime + let startupTimeMilliseconds = Int(Double(startupTimeNanoseconds) / 1_000_000) return [ + Property.startupTime: startupTimeMilliseconds, Property.unsupportedBlocks: unsupportedBlocks ].merging(commonProperties, uniquingKeysWith: { $1 }) } @@ -82,6 +88,7 @@ private extension PostEditorAnalyticsSession { static let outcome = "outcome" static let sessionId = "session_id" static let template = "template" + static let startupTime = "startup_time_ms" } var commonProperties: [String: String] { From d9e7398718b181e9c7420fb2fd57feb45d2e0663 Mon Sep 17 00:00:00 2001 From: Jorge Bernal Date: Mon, 9 Mar 2020 16:41:31 +0100 Subject: [PATCH 2/2] Add explanation about assumptions for start method --- .../ViewRelated/Gutenberg/GutenbergViewController.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/WordPress/Classes/ViewRelated/Gutenberg/GutenbergViewController.swift b/WordPress/Classes/ViewRelated/Gutenberg/GutenbergViewController.swift index 787e1b5e136d..cb96490fe411 100644 --- a/WordPress/Classes/ViewRelated/Gutenberg/GutenbergViewController.swift +++ b/WordPress/Classes/ViewRelated/Gutenberg/GutenbergViewController.swift @@ -560,6 +560,10 @@ extension GutenbergViewController: GutenbergBridgeDelegate { func gutenbergDidMount(unsupportedBlockNames: [String]) { if !editorSession.started { + // Note that this method is also used to track startup performance + // It assumes this is being called when the editor has finished loading + // If you need to refactor this, please ensure that the startup_time_ms property + // is still reflecting the actual startup time of the editor editorSession.start(unsupportedBlocks: unsupportedBlockNames) } }