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 FXIOS-10896 iOS Add additional fields to the usage ping #23950

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
16 changes: 16 additions & 0 deletions BrowserKit/Sources/Shared/InstallationUtils.swift
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
}
}
8 changes: 8 additions & 0 deletions firefox-ios/Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,8 @@
8C92DE8B2A711ED60090BD28 /* FakespotClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C92DE8A2A711ED60090BD28 /* FakespotClient.swift */; };
8C92DE912A7128CB0090BD28 /* ProductAnalysisResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C92DE902A7128CB0090BD28 /* ProductAnalysisResponse.swift */; };
8C92DE932A7128DE0090BD28 /* ProductAdsResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C92DE922A7128DE0090BD28 /* ProductAdsResponse.swift */; };
8CA4E80D2D22C066007207C1 /* GleanUsageReporting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CA4E80C2D22C066007207C1 /* GleanUsageReporting.swift */; };
8CA4E80F2D22D2C7007207C1 /* GleanUsageReportingLifecycleObserverTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CA4E80E2D22D2C7007207C1 /* GleanUsageReportingLifecycleObserverTest.swift */; };
8CAF29A02AA5E76B00DC3486 /* FakespotMessageCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CAF299F2AA5E76B00DC3486 /* FakespotMessageCardView.swift */; };
8CBDE8E32AB09804001985BF /* ProductAnalyzeResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CBDE8E22AB09804001985BF /* ProductAnalyzeResponse.swift */; };
8CC033FA2BA476840033449E /* FormAutofillHelper.js in Resources */ = {isa = PBXBuildFile; fileRef = 8CC033F92BA476840033449E /* FormAutofillHelper.js */; };
Expand Down Expand Up @@ -7913,6 +7915,8 @@
8C92DE8A2A711ED60090BD28 /* FakespotClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FakespotClient.swift; sourceTree = "<group>"; };
8C92DE902A7128CB0090BD28 /* ProductAnalysisResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductAnalysisResponse.swift; sourceTree = "<group>"; };
8C92DE922A7128DE0090BD28 /* ProductAdsResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductAdsResponse.swift; sourceTree = "<group>"; };
8CA4E80C2D22C066007207C1 /* GleanUsageReporting.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GleanUsageReporting.swift; sourceTree = "<group>"; };
8CA4E80E2D22D2C7007207C1 /* GleanUsageReportingLifecycleObserverTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GleanUsageReportingLifecycleObserverTest.swift; sourceTree = "<group>"; };
8CA841E0986514988B705D97 /* id */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = id; path = id.lproj/Menu.strings; sourceTree = "<group>"; };
8CAF299F2AA5E76B00DC3486 /* FakespotMessageCardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FakespotMessageCardView.swift; sourceTree = "<group>"; };
8CBDE8E22AB09804001985BF /* ProductAnalyzeResponse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProductAnalyzeResponse.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -14063,6 +14067,7 @@
8A44F20D2B585E1F0016BC81 /* HomepageTelemetry.swift */,
8A95FF632B1E969E00AC303D /* TelemetryContextualIdentifier.swift */,
EBF47E6F1F7979DF00899189 /* TelemetryWrapper.swift */,
8CA4E80C2D22C066007207C1 /* GleanUsageReporting.swift */,
1DD4B26D2CA4D09100B51945 /* TabErrorTelemetryHelper.swift */,
8A0727452B4890B50071BB9F /* WebviewTelemetry.swift */,
8A359EF42A1FD4CF004A5BB7 /* Wrapper */,
Expand Down Expand Up @@ -14299,6 +14304,7 @@
F84B21D91A090F8100AAB793 /* ClientTests.swift */,
8A86DAD7277298DE00D7BFFF /* ClosedTabsStoreTests.swift */,
C2200A692B7D148C00DC062A /* ContentBlockerTests.swift */,
8CA4E80E2D22D2C7007207C1 /* GleanUsageReportingLifecycleObserverTest.swift */,
C889D7CD2858C4B500121E1D /* ContextMenuHelperTests.swift */,
8A93F86329D37314004159D9 /* Coordinators */,
43B658D729CE249D00C9EF08 /* CreditCard */,
Expand Down Expand Up @@ -16709,6 +16715,7 @@
6669B5E2211418A200CA117B /* WebsiteDataSearchResultsViewController.swift in Sources */,
D51EA5CF26406D8300334331 /* ExperimentsViewController.swift in Sources */,
ED7A08DB2CF674730035EC8F /* ShareMessage.swift in Sources */,
8CA4E80D2D22C066007207C1 /* GleanUsageReporting.swift in Sources */,
1DFE57FB27B2CB870025DE58 /* HighlightItem.swift in Sources */,
CA77ABFD24773C92005079F9 /* BreachAlertsManager.swift in Sources */,
8AB8572727D93AEC0075C173 /* TopSiteHistoryManager.swift in Sources */,
Expand Down Expand Up @@ -17189,6 +17196,7 @@
2165B2C42860CB34004C0786 /* MockAdjustTelemetryData.swift in Sources */,
C29B64872AD69D0200F3244B /* QRCodeCoordinatorTests.swift in Sources */,
0BA8964B1A250E6500C1010C /* ProfileTest.swift in Sources */,
8CA4E80F2D22D2C7007207C1 /* GleanUsageReportingLifecycleObserverTest.swift in Sources */,
8AE80BAF2891960300BC12EA /* MockTraitCollection.swift in Sources */,
E19443F82AF953B000964EA5 /* MockSidebarEnabledView.swift in Sources */,
8A55E8042BFBA9BE006DBD85 /* MicrosurveyCoordinatorTests.swift in Sources */,
Expand Down
108 changes: 108 additions & 0 deletions firefox-ios/Client/Telemetry/GleanUsageReporting.swift
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()
}
}
175 changes: 175 additions & 0 deletions firefox-ios/Client/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

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.

Copy link
Collaborator Author

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?

Copy link
Member

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!

- 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:
Expand Down
Loading