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

Add editor startup time #13605

Merged
merged 2 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 })
}
Expand Down Expand Up @@ -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] {
Expand Down