Skip to content

Commit af668fb

Browse files
committed
Remove the device to friendly model name mapping
It was out of date, and a PITA to keep up to date.
1 parent 0483cc0 commit af668fb

File tree

3 files changed

+7
-201
lines changed

3 files changed

+7
-201
lines changed

Sources/AnalyticsKit/Events/AppLaunchEvent.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ public struct AppLaunchEvent: AnalyticsEvent {
99
"ios_version": self.device.osVersion,
1010
"app_version": self.app.version,
1111
"app_build": self.app.build,
12-
"device_model": self.device.device.modelCode,
13-
"device_description": self.device.device.model.rawValue,
12+
"device_model": self.device.deviceModelIdentifier,
1413
"ram_size_mb": self.device.ramSizeMB,
1514
"free_disk_space_mb": self.device.freeDiskSpaceMB,
1615
"language_code": Locale.current.language.languageCode?.identifier ?? "unknown",

Sources/AnalyticsKit/UserAndDeviceInfo/DeviceInfo.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ public struct DeviceInfo {
55
public let osVersion: String
66
public let ramSizeMB: Int
77
public let freeDiskSpaceMB: Int
8-
public let device: Platform.Device
8+
public let deviceModelIdentifier = Platform.modelIdentifier
99

1010
public init() {
1111
self.osVersion = UIDevice.current.systemVersion
1212
self.ramSizeMB = Int(Platform.deviceRAM.converted(to: .megabytes))
13-
self.device = Platform.device
1413
self.freeDiskSpaceMB = Int((UIDevice.current.freeDiskSpace() ?? 0).converted(to: .megabytes))
1514
}
1615
}

Sources/AnalyticsKit/UserAndDeviceInfo/Platform.swift

Lines changed: 5 additions & 197 deletions
Original file line numberDiff line numberDiff line change
@@ -16,209 +16,17 @@ public enum Platform {
1616
}
1717
}
1818

19-
public struct Device {
20-
public let model: Model
21-
public let modelCode: String
22-
}
23-
24-
public enum Model: String {
25-
case simulator = "simulator/sandbox",
26-
iPod1 = "iPod 1",
27-
iPod2 = "iPod 2",
28-
iPod3 = "iPod 3",
29-
iPod4 = "iPod 4",
30-
iPod5 = "iPod 5",
31-
iPod6 = "iPod 6",
32-
iPod7 = "iPod 7",
33-
iPad2 = "iPad 2",
34-
iPad3 = "iPad 3",
35-
iPad4 = "iPad 4",
36-
iPad6 = "iPad 6",
37-
iPad7 = "iPad 7",
38-
iPhone4 = "iPhone 4",
39-
iPhone4S = "iPhone 4S",
40-
iPhone5 = "iPhone 5",
41-
iPhone5S = "iPhone 5S",
42-
iPhone5C = "iPhone 5C",
43-
iPadMini1 = "iPad Mini 1",
44-
iPadMini2 = "iPad Mini 2",
45-
iPadMini3 = "iPad Mini 3",
46-
iPadMini4 = "iPad Mini 4",
47-
iPadMini5 = "iPad Mini 5",
48-
iPadAir1 = "iPad Air 1",
49-
iPadAir2 = "iPad Air 2",
50-
iPadAir2Cell = "iPad Air 2 cellular",
51-
iPadAir3 = "iPad Air 3",
52-
iPadPro97 = "iPad Pro 9.7\"",
53-
iPadPro97Cell = "iPad Pro 9.7\" cellular",
54-
iPadPro105 = "iPad Pro 10.5\"",
55-
iPadPro105Cell = "iPad Pro 10.5\" cellular",
56-
iPadPro11 = "iPad Pro 11\"",
57-
iPadPro11Cell = "iPad Pro 11\" cellular",
58-
iPadPro11Gen2 = "iPad Pro 11\" (2nd gen)",
59-
iPadPro11CellGen2 = "iPad Pro 11\" cellular (2nd gen)",
60-
iPadPro129 = "iPad Pro 12.9\"",
61-
iPadPro129Cell = "iPad Pro 12.9\" cellular",
62-
iPadPro129Gen2 = "iPad Pro 12.9\" (2nd gen)",
63-
iPadPro129CellGen2 = "iPad Pro 12.9\" cellular (2nd gen)",
64-
iPadPro129Gen3 = "iPad Pro 12.9\" (3rd gen)",
65-
iPadPro129CellGen3 = "iPad Pro 12.9\" cellular (3rd gen)",
66-
iPadPro129Gen4 = "iPad Pro 12.9\" (4th gen)",
67-
iPadPro129CellGen4 = "iPad Pro 12.9\" cellular (4th gen)",
68-
// It appears that M1 equipped Macs report as the iPad pro 12.9" 1TB 3rd gen
69-
// It also could be one of those iPads. However the 3rd gen 1TB 12.9" is a pretty rare model, that is also
70-
// no longer sold. So if we see many of these, it's likely a Mac.
71-
iPadPro129Gen3_1TbOrMacM1 = "iPad Pro 12.9-inch 1TB (3rd gen) OR Mac with M1",
72-
iPhone6 = "iPhone 6",
73-
iPhone6Plus = "iPhone 6 Plus",
74-
iPhone6S = "iPhone 6S",
75-
iPhone6SPlus = "iPhone 6S Plus",
76-
iPhoneSE = "iPhone SE",
77-
iPhoneSEGen2 = "iPhone SE (2nd gen)",
78-
iPhone7 = "iPhone 7",
79-
iPhone7Plus = "iPhone 7 Plus",
80-
iPhone8 = "iPhone 8",
81-
iPhone8Plus = "iPhone 8 Plus",
82-
iPhoneX = "iPhone X",
83-
iPhoneXs = "iPhone Xs",
84-
iPhoneXsMax = "iPhone Xs Max",
85-
iPhoneXr = "iPhone Xr",
86-
iPhone11 = "iPhone 11",
87-
iPhone11Pro = "iPhone 11 Pro",
88-
iPhone11ProMax = "iPhone 11 Pro Max",
89-
iPhone12Mini = "iPhone 12 mini",
90-
iPhone12 = "iPhone 12",
91-
iPhone12Pro = "iPhone 12 Pro",
92-
iPhone12ProMax = "iPhone 12 Pro Max",
93-
unrecognized = "Unrecognized"
94-
}
95-
96-
public static var device: Device {
19+
/// Identifier such as `iPhone4,1` to identify a specific model.
20+
public static var modelIdentifier: String = {
9721
var systemInfo = utsname()
9822
uname(&systemInfo)
9923
let machineMirror = Mirror(reflecting: systemInfo.machine)
100-
let modelCode = machineMirror.children.reduce("") { identifier, element in
24+
let modelIdentifier = machineMirror.children.reduce("") { identifier, element in
10125
guard let value = element.value as? Int8, value != 0 else { return identifier }
10226
return identifier + String(UnicodeScalar(UInt8(value)))
10327
}
104-
105-
/// Apple uses identifiers like iPhone4,1 for their devices. There are often varients of their devices that
106-
/// are either slightly different for different markets, or cell vs wifi models. The first number is the
107-
/// primary model, and the second is any small variations (wifi vs cell vs international).
108-
/// Typically we don't want to see these raw model numbers in our analytics. We also don't want our analytics
109-
/// split up by sub-model number. We primarily care about iPhone 7 vs iPhone 11 usage, so this maps those
110-
/// detailed model numbers, to a more generic identifier. We should log both the raw `modelCode` and `Model`.
111-
/// That way most of the time we can use `Model` since its higher level, but if a new model comes out,
112-
/// we will at least capture it's `modelCode` until we add it to our `Model`.
113-
let modelMap: [String: Model] = [
114-
"i386": .simulator,
115-
"x86_64": .simulator,
116-
"iPod1,1": .iPod1,
117-
"iPod2,1": .iPod2,
118-
"iPod3,1": .iPod3,
119-
"iPod4,1": .iPod4,
120-
"iPod5,1": .iPod5,
121-
"iPod7,1": .iPod6,
122-
"iPod9,1": .iPod7,
123-
"iPad2,1": .iPad2,
124-
"iPad2,2": .iPad2,
125-
"iPad2,3": .iPad2,
126-
"iPad2,4": .iPad2,
127-
"iPad2,5": .iPadMini1,
128-
"iPad2,6": .iPadMini1,
129-
"iPad2,7": .iPadMini1,
130-
"iPhone3,1": .iPhone4,
131-
"iPhone3,2": .iPhone4,
132-
"iPhone3,3": .iPhone4,
133-
"iPhone4,1": .iPhone4S,
134-
"iPhone5,1": .iPhone5,
135-
"iPhone5,2": .iPhone5,
136-
"iPhone5,3": .iPhone5C,
137-
"iPhone5,4": .iPhone5C,
138-
"iPad3,1": .iPad3,
139-
"iPad3,2": .iPad3,
140-
"iPad3,3": .iPad3,
141-
"iPad3,4": .iPad4,
142-
"iPad3,5": .iPad4,
143-
"iPad3,6": .iPad4,
144-
"iPhone6,1": .iPhone5S,
145-
"iPhone6,2": .iPhone5S,
146-
"iPad4,1": .iPadAir1,
147-
"iPad4,2": .iPadAir1,
148-
"iPad4,4": .iPadMini2,
149-
"iPad4,5": .iPadMini2,
150-
"iPad4,6": .iPadMini2,
151-
"iPad4,7": .iPadMini3,
152-
"iPad4,8": .iPadMini3,
153-
"iPad4,9": .iPadMini3,
154-
"iPad5,3": .iPadAir2,
155-
"iPad5,4": .iPadAir2Cell,
156-
"iPad5,1": .iPadMini4,
157-
"iPad5,2": .iPadMini4,
158-
"iPad6,3": .iPadPro97,
159-
"iPad6,11": .iPadPro97,
160-
"iPad6,4": .iPadPro97Cell,
161-
"iPad6,12": .iPadPro97Cell,
162-
"iPad6,7": .iPadPro129,
163-
"iPad6,8": .iPadPro129Cell,
164-
"iPad7,1": .iPadPro129Gen2,
165-
"iPad7,2": .iPadPro129CellGen2,
166-
"iPad7,3": .iPadPro105,
167-
"iPad7,4": .iPadPro105Cell,
168-
"iPad7,5": .iPad6,
169-
"iPad7,6": .iPad6,
170-
"iPad7,11": .iPad7,
171-
"iPad7,12": .iPad7,
172-
"iPad8,1": .iPadPro11,
173-
"iPad8,2": .iPadPro11,
174-
"iPad8,3": .iPadPro11Cell,
175-
"iPad8,4": .iPadPro11Cell,
176-
"iPad8,5": .iPadPro129Gen3,
177-
"iPad8,6": .iPadPro129Gen3_1TbOrMacM1,
178-
"iPad8,7": .iPadPro129CellGen3,
179-
"iPad8,8": .iPadPro129CellGen3,
180-
"iPad8,9": .iPadPro11Gen2,
181-
"iPad8,10": .iPadPro11CellGen2,
182-
"iPad8,11": .iPadPro129Gen4,
183-
"iPad8,12": .iPadPro129CellGen4,
184-
"iPad11,1": .iPadMini5,
185-
"iPad11,2": .iPadMini5,
186-
"iPad11,3": .iPadAir3,
187-
"iPad11,4": .iPadAir3,
188-
"iPhone7,1": .iPhone6Plus,
189-
"iPhone7,2": .iPhone6,
190-
"iPhone8,1": .iPhone6S,
191-
"iPhone8,2": .iPhone6SPlus,
192-
"iPhone8,4": .iPhoneSE,
193-
"iPhone9,1": .iPhone7,
194-
"iPhone9,2": .iPhone7Plus,
195-
"iPhone9,3": .iPhone7,
196-
"iPhone9,4": .iPhone7Plus,
197-
"iPhone10,1": .iPhone8,
198-
"iPhone10,2": .iPhone8Plus,
199-
"iPhone10,3": .iPhoneX,
200-
"iPhone10,4": .iPhone8,
201-
"iPhone10,5": .iPhone8Plus,
202-
"iPhone10,6": .iPhoneX,
203-
"iPhone11,2": .iPhoneXs,
204-
"iPhone11,4": .iPhoneXsMax,
205-
"iPhone11,6": .iPhoneXsMax,
206-
"iPhone11,8": .iPhoneXr,
207-
"iPhone12,1": .iPhone11,
208-
"iPhone12,3": .iPhone11Pro,
209-
"iPhone12,5": .iPhone11ProMax,
210-
"iPhone12,8": .iPhoneSEGen2,
211-
"iPhone13,1": .iPhone12Mini,
212-
"iPhone13,2": .iPhone12,
213-
"iPhone13,3": .iPhone12Pro,
214-
"iPhone13,4": .iPhone12ProMax
215-
]
216-
217-
if let model = modelMap[modelCode] {
218-
return Device(model: model, modelCode: modelCode)
219-
}
220-
return Device(model: .unrecognized, modelCode: modelCode)
221-
}
28+
return modelIdentifier
29+
}()
22230

22331
/// How much total RAM does this device have.
22432
public static var deviceRAM: Bytes = {

0 commit comments

Comments
 (0)