-
-
Save Bunn/e1457fb3c275fd8f8289d660edfb23ed to your computer and use it in GitHub Desktop.
Firebase iOS Version breakdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// How to: | |
// 1. Go in the Firebase Analytics Dashboard | |
// 2. Filter iOS Platform only | |
// 3. Scroll down, select `Device` under the "What is your audience like?" widget | |
// 4. Export the CSV data (top right of the corner, there's a `...` menu with Download CSV option) | |
// 5. Open the file and select the Device model breakdown raw data | |
// 6. Replace your data with the sample data in this script | |
// 7. Run the script in a Xcode Playground | |
// 8. See the terminal output | |
// Forked from https://gist.github.com/zntfdr/450fb3ee35ccde3f34085269eecafb9a | |
import Foundation | |
var data = """ | |
iPhone 8 Plus,938 | |
iPhone,894 | |
iPhone XR,443 | |
iPhone X,253 | |
iPhone XS Max,249 | |
iPhone 8,193 | |
iPhone 7 Plus,168 | |
(not set),160 | |
iPhone XS,152 | |
iPad,131 | |
iPhone 7,123 | |
iPad Pro 12.9 2nd gen,105 | |
iPhone 6,19 | |
iPad Mini 2,17 | |
iPad Pro 12.9 inch,17 | |
iPad Air,12 | |
iPad Pro 10.5,11 | |
iPhone 6 Plus,10 | |
iPad Pro 9.7 inch,8 | |
iPad Mini 3,2 | |
""" | |
let lines = data.split { $0.isNewline } | |
let devices = ["iphone", "ipad", "ipod"] | |
let deviceDictionary = lines.reduce([String: Int]()) { (dict, line) -> [String: Int] in | |
var dict = dict | |
var deviceType = "other" | |
for device in devices { | |
if line.lowercased().contains(device) { | |
deviceType = device | |
break | |
} | |
} | |
let numberOfUsers = Int(line.split(separator: ",").last!)! | |
dict[deviceType, default: 0] += numberOfUsers | |
return dict | |
} | |
let totalUsers: Int = deviceDictionary.values.reduce(into: 0, { $0 += $1 }) | |
for (deviceType, numberOfUsers) in deviceDictionary { | |
let percent = String(format: "%.2f", Double(numberOfUsers) / Double(totalUsers) * Double(100)) | |
print("\(deviceType): \(percent)%") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result example: