Skip to content
Merged
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
26 changes: 22 additions & 4 deletions LoopSupportKitUI/LoopKitAnalytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,6 +40,8 @@ public class LoopKitAnalytics {
} else if oldValue == .noSharing {
createClient()
}

resendIdentifiedProperties()
}
}

Expand Down Expand Up @@ -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)
}

}
Expand Down