-
Notifications
You must be signed in to change notification settings - Fork 3k
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 FXIOS-10896 iOS Add additional fields to the usage ping #23950
Merged
razvanlitianu
merged 9 commits into
main
from
rlitianu/FXIOS-10896-#23785-iOS-Add-additional-fields-to-the-usage-ping
Jan 14, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c943d4e
FXIOS-10896 #23785 iOS Add additional fields to the usage ping
razvanlitianu f914259
Update links
razvanlitianu 551c1e7
Add GleanUsageReporting
razvanlitianu 23acb00
Swiftlint fix
razvanlitianu df85a0c
Swiftlint fix
razvanlitianu dda39a7
Use glean timer
razvanlitianu 462f833
Update metrics with glean links
razvanlitianu 1519fd7
Add instalation usage
razvanlitianu d023b4b
Add a way to stop observing
razvanlitianu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/ | ||
|
||
import Foundation | ||
|
||
public struct InstallationUtils { | ||
/// Fetches the app's inferred installation date from the creation date of the Documents directory. | ||
public static var inferredDateInstalledOn: Date? { | ||
guard | ||
let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last, | ||
let attributes = try? FileManager.default.attributesOfItem(atPath: documentsURL.path) | ||
else { return nil } | ||
return attributes[.creationDate] as? Date | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/ | ||
|
||
import Foundation | ||
import UIKit | ||
import Glean | ||
import Shared | ||
|
||
enum UsageReason: String { | ||
case active | ||
case inactive | ||
} | ||
|
||
protocol GleanUsageReportingApi { | ||
func setUsageReason(_ usageReason: UsageReason) | ||
func submitPing() | ||
} | ||
|
||
class GleanUsageReporting: GleanUsageReportingApi { | ||
func setUsageReason(_ usageReason: UsageReason) { | ||
GleanMetrics.Usage.reason.set(usageReason.rawValue) | ||
} | ||
|
||
func submitPing() { | ||
setUsageConstantValues() | ||
GleanMetrics.Pings.shared.usageReporting.submit() | ||
} | ||
|
||
private func setUsageConstantValues() { | ||
GleanMetrics.Usage.os.set("iOS") | ||
GleanMetrics.Usage.osVersion.set(UIDevice.current.systemVersion) | ||
GleanMetrics.Usage.appDisplayVersion.set(Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "") | ||
GleanMetrics.Usage.appBuild.set(Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "") | ||
GleanMetrics.Usage.appChannel.set(AppConstants.buildChannel.rawValue) | ||
if let date = InstallationUtils.inferredDateInstalledOn { | ||
GleanMetrics.Usage.firstRunDate.set(date) | ||
} | ||
} | ||
} | ||
|
||
class GleanLifecycleObserver { | ||
private let gleanUsageReportingApi: GleanUsageReportingApi | ||
private var id: TimerId? | ||
private var isObserving: Bool = false | ||
|
||
init(gleanUsageReportingApi: GleanUsageReportingApi = GleanUsageReporting()) { | ||
self.gleanUsageReportingApi = gleanUsageReportingApi | ||
} | ||
|
||
func startObserving() { | ||
guard !isObserving else { return } | ||
isObserving = true | ||
|
||
NotificationCenter.default.addObserver( | ||
self, | ||
selector: #selector(appWillEnterForeground), | ||
name: UIApplication.willEnterForegroundNotification, | ||
object: nil | ||
) | ||
|
||
NotificationCenter.default.addObserver( | ||
self, | ||
selector: #selector(appDidEnterBackground), | ||
name: UIApplication.didEnterBackgroundNotification, | ||
object: nil | ||
) | ||
} | ||
|
||
func stopObserving() { | ||
guard isObserving else { return } | ||
isObserving = false | ||
|
||
NotificationCenter.default.removeObserver( | ||
self, | ||
name: UIApplication.willEnterForegroundNotification, | ||
object: nil | ||
) | ||
|
||
NotificationCenter.default.removeObserver( | ||
self, | ||
name: UIApplication.didEnterBackgroundNotification, | ||
object: nil | ||
) | ||
} | ||
|
||
@objc | ||
private func appWillEnterForeground(notification: NSNotification) { | ||
handleForegroundEvent() | ||
} | ||
|
||
@objc | ||
private func appDidEnterBackground(notification: NSNotification) { | ||
handleBackgroundEvent() | ||
} | ||
|
||
func handleForegroundEvent() { | ||
id = GleanMetrics.Usage.duration.start() | ||
gleanUsageReportingApi.setUsageReason(.active) | ||
gleanUsageReportingApi.submitPing() | ||
} | ||
|
||
func handleBackgroundEvent() { | ||
id.map(GleanMetrics.Usage.duration.stopAndAccumulate) | ||
gleanUsageReportingApi.setUsageReason(.inactive) | ||
gleanUsageReportingApi.submitPing() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -753,6 +753,181 @@ usage: | |
send_in_pings: | ||
- usage-reporting | ||
|
||
duration: | ||
type: timing_distribution | ||
time_unit: millisecond | ||
description: | | ||
The duration of the last foreground session. | ||
time_unit: second | ||
send_in_pings: | ||
- usage-reporting | ||
bugs: | ||
- https://github.com/mozilla-mobile/firefox-ios/issues/23785 | ||
- https://bugzilla.mozilla.org/1497894 | ||
- https://bugzilla.mozilla.org/1519120 | ||
data_reviews: | ||
- https://github.com/mozilla-mobile/firefox-ios/pull/23950 | ||
- https://bugzilla.mozilla.org/show_bug.cgi?id=1512938#c3 | ||
data_sensitivity: | ||
- technical | ||
- interaction | ||
notification_emails: | ||
- [email protected] | ||
- [email protected] | ||
expires: never | ||
|
||
reason: | ||
type: string | ||
lifetime: ping | ||
send_in_pings: | ||
- usage-reporting | ||
description: | | ||
The optional reason the ping was submitted. | ||
The specific values for reason are specific to each ping, and are | ||
documented in the ping's pings.yaml file. | ||
bugs: | ||
- https://github.com/mozilla-mobile/firefox-ios/issues/23785 | ||
- https://bugzilla.mozilla.org/show_bug.cgi?id=1557048 | ||
data_reviews: | ||
- https://github.com/mozilla-mobile/firefox-ios/pull/23950 | ||
- https://bugzilla.mozilla.org/show_bug.cgi?id=1609218#c4 | ||
data_sensitivity: | ||
- technical | ||
notification_emails: | ||
- [email protected] | ||
- [email protected] | ||
expires: never | ||
|
||
os: | ||
type: string | ||
lifetime: application | ||
send_in_pings: | ||
- usage-reporting | ||
description: | | ||
The name of the operating system. | ||
Possible values: | ||
Android, iOS, Linux, Darwin, Windows, | ||
FreeBSD, NetBSD, OpenBSD, Solaris, Unknown | ||
bugs: | ||
- https://github.com/mozilla-mobile/firefox-ios/issues/23785 | ||
- https://bugzilla.mozilla.org/1497894 | ||
data_reviews: | ||
- https://github.com/mozilla-mobile/firefox-ios/pull/23950 | ||
- https://bugzilla.mozilla.org/show_bug.cgi?id=1512938#c3 | ||
data_sensitivity: | ||
- technical | ||
notification_emails: | ||
- [email protected] | ||
- [email protected] | ||
expires: never | ||
|
||
os_version: | ||
type: string | ||
lifetime: application | ||
send_in_pings: | ||
- usage-reporting | ||
description: | | ||
The user-visible version of the operating system (e.g. "1.2.3"). | ||
If the version detection fails, this metric gets set to `Unknown`. | ||
bugs: | ||
- https://github.com/mozilla-mobile/firefox-ios/issues/23785 | ||
- https://bugzilla.mozilla.org/1497894 | ||
data_reviews: | ||
- https://github.com/mozilla-mobile/firefox-ios/pull/23950 | ||
- https://bugzilla.mozilla.org/show_bug.cgi?id=1512938#c3 | ||
data_sensitivity: | ||
- technical | ||
notification_emails: | ||
- [email protected] | ||
- [email protected] | ||
expires: never | ||
|
||
app_display_version: | ||
type: string | ||
lifetime: application | ||
send_in_pings: | ||
- usage-reporting | ||
description: | | ||
The user visible version string (e.g. "1.0.3"). | ||
If the value was not provided through configuration, | ||
this metric gets set to `Unknown`. | ||
bugs: | ||
- https://github.com/mozilla-mobile/firefox-ios/issues/23785 | ||
- https://bugzilla.mozilla.org/1508305 | ||
data_reviews: | ||
- https://github.com/mozilla-mobile/firefox-ios/pull/23950 | ||
- https://bugzilla.mozilla.org/show_bug.cgi?id=1508305#c9 | ||
data_sensitivity: | ||
- technical | ||
notification_emails: | ||
- [email protected] | ||
- [email protected] | ||
expires: never | ||
|
||
app_channel: | ||
type: string | ||
lifetime: application | ||
send_in_pings: | ||
- usage-reporting | ||
description: | | ||
The channel the application is being distributed on. | ||
bugs: | ||
- https://github.com/mozilla-mobile/firefox-ios/issues/23785 | ||
- https://bugzilla.mozilla.org/1520741 | ||
data_reviews: | ||
- https://github.com/mozilla-mobile/firefox-ios/pull/23950 | ||
- https://bugzilla.mozilla.org/show_bug.cgi?id=1520741#c18 | ||
data_sensitivity: | ||
- technical | ||
notification_emails: | ||
notification_emails: | ||
- [email protected] | ||
- [email protected] | ||
expires: never | ||
|
||
first_run_date: | ||
type: datetime | ||
lifetime: user | ||
send_in_pings: | ||
- usage-reporting | ||
time_unit: day | ||
description: | | ||
The date of the first run of the application. | ||
bugs: | ||
- https://github.com/mozilla-mobile/firefox-ios/issues/23785 | ||
- https://bugzilla.mozilla.org/1525045 | ||
data_reviews: | ||
- https://github.com/mozilla-mobile/firefox-ios/pull/23950 | ||
- https://bugzilla.mozilla.org/show_bug.cgi?id=1525045#c18 | ||
data_sensitivity: | ||
- technical | ||
notification_emails: | ||
- [email protected] | ||
- [email protected] | ||
expires: never | ||
|
||
app_build: | ||
type: string | ||
lifetime: application | ||
send_in_pings: | ||
- usage-reporting | ||
description: | | ||
The build identifier generated by the CI system (e.g. "1234/A"). | ||
If the value was not provided through configuration, | ||
this metric gets set to `Unknown`. | ||
bugs: | ||
- https://github.com/mozilla-mobile/firefox-ios/issues/23785 | ||
- https://bugzilla.mozilla.org/1508305 | ||
data_reviews: | ||
- https://github.com/mozilla-mobile/firefox-ios/pull/23950 | ||
- https://bugzilla.mozilla.org/show_bug.cgi?id=1512938#c3 | ||
data_sensitivity: | ||
- technical | ||
notification_emails: | ||
- [email protected] | ||
- [email protected] | ||
expires: never | ||
|
||
# Downloads | ||
downloads: | ||
download_now_button_tapped: | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please link to the original Glean duration for the data-review and bugs also, as that is the review that covers this collection. You can find these links in the Glean dictionary for this and other metrics which have been duplicated for the purpose of the usage-reporting ping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@travis79 Just to double check, I searched Glean Dictionary and the only metrics from which we duplicated seems to be in the Glean repo here. Are these to be linked?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is correct. Please include the data-review link(s) from the Glean definitions in the definitions you are adding. That way the data-review that covers the collection of these is linked in the metadata and easy to find from the Glean Dictionary and other tools. You can also copy over the linked bugs, but that isn't as necessary as the data-reviews. Thanks!