Skip to content

Commit 527275b

Browse files
nbhasin2dnarcese
authored andcommitted
FXIOS-1220 ⁃ Fixes mozilla-mobile#6933: Added a follow-up commit to send hashed device id to glean deletion ping (mozilla-mobile#7660)
- updated metrics yaml type to string in order to support hashed device id instead of uuid - changed client guid protection level to public so that we can use it for deletion ping
1 parent e9c0cb6 commit 527275b

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

Client/Telemetry/TelemetryWrapper.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import MozillaAppServices
66
import Shared
77
import Telemetry
8+
import Account
9+
import Sync
810

911
class TelemetryWrapper {
1012
let legacyTelemetry = Telemetry.default
@@ -155,13 +157,8 @@ class TelemetryWrapper {
155157
// Save the profile so we can record settings from it when the notification below fires.
156158
self.profile = profile
157159

158-
// Get the FxA device id and record it in Glean for the deletion-request ping
159-
profile.getCachedClients().upon { maybeClient in
160-
guard
161-
let deviceId = maybeClient.successValue?.first?.fxaDeviceId.flatMap(UUID.init(uuidString:)) else { return }
162-
GleanMetrics.Deletion.fxaDeviceId.set(deviceId)
163-
}
164-
160+
setSyncDeviceId()
161+
165162
// Register an observer to record settings and other metrics that are more appropriate to
166163
// record on going to background rather than during initialization.
167164
NotificationCenter.default.addObserver(
@@ -171,6 +168,19 @@ class TelemetryWrapper {
171168
object: nil
172169
)
173170
}
171+
172+
// Sets hashed fxa sync device id for glean deletion ping
173+
func setSyncDeviceId() {
174+
guard let prefs = profile?.prefs else { return }
175+
// Grab our token so we can use the hashed_fxa_uid and clientGUID from our scratchpad for deletion-request ping
176+
RustFirefoxAccounts.shared.syncAuthState.token(Date.now(), canBeExpired: true) >>== { (token, kSync) in
177+
let scratchpadPrefs = prefs.branch("sync.scratchpad")
178+
guard let scratchpad = Scratchpad.restoreFromPrefs(scratchpadPrefs, syncKeyBundle: KeyBundle.fromKSync(kSync)) else { return }
179+
180+
let deviceId = (scratchpad.clientGUID + token.hashedFxAUID).sha256.hexEncodedString
181+
GleanMetrics.Deletion.syncDeviceId.set(deviceId)
182+
}
183+
}
174184

175185
// Function for recording metrics that are better recorded when going to background due
176186
// to the particular measurement, or availability of the information.

Client/metrics.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,8 @@ legacy.ids:
599599
expires: never
600600

601601
deletion:
602-
fxa_device_id:
603-
type: uuid
602+
sync_device_id:
603+
type: string
604604
lifetime: user
605605
description: |
606606
The FxA device id.

Docs/metrics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The following metrics are added to the ping:
2222

2323
| Name | Type | Description | Data reviews | Extras | Expiration | [Data Sensitivity](https://wiki.mozilla.org/Firefox/Data_Collection) |
2424
| --- | --- | --- | --- | --- | --- | --- |
25-
| deletion.fxa_device_id |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |The FxA device id. |[1](TBD)||never | |
25+
| deletion.sync_device_id |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |The FxA device id. |[1](https://github.com/mozilla-mobile/firefox-ios/pull/7629#issuecomment-723312428)||never | |
2626
| legacy.ids.client_id |[uuid](https://mozilla.github.io/glean/book/user/metrics/uuid.html) |The client id from legacy telemetry. |[1](https://bugzilla.mozilla.org/show_bug.cgi?id=1635427)||never | |
2727

2828
## events

Sync/State.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,9 @@ open class Scratchpad {
368368

369369
// What's our client name?
370370
let clientName: String
371-
let clientGUID: String
372371
let fxaDeviceId: String
373372
let hashedUID: String?
373+
public let clientGUID: String
374374

375375
var hashedDeviceID: String? {
376376
guard let hashedUID = hashedUID else {

0 commit comments

Comments
 (0)