Last active
September 24, 2024 06:29
-
-
Save zntfdr/450fb3ee35ccde3f34085269eecafb9a 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. Open the Firebase Analytics Dashboard | |
// 2. Scroll to bottom, where you see the "Users by Device model" widget | |
// 3. Click "View device models" in that widget (this opens the "Tech details" Firebase Analytics page) | |
// 4. Above the table shown in the new page, click on the “Device model” drop down menu and select “OS with Version” | |
// 5. Make sure to select “OS with version” and not “OS Version” | |
// 6. On the top right corner of the page, click on the “Share this report” icon (next to the date) | |
// 7. Click “Download file” on the new side bar, then “Download CSV" | |
// 8. Open the file and select the iOS/Android breakdown raw data | |
// 9. Replace the sample data in this script with your data | |
// 10. Run the script in a Xcode Playground or command line | |
// 11. See the terminal output | |
import Foundation | |
var data = """ | |
iOS 15.0.2,3160,890 | |
iOS 15.1,3049,814 | |
iOS 14.8,2882,574 | |
Android 11,2636,743 | |
iOS 14.8.1,1877,234 | |
Android 10,1255,280 | |
iOS 14.7.1,1155,261 | |
Android 9,459,122 | |
iOS 15.0,411,209 | |
iOS 14.6,391,92 | |
iOS 15.0.1,353,175 | |
iOS 14.4.2,147,39 | |
iOS 15.1.1,135,28 | |
""" | |
let lines = data.split { $0.isNewline } | |
var iOSDictionary: [String: Int] = [:] | |
for line in lines where line.hasPrefix("iOS"){ | |
let iOSVersion: String = String(line.split(separator: ".").first!) | |
let numberOfUsers = Int(line.split(separator: ",")[1])! | |
iOSDictionary[iOSVersion, default: 0] += numberOfUsers | |
} | |
let totalUsers: Int = iOSDictionary.values.reduce(into: 0, { $0 += $1 }) | |
for (iOSVersion, numberOfUsers) in iOSDictionary.sorted(by: >) { | |
let percent = String(format: "%.2f", Double(numberOfUsers) / Double(totalUsers) * Double(100)) | |
print("\(iOSVersion): \(percent)%") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@paulhimes nice catch 👏🏻 Gist updated, thank you!