From 70e7a270e6791fc0a3245a3fc1958d0b6536ecb4 Mon Sep 17 00:00:00 2001 From: Pete Schwamb Date: Tue, 13 Oct 2026 01:39:39 -0500 Subject: [PATCH] Re-send analytics user properties when usage sharing is turned on User properties such as App Name, Workspace Revision and Pump Type are identified once at launch. If usage data sharing was off then, they were dropped, and nothing sent them once sharing was turned on, so they stayed empty until Loop was relaunched. Keep the latest value of each property and send them all when the preference changes to Share Usage Data. --- LoopSupportKitUI/LoopKitAnalytics.swift | 26 +++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/LoopSupportKitUI/LoopKitAnalytics.swift b/LoopSupportKitUI/LoopKitAnalytics.swift index 73f39af..2a023ab 100644 --- a/LoopSupportKitUI/LoopKitAnalytics.swift +++ b/LoopSupportKitUI/LoopKitAnalytics.swift @@ -20,6 +20,8 @@ public class LoopKitAnalytics { private var client: Amplitude? + private var identifiedProperties: [String: NSObject] = [:] + public private(set) var usageDataPrivacyPreference: UsageDataPrivacyPreference? { get { return UserDefaults.standard.usageDataPrivacyPreference @@ -38,6 +40,8 @@ public class LoopKitAnalytics { } else if oldValue == .noSharing { createClient() } + + resendIdentifiedProperties() } } @@ -71,15 +75,29 @@ public class LoopKitAnalytics { } public func recordIdentify(_ property: String, value: String) { - if usageDataPrivacyPreference == .shareUsageDetailsWithDevelopers { - client?.identify(AMPIdentify().set(property, value: value as NSString)) - } + recordIdentify(property, object: value as NSString) } public func recordIdentify(_ property: String, array: [String]) { + recordIdentify(property, object: array as NSArray) + } + + private func recordIdentify(_ property: String, object: NSObject) { + identifiedProperties[property] = object if usageDataPrivacyPreference == .shareUsageDetailsWithDevelopers { - client?.identify(AMPIdentify().set(property, value: array as NSArray)) + client?.identify(AMPIdentify().set(property, value: object)) + } + } + + private func resendIdentifiedProperties() { + guard usageDataPrivacyPreference == .shareUsageDetailsWithDevelopers, let client, !identifiedProperties.isEmpty else { + return + } + let identify = AMPIdentify() + for (property, object) in identifiedProperties { + identify.set(property, value: object) } + client.identify(identify) } }